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