Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: remove TransactionEffectsV1 and rename V2 to V1 #12

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AAADAAAAAAAAAEBCDwAAAAAAgE08AAAAAADAJh4AAAAAAAAAAAAAAAAAIOrjkZAn7XCCmrYeV5FY1h8Qwc2PmKwuvMs/dTkbKtmTAQAAAAAAAiCWPACmeHYzWNdw8Ug2nmoZwl7EmkW8V+oxKTWVbwg5yiCo7vWKhdFVfDBrhPNL/dm8lEUakRX2mo7pCM88f1cyXgMAAAAAAAAABA0rm7unaqByv19SmTZUrEy3iuEr8ukanp4FrDMN6EfZAQIAAAAAAAAAIJWu62cTMqk+i1lFBl0iun+3KOQw7XAgDK+RqZSzaqt7AJk4yU9BGBU7vtCPFK504lVxclQvWb8LejBumdWgsIluASAlJdo1uqyLc5uH9KnW75V5bwhf33YlKxtSVdDDdKXm3gCZOMlPQRgVO77QjxSudOJVcXJUL1m/C3owbpnVoLCJbgA1pUMbk/MztWrX2Wa7iRXtR4ecZX8BcbvXc5MqIUEsbAECAAAAAAAAACAknN02wZZXy0Vt2HVbsGCwEfdCPTkhkY6rbsZe6CSglAC3nqEtCu8+wgTryseqZkghMId1VZVPgf5oS762Sf9SOwEg0jgoqZhslHjFBmrZYP3c48gRPyGLWitsZ4gjk4yV4i4At56hLQrvPsIE68rHqmZIITCHdVWVT4H+aEu+tkn/UjsATTNeZ5wwmp9/+V0eh+RjzaMQhicyggV0NkUuGpSA2WMAASAjU2eF/7mEyaUbPMsXC77uMKQoXswLmwwxXwDfX/6fwAARERERFQTpNQ5jXWXNOMzSwClDTGo6SA2JR6m6ahWyFQHFTwjk5nvh3VJK+l8LTEI2uQdL1pdHUqJEocE6eeRZ5wABIDemFa4c2TycELxsMrtzDbLu2v5NV0U8Ut+xAuiwFAntAKGpfSC7rXnirInyFaOzxPL/mhqjzCblKb3m57xVANYQAQAA
25 changes: 6 additions & 19 deletions crates/iota-rust-sdk/src/types/effects/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod v1;
mod v2;

pub use v1::{ModifiedAtVersion, ObjectReferenceWithOwner, TransactionEffectsV1};
pub use v2::{
ChangedObject, EffectsObjectChange, IdOperation, ObjectIn, ObjectOut, TransactionEffectsV2,
pub use v1::{
ChangedObject, EffectsObjectChange, IdOperation, ObjectIn, ObjectOut, TransactionEffectsV1,
UnchangedSharedKind, UnchangedSharedObject,
};

Expand All @@ -18,45 +16,37 @@ pub use v2::{
pub enum TransactionEffects {
#[cfg_attr(feature = "schemars", schemars(rename = "1"))]
V1(Box<TransactionEffectsV1>),
#[cfg_attr(feature = "schemars", schemars(rename = "2"))]
V2(Box<TransactionEffectsV2>),
}

#[cfg(feature = "serde")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
mod serialization {
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use super::{TransactionEffects, TransactionEffectsV1, TransactionEffectsV2};
use super::{TransactionEffects, TransactionEffectsV1};

#[derive(serde_derive::Serialize)]
#[serde(tag = "version")]
enum ReadableEffectsRef<'a> {
#[serde(rename = "1")]
V1(&'a TransactionEffectsV1),
#[serde(rename = "2")]
V2(&'a TransactionEffectsV2),
}

#[derive(serde_derive::Deserialize)]
#[serde(tag = "version")]
pub enum ReadableEffects {
#[serde(rename = "1")]
V1(Box<TransactionEffectsV1>),
#[serde(rename = "2")]
V2(Box<TransactionEffectsV2>),
}

#[derive(serde_derive::Serialize)]
enum BinaryEffectsRef<'a> {
V1(&'a TransactionEffectsV1),
V2(&'a TransactionEffectsV2),
}

#[derive(serde_derive::Deserialize)]
pub enum BinaryEffects {
V1(Box<TransactionEffectsV1>),
V2(Box<TransactionEffectsV2>),
}

impl Serialize for TransactionEffects {
Expand All @@ -67,13 +57,11 @@ mod serialization {
if serializer.is_human_readable() {
let readable = match self {
TransactionEffects::V1(fx) => ReadableEffectsRef::V1(fx),
TransactionEffects::V2(fx) => ReadableEffectsRef::V2(fx),
};
readable.serialize(serializer)
} else {
let binary = match self {
TransactionEffects::V1(fx) => BinaryEffectsRef::V1(fx),
TransactionEffects::V2(fx) => BinaryEffectsRef::V2(fx),
};
binary.serialize(serializer)
}
Expand All @@ -88,12 +76,10 @@ mod serialization {
if deserializer.is_human_readable() {
ReadableEffects::deserialize(deserializer).map(|readable| match readable {
ReadableEffects::V1(fx) => Self::V1(fx),
ReadableEffects::V2(fx) => Self::V2(fx),
})
} else {
BinaryEffects::deserialize(deserializer).map(|binary| match binary {
BinaryEffects::V1(fx) => Self::V1(fx),
BinaryEffects::V2(fx) => Self::V2(fx),
})
}
}
Expand All @@ -109,10 +95,11 @@ mod serialization {

#[test]
fn effects_fixtures() {
// The files contain the bas64 encoded raw effects of transactions
const GENESIS_EFFECTS: &str = include_str!("fixtures/genesis-transaction-effects");
const PYTH_WORMHOLE_V2: &str = include_str!("fixtures/pyth-wormhole-v2");
const SPONSOR_TX_EFFECTS: &str = include_str!("fixtures/sponsor-tx-effects");

for fixture in [GENESIS_EFFECTS, PYTH_WORMHOLE_V2] {
for fixture in [GENESIS_EFFECTS, SPONSOR_TX_EFFECTS] {
let fixture = Base64::decode_vec(fixture.trim()).unwrap();
let fx: TransactionEffects = bcs::from_bytes(&fixture).unwrap();
assert_eq!(bcs::to_bytes(&fx).unwrap(), fixture);
Expand Down
Loading