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