86 lines
2.6 KiB
Rust
86 lines
2.6 KiB
Rust
// file: crates/ksp-interface-lib/src/transaction_execution.rs
|
|
// version: 1
|
|
|
|
/// Canonical 64-byte Solana transaction signature used by passive Interface events.
|
|
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
pub struct TransactionSignature([u8; 64]);
|
|
|
|
impl TransactionSignature {
|
|
/// Creates one transaction signature from already-decoded canonical bytes.
|
|
#[must_use]
|
|
pub const fn new(bytes: [u8; 64]) -> Self {
|
|
return Self(bytes);
|
|
}
|
|
|
|
/// Returns the exact canonical signature bytes.
|
|
#[must_use]
|
|
pub const fn as_bytes(&self) -> &[u8; 64] {
|
|
return &self.0;
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Debug for TransactionSignature {
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
return formatter.write_str("TransactionSignature(..)");
|
|
}
|
|
}
|
|
|
|
/// Provider-neutral outcome of one observed transaction execution.
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
#[non_exhaustive]
|
|
pub enum TransactionExecutionOutcome {
|
|
/// The observed transaction execution completed without a transaction error.
|
|
Succeeded,
|
|
/// The observed transaction execution completed with a transaction error.
|
|
Failed,
|
|
}
|
|
|
|
/// Passive provider-neutral observation of one transaction execution result.
|
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
|
pub struct TransactionExecutionEvent {
|
|
slot: u64,
|
|
signature: TransactionSignature,
|
|
outcome: TransactionExecutionOutcome,
|
|
}
|
|
|
|
impl TransactionExecutionEvent {
|
|
/// Creates one transaction execution event from its common provider-neutral fields.
|
|
#[must_use]
|
|
pub const fn new(slot: u64, signature: TransactionSignature, outcome: TransactionExecutionOutcome) -> Self {
|
|
return Self { slot, signature, outcome };
|
|
}
|
|
|
|
/// Returns the containing slot exactly as observed by the producer.
|
|
#[must_use]
|
|
pub const fn slot(&self) -> u64 {
|
|
return self.slot;
|
|
}
|
|
|
|
/// Returns the canonical transaction signature.
|
|
#[must_use]
|
|
pub const fn signature(&self) -> TransactionSignature {
|
|
return self.signature;
|
|
}
|
|
|
|
/// Returns the normalized execution outcome.
|
|
#[must_use]
|
|
pub const fn outcome(&self) -> TransactionExecutionOutcome {
|
|
return self.outcome;
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Debug for TransactionExecutionEvent {
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
return formatter
|
|
.debug_struct("TransactionExecutionEvent")
|
|
.field("slot", &self.slot)
|
|
.field("signature", &"<omitted>")
|
|
.field("outcome", &self.outcome)
|
|
.finish();
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "../unit_tests/transaction_execution.rs"]
|
|
mod tests;
|