use super::Address;
use super::CheckpointTimestamp;
use super::ConsensusCommitDigest;
use super::EpochId;
use super::GenesisObject;
use super::Identifier;
use super::Jwk;
use super::JwkId;
use super::ObjectId;
use super::ObjectReference;
use super::ProtocolVersion;
use super::TransactionDigest;
use super::TypeTag;
use super::UserSignature;
use super::Version;
#[cfg(feature = "serde")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
mod serialization;
#[cfg(feature = "serde")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
pub(crate) use serialization::SignedTransactionWithIntentMessage;
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Transaction {
pub kind: TransactionKind,
pub sender: Address,
pub gas_payment: GasPayment,
pub expiration: TransactionExpiration,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct SignedTransaction {
pub transaction: Transaction,
pub signatures: Vec<UserSignature>,
}
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub enum TransactionExpiration {
#[default]
None,
Epoch(EpochId),
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct GasPayment {
pub objects: Vec<ObjectReference>,
pub owner: Address,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub price: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub budget: u64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct RandomnessStateUpdate {
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub epoch: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub randomness_round: u64,
#[cfg_attr(
feature = "serde",
serde(with = "crate::_serde::ReadableBase64Encoded")
)]
pub random_bytes: Vec<u8>,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub randomness_obj_initial_shared_version: u64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub enum TransactionKind {
ProgrammableTransaction(ProgrammableTransaction),
ChangeEpoch(ChangeEpoch),
Genesis(GenesisTransaction),
ConsensusCommitPrologue(ConsensusCommitPrologue),
AuthenticatorStateUpdate(AuthenticatorStateUpdate),
EndOfEpoch(Vec<EndOfEpochTransactionKind>),
RandomnessStateUpdate(RandomnessStateUpdate),
ConsensusCommitPrologueV2(ConsensusCommitPrologueV2),
ConsensusCommitPrologueV3(ConsensusCommitPrologueV3),
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub enum EndOfEpochTransactionKind {
ChangeEpoch(ChangeEpoch),
AuthenticatorStateCreate,
AuthenticatorStateExpire(AuthenticatorStateExpire),
RandomnessStateCreate,
DenyListStateCreate,
BridgeStateCreate { chain_id: super::CheckpointDigest },
BridgeCommitteeInit { bridge_object_version: u64 },
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct AuthenticatorStateExpire {
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub min_epoch: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub authenticator_object_initial_shared_version: u64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct AuthenticatorStateUpdate {
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub epoch: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub round: u64,
pub new_active_jwks: Vec<ActiveJwk>,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub authenticator_obj_initial_shared_version: u64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct ActiveJwk {
pub jwk_id: JwkId,
pub jwk: Jwk,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub epoch: u64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct ConsensusCommitPrologue {
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub epoch: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub round: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub commit_timestamp_ms: CheckpointTimestamp,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct ConsensusCommitPrologueV2 {
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub epoch: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub round: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub commit_timestamp_ms: CheckpointTimestamp,
pub consensus_commit_digest: ConsensusCommitDigest,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub enum ConsensusDeterminedVersionAssignments {
CancelledTransactions {
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
cancelled_transactions: Vec<CancelledTransaction>,
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct CancelledTransaction {
pub digest: TransactionDigest,
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub version_assignments: Vec<VersionAssignment>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct VersionAssignment {
pub object_id: ObjectId,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub version: Version,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct ConsensusCommitPrologueV3 {
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub epoch: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub round: u64,
#[cfg_attr(
feature = "serde",
serde(with = "crate::_serde::OptionReadableDisplay")
)]
pub sub_dag_index: Option<u64>,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub commit_timestamp_ms: CheckpointTimestamp,
pub consensus_commit_digest: ConsensusCommitDigest,
pub consensus_determined_version_assignments: ConsensusDeterminedVersionAssignments,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct ChangeEpoch {
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub epoch: EpochId,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub protocol_version: ProtocolVersion,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub storage_charge: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub computation_charge: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub storage_rebate: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub non_refundable_storage_fee: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub epoch_start_timestamp_ms: u64,
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub system_packages: Vec<SystemPackage>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct SystemPackage {
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
pub version: Version,
#[cfg_attr(
feature = "serde",
serde(
with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
)
)]
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub modules: Vec<Vec<u8>>,
pub dependencies: Vec<ObjectId>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct GenesisTransaction {
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub objects: Vec<GenesisObject>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct ProgrammableTransaction {
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=10).lift()))]
pub inputs: Vec<Input>,
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=10).lift()))]
pub commands: Vec<Command>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub enum Input {
Pure {
value: Vec<u8>,
},
ImmutableOrOwned(ObjectReference),
Shared {
object_id: ObjectId,
initial_shared_version: u64,
mutable: bool,
},
Receiving(ObjectReference),
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub enum Command {
MoveCall(MoveCall),
TransferObjects(TransferObjects),
SplitCoins(SplitCoins),
MergeCoins(MergeCoins),
Publish(Publish),
MakeMoveVector(MakeMoveVector),
Upgrade(Upgrade),
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct TransferObjects {
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub objects: Vec<Argument>,
pub address: Argument,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct SplitCoins {
pub coin: Argument,
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub amounts: Vec<Argument>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct MergeCoins {
pub coin: Argument,
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub coins_to_merge: Vec<Argument>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Publish {
#[cfg_attr(
feature = "serde",
serde(
with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
)
)]
pub modules: Vec<Vec<u8>>,
pub dependencies: Vec<ObjectId>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct MakeMoveVector {
#[cfg_attr(feature = "serde", serde(rename = "type"))]
pub type_: Option<TypeTag>,
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub elements: Vec<Argument>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Upgrade {
#[cfg_attr(
feature = "serde",
serde(
with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
)
)]
pub modules: Vec<Vec<u8>>,
pub dependencies: Vec<ObjectId>,
pub package: ObjectId,
pub ticket: Argument,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub enum Argument {
Gas,
Input(u16),
Result(u16),
NestedResult(u16, u16),
}
impl Argument {
pub fn nested(&self, ix: u16) -> Option<Argument> {
match self {
Argument::Result(i) => Some(Argument::NestedResult(*i, ix)),
_ => None,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct MoveCall {
pub package: ObjectId,
pub module: Identifier,
pub function: Identifier,
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub type_arguments: Vec<TypeTag>,
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub arguments: Vec<Argument>,
}