1use std::collections::BTreeSet;
6
7use super::{
8 Address, CheckpointTimestamp, ConsensusCommitDigest, EpochId, Event, GenesisObject, Identifier,
9 Intent, IntentMessage, MoveAuthenticator, ObjectId, ObjectReference, ProtocolVersion,
10 TransactionDigest, TypeTag, UserSignature, Version,
11};
12
13mod randomness_round;
14pub use randomness_round::RandomnessRound;
15
16#[cfg(feature = "serde")]
17#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
18mod serialization;
19#[cfg(feature = "serde")]
20#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
21pub(crate) use serialization::SignedTransactionWithIntentMessage;
22
23#[derive(Clone, Debug, Eq, Hash, PartialEq)]
35#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
36#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
37#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
38#[non_exhaustive]
39pub enum Transaction {
40 V1(TransactionV1),
41 }
44
45impl Transaction {
46 crate::def_is_as_into_opt!(V1(TransactionV1));
47
48 pub fn intent_message(&self) -> IntentMessage<&Self> {
51 IntentMessage::new(Intent::iota_transaction(), self)
52 }
53}
54
55impl From<TransactionV1> for Transaction {
56 fn from(v1: TransactionV1) -> Self {
57 Transaction::V1(v1)
58 }
59}
60
61impl crate::TreeDisplay for Transaction {
62 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
63 w.enum_name("Transaction");
64 match self {
65 Self::V1(v1) => v1.fmt_tree(w),
66 }
67 }
68}
69
70#[derive(Clone, Debug, Eq, Hash, PartialEq)]
71#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
72#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
73#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
74pub struct TransactionV1 {
75 pub kind: TransactionKind,
76 pub sender: Address,
77 pub gas_payment: GasPayment,
78 pub expiration: TransactionExpiration,
79}
80
81impl crate::TreeDisplay for TransactionV1 {
82 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
83 w.header("Transaction V1")?;
84 w.child("Kind", &self.kind, false)?;
85 w.leaf("Sender", &self.sender, false)?;
86 w.child("Gas Payment", &self.gas_payment, false)?;
87 w.leaf("Expiration", &self.expiration, true)
88 }
89}
90
91#[derive(Clone, Debug, derive_more::Deref, Eq, Hash, PartialEq)]
101#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
102#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
103pub struct SenderSignedTransaction(
104 #[cfg_attr(
105 feature = "serde",
106 serde(with = "::serde_with::As::<crate::_serde::SignedTransactionWithIntentMessage>")
107 )]
108 SignedTransaction,
109);
110
111impl SenderSignedTransaction {
112 pub fn new(transaction: Transaction, signatures: Vec<UserSignature>) -> Self {
113 Self(SignedTransaction {
114 transaction,
115 signatures,
116 })
117 }
118
119 pub fn signed_transaction(&self) -> &SignedTransaction {
121 &self.0
122 }
123
124 pub fn signed_transaction_mut(&mut self) -> &mut SignedTransaction {
126 &mut self.0
127 }
128
129 pub fn into_signed_transaction(self) -> SignedTransaction {
132 self.0
133 }
134}
135
136impl From<SignedTransaction> for SenderSignedTransaction {
137 fn from(transaction: SignedTransaction) -> Self {
138 Self(transaction)
139 }
140}
141
142impl std::fmt::Display for SenderSignedTransaction {
143 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
144 write!(f, "{}", self.0)
145 }
146}
147
148#[derive(Clone, Debug, Eq, Hash, PartialEq)]
149#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
150#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
151#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
152pub struct SignedTransaction {
153 pub transaction: Transaction,
154 pub signatures: Vec<UserSignature>,
155}
156
157impl SignedTransaction {
158 pub fn transaction(&self) -> &Transaction {
159 &self.transaction
160 }
161
162 pub fn signatures(&self) -> &[UserSignature] {
163 &self.signatures
164 }
165
166 pub fn intent_message(&self) -> IntentMessage<&Transaction> {
169 self.transaction.intent_message()
170 }
171
172 pub fn move_authenticators(&self) -> Vec<&MoveAuthenticator> {
174 self.signatures
175 .iter()
176 .filter_map(|signature| signature.as_opt_move_authenticator())
177 .collect()
178 }
179
180 pub fn sender_move_authenticator(&self) -> Option<&MoveAuthenticator> {
182 let Transaction::V1(transaction) = &self.transaction;
183
184 self.move_authenticators()
185 .into_iter()
186 .find(|authenticator| authenticator.address() == transaction.sender)
187 }
188
189 pub fn sponsor_move_authenticator(&self) -> Option<&MoveAuthenticator> {
192 let Transaction::V1(transaction) = &self.transaction;
193 let gas_owner = transaction.gas_payment.owner;
194
195 if gas_owner != transaction.sender {
196 self.move_authenticators()
197 .into_iter()
198 .find(|authenticator| authenticator.address() == gas_owner)
199 } else {
200 None
201 }
202 }
203}
204
205impl From<SenderSignedTransaction> for SignedTransaction {
206 fn from(transaction: SenderSignedTransaction) -> Self {
207 transaction.0
208 }
209}
210
211impl crate::TreeDisplay for SignedTransaction {
212 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
213 w.header("Signed Transaction")?;
214 w.child("Transaction", &self.transaction, false)?;
215 w.children("Signatures", &self.signatures, true)
216 }
217}
218
219#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
230#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
231#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
232#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
233#[non_exhaustive]
234pub enum TransactionExpiration {
235 #[default]
237 None,
238 Epoch(
241 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
242 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
243 EpochId,
244 ),
245}
246
247impl TransactionExpiration {
248 crate::def_is!(None);
249
250 crate::def_is_as_into_opt!(Epoch(EpochId));
251}
252
253impl std::fmt::Display for TransactionExpiration {
254 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
255 match self {
256 TransactionExpiration::None => write!(f, "None"),
257 TransactionExpiration::Epoch(id) => write!(f, "Epoch({id})"),
258 }
259 }
260}
261
262#[derive(Clone, Debug, Eq, Hash, PartialEq)]
275#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
276#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
277#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
278pub struct GasPayment {
279 pub objects: Vec<ObjectReference>,
280 pub owner: Address,
282 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
287 pub price: u64,
288 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
290 pub budget: u64,
291}
292
293impl crate::TreeDisplay for GasPayment {
294 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
295 w.header("Gas Payment")?;
296 w.children("Objects", &self.objects, false)?;
297 w.leaf("Owner", &self.owner, false)?;
298 w.leaf("Price", &self.price, false)?;
299 w.leaf("Budget", &self.budget, true)
300 }
301}
302
303#[derive(Clone, derive_more::Debug, Eq, Hash, PartialEq)]
313#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
314#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
315#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
316pub struct RandomnessStateUpdate {
317 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
319 pub epoch: u64,
320 pub randomness_round: RandomnessRound,
322 #[cfg_attr(
324 feature = "serde",
325 serde(with = "crate::_serde::ReadableBase64Encoded")
326 )]
327 #[debug("{:?}", <base64ct::Base64 as base64ct::Encoding>::encode_string(random_bytes))]
328 pub random_bytes: Vec<u8>,
329 pub randomness_obj_initial_shared_version: Version,
331}
332
333impl crate::TreeDisplay for RandomnessStateUpdate {
334 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
335 w.header("Randomness State Update")?;
336 w.leaf("Epoch", &self.epoch, false)?;
337 w.leaf("Randomness Round", &self.randomness_round, false)?;
338 w.leaf("Random Bytes", &hex::encode(&self.random_bytes), false)?;
339 w.leaf(
340 "Randomness Obj Initial Shared Version",
341 &self.randomness_obj_initial_shared_version,
342 true,
343 )
344 }
345}
346
347#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
371#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
372#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
373#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
374pub struct DenyRuleSet {
375 pub denied_addresses: BTreeSet<Address>,
378 pub denied_objects: BTreeSet<ObjectId>,
380 pub denied_packages: BTreeSet<ObjectId>,
383 pub package_publish_disabled: bool,
385 pub package_upgrade_disabled: bool,
387 pub shared_object_disabled: bool,
389 pub user_transaction_disabled: bool,
391 pub receiving_objects_disabled: bool,
393 pub move_authenticator_disabled: bool,
395}
396
397#[derive(Clone, Debug, Eq, Hash, PartialEq)]
427#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
428#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
429#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
430pub struct TransactionDenyRulesUpdate {
431 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
433 pub epoch: u64,
434 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
436 pub round: u64,
437 pub added_addresses: BTreeSet<Address>,
439 pub removed_addresses: BTreeSet<Address>,
441 pub added_objects: BTreeSet<ObjectId>,
443 pub removed_objects: BTreeSet<ObjectId>,
445 pub added_packages: BTreeSet<ObjectId>,
447 pub removed_packages: BTreeSet<ObjectId>,
449 pub package_publish_disabled: bool,
451 pub package_upgrade_disabled: bool,
453 pub shared_object_disabled: bool,
455 pub user_transaction_disabled: bool,
457 pub receiving_objects_disabled: bool,
459 pub move_authenticator_disabled: bool,
461 pub deny_rules_obj_initial_shared_version: Version,
463}
464
465impl crate::TreeDisplay for DenyRuleSet {
466 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
467 w.header("Deny Rule Set")?;
468 w.leaves("Denied Addresses", &self.denied_addresses, false)?;
469 w.leaves("Denied Objects", &self.denied_objects, false)?;
470 w.leaves("Denied Packages", &self.denied_packages, false)?;
471 w.leaf(
472 "Package Publish Disabled",
473 &self.package_publish_disabled,
474 false,
475 )?;
476 w.leaf(
477 "Package Upgrade Disabled",
478 &self.package_upgrade_disabled,
479 false,
480 )?;
481 w.leaf(
482 "Shared Object Disabled",
483 &self.shared_object_disabled,
484 false,
485 )?;
486 w.leaf(
487 "User Transaction Disabled",
488 &self.user_transaction_disabled,
489 false,
490 )?;
491 w.leaf(
492 "Receiving Objects Disabled",
493 &self.receiving_objects_disabled,
494 false,
495 )?;
496 w.leaf(
497 "Move Authenticator Disabled",
498 &self.move_authenticator_disabled,
499 true,
500 )
501 }
502}
503
504impl crate::TreeDisplay for TransactionDenyRulesUpdate {
505 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
506 w.header("Transaction Deny Rules Update")?;
507 w.leaf("Epoch", &self.epoch, false)?;
508 w.leaf("Round", &self.round, false)?;
509 w.leaves("Added Addresses", &self.added_addresses, false)?;
510 w.leaves("Removed Addresses", &self.removed_addresses, false)?;
511 w.leaves("Added Objects", &self.added_objects, false)?;
512 w.leaves("Removed Objects", &self.removed_objects, false)?;
513 w.leaves("Added Packages", &self.added_packages, false)?;
514 w.leaves("Removed Packages", &self.removed_packages, false)?;
515 w.leaf(
516 "Package Publish Disabled",
517 &self.package_publish_disabled,
518 false,
519 )?;
520 w.leaf(
521 "Package Upgrade Disabled",
522 &self.package_upgrade_disabled,
523 false,
524 )?;
525 w.leaf(
526 "Shared Object Disabled",
527 &self.shared_object_disabled,
528 false,
529 )?;
530 w.leaf(
531 "User Transaction Disabled",
532 &self.user_transaction_disabled,
533 false,
534 )?;
535 w.leaf(
536 "Receiving Objects Disabled",
537 &self.receiving_objects_disabled,
538 false,
539 )?;
540 w.leaf(
541 "Move Authenticator Disabled",
542 &self.move_authenticator_disabled,
543 false,
544 )?;
545 w.leaf(
546 "Deny Rules Obj Initial Shared Version",
547 &self.deny_rules_obj_initial_shared_version,
548 true,
549 )
550 }
551}
552
553#[derive(Clone, Debug, Eq, Hash, PartialEq)]
569#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
570#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
571#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
572#[non_exhaustive]
573pub enum TransactionKind {
574 Programmable(ProgrammableTransaction),
576 Genesis(GenesisTransaction),
581 ConsensusCommitPrologueV1(ConsensusCommitPrologueV1),
583 AuthenticatorStateUpdateV1Deprecated,
585 EndOfEpoch(Vec<EndOfEpochTransactionKind>),
588 RandomnessStateUpdate(RandomnessStateUpdate),
590 TransactionDenyRulesUpdate(TransactionDenyRulesUpdate),
592}
593
594impl TransactionKind {
595 crate::def_is_as_into_opt! {
596 ConsensusCommitPrologueV1,
597 RandomnessStateUpdate,
598 TransactionDenyRulesUpdate,
599 }
600
601 crate::def_is_as_into_opt! {
602 Programmable(ProgrammableTransaction),
603 Genesis(GenesisTransaction),
604 EndOfEpoch(Vec<EndOfEpochTransactionKind>),
605 }
606
607 pub fn new_programmable(transaction: ProgrammableTransaction) -> Self {
609 Self::Programmable(transaction)
610 }
611
612 pub fn new_genesis(transaction: GenesisTransaction) -> Self {
614 Self::Genesis(transaction)
615 }
616
617 pub fn new_consensus_commit_prologue_v1(transaction: ConsensusCommitPrologueV1) -> Self {
619 Self::ConsensusCommitPrologueV1(transaction)
620 }
621
622 pub fn new_end_of_epoch(transaction: Vec<EndOfEpochTransactionKind>) -> Self {
624 Self::EndOfEpoch(transaction)
625 }
626
627 pub fn new_randomness_state_update(transaction: RandomnessStateUpdate) -> Self {
629 Self::RandomnessStateUpdate(transaction)
630 }
631
632 pub fn new_transaction_deny_rules_update(transaction: TransactionDenyRulesUpdate) -> Self {
634 Self::TransactionDenyRulesUpdate(transaction)
635 }
636
637 pub fn is_system(&self) -> bool {
639 match self {
640 TransactionKind::Genesis(_)
641 | TransactionKind::ConsensusCommitPrologueV1(_)
642 | TransactionKind::AuthenticatorStateUpdateV1Deprecated
643 | TransactionKind::RandomnessStateUpdate(_)
644 | TransactionKind::TransactionDenyRulesUpdate(_)
645 | TransactionKind::EndOfEpoch(_) => true,
646 TransactionKind::Programmable(_) => false,
647 }
648 }
649
650 pub fn num_commands(&self) -> usize {
652 match self {
653 TransactionKind::Programmable(pt) => pt.commands.len(),
654 _ => 0,
655 }
656 }
657
658 pub fn num_transactions(&self) -> usize {
660 match self {
661 TransactionKind::Programmable(pt) => pt.commands.len(),
662 _ => 1,
663 }
664 }
665}
666
667impl crate::TreeDisplay for TransactionKind {
668 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
669 w.enum_name("Transaction Kind");
670 match self {
671 Self::Programmable(pt) => pt.fmt_tree(w),
672 Self::Genesis(v) => v.fmt_tree(w),
673 Self::ConsensusCommitPrologueV1(v) => v.fmt_tree(w),
674 Self::AuthenticatorStateUpdateV1Deprecated => {
675 w.header("Authenticator State Update V1 (Deprecated)")
676 }
677 Self::EndOfEpoch(items) => {
678 w.header("End of Epoch")?;
679 w.children("Transactions", items, true)
680 }
681 Self::RandomnessStateUpdate(v) => v.fmt_tree(w),
682 Self::TransactionDenyRulesUpdate(v) => v.fmt_tree(w),
683 }
684 }
685}
686
687#[derive(Clone, Debug, Eq, Hash, PartialEq)]
701#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
702#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
703#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
704#[non_exhaustive]
705pub enum EndOfEpochTransactionKind {
706 ChangeEpoch(ChangeEpoch),
708 ChangeEpochV2(ChangeEpochV2),
710 ChangeEpochV3(ChangeEpochV3),
712 ChangeEpochV4(ChangeEpochV4),
714 TransactionDenyRulesCreate,
716}
717
718impl EndOfEpochTransactionKind {
719 crate::def_is_as_into_opt!(ChangeEpoch, ChangeEpochV2, ChangeEpochV3, ChangeEpochV4,);
720
721 crate::def_is!(TransactionDenyRulesCreate);
722
723 #[expect(clippy::too_many_arguments)]
725 pub fn new_change_epoch(
726 next_epoch: EpochId,
727 protocol_version: ProtocolVersion,
728 storage_charge: u64,
729 computation_charge: u64,
730 storage_rebate: u64,
731 non_refundable_storage_fee: u64,
732 epoch_start_timestamp_ms: u64,
733 system_packages: Vec<SystemPackage>,
734 ) -> Self {
735 Self::ChangeEpoch(ChangeEpoch {
736 epoch: next_epoch,
737 protocol_version,
738 storage_charge,
739 computation_charge,
740 storage_rebate,
741 non_refundable_storage_fee,
742 epoch_start_timestamp_ms,
743 system_packages,
744 })
745 }
746
747 #[expect(clippy::too_many_arguments)]
749 pub fn new_change_epoch_v2(
750 next_epoch: EpochId,
751 protocol_version: ProtocolVersion,
752 storage_charge: u64,
753 computation_charge: u64,
754 computation_charge_burned: u64,
755 storage_rebate: u64,
756 non_refundable_storage_fee: u64,
757 epoch_start_timestamp_ms: u64,
758 system_packages: Vec<SystemPackage>,
759 ) -> Self {
760 Self::ChangeEpochV2(ChangeEpochV2 {
761 epoch: next_epoch,
762 protocol_version,
763 storage_charge,
764 computation_charge,
765 computation_charge_burned,
766 storage_rebate,
767 non_refundable_storage_fee,
768 epoch_start_timestamp_ms,
769 system_packages,
770 })
771 }
772
773 #[expect(clippy::too_many_arguments)]
775 pub fn new_change_epoch_v3(
776 next_epoch: EpochId,
777 protocol_version: ProtocolVersion,
778 storage_charge: u64,
779 computation_charge: u64,
780 computation_charge_burned: u64,
781 storage_rebate: u64,
782 non_refundable_storage_fee: u64,
783 epoch_start_timestamp_ms: u64,
784 system_packages: Vec<SystemPackage>,
785 eligible_active_validators: Vec<u64>,
786 ) -> Self {
787 Self::ChangeEpochV3(ChangeEpochV3 {
788 epoch: next_epoch,
789 protocol_version,
790 storage_charge,
791 computation_charge,
792 computation_charge_burned,
793 storage_rebate,
794 non_refundable_storage_fee,
795 epoch_start_timestamp_ms,
796 system_packages,
797 eligible_active_validators,
798 })
799 }
800
801 #[expect(clippy::too_many_arguments)]
803 pub fn new_change_epoch_v4(
804 next_epoch: EpochId,
805 protocol_version: ProtocolVersion,
806 storage_charge: u64,
807 computation_charge: u64,
808 computation_charge_burned: u64,
809 storage_rebate: u64,
810 non_refundable_storage_fee: u64,
811 epoch_start_timestamp_ms: u64,
812 system_packages: Vec<SystemPackage>,
813 eligible_active_validators: Vec<u64>,
814 scores: Vec<u64>,
815 adjust_rewards_by_score: bool,
816 ) -> Self {
817 Self::ChangeEpochV4(ChangeEpochV4 {
818 epoch: next_epoch,
819 protocol_version,
820 storage_charge,
821 computation_charge,
822 computation_charge_burned,
823 storage_rebate,
824 non_refundable_storage_fee,
825 epoch_start_timestamp_ms,
826 system_packages,
827 eligible_active_validators,
828 scores,
829 adjust_rewards_by_score,
830 })
831 }
832
833 pub fn new_transaction_deny_rules_create() -> Self {
836 Self::TransactionDenyRulesCreate
837 }
838
839 pub fn shared_input_objects(&self) -> impl Iterator<Item = SharedObjectReference> + '_ {
842 match self {
843 Self::ChangeEpoch(_)
844 | Self::ChangeEpochV2(_)
845 | Self::ChangeEpochV3(_)
846 | Self::ChangeEpochV4(_) => {
847 vec![SharedObjectReference::IOTA_SYSTEM_STATE_OBJ_MUTABLE].into_iter()
848 }
849 Self::TransactionDenyRulesCreate => vec![].into_iter(),
852 }
853 }
854}
855
856impl crate::TreeDisplay for EndOfEpochTransactionKind {
857 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
858 w.enum_name("End of Epoch Transaction Kind");
859 match self {
860 Self::ChangeEpoch(v) => v.fmt_tree(w),
861 Self::ChangeEpochV2(v) => v.fmt_tree(w),
862 Self::ChangeEpochV3(v) => v.fmt_tree(w),
863 Self::ChangeEpochV4(v) => v.fmt_tree(w),
864 Self::TransactionDenyRulesCreate => w.header("Transaction Deny Rules Create"),
865 }
866 }
867}
868
869#[derive(Clone, Debug, Eq, Hash, PartialEq)]
870#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
871#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
872#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
873#[non_exhaustive]
874pub enum ConsensusDeterminedVersionAssignments {
875 CanceledTransactions {
877 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
878 canceled_transactions: Vec<CanceledTransaction>,
879 },
880}
881
882impl ConsensusDeterminedVersionAssignments {
883 crate::def_is!(CanceledTransactions);
884
885 pub fn as_canceled_transactions(&self) -> &[CanceledTransaction] {
886 let Self::CanceledTransactions {
887 canceled_transactions,
888 } = self;
889 canceled_transactions
890 }
891}
892
893impl crate::TreeDisplay for ConsensusDeterminedVersionAssignments {
894 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
895 w.enum_name("Consensus Determined Version Assignments");
896 match self {
897 ConsensusDeterminedVersionAssignments::CanceledTransactions {
898 canceled_transactions,
899 } => {
900 w.header("Canceled Transactions")?;
901 w.children("Transactions", canceled_transactions, true)
902 }
903 }
904 }
905}
906
907#[derive(Clone, Debug, Eq, Hash, PartialEq)]
917#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
918#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
919#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
920pub struct CanceledTransaction {
921 pub digest: TransactionDigest,
922 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
923 pub version_assignments: Vec<VersionAssignment>,
924}
925
926impl crate::TreeDisplay for CanceledTransaction {
927 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
928 w.header("Canceled Transaction")?;
929 w.leaf("Digest", &self.digest, false)?;
930 w.children("Version Assignments", &self.version_assignments, true)
931 }
932}
933
934#[derive(Clone, Debug, Eq, Hash, PartialEq)]
945#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
946#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
947#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
948pub struct VersionAssignment {
949 pub object_id: ObjectId,
950 pub version: Version,
951}
952
953impl VersionAssignment {
954 pub fn new(object_id: ObjectId, version: Version) -> Self {
956 Self { object_id, version }
957 }
958}
959
960impl crate::TreeDisplay for VersionAssignment {
961 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
962 w.header("Version Assignment")?;
963 w.leaf("Object ID", &self.object_id, false)?;
964 w.leaf("Version", &self.version, true)
965 }
966}
967
968#[derive(Clone, Debug, Eq, Hash, PartialEq)]
979#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
980#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
981#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
982pub struct ConsensusCommitPrologueV1 {
983 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
985 pub epoch: u64,
986 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
988 pub round: u64,
989 #[cfg_attr(
992 feature = "serde",
993 serde(with = "crate::_serde::OptionReadableDisplay")
994 )]
995 pub sub_dag_index: Option<u64>,
996 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
998 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
999 pub commit_timestamp_ms: CheckpointTimestamp,
1000 pub consensus_commit_digest: ConsensusCommitDigest,
1002 pub consensus_determined_version_assignments: ConsensusDeterminedVersionAssignments,
1004}
1005
1006impl crate::TreeDisplay for ConsensusCommitPrologueV1 {
1007 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1008 w.header("Consensus Commit Prologue V1")?;
1009 w.leaf("Epoch", &self.epoch, false)?;
1010 w.leaf("Round", &self.round, false)?;
1011 w.option_leaf("Sub DAG Index", &self.sub_dag_index, false)?;
1012 w.leaf("Commit Timestamp Ms", &self.commit_timestamp_ms, false)?;
1013 w.leaf(
1014 "Consensus Commit Digest",
1015 &self.consensus_commit_digest,
1016 false,
1017 )?;
1018 w.child(
1019 "Consensus Determined Version Assignments",
1020 &self.consensus_determined_version_assignments,
1021 true,
1022 )
1023 }
1024}
1025
1026#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1043#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1044#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1045#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1046pub struct ChangeEpoch {
1047 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1049 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
1050 pub epoch: EpochId,
1051 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1053 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
1054 pub protocol_version: ProtocolVersion,
1055 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1057 pub storage_charge: u64,
1058 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1060 pub computation_charge: u64,
1061 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1063 pub storage_rebate: u64,
1064 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1066 pub non_refundable_storage_fee: u64,
1067 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1069 pub epoch_start_timestamp_ms: u64,
1070 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1077 pub system_packages: Vec<SystemPackage>,
1078}
1079
1080impl crate::TreeDisplay for ChangeEpoch {
1081 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1082 w.header("Change Epoch")?;
1083 w.leaf("Epoch", &self.epoch, false)?;
1084 w.leaf("Protocol Version", &self.protocol_version, false)?;
1085 w.leaf("Storage Charge", &self.storage_charge, false)?;
1086 w.leaf("Computation Charge", &self.computation_charge, false)?;
1087 w.leaf("Storage Rebate", &self.storage_rebate, false)?;
1088 w.leaf(
1089 "Non-Refundable Storage Fee",
1090 &self.non_refundable_storage_fee,
1091 false,
1092 )?;
1093 w.leaf(
1094 "Epoch Start Timestamp Ms",
1095 &self.epoch_start_timestamp_ms,
1096 false,
1097 )?;
1098 w.children("System Packages", &self.system_packages, true)
1099 }
1100}
1101
1102#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1120#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1121#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1122#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1123pub struct ChangeEpochV2 {
1124 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1126 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
1127 pub epoch: EpochId,
1128 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1130 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
1131 pub protocol_version: ProtocolVersion,
1132 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1134 pub storage_charge: u64,
1135 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1137 pub computation_charge: u64,
1138 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1140 pub computation_charge_burned: u64,
1141 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1143 pub storage_rebate: u64,
1144 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1146 pub non_refundable_storage_fee: u64,
1147 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1149 pub epoch_start_timestamp_ms: u64,
1150 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1157 pub system_packages: Vec<SystemPackage>,
1158}
1159
1160impl crate::TreeDisplay for ChangeEpochV2 {
1161 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1162 w.header("Change Epoch V2")?;
1163 w.leaf("Epoch", &self.epoch, false)?;
1164 w.leaf("Protocol Version", &self.protocol_version, false)?;
1165 w.leaf("Storage Charge", &self.storage_charge, false)?;
1166 w.leaf("Computation Charge", &self.computation_charge, false)?;
1167 w.leaf(
1168 "Computation Charge Burned",
1169 &self.computation_charge_burned,
1170 false,
1171 )?;
1172 w.leaf("Storage Rebate", &self.storage_rebate, false)?;
1173 w.leaf(
1174 "Non-Refundable Storage Fee",
1175 &self.non_refundable_storage_fee,
1176 false,
1177 )?;
1178 w.leaf(
1179 "Epoch Start Timestamp Ms",
1180 &self.epoch_start_timestamp_ms,
1181 false,
1182 )?;
1183 w.children("System Packages", &self.system_packages, true)
1184 }
1185}
1186
1187#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1188#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1189#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1190#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1191pub struct ChangeEpochV3 {
1192 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1194 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
1195 pub epoch: EpochId,
1196 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1198 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
1199 pub protocol_version: ProtocolVersion,
1200 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1202 pub storage_charge: u64,
1203 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1205 pub computation_charge: u64,
1206 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1208 pub computation_charge_burned: u64,
1209 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1211 pub storage_rebate: u64,
1212 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1214 pub non_refundable_storage_fee: u64,
1215 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1217 pub epoch_start_timestamp_ms: u64,
1218 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1225 pub system_packages: Vec<SystemPackage>,
1226 pub eligible_active_validators: Vec<u64>,
1229}
1230
1231impl crate::TreeDisplay for ChangeEpochV3 {
1232 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1233 w.header("Change Epoch V3")?;
1234 w.leaf("Epoch", &self.epoch, false)?;
1235 w.leaf("Protocol Version", &self.protocol_version, false)?;
1236 w.leaf("Storage Charge", &self.storage_charge, false)?;
1237 w.leaf("Computation Charge", &self.computation_charge, false)?;
1238 w.leaf(
1239 "Computation Charge Burned",
1240 &self.computation_charge_burned,
1241 false,
1242 )?;
1243 w.leaf("Storage Rebate", &self.storage_rebate, false)?;
1244 w.leaf(
1245 "Non-Refundable Storage Fee",
1246 &self.non_refundable_storage_fee,
1247 false,
1248 )?;
1249 w.leaf(
1250 "Epoch Start Timestamp Ms",
1251 &self.epoch_start_timestamp_ms,
1252 false,
1253 )?;
1254 w.children("System Packages", &self.system_packages, false)?;
1255 w.leaves(
1256 "Eligible Active Validators",
1257 &self.eligible_active_validators,
1258 true,
1259 )
1260 }
1261}
1262
1263#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1264#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1265#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1266#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1267pub struct ChangeEpochV4 {
1268 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1270 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
1271 pub epoch: EpochId,
1272 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1274 #[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
1275 pub protocol_version: ProtocolVersion,
1276 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1278 pub storage_charge: u64,
1279 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1281 pub computation_charge: u64,
1282 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1284 pub computation_charge_burned: u64,
1285 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1287 pub storage_rebate: u64,
1288 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1290 pub non_refundable_storage_fee: u64,
1291 #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
1293 pub epoch_start_timestamp_ms: u64,
1294 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1301 pub system_packages: Vec<SystemPackage>,
1302 pub eligible_active_validators: Vec<u64>,
1305 pub scores: Vec<u64>,
1308 pub adjust_rewards_by_score: bool,
1310}
1311
1312impl crate::TreeDisplay for ChangeEpochV4 {
1313 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1314 w.header("Change Epoch V4")?;
1315 w.leaf("Epoch", &self.epoch, false)?;
1316 w.leaf("Protocol Version", &self.protocol_version, false)?;
1317 w.leaf("Storage Charge", &self.storage_charge, false)?;
1318 w.leaf("Computation Charge", &self.computation_charge, false)?;
1319 w.leaf(
1320 "Computation Charge Burned",
1321 &self.computation_charge_burned,
1322 false,
1323 )?;
1324 w.leaf("Storage Rebate", &self.storage_rebate, false)?;
1325 w.leaf(
1326 "Non-Refundable Storage Fee",
1327 &self.non_refundable_storage_fee,
1328 false,
1329 )?;
1330 w.leaf(
1331 "Epoch Start Timestamp Ms",
1332 &self.epoch_start_timestamp_ms,
1333 false,
1334 )?;
1335 w.children("System Packages", &self.system_packages, false)?;
1336 w.leaves(
1337 "Eligible Active Validators",
1338 &self.eligible_active_validators,
1339 false,
1340 )?;
1341 w.leaves("Scores", &self.scores, false)?;
1342 w.leaf(
1343 "Adjust Rewards By Score",
1344 &self.adjust_rewards_by_score,
1345 true,
1346 )
1347 }
1348}
1349
1350#[derive(Clone, derive_more::Debug, Eq, Hash, PartialEq)]
1351#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1352#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1353#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1354pub struct SystemPackage {
1355 pub version: Version,
1356 #[cfg_attr(
1357 feature = "serde",
1358 serde(
1359 with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
1360 )
1361 )]
1362 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1363 #[debug(
1364 "{:?}",
1365 modules
1366 .iter()
1367 .map(|m| <base64ct::Base64 as base64ct::Encoding>::encode_string(m))
1368 .collect::<Vec<_>>()
1369 )]
1370 pub modules: Vec<Vec<u8>>,
1371 pub dependencies: Vec<ObjectId>,
1372}
1373
1374impl crate::TreeDisplay for SystemPackage {
1375 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1376 w.header("System Package")?;
1377 w.leaf("Version", &self.version, false)?;
1378 w.base64_leaves("Modules", &self.modules, false)?;
1379 w.leaves("Dependencies", &self.dependencies, true)
1380 }
1381}
1382
1383#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1393#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1394#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1395#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1396pub struct GenesisTransaction {
1397 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1398 pub objects: Vec<GenesisObject>,
1399 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=10).lift()))]
1400 pub events: Vec<Event>,
1401}
1402
1403impl crate::TreeDisplay for GenesisTransaction {
1404 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1405 w.header("Genesis Transaction")?;
1406 w.children("Objects", &self.objects, false)?;
1407 w.children("Events", &self.events, true)
1408 }
1409}
1410
1411#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1424#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1425#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1426#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1427pub struct ProgrammableTransaction {
1428 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=10).lift()))]
1430 pub inputs: Vec<Input>,
1431 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=10).lift()))]
1434 pub commands: Vec<Command>,
1435}
1436
1437impl crate::TreeDisplay for ProgrammableTransaction {
1438 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1439 w.header("Programmable Transaction")?;
1440 w.children("Inputs", &self.inputs, false)?;
1441 w.children("Commands", &self.commands, true)
1442 }
1443}
1444#[derive(Clone, derive_more::Debug, Eq, Hash, PartialEq)]
1461#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1462#[cfg_attr(
1463 feature = "bcs-schema",
1464 derive(iota_bcs_schema::BcsSchema),
1465 bcs_schema(definition = "call-arg")
1466)]
1467#[non_exhaustive]
1468pub enum Input {
1469 Pure(#[debug("{:?}", <base64ct::Base64 as base64ct::Encoding>::encode_string(_0))] Vec<u8>),
1474 ImmutableOrOwned(ObjectReference),
1476 Shared(SharedObjectReference),
1478 Receiving(ObjectReference),
1481}
1482
1483impl Input {
1484 pub const IOTA_SYSTEM_MUTABLE: Self = Self::Shared(SharedObjectReference {
1486 object_id: ObjectId::SYSTEM_STATE,
1487 initial_shared_version: Version::INITIAL_SHARED_VERSION,
1488 mutable: true,
1489 });
1490
1491 pub const CLOCK_IMMUTABLE: Self = Self::Shared(SharedObjectReference {
1493 object_id: ObjectId::CLOCK,
1494 initial_shared_version: Version::INITIAL_SHARED_VERSION,
1495 mutable: false,
1496 });
1497
1498 pub const CLOCK_MUTABLE: Self = Self::Shared(SharedObjectReference {
1500 object_id: ObjectId::CLOCK,
1501 initial_shared_version: Version::INITIAL_SHARED_VERSION,
1502 mutable: true,
1503 });
1504
1505 crate::def_is_as_into_opt!(
1506 Pure(Vec<u8>),
1507 ImmutableOrOwned(ObjectReference),
1508 Shared(SharedObjectReference),
1509 Receiving(ObjectReference)
1510 );
1511
1512 #[cfg(feature = "serde")]
1514 #[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
1515 pub fn pure<T: serde::Serialize>(value: &T) -> Self {
1516 Self::Pure(bcs::to_bytes(value).expect("value should be serializable"))
1517 }
1518
1519 pub fn opt_object_id(&self) -> Option<&ObjectId> {
1523 match self {
1524 Self::Pure { .. } => None,
1525 Self::ImmutableOrOwned(obj_ref) | Self::Receiving(obj_ref) => Some(&obj_ref.object_id),
1526 Self::Shared(SharedObjectReference { object_id, .. }) => Some(object_id),
1527 }
1528 }
1529
1530 pub fn is_mutable_shared(&self) -> bool {
1532 matches!(
1533 self,
1534 Self::Shared(SharedObjectReference { mutable: true, .. })
1535 )
1536 }
1537
1538 pub fn as_opt_object_ref(&self) -> Option<&ObjectReference> {
1541 match self {
1542 Self::ImmutableOrOwned(obj_ref) | Self::Receiving(obj_ref) => Some(obj_ref),
1543 _ => None,
1544 }
1545 }
1546}
1547
1548impl crate::TreeDisplay for Input {
1549 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1550 w.enum_name("Input");
1551 match self {
1552 Self::Pure(value) => {
1553 w.header("Pure")?;
1554 w.leaf("Value", &hex::encode(value), true)
1555 }
1556 Self::ImmutableOrOwned(obj_ref) => {
1557 w.header("Immutable Or Owned")?;
1558 w.inline_child(obj_ref)
1559 }
1560 Self::Shared(shared) => {
1561 w.header("Shared")?;
1562 w.inline_child(shared)
1563 }
1564 Self::Receiving(obj_ref) => {
1565 w.header("Receiving")?;
1566 w.inline_child(obj_ref)
1567 }
1568 }
1569 }
1570}
1571
1572#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
1574#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1575#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1576pub struct SharedObjectReference {
1577 pub object_id: ObjectId,
1578 pub initial_shared_version: Version,
1579 pub mutable: bool,
1582}
1583
1584impl SharedObjectReference {
1585 pub const IOTA_SYSTEM_STATE_OBJ_MUTABLE: Self = Self {
1586 object_id: ObjectId::SYSTEM_STATE,
1587 initial_shared_version: Version::INITIAL_SHARED_VERSION,
1588 mutable: true,
1589 };
1590
1591 pub const fn new(object_id: ObjectId, initial_shared_version: Version, mutable: bool) -> Self {
1594 Self {
1595 object_id,
1596 initial_shared_version,
1597 mutable,
1598 }
1599 }
1600}
1601
1602impl crate::TreeDisplay for SharedObjectReference {
1603 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1604 w.header("Shared Object Reference")?;
1605 w.leaf("Object ID", &self.object_id, false)?;
1606 w.leaf(
1607 "Initial Shared Version",
1608 &self.initial_shared_version,
1609 false,
1610 )?;
1611 w.leaf("Mutable", &self.mutable, true)
1612 }
1613}
1614
1615#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1639#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1640#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1641#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1642#[non_exhaustive]
1643pub enum Command {
1644 MoveCall(MoveCall),
1646 TransferObjects(TransferObjects),
1651 SplitCoins(SplitCoins),
1654 MergeCoins(MergeCoins),
1657 Publish(Publish),
1660 MakeMoveVector(MakeMoveVector),
1664 Upgrade(Upgrade),
1673}
1674
1675impl Command {
1676 crate::def_is_as_into_opt!(
1677 MoveCall,
1678 TransferObjects,
1679 SplitCoins,
1680 MergeCoins,
1681 Publish,
1682 MakeMoveVector,
1683 Upgrade,
1684 );
1685
1686 pub fn new_move_call(
1688 package: ObjectId,
1689 module: Identifier,
1690 function: Identifier,
1691 type_arguments: Vec<TypeTag>,
1692 arguments: Vec<Argument>,
1693 ) -> Self {
1694 Command::MoveCall(MoveCall {
1695 package,
1696 module,
1697 function,
1698 type_arguments,
1699 arguments,
1700 })
1701 }
1702
1703 pub fn new_transfer_objects(objects: Vec<Argument>, address: Argument) -> Self {
1705 Command::TransferObjects(TransferObjects { objects, address })
1706 }
1707
1708 pub fn new_split_coins(coin: Argument, amounts: Vec<Argument>) -> Self {
1710 Command::SplitCoins(SplitCoins { coin, amounts })
1711 }
1712
1713 pub fn new_merge_coins(coin: Argument, coins_to_merge: Vec<Argument>) -> Self {
1715 Command::MergeCoins(MergeCoins {
1716 coin,
1717 coins_to_merge,
1718 })
1719 }
1720
1721 pub fn new_publish(modules: Vec<Vec<u8>>, dependencies: Vec<ObjectId>) -> Self {
1723 Command::Publish(Publish {
1724 modules,
1725 dependencies,
1726 })
1727 }
1728
1729 pub fn new_make_move_vector(type_tag: Option<TypeTag>, elements: Vec<Argument>) -> Self {
1731 Command::MakeMoveVector(MakeMoveVector { type_tag, elements })
1732 }
1733
1734 pub fn new_upgrade(
1736 modules: Vec<Vec<u8>>,
1737 dependencies: Vec<ObjectId>,
1738 package: ObjectId,
1739 ticket: Argument,
1740 ) -> Self {
1741 Command::Upgrade(Upgrade {
1742 modules,
1743 dependencies,
1744 package,
1745 ticket,
1746 })
1747 }
1748}
1749
1750impl crate::TreeDisplay for Command {
1751 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1752 w.enum_name("Command");
1753 match self {
1754 Self::MoveCall(v) => v.fmt_tree(w),
1755 Self::TransferObjects(v) => v.fmt_tree(w),
1756 Self::SplitCoins(v) => v.fmt_tree(w),
1757 Self::MergeCoins(v) => v.fmt_tree(w),
1758 Self::Publish(v) => v.fmt_tree(w),
1759 Self::MakeMoveVector(v) => v.fmt_tree(w),
1760 Self::Upgrade(v) => v.fmt_tree(w),
1761 }
1762 }
1763}
1764
1765#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1775#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1776#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1777#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1778pub struct TransferObjects {
1779 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1781 pub objects: Vec<Argument>,
1782 pub address: Argument,
1784}
1785
1786impl crate::TreeDisplay for TransferObjects {
1787 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1788 w.header("Transfer Objects")?;
1789 w.leaves("Objects", &self.objects, false)?;
1790 w.leaf("Address", &self.address, true)
1791 }
1792}
1793
1794#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1804#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1805#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1806#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1807pub struct SplitCoins {
1808 pub coin: Argument,
1810 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1812 pub amounts: Vec<Argument>,
1813}
1814
1815impl crate::TreeDisplay for SplitCoins {
1816 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1817 w.header("Split Coins")?;
1818 w.leaf("Coin", &self.coin, false)?;
1819 w.leaves("Amounts", &self.amounts, true)
1820 }
1821}
1822
1823#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1833#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1834#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1835#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1836pub struct MergeCoins {
1837 pub coin: Argument,
1839 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1843 pub coins_to_merge: Vec<Argument>,
1844}
1845
1846impl crate::TreeDisplay for MergeCoins {
1847 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1848 w.header("Merge Coins")?;
1849 w.leaf("Coin", &self.coin, false)?;
1850 w.leaves("Coins To Merge", &self.coins_to_merge, true)
1851 }
1852}
1853
1854#[derive(Clone, derive_more::Debug, Eq, Hash, PartialEq)]
1865#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1866#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1867#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1868pub struct Publish {
1869 #[cfg_attr(
1871 feature = "serde",
1872 serde(
1873 with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
1874 )
1875 )]
1876 #[debug(
1877 "{:?}",
1878 modules
1879 .iter()
1880 .map(|m| <base64ct::Base64 as base64ct::Encoding>::encode_string(m))
1881 .collect::<Vec<_>>()
1882 )]
1883 pub modules: Vec<Vec<u8>>,
1884 pub dependencies: Vec<ObjectId>,
1886}
1887
1888impl crate::TreeDisplay for Publish {
1889 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1890 w.header("Publish")?;
1891 w.base64_leaves("Modules", &self.modules, false)?;
1892 w.leaves("Dependencies", &self.dependencies, true)
1893 }
1894}
1895
1896#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1906#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1907#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1908#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1909pub struct MakeMoveVector {
1910 #[cfg_attr(feature = "serde", serde(rename = "type"))]
1915 pub type_tag: Option<TypeTag>,
1916 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1918 pub elements: Vec<Argument>,
1919}
1920
1921impl crate::TreeDisplay for MakeMoveVector {
1922 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1923 w.header("Make Move Vector")?;
1924 w.option_leaf("Type Tag", &self.type_tag, false)?;
1925 w.leaves("Elements", &self.elements, true)
1926 }
1927}
1928
1929#[derive(Clone, derive_more::Debug, Eq, Hash, PartialEq)]
1942#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1943#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1944#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
1945pub struct Upgrade {
1946 #[cfg_attr(
1948 feature = "serde",
1949 serde(
1950 with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
1951 )
1952 )]
1953 #[debug(
1954 "{:?}",
1955 modules
1956 .iter()
1957 .map(|m| <base64ct::Base64 as base64ct::Encoding>::encode_string(m))
1958 .collect::<Vec<_>>()
1959 )]
1960 pub modules: Vec<Vec<u8>>,
1961 pub dependencies: Vec<ObjectId>,
1963 pub package: ObjectId,
1965 pub ticket: Argument,
1967}
1968
1969impl crate::TreeDisplay for Upgrade {
1970 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
1971 w.header("Upgrade")?;
1972 w.base64_leaves("Modules", &self.modules, false)?;
1973 w.leaves("Dependencies", &self.dependencies, false)?;
1974 w.leaf("Package", &self.package, false)?;
1975 w.leaf("Ticket", &self.ticket, true)
1976 }
1977}
1978
1979#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
1997#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1998#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1999#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
2000#[non_exhaustive]
2001pub enum Argument {
2002 Gas,
2005 Input(u16),
2008 Result(u16),
2010 NestedResult(u16, u16),
2015}
2016
2017impl std::fmt::Display for Argument {
2018 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2019 match self {
2020 Argument::Gas => write!(f, "Gas"),
2021 Argument::Input(i) => write!(f, "Input({i})"),
2022 Argument::Result(i) => write!(f, "Result({i})"),
2023 Argument::NestedResult(i, j) => write!(f, "NestedResult({i}, {j})"),
2024 }
2025 }
2026}
2027
2028impl Argument {
2029 crate::def_is!(Gas, Input, Result, NestedResult);
2030
2031 pub fn as_opt_input(&self) -> Option<u16> {
2032 if let Self::Input(idx) = self {
2033 Some(*idx)
2034 } else {
2035 None
2036 }
2037 }
2038
2039 pub fn as_input(&self) -> u16 {
2040 self.as_opt_input().expect("not an input")
2041 }
2042
2043 pub fn as_opt_result(&self) -> Option<u16> {
2044 if let Self::Result(idx) = self {
2045 Some(*idx)
2046 } else {
2047 None
2048 }
2049 }
2050
2051 pub fn as_result(&self) -> u16 {
2052 self.as_opt_result().expect("not a result")
2053 }
2054
2055 pub fn as_opt_nested_result(&self) -> Option<(u16, u16)> {
2056 if let Self::NestedResult(idx0, idx1) = self {
2057 Some((*idx0, *idx1))
2058 } else {
2059 None
2060 }
2061 }
2062
2063 pub fn as_nested_result(&self) -> (u16, u16) {
2064 self.as_opt_nested_result().expect("not a nested result")
2065 }
2066
2067 pub fn get_nested_result(&self, ix: u16) -> Option<Argument> {
2070 match self {
2071 Argument::Result(i) => Some(Argument::NestedResult(*i, ix)),
2072 _ => None,
2073 }
2074 }
2075}
2076
2077#[derive(Clone, Debug, Eq, Hash, PartialEq)]
2095#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
2096#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
2097#[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
2098pub struct MoveCall {
2099 pub package: ObjectId,
2101 #[cfg_attr(
2103 feature = "serde",
2104 serde(deserialize_with = "serialization::deserialize_ident_unchecked")
2105 )]
2106 pub module: Identifier,
2107 pub function: Identifier,
2109 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
2111 pub type_arguments: Vec<TypeTag>,
2112 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
2114 pub arguments: Vec<Argument>,
2115}
2116
2117impl crate::TreeDisplay for MoveCall {
2118 fn fmt_tree(&self, w: &mut crate::TreeWriter<'_, '_>) -> std::fmt::Result {
2119 w.header("Move Call")?;
2120 w.leaf("Package", &self.package, false)?;
2121 w.leaf("Module", &self.module, false)?;
2122 w.leaf("Function", &self.function, false)?;
2123 w.leaves("Type Arguments", &self.type_arguments, false)?;
2124 w.leaves("Arguments", &self.arguments, true)
2125 }
2126}
2127
2128crate::impl_tree_display!(
2129 Transaction,
2130 DenyRuleSet,
2131 TransactionDenyRulesUpdate,
2132 TransactionV1,
2133 SignedTransaction,
2134 GasPayment,
2135 RandomnessStateUpdate,
2136 TransactionKind,
2137 EndOfEpochTransactionKind,
2138 ConsensusDeterminedVersionAssignments,
2139 CanceledTransaction,
2140 VersionAssignment,
2141 ConsensusCommitPrologueV1,
2142 ChangeEpoch,
2143 ChangeEpochV2,
2144 ChangeEpochV3,
2145 ChangeEpochV4,
2146 SystemPackage,
2147 GenesisTransaction,
2148 ProgrammableTransaction,
2149 SharedObjectReference,
2150 Input,
2151 Command,
2152 TransferObjects,
2153 SplitCoins,
2154 MergeCoins,
2155 Publish,
2156 MakeMoveVector,
2157 Upgrade,
2158 MoveCall,
2159);