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

chore(types): cleaned up removed and renamed transaction types #5

Merged
merged 1 commit into from
Oct 18, 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
14 changes: 7 additions & 7 deletions crates/iota-rust-sdk/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ pub use object_id::ObjectId;
pub(crate) use transaction::SignedTransactionWithIntentMessage;
pub use transaction::{
ActiveJwk, Argument, AuthenticatorStateExpire, AuthenticatorStateUpdate, CancelledTransaction,
ChangeEpoch, Command, ConsensusCommitPrologue, ConsensusCommitPrologueV2,
ConsensusCommitPrologueV3, ConsensusDeterminedVersionAssignments, EndOfEpochTransactionKind,
GasPayment, GenesisTransaction, InputArgument, MakeMoveVector, MergeCoins, MoveCall,
ProgrammableTransaction, Publish, RandomnessStateUpdate, SignedTransaction, SplitCoins,
SystemPackage, Transaction, TransactionExpiration, TransactionKind, TransferObjects,
UnresolvedGasPayment, UnresolvedInputArgument, UnresolvedObjectReference,
UnresolvedProgrammableTransaction, UnresolvedTransaction, Upgrade, VersionAssignment,
ChangeEpoch, Command, ConsensusCommitPrologueV1, ConsensusDeterminedVersionAssignments,
EndOfEpochTransactionKind, GasPayment, GenesisTransaction, InputArgument, MakeMoveVector,
MergeCoins, MoveCall, ProgrammableTransaction, Publish, RandomnessStateUpdate,
SignedTransaction, SplitCoins, SystemPackage, Transaction, TransactionExpiration,
TransactionKind, TransferObjects, UnresolvedGasPayment, UnresolvedInputArgument,
UnresolvedObjectReference, UnresolvedProgrammableTransaction, UnresolvedTransaction, Upgrade,
VersionAssignment,
};
pub use type_tag::{Identifier, StructTag, TypeParseError, TypeTag};

Expand Down
4 changes: 1 addition & 3 deletions crates/iota-rust-sdk/src/types/serialization_proptests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ serialization_test!(AuthenticatorStateExpire);
serialization_test!(AuthenticatorStateUpdate);
serialization_test!(ChangeEpoch);
serialization_test!(Command);
serialization_test!(ConsensusCommitPrologue);
serialization_test!(ConsensusCommitPrologueV2);
serialization_test!(ConsensusCommitPrologueV3);
serialization_test!(ConsensusCommitPrologueV1);
serialization_test!(CancelledTransaction);
serialization_test!(ConsensusDeterminedVersionAssignments);
serialization_test!(VersionAssignment);
Expand Down
62 changes: 2 additions & 60 deletions crates/iota-rust-sdk/src/types/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,15 @@ pub enum TransactionKind {
/// It also doesn't require/use a gas object.
/// A validator will not sign a transaction of this kind from outside. It
/// only signs internally during epoch changes.
///
/// The ChangeEpoch enumerant is now deprecated (but the ChangeEpoch struct
/// is still used by EndOfEpochTransaction below).
ChangeEpoch(ChangeEpoch),
Genesis(GenesisTransaction),
ConsensusCommitPrologue(ConsensusCommitPrologue),
ConsensusCommitPrologueV1(ConsensusCommitPrologueV1),
AuthenticatorStateUpdate(AuthenticatorStateUpdate),

/// EndOfEpochTransaction replaces ChangeEpoch with a list of transactions
/// that are allowed to run at the end of the epoch.
EndOfEpoch(Vec<EndOfEpochTransactionKind>),

RandomnessStateUpdate(RandomnessStateUpdate),
// V2 ConsensusCommitPrologue also includes the digest of the current consensus output.
ConsensusCommitPrologueV2(ConsensusCommitPrologueV2),

ConsensusCommitPrologueV3(ConsensusCommitPrologueV3),
// .. more transaction types go here
}

Expand All @@ -143,7 +135,6 @@ pub enum EndOfEpochTransactionKind {
ChangeEpoch(ChangeEpoch),
AuthenticatorStateCreate,
AuthenticatorStateExpire(AuthenticatorStateExpire),
RandomnessStateCreate,
DenyListStateCreate,
BridgeStateCreate {
chain_id: super::CheckpointDigest,
Expand Down Expand Up @@ -214,55 +205,6 @@ pub struct ActiveJwk {
pub epoch: u64,
}

/// Only commit_timestamp_ms is passed to the move call currently.
/// However we include epoch and round to make sure each ConsensusCommitPrologue
/// has a unique tx digest.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub struct ConsensusCommitPrologue {
/// Epoch of the commit prologue transaction
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub epoch: u64,
/// Consensus round of the commit
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub round: u64,
/// Unix timestamp from consensus
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub commit_timestamp_ms: CheckpointTimestamp,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub struct ConsensusCommitPrologueV2 {
/// Epoch of the commit prologue transaction
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub epoch: u64,
/// Consensus round of the commit
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub round: u64,
/// Unix timestamp from consensus
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub commit_timestamp_ms: CheckpointTimestamp,
/// Digest of consensus output
pub consensus_commit_digest: ConsensusCommitDigest,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "schemars",
Expand Down Expand Up @@ -312,7 +254,7 @@ pub struct VersionAssignment {
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub struct ConsensusCommitPrologueV3 {
pub struct ConsensusCommitPrologueV1 {
/// Epoch of the commit prologue transaction
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
Expand Down
86 changes: 15 additions & 71 deletions crates/iota-rust-sdk/src/types/transaction/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,21 @@ mod transaction {
mod transaction_kind {
use super::*;
use crate::types::transaction::{
AuthenticatorStateUpdate, ChangeEpoch, ConsensusCommitPrologue, ConsensusCommitPrologueV2,
ConsensusCommitPrologueV3, EndOfEpochTransactionKind, GenesisTransaction,
ProgrammableTransaction, RandomnessStateUpdate, TransactionKind,
AuthenticatorStateUpdate, ConsensusCommitPrologueV1, EndOfEpochTransactionKind,
GenesisTransaction, ProgrammableTransaction, RandomnessStateUpdate, TransactionKind,
};

#[derive(serde_derive::Serialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
enum ReadableTransactionKindRef<'a> {
ProgrammableTransaction(&'a ProgrammableTransaction),
ChangeEpoch(&'a ChangeEpoch),
Genesis(&'a GenesisTransaction),
ConsensusCommitPrologue(&'a ConsensusCommitPrologue),
ConsensusCommitPrologueV1(&'a ConsensusCommitPrologueV1),
AuthenticatorStateUpdate(&'a AuthenticatorStateUpdate),
EndOfEpoch {
commands: &'a Vec<EndOfEpochTransactionKind>,
},
RandomnessStateUpdate(&'a RandomnessStateUpdate),
ConsensusCommitPrologueV2(&'a ConsensusCommitPrologueV2),
ConsensusCommitPrologueV3(&'a ConsensusCommitPrologueV3),
}

#[derive(serde_derive::Deserialize)]
Expand All @@ -151,16 +147,13 @@ mod transaction_kind {
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
enum ReadableTransactionKind {
ProgrammableTransaction(ProgrammableTransaction),
ChangeEpoch(ChangeEpoch),
Genesis(GenesisTransaction),
ConsensusCommitPrologue(ConsensusCommitPrologue),
ConsensusCommitPrologueV1(ConsensusCommitPrologueV1),
AuthenticatorStateUpdate(AuthenticatorStateUpdate),
EndOfEpoch {
commands: Vec<EndOfEpochTransactionKind>,
},
RandomnessStateUpdate(RandomnessStateUpdate),
ConsensusCommitPrologueV2(ConsensusCommitPrologueV2),
ConsensusCommitPrologueV3(ConsensusCommitPrologueV3),
}

#[cfg(feature = "schemars")]
Expand All @@ -177,26 +170,20 @@ mod transaction_kind {
#[derive(serde_derive::Serialize)]
enum BinaryTransactionKindRef<'a> {
ProgrammableTransaction(&'a ProgrammableTransaction),
ChangeEpoch(&'a ChangeEpoch),
Genesis(&'a GenesisTransaction),
ConsensusCommitPrologue(&'a ConsensusCommitPrologue),
ConsensusCommitPrologueV1(&'a ConsensusCommitPrologueV1),
AuthenticatorStateUpdate(&'a AuthenticatorStateUpdate),
EndOfEpoch(&'a Vec<EndOfEpochTransactionKind>),
RandomnessStateUpdate(&'a RandomnessStateUpdate),
ConsensusCommitPrologueV2(&'a ConsensusCommitPrologueV2),
ConsensusCommitPrologueV3(&'a ConsensusCommitPrologueV3),
}
#[derive(serde_derive::Deserialize)]
enum BinaryTransactionKind {
ProgrammableTransaction(ProgrammableTransaction),
ChangeEpoch(ChangeEpoch),
Genesis(GenesisTransaction),
ConsensusCommitPrologue(ConsensusCommitPrologue),
ConsensusCommitPrologueV1(ConsensusCommitPrologueV1),
AuthenticatorStateUpdate(AuthenticatorStateUpdate),
EndOfEpoch(Vec<EndOfEpochTransactionKind>),
RandomnessStateUpdate(RandomnessStateUpdate),
ConsensusCommitPrologueV2(ConsensusCommitPrologueV2),
ConsensusCommitPrologueV3(ConsensusCommitPrologueV3),
}

impl Serialize for TransactionKind {
Expand All @@ -209,10 +196,9 @@ mod transaction_kind {
Self::ProgrammableTransaction(k) => {
ReadableTransactionKindRef::ProgrammableTransaction(k)
}
Self::ChangeEpoch(k) => ReadableTransactionKindRef::ChangeEpoch(k),
Self::Genesis(k) => ReadableTransactionKindRef::Genesis(k),
Self::ConsensusCommitPrologue(k) => {
ReadableTransactionKindRef::ConsensusCommitPrologue(k)
Self::ConsensusCommitPrologueV1(k) => {
ReadableTransactionKindRef::ConsensusCommitPrologueV1(k)
}
Self::AuthenticatorStateUpdate(k) => {
ReadableTransactionKindRef::AuthenticatorStateUpdate(k)
Expand All @@ -223,23 +209,16 @@ mod transaction_kind {
Self::RandomnessStateUpdate(k) => {
ReadableTransactionKindRef::RandomnessStateUpdate(k)
}
Self::ConsensusCommitPrologueV2(k) => {
ReadableTransactionKindRef::ConsensusCommitPrologueV2(k)
}
Self::ConsensusCommitPrologueV3(k) => {
ReadableTransactionKindRef::ConsensusCommitPrologueV3(k)
}
};
readable.serialize(serializer)
} else {
let binary = match self {
Self::ProgrammableTransaction(k) => {
BinaryTransactionKindRef::ProgrammableTransaction(k)
}
Self::ChangeEpoch(k) => BinaryTransactionKindRef::ChangeEpoch(k),
Self::Genesis(k) => BinaryTransactionKindRef::Genesis(k),
Self::ConsensusCommitPrologue(k) => {
BinaryTransactionKindRef::ConsensusCommitPrologue(k)
Self::ConsensusCommitPrologueV1(k) => {
BinaryTransactionKindRef::ConsensusCommitPrologueV1(k)
}
Self::AuthenticatorStateUpdate(k) => {
BinaryTransactionKindRef::AuthenticatorStateUpdate(k)
Expand All @@ -248,12 +227,6 @@ mod transaction_kind {
Self::RandomnessStateUpdate(k) => {
BinaryTransactionKindRef::RandomnessStateUpdate(k)
}
Self::ConsensusCommitPrologueV2(k) => {
BinaryTransactionKindRef::ConsensusCommitPrologueV2(k)
}
Self::ConsensusCommitPrologueV3(k) => {
BinaryTransactionKindRef::ConsensusCommitPrologueV3(k)
}
};
binary.serialize(serializer)
}
Expand All @@ -270,10 +243,9 @@ mod transaction_kind {
ReadableTransactionKind::ProgrammableTransaction(k) => {
Self::ProgrammableTransaction(k)
}
ReadableTransactionKind::ChangeEpoch(k) => Self::ChangeEpoch(k),
ReadableTransactionKind::Genesis(k) => Self::Genesis(k),
ReadableTransactionKind::ConsensusCommitPrologue(k) => {
Self::ConsensusCommitPrologue(k)
ReadableTransactionKind::ConsensusCommitPrologueV1(k) => {
Self::ConsensusCommitPrologueV1(k)
}
ReadableTransactionKind::AuthenticatorStateUpdate(k) => {
Self::AuthenticatorStateUpdate(k)
Expand All @@ -282,22 +254,15 @@ mod transaction_kind {
ReadableTransactionKind::RandomnessStateUpdate(k) => {
Self::RandomnessStateUpdate(k)
}
ReadableTransactionKind::ConsensusCommitPrologueV2(k) => {
Self::ConsensusCommitPrologueV2(k)
}
ReadableTransactionKind::ConsensusCommitPrologueV3(k) => {
Self::ConsensusCommitPrologueV3(k)
}
})
} else {
BinaryTransactionKind::deserialize(deserializer).map(|binary| match binary {
BinaryTransactionKind::ProgrammableTransaction(k) => {
Self::ProgrammableTransaction(k)
}
BinaryTransactionKind::ChangeEpoch(k) => Self::ChangeEpoch(k),
BinaryTransactionKind::Genesis(k) => Self::Genesis(k),
BinaryTransactionKind::ConsensusCommitPrologue(k) => {
Self::ConsensusCommitPrologue(k)
BinaryTransactionKind::ConsensusCommitPrologueV1(k) => {
Self::ConsensusCommitPrologueV1(k)
}
BinaryTransactionKind::AuthenticatorStateUpdate(k) => {
Self::AuthenticatorStateUpdate(k)
Expand All @@ -306,12 +271,6 @@ mod transaction_kind {
BinaryTransactionKind::RandomnessStateUpdate(k) => {
Self::RandomnessStateUpdate(k)
}
BinaryTransactionKind::ConsensusCommitPrologueV2(k) => {
Self::ConsensusCommitPrologueV2(k)
}
BinaryTransactionKind::ConsensusCommitPrologueV3(k) => {
Self::ConsensusCommitPrologueV3(k)
}
})
}
}
Expand All @@ -331,7 +290,6 @@ mod end_of_epoch {
ChangeEpoch(&'a ChangeEpoch),
AuthenticatorStateCreate,
AuthenticatorStateExpire(&'a AuthenticatorStateExpire),
RandomnessStateCreate,
DenyListStateCreate,
BridgeStateCreate {
chain_id: &'a CheckpointDigest,
Expand All @@ -348,7 +306,6 @@ mod end_of_epoch {
ChangeEpoch(ChangeEpoch),
AuthenticatorStateCreate,
AuthenticatorStateExpire(AuthenticatorStateExpire),
RandomnessStateCreate,
DenyListStateCreate,
BridgeStateCreate {
chain_id: CheckpointDigest,
Expand All @@ -364,7 +321,6 @@ mod end_of_epoch {
ChangeEpoch(&'a ChangeEpoch),
AuthenticatorStateCreate,
AuthenticatorStateExpire(&'a AuthenticatorStateExpire),
RandomnessStateCreate,
DenyListStateCreate,
BridgeStateCreate { chain_id: &'a CheckpointDigest },
BridgeCommitteeInit { bridge_object_version: u64 },
Expand All @@ -375,7 +331,6 @@ mod end_of_epoch {
ChangeEpoch(ChangeEpoch),
AuthenticatorStateCreate,
AuthenticatorStateExpire(AuthenticatorStateExpire),
RandomnessStateCreate,
DenyListStateCreate,
BridgeStateCreate { chain_id: CheckpointDigest },
BridgeCommitteeInit { bridge_object_version: u64 },
Expand All @@ -395,9 +350,6 @@ mod end_of_epoch {
Self::AuthenticatorStateExpire(k) => {
ReadableEndOfEpochTransactionKindRef::AuthenticatorStateExpire(k)
}
Self::RandomnessStateCreate => {
ReadableEndOfEpochTransactionKindRef::RandomnessStateCreate
}
Self::DenyListStateCreate => {
ReadableEndOfEpochTransactionKindRef::DenyListStateCreate
}
Expand All @@ -420,9 +372,6 @@ mod end_of_epoch {
Self::AuthenticatorStateExpire(k) => {
BinaryEndOfEpochTransactionKindRef::AuthenticatorStateExpire(k)
}
Self::RandomnessStateCreate => {
BinaryEndOfEpochTransactionKindRef::RandomnessStateCreate
}
Self::DenyListStateCreate => {
BinaryEndOfEpochTransactionKindRef::DenyListStateCreate
}
Expand Down Expand Up @@ -455,9 +404,6 @@ mod end_of_epoch {
ReadableEndOfEpochTransactionKind::AuthenticatorStateExpire(k) => {
Self::AuthenticatorStateExpire(k)
}
ReadableEndOfEpochTransactionKind::RandomnessStateCreate => {
Self::RandomnessStateCreate
}
ReadableEndOfEpochTransactionKind::DenyListStateCreate => {
Self::DenyListStateCreate
}
Expand All @@ -481,9 +427,6 @@ mod end_of_epoch {
BinaryEndOfEpochTransactionKind::AuthenticatorStateExpire(k) => {
Self::AuthenticatorStateExpire(k)
}
BinaryEndOfEpochTransactionKind::RandomnessStateCreate => {
Self::RandomnessStateCreate
}
BinaryEndOfEpochTransactionKind::DenyListStateCreate => {
Self::DenyListStateCreate
}
Expand Down Expand Up @@ -1325,6 +1268,7 @@ mod test {
}

#[test]
#[ignore = "https://github.com/iotaledger/iota/issues/3475"]
fn transaction_fixtures() {
const GENESIS_TRANSACTION: &str = include_str!("fixtures/genesis-transaction");
const CONSENSUS_PROLOGUE: &str = "AAMAAAAAAAAAAAIAAAAAAAAAtkjHeocBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAA==";
Expand Down