sui_sdk_types/effects/
mod.rs

1mod v1;
2mod v2;
3
4pub use v1::ModifiedAtVersion;
5pub use v1::ObjectReferenceWithOwner;
6pub use v1::TransactionEffectsV1;
7pub use v2::AccumulatorOperation;
8pub use v2::AccumulatorValue;
9pub use v2::AccumulatorWrite;
10pub use v2::ChangedObject;
11pub use v2::IdOperation;
12pub use v2::ObjectIn;
13pub use v2::ObjectOut;
14pub use v2::TransactionEffectsV2;
15pub use v2::UnchangedConsensusKind;
16pub use v2::UnchangedConsensusObject;
17
18use crate::execution_status::ExecutionStatus;
19
20/// The output or effects of executing a transaction
21///
22/// # BCS
23///
24/// The BCS serialized form for this type is defined by the following ABNF:
25///
26/// ```text
27/// transaction-effects =  %x00 effects-v1
28///                     =/ %x01 effects-v2
29/// ```
30#[derive(Eq, PartialEq, Clone, Debug)]
31#[cfg_attr(
32    feature = "serde",
33    derive(serde_derive::Serialize, serde_derive::Deserialize)
34)]
35#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
36pub enum TransactionEffects {
37    V1(Box<TransactionEffectsV1>),
38    V2(Box<TransactionEffectsV2>),
39}
40
41impl TransactionEffects {
42    /// Return the status of the transaction.
43    pub fn status(&self) -> &ExecutionStatus {
44        match self {
45            TransactionEffects::V1(e) => e.status(),
46            TransactionEffects::V2(e) => e.status(),
47        }
48    }
49
50    /// Return the epoch in which this transaction was executed.
51    pub fn epoch(&self) -> u64 {
52        match self {
53            TransactionEffects::V1(e) => e.epoch(),
54            TransactionEffects::V2(e) => e.epoch(),
55        }
56    }
57
58    /// Return the gas cost summary of the transaction.
59    pub fn gas_summary(&self) -> &crate::gas::GasCostSummary {
60        match self {
61            TransactionEffects::V1(e) => e.gas_summary(),
62            TransactionEffects::V2(e) => e.gas_summary(),
63        }
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::TransactionEffects;
70
71    use base64ct::Base64;
72    use base64ct::Encoding;
73
74    #[cfg(target_arch = "wasm32")]
75    use wasm_bindgen_test::wasm_bindgen_test as test;
76
77    #[test]
78    fn effects_fixtures() {
79        const GENESIS_EFFECTS: &str = include_str!("fixtures/genesis-transaction-effects");
80        const PYTH_WORMHOLE_V2: &str = include_str!("fixtures/pyth-wormhole-v2");
81
82        for fixture in [GENESIS_EFFECTS, PYTH_WORMHOLE_V2] {
83            let fixture = Base64::decode_vec(fixture.trim()).unwrap();
84            let fx: TransactionEffects = bcs::from_bytes(&fixture).unwrap();
85            assert_eq!(bcs::to_bytes(&fx).unwrap(), fixture);
86
87            let json = serde_json::to_string_pretty(&fx).unwrap();
88            println!("{json}");
89            assert_eq!(fx, serde_json::from_str(&json).unwrap());
90        }
91    }
92}