sui_sdk_types/transaction/mod.rs
1use crate::Digest;
2
3use super::Address;
4use super::CheckpointTimestamp;
5use super::EpochId;
6use super::GenesisObject;
7use super::Identifier;
8use super::Jwk;
9use super::JwkId;
10use super::ObjectReference;
11use super::ProtocolVersion;
12use super::TypeTag;
13use super::UserSignature;
14use super::Version;
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/// A transaction
24///
25/// # BCS
26///
27/// The BCS serialized form for this type is defined by the following ABNF:
28///
29/// ```text
30/// transaction = %x00 transaction-v1
31///
32/// transaction-v1 = transaction-kind address gas-payment transaction-expiration
33/// ```
34#[derive(Clone, Debug, PartialEq, Eq)]
35#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
36pub struct Transaction {
37 pub kind: TransactionKind,
38 pub sender: Address,
39 pub gas_payment: GasPayment,
40 pub expiration: TransactionExpiration,
41}
42
43#[derive(Clone, Debug, PartialEq, Eq)]
44#[cfg_attr(
45 feature = "serde",
46 derive(serde_derive::Serialize, serde_derive::Deserialize)
47)]
48#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
49pub struct SignedTransaction {
50 pub transaction: Transaction,
51 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
52 pub signatures: Vec<UserSignature>,
53}
54
55/// A TTL for a transaction
56///
57/// # BCS
58///
59/// The BCS serialized form for this type is defined by the following ABNF:
60///
61/// ```text
62/// transaction-expiration = %x00 ; none
63/// =/ %x01 u64 ; epoch
64/// ```
65#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Hash)]
66#[cfg_attr(
67 feature = "serde",
68 derive(serde_derive::Serialize, serde_derive::Deserialize)
69)]
70#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
71#[non_exhaustive]
72pub enum TransactionExpiration {
73 /// The transaction has no expiration
74 #[default]
75 None,
76
77 /// Validators wont sign a transaction unless the expiration Epoch
78 /// is greater than or equal to the current epoch
79 Epoch(EpochId),
80}
81
82/// Payment information for executing a transaction
83///
84/// # BCS
85///
86/// The BCS serialized form for this type is defined by the following ABNF:
87///
88/// ```text
89/// gas-payment = (vector object-ref) ; gas coin objects
90/// address ; owner
91/// u64 ; price
92/// u64 ; budget
93/// ```
94#[derive(Clone, Debug, PartialEq, Eq)]
95#[cfg_attr(
96 feature = "serde",
97 derive(serde_derive::Serialize, serde_derive::Deserialize)
98)]
99#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
100pub struct GasPayment {
101 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
102 pub objects: Vec<ObjectReference>,
103
104 /// Owner of the gas objects, either the transaction sender or a sponsor
105 pub owner: Address,
106
107 /// Gas unit price to use when charging for computation
108 ///
109 /// Must be greater-than-or-equal-to the network's current RGP (reference gas price)
110 pub price: u64,
111
112 /// Total budget willing to spend for the execution of a transaction
113 pub budget: u64,
114}
115
116/// Randomness update
117///
118/// # BCS
119///
120/// The BCS serialized form for this type is defined by the following ABNF:
121///
122/// ```text
123/// randomness-state-update = u64 u64 bytes u64
124/// ```
125#[derive(Clone, Debug, PartialEq, Eq)]
126#[cfg_attr(
127 feature = "serde",
128 derive(serde_derive::Serialize, serde_derive::Deserialize)
129)]
130#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
131pub struct RandomnessStateUpdate {
132 /// Epoch of the randomness state update transaction
133 pub epoch: u64,
134
135 /// Randomness round of the update
136 pub randomness_round: u64,
137
138 /// Updated random bytes
139 #[cfg_attr(
140 feature = "serde",
141 serde(with = "crate::_serde::ReadableBase64Encoded")
142 )]
143 pub random_bytes: Vec<u8>,
144
145 /// The initial version of the randomness object that it was shared at.
146 pub randomness_obj_initial_shared_version: u64,
147}
148
149/// Transaction type
150///
151/// # BCS
152///
153/// The BCS serialized form for this type is defined by the following ABNF:
154///
155/// ```text
156/// transaction-kind = %x00 ptb
157/// =/ %x01 change-epoch
158/// =/ %x02 genesis-transaction
159/// =/ %x03 consensus-commit-prologue
160/// =/ %x04 authenticator-state-update
161/// =/ %x05 (vector end-of-epoch-transaction-kind)
162/// =/ %x06 randomness-state-update
163/// =/ %x07 consensus-commit-prologue-v2
164/// =/ %x08 consensus-commit-prologue-v3
165/// =/ %x09 consensus-commit-prologue-v4
166/// =/ %x0A ptb
167/// ```
168#[derive(Clone, Debug, PartialEq, Eq)]
169#[cfg_attr(
170 feature = "serde",
171 derive(serde_derive::Serialize, serde_derive::Deserialize)
172)]
173#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
174#[non_exhaustive]
175pub enum TransactionKind {
176 /// A user transaction comprised of a list of native commands and move calls
177 ProgrammableTransaction(ProgrammableTransaction),
178
179 /// System transaction used to end an epoch.
180 ///
181 /// The ChangeEpoch variant is now deprecated (but the ChangeEpoch struct is still used by
182 /// EndOfEpochTransaction below).
183 ChangeEpoch(ChangeEpoch),
184
185 /// Transaction used to initialize the chain state.
186 ///
187 /// Only valid if in the genesis checkpoint (0) and if this is the very first transaction ever
188 /// executed on the chain.
189 Genesis(GenesisTransaction),
190
191 /// V1 consensus commit update
192 ConsensusCommitPrologue(ConsensusCommitPrologue),
193
194 /// Update set of valid JWKs used for zklogin
195 AuthenticatorStateUpdate(AuthenticatorStateUpdate),
196
197 /// Set of operations to run at the end of the epoch to close out the current epoch and start
198 /// the next one.
199 EndOfEpoch(
200 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
201 Vec<EndOfEpochTransactionKind>,
202 ),
203
204 /// Randomness update
205 RandomnessStateUpdate(RandomnessStateUpdate),
206
207 /// V2 consensus commit update
208 ConsensusCommitPrologueV2(ConsensusCommitPrologueV2),
209
210 /// V3 consensus commit update
211 ConsensusCommitPrologueV3(ConsensusCommitPrologueV3),
212
213 /// V4 consensus commit update
214 ConsensusCommitPrologueV4(ConsensusCommitPrologueV4),
215
216 /// A system transaction comprised of a list of native commands and move calls
217 ProgrammableSystemTransaction(ProgrammableTransaction),
218}
219
220/// Operation run at the end of an epoch
221///
222/// # BCS
223///
224/// The BCS serialized form for this type is defined by the following ABNF:
225///
226/// ```text
227/// end-of-epoch-transaction-kind = eoe-change-epoch
228/// =/ eoe-authenticator-state-create
229/// =/ eoe-authenticator-state-expire
230/// =/ eoe-randomness-state-create
231/// =/ eoe-deny-list-state-create
232/// =/ eoe-bridge-state-create
233/// =/ eoe-bridge-committee-init
234/// =/ eoe-store-execution-time-observations
235///
236/// eoe-change-epoch = %x00 change-epoch
237/// eoe-authenticator-state-create = %x01
238/// eoe-authenticator-state-expire = %x02 authenticator-state-expire
239/// eoe-randomness-state-create = %x03
240/// eoe-deny-list-state-create = %x04
241/// eoe-bridge-state-create = %x05 digest
242/// eoe-bridge-committee-init = %x06 u64
243/// eoe-store-execution-time-observations = %x07 stored-execution-time-observations
244/// ```
245#[derive(Clone, Debug, PartialEq, Eq)]
246#[cfg_attr(
247 feature = "serde",
248 derive(serde_derive::Serialize, serde_derive::Deserialize)
249)]
250#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
251#[non_exhaustive]
252pub enum EndOfEpochTransactionKind {
253 /// End the epoch and start the next one
254 ChangeEpoch(ChangeEpoch),
255
256 /// Create and initialize the authenticator object used for zklogin
257 AuthenticatorStateCreate,
258
259 /// Expire JWKs used for zklogin
260 AuthenticatorStateExpire(AuthenticatorStateExpire),
261
262 /// Create and initialize the randomness object
263 RandomnessStateCreate,
264
265 /// Create and initialize the deny list object
266 DenyListStateCreate,
267
268 /// Create and initialize the bridge object
269 BridgeStateCreate { chain_id: Digest },
270
271 /// Initialize the bridge committee
272 BridgeCommitteeInit { bridge_object_version: u64 },
273
274 /// Execution time observations from the committee to preserve cross epoch
275 StoreExecutionTimeObservations(ExecutionTimeObservations),
276
277 /// Create and initialize the accumulator root object
278 AccumulatorRootCreate,
279
280 /// Create and initialize the coin metadata registry object
281 CoinRegistryCreate,
282}
283
284/// Set of Execution Time Observations from the committee.
285///
286/// # BCS
287///
288/// The BCS serialized form for this type is defined by the following ABNF:
289///
290/// ```text
291/// stored-execution-time-observations = %x00 v1-stored-execution-time-observations
292///
293/// v1-stored-execution-time-observations = (vec
294/// execution-time-observation-key
295/// (vec execution-time-observation)
296/// )
297/// ```
298#[derive(Debug, Hash, PartialEq, Eq, Clone)]
299#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
300#[cfg_attr(
301 feature = "serde",
302 derive(serde_derive::Serialize, serde_derive::Deserialize)
303)]
304#[non_exhaustive]
305pub enum ExecutionTimeObservations {
306 V1(
307 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
308 Vec<(
309 ExecutionTimeObservationKey,
310 Vec<ValidatorExecutionTimeObservation>,
311 )>,
312 ),
313}
314
315/// An execution time observation from a particular validator
316///
317/// # BCS
318///
319/// The BCS serialized form for this type is defined by the following ABNF:
320///
321/// ```text
322/// execution-time-observation = bls-public-key duration
323/// duration = u64 ; seconds
324/// u32 ; subsecond nanoseconds
325/// ```
326#[derive(Debug, Hash, PartialEq, Eq, Clone)]
327#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
328#[cfg_attr(
329 feature = "serde",
330 derive(serde_derive::Serialize, serde_derive::Deserialize)
331)]
332pub struct ValidatorExecutionTimeObservation {
333 pub validator: crate::Bls12381PublicKey,
334 #[cfg_attr(feature = "proptest", strategy(proptest::strategy::Strategy::prop_map(proptest::arbitrary::any::<u32>(), |x| std::time::Duration::from_millis(x.into()))))]
335 pub duration: std::time::Duration,
336}
337
338/// Key for an execution time observation
339///
340/// # BCS
341///
342/// The BCS serialized form for this type is defined by the following ABNF:
343///
344/// ```text
345/// execution-time-observation-key = %x00 move-entry-point
346/// =/ %x01 ; transfer-objects
347/// =/ %x02 ; split-coins
348/// =/ %x03 ; merge-coins
349/// =/ %x04 ; publish
350/// =/ %x05 ; make-move-vec
351/// =/ %x06 ; upgrade
352/// ValidatorExecutionTimeObservation
353/// move-entry-point = address string string (vec type-tag)
354/// ```
355#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone)]
356#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
357#[cfg_attr(
358 feature = "serde",
359 derive(serde_derive::Serialize, serde_derive::Deserialize)
360)]
361#[non_exhaustive]
362pub enum ExecutionTimeObservationKey {
363 // Containts all the fields from `ProgrammableMoveCall` besides `arguments`.
364 MoveEntryPoint {
365 /// The package containing the module and function.
366 package: Address,
367 /// The specific module in the package containing the function.
368 module: String,
369 /// The function to be called.
370 function: String,
371 /// The type arguments to the function.
372 /// NOTE: This field is currently not populated.
373 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
374 type_arguments: Vec<TypeTag>,
375 },
376 TransferObjects,
377 SplitCoins,
378 MergeCoins,
379 Publish, // special case: should not be used; we only use hard-coded estimate for this
380 MakeMoveVec,
381 Upgrade,
382}
383
384/// Expire old JWKs
385///
386/// # BCS
387///
388/// The BCS serialized form for this type is defined by the following ABNF:
389///
390/// ```text
391/// authenticator-state-expire = u64 u64
392/// ```
393#[derive(Clone, Debug, PartialEq, Eq)]
394#[cfg_attr(
395 feature = "serde",
396 derive(serde_derive::Serialize, serde_derive::Deserialize)
397)]
398#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
399pub struct AuthenticatorStateExpire {
400 /// expire JWKs that have a lower epoch than this
401 pub min_epoch: u64,
402
403 /// The initial version of the authenticator object that it was shared at.
404 pub authenticator_object_initial_shared_version: u64,
405}
406
407/// Update the set of valid JWKs
408///
409/// # BCS
410///
411/// The BCS serialized form for this type is defined by the following ABNF:
412///
413/// ```text
414/// authenticator-state-update = u64 ; epoch
415/// u64 ; round
416/// (vector active-jwk)
417/// u64 ; initial version of the authenticator object
418/// ```
419#[derive(Clone, Debug, PartialEq, Eq)]
420#[cfg_attr(
421 feature = "serde",
422 derive(serde_derive::Serialize, serde_derive::Deserialize)
423)]
424#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
425pub struct AuthenticatorStateUpdate {
426 /// Epoch of the authenticator state update transaction
427 pub epoch: u64,
428
429 /// Consensus round of the authenticator state update
430 pub round: u64,
431
432 /// newly active jwks
433 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
434 pub new_active_jwks: Vec<ActiveJwk>,
435
436 /// The initial version of the authenticator object that it was shared at.
437 pub authenticator_obj_initial_shared_version: u64,
438}
439
440/// A new Jwk
441///
442/// # BCS
443///
444/// The BCS serialized form for this type is defined by the following ABNF:
445///
446/// ```text
447/// active-jwk = jwk-id jwk u64
448/// ```
449#[derive(Clone, Debug, PartialEq, Eq)]
450#[cfg_attr(
451 feature = "serde",
452 derive(serde_derive::Serialize, serde_derive::Deserialize)
453)]
454#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
455pub struct ActiveJwk {
456 /// Identifier used to uniquely identify a Jwk
457 pub jwk_id: JwkId,
458
459 /// The Jwk
460 pub jwk: Jwk,
461
462 /// Most recent epoch in which the jwk was validated
463 pub epoch: u64,
464}
465
466/// V1 of the consensus commit prologue system transaction
467///
468/// # BCS
469///
470/// The BCS serialized form for this type is defined by the following ABNF:
471///
472/// ```text
473/// consensus-commit-prologue = u64 u64 u64
474/// ```
475#[derive(Clone, Debug, PartialEq, Eq)]
476#[cfg_attr(
477 feature = "serde",
478 derive(serde_derive::Serialize, serde_derive::Deserialize)
479)]
480#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
481pub struct ConsensusCommitPrologue {
482 /// Epoch of the commit prologue transaction
483 pub epoch: u64,
484
485 /// Consensus round of the commit
486 pub round: u64,
487
488 /// Unix timestamp from consensus
489 pub commit_timestamp_ms: CheckpointTimestamp,
490}
491
492/// V2 of the consensus commit prologue system transaction
493///
494/// # BCS
495///
496/// The BCS serialized form for this type is defined by the following ABNF:
497///
498/// ```text
499/// consensus-commit-prologue-v2 = u64 u64 u64 digest
500/// ```
501#[derive(Clone, Debug, PartialEq, Eq)]
502#[cfg_attr(
503 feature = "serde",
504 derive(serde_derive::Serialize, serde_derive::Deserialize)
505)]
506#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
507pub struct ConsensusCommitPrologueV2 {
508 /// Epoch of the commit prologue transaction
509 pub epoch: u64,
510
511 /// Consensus round of the commit
512 pub round: u64,
513
514 /// Unix timestamp from consensus
515 pub commit_timestamp_ms: CheckpointTimestamp,
516
517 /// Digest of consensus output
518 pub consensus_commit_digest: Digest,
519}
520
521/// Version assignments performed by consensus
522///
523/// # BCS
524///
525/// The BCS serialized form for this type is defined by the following ABNF:
526///
527/// ```text
528/// consensus-determined-version-assignments = canceled-transactions
529///
530/// canceled-transactions = %x00 (vector canceled-transaction)
531/// = %x01 (vector canceled-transaction-v2)
532/// ```
533#[derive(Clone, Debug, PartialEq, Eq)]
534#[cfg_attr(
535 feature = "serde",
536 derive(serde_derive::Serialize, serde_derive::Deserialize)
537)]
538#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
539#[non_exhaustive]
540pub enum ConsensusDeterminedVersionAssignments {
541 /// Canceled transaction version assignment.
542 CanceledTransactions {
543 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
544 canceled_transactions: Vec<CanceledTransaction>,
545 },
546 /// Canceled transaction version assignment V2.
547 CanceledTransactionsV2 {
548 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
549 canceled_transactions: Vec<CanceledTransactionV2>,
550 },
551}
552
553/// A transaction that was canceled
554///
555/// # BCS
556///
557/// The BCS serialized form for this type is defined by the following ABNF:
558///
559/// ```text
560/// canceled-transaction = digest (vector version-assignment)
561/// ```
562#[derive(Clone, Debug, PartialEq, Eq)]
563#[cfg_attr(
564 feature = "serde",
565 derive(serde_derive::Serialize, serde_derive::Deserialize)
566)]
567#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
568pub struct CanceledTransaction {
569 pub digest: Digest,
570 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
571 pub version_assignments: Vec<VersionAssignment>,
572}
573
574/// Object version assignment from consensus
575///
576/// # BCS
577///
578/// The BCS serialized form for this type is defined by the following ABNF:
579///
580/// ```text
581/// version-assignment = address u64
582/// ```
583#[derive(Clone, Debug, PartialEq, Eq)]
584#[cfg_attr(
585 feature = "serde",
586 derive(serde_derive::Serialize, serde_derive::Deserialize)
587)]
588#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
589pub struct VersionAssignment {
590 pub object_id: Address,
591 pub version: Version,
592}
593
594/// A transaction that was canceled
595///
596/// # BCS
597///
598/// The BCS serialized form for this type is defined by the following ABNF:
599///
600/// ```text
601/// canceled-transaction-v2 = digest (vector version-assignment-v2)
602/// ```
603#[derive(Clone, Debug, PartialEq, Eq)]
604#[cfg_attr(
605 feature = "serde",
606 derive(serde_derive::Serialize, serde_derive::Deserialize)
607)]
608#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
609pub struct CanceledTransactionV2 {
610 pub digest: Digest,
611 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
612 pub version_assignments: Vec<VersionAssignmentV2>,
613}
614
615/// Object version assignment from consensus
616///
617/// # BCS
618///
619/// The BCS serialized form for this type is defined by the following ABNF:
620///
621/// ```text
622/// version-assignment-v2 = address u64 u64
623/// ```
624#[derive(Clone, Debug, PartialEq, Eq)]
625#[cfg_attr(
626 feature = "serde",
627 derive(serde_derive::Serialize, serde_derive::Deserialize)
628)]
629#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
630pub struct VersionAssignmentV2 {
631 pub object_id: Address,
632 pub start_version: Version,
633 pub version: Version,
634}
635
636/// V3 of the consensus commit prologue system transaction
637///
638/// # BCS
639///
640/// The BCS serialized form for this type is defined by the following ABNF:
641///
642/// ```text
643/// consensus-commit-prologue-v3 = u64 u64 (option u64) u64 digest
644/// consensus-determined-version-assignments
645/// ```
646#[derive(Clone, Debug, PartialEq, Eq)]
647#[cfg_attr(
648 feature = "serde",
649 derive(serde_derive::Serialize, serde_derive::Deserialize)
650)]
651#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
652pub struct ConsensusCommitPrologueV3 {
653 /// Epoch of the commit prologue transaction
654 pub epoch: u64,
655
656 /// Consensus round of the commit
657 pub round: u64,
658
659 /// The sub DAG index of the consensus commit. This field will be populated if there
660 /// are multiple consensus commits per round.
661 pub sub_dag_index: Option<u64>,
662
663 /// Unix timestamp from consensus
664 pub commit_timestamp_ms: CheckpointTimestamp,
665
666 /// Digest of consensus output
667 pub consensus_commit_digest: Digest,
668
669 /// Stores consensus handler determined shared object version assignments.
670 pub consensus_determined_version_assignments: ConsensusDeterminedVersionAssignments,
671}
672
673/// V4 of the consensus commit prologue system transaction
674///
675/// # BCS
676///
677/// The BCS serialized form for this type is defined by the following ABNF:
678///
679/// ```text
680/// consensus-commit-prologue-v4 = u64 u64 (option u64) u64 digest
681/// consensus-determined-version-assignments
682/// digest
683/// ```
684#[derive(Clone, Debug, PartialEq, Eq)]
685#[cfg_attr(
686 feature = "serde",
687 derive(serde_derive::Serialize, serde_derive::Deserialize)
688)]
689#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
690pub struct ConsensusCommitPrologueV4 {
691 /// Epoch of the commit prologue transaction
692 pub epoch: u64,
693
694 /// Consensus round of the commit
695 pub round: u64,
696
697 /// The sub DAG index of the consensus commit. This field will be populated if there
698 /// are multiple consensus commits per round.
699 pub sub_dag_index: Option<u64>,
700
701 /// Unix timestamp from consensus
702 pub commit_timestamp_ms: CheckpointTimestamp,
703
704 /// Digest of consensus output
705 pub consensus_commit_digest: Digest,
706
707 /// Stores consensus handler determined shared object version assignments.
708 pub consensus_determined_version_assignments: ConsensusDeterminedVersionAssignments,
709
710 /// Digest of any additional state computed by the consensus handler.
711 /// Used to detect forking bugs as early as possible.
712 pub additional_state_digest: Digest,
713}
714
715/// System transaction used to change the epoch
716///
717/// # BCS
718///
719/// The BCS serialized form for this type is defined by the following ABNF:
720///
721/// ```text
722/// change-epoch = u64 ; next epoch
723/// u64 ; protocol version
724/// u64 ; storage charge
725/// u64 ; computation charge
726/// u64 ; storage rebate
727/// u64 ; non-refundable storage fee
728/// u64 ; epoch start timestamp
729/// (vector system-package)
730/// ```
731#[derive(Clone, Debug, PartialEq, Eq)]
732#[cfg_attr(
733 feature = "serde",
734 derive(serde_derive::Serialize, serde_derive::Deserialize)
735)]
736#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
737pub struct ChangeEpoch {
738 /// The next (to become) epoch ID.
739 pub epoch: EpochId,
740
741 /// The protocol version in effect in the new epoch.
742 pub protocol_version: ProtocolVersion,
743
744 /// The total amount of gas charged for storage during the epoch.
745 pub storage_charge: u64,
746
747 /// The total amount of gas charged for computation during the epoch.
748 pub computation_charge: u64,
749
750 /// The amount of storage rebate refunded to the txn senders.
751 pub storage_rebate: u64,
752
753 /// The non-refundable storage fee.
754 pub non_refundable_storage_fee: u64,
755
756 /// Unix timestamp when epoch started
757 pub epoch_start_timestamp_ms: u64,
758
759 /// System packages (specifically framework and move stdlib) that are written before the new
760 /// epoch starts. This tracks framework upgrades on chain. When executing the ChangeEpoch txn,
761 /// the validator must write out the modules below. Modules are provided with the version they
762 /// will be upgraded to, their modules in serialized form (which include their package ID), and
763 /// a list of their transitive dependencies.
764 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
765 pub system_packages: Vec<SystemPackage>,
766}
767
768/// System package
769///
770/// # BCS
771///
772/// The BCS serialized form for this type is defined by the following ABNF:
773///
774/// ```text
775/// system-package = u64 ; version
776/// (vector bytes) ; modules
777/// (vector address) ; dependencies
778/// ```
779#[derive(Clone, Debug, PartialEq, Eq)]
780#[cfg_attr(
781 feature = "serde",
782 derive(serde_derive::Serialize, serde_derive::Deserialize)
783)]
784#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
785pub struct SystemPackage {
786 pub version: Version,
787 #[cfg_attr(
788 feature = "serde",
789 serde(
790 with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
791 )
792 )]
793 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
794 pub modules: Vec<Vec<u8>>,
795 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
796 pub dependencies: Vec<Address>,
797}
798
799/// The genesis transaction
800///
801/// # BCS
802///
803/// The BCS serialized form for this type is defined by the following ABNF:
804///
805/// ```text
806/// genesis-transaction = (vector genesis-object)
807/// ```
808#[derive(Clone, Debug, PartialEq, Eq)]
809#[cfg_attr(
810 feature = "serde",
811 derive(serde_derive::Serialize, serde_derive::Deserialize)
812)]
813#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
814pub struct GenesisTransaction {
815 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
816 pub objects: Vec<GenesisObject>,
817}
818
819/// A user transaction
820///
821/// Contains a series of native commands and move calls where the results of one command can be
822/// used in future commands.
823///
824/// # BCS
825///
826/// The BCS serialized form for this type is defined by the following ABNF:
827///
828/// ```text
829/// ptb = (vector input) (vector command)
830/// ```
831#[derive(Clone, Debug, PartialEq, Eq)]
832#[cfg_attr(
833 feature = "serde",
834 derive(serde_derive::Serialize, serde_derive::Deserialize)
835)]
836#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
837pub struct ProgrammableTransaction {
838 /// Input objects or primitive values
839 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=10).lift()))]
840 pub inputs: Vec<Input>,
841
842 /// The commands to be executed sequentially. A failure in any command will
843 /// result in the failure of the entire transaction.
844 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
845 pub commands: Vec<Command>,
846}
847
848/// An input to a user transaction
849///
850/// # BCS
851///
852/// The BCS serialized form for this type is defined by the following ABNF:
853///
854/// ```text
855/// input = input-pure / input-immutable-or-owned / input-shared / input-receiving
856///
857/// input-pure = %x00 bytes
858/// input-immutable-or-owned = %x01 object-ref
859/// input-shared = %x02 address u64 bool
860/// input-receiving = %x04 object-ref
861/// ```
862#[derive(Clone, Debug, PartialEq, Eq)]
863#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
864#[non_exhaustive]
865pub enum Input {
866 /// A move value serialized as BCS.
867 ///
868 /// For normal operations this is required to be a move primitive type and not contain structs
869 /// or objects.
870 Pure { value: Vec<u8> },
871
872 /// A move object that is either immutable or address owned
873 ImmutableOrOwned(ObjectReference),
874
875 /// A move object whose owner is "Shared"
876 Shared {
877 object_id: Address,
878 initial_shared_version: u64,
879
880 /// Controls whether the caller asks for a mutable reference to the shared object.
881 mutable: bool,
882 },
883
884 /// A move object that is attempted to be received in this transaction.
885 // TODO add discussion around what receiving is
886 Receiving(ObjectReference),
887}
888
889/// A single command in a programmable transaction.
890///
891/// # BCS
892///
893/// The BCS serialized form for this type is defined by the following ABNF:
894///
895/// ```text
896/// command = command-move-call
897/// =/ command-transfer-objects
898/// =/ command-split-coins
899/// =/ command-merge-coins
900/// =/ command-publish
901/// =/ command-make-move-vector
902/// =/ command-upgrade
903///
904/// command-move-call = %x00 move-call
905/// command-transfer-objects = %x01 transfer-objects
906/// command-split-coins = %x02 split-coins
907/// command-merge-coins = %x03 merge-coins
908/// command-publish = %x04 publish
909/// command-make-move-vector = %x05 make-move-vector
910/// command-upgrade = %x06 upgrade
911/// ```
912#[derive(Clone, Debug, PartialEq, Eq)]
913#[cfg_attr(
914 feature = "serde",
915 derive(serde_derive::Serialize, serde_derive::Deserialize)
916)]
917#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
918#[non_exhaustive]
919pub enum Command {
920 /// A call to either an entry or a public Move function
921 MoveCall(MoveCall),
922
923 /// `(Vec<forall T:key+store. T>, address)`
924 /// It sends n-objects to the specified address. These objects must have store
925 /// (public transfer) and either the previous owner must be an address or the object must
926 /// be newly created.
927 TransferObjects(TransferObjects),
928
929 /// `(&mut Coin<T>, Vec<u64>)` -> `Vec<Coin<T>>`
930 /// It splits off some amounts into a new coins with those amounts
931 SplitCoins(SplitCoins),
932
933 /// `(&mut Coin<T>, Vec<Coin<T>>)`
934 /// It merges n-coins into the first coin
935 MergeCoins(MergeCoins),
936
937 /// Publishes a Move package. It takes the package bytes and a list of the package's transitive
938 /// dependencies to link against on-chain.
939 Publish(Publish),
940
941 /// `forall T: Vec<T> -> vector<T>`
942 /// Given n-values of the same type, it constructs a vector. For non objects or an empty vector,
943 /// the type tag must be specified.
944 MakeMoveVector(MakeMoveVector),
945
946 /// Upgrades a Move package
947 /// Takes (in order):
948 /// 1. A vector of serialized modules for the package.
949 /// 2. A vector of object ids for the transitive dependencies of the new package.
950 /// 3. The object ID of the package being upgraded.
951 /// 4. An argument holding the `UpgradeTicket` that must have been produced from an earlier command in the same
952 /// programmable transaction.
953 Upgrade(Upgrade),
954}
955
956/// Command to transfer ownership of a set of objects to an address
957///
958/// # BCS
959///
960/// The BCS serialized form for this type is defined by the following ABNF:
961///
962/// ```text
963/// transfer-objects = (vector argument) argument
964/// ```
965#[derive(Clone, Debug, PartialEq, Eq)]
966#[cfg_attr(
967 feature = "serde",
968 derive(serde_derive::Serialize, serde_derive::Deserialize)
969)]
970#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
971pub struct TransferObjects {
972 /// Set of objects to transfer
973 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
974 pub objects: Vec<Argument>,
975
976 /// The address to transfer ownership to
977 pub address: Argument,
978}
979
980/// Command to split a single coin object into multiple coins
981///
982/// # BCS
983///
984/// The BCS serialized form for this type is defined by the following ABNF:
985///
986/// ```text
987/// split-coins = argument (vector argument)
988/// ```
989#[derive(Clone, Debug, PartialEq, Eq)]
990#[cfg_attr(
991 feature = "serde",
992 derive(serde_derive::Serialize, serde_derive::Deserialize)
993)]
994#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
995pub struct SplitCoins {
996 /// The coin to split
997 pub coin: Argument,
998
999 /// The amounts to split off
1000 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1001 pub amounts: Vec<Argument>,
1002}
1003
1004/// Command to merge multiple coins of the same type into a single coin
1005///
1006/// # BCS
1007///
1008/// The BCS serialized form for this type is defined by the following ABNF:
1009///
1010/// ```text
1011/// merge-coins = argument (vector argument)
1012/// ```
1013#[derive(Clone, Debug, PartialEq, Eq)]
1014#[cfg_attr(
1015 feature = "serde",
1016 derive(serde_derive::Serialize, serde_derive::Deserialize)
1017)]
1018#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1019pub struct MergeCoins {
1020 /// Coin to merge coins into
1021 pub coin: Argument,
1022
1023 /// Set of coins to merge into `coin`
1024 ///
1025 /// All listed coins must be of the same type and be the same type as `coin`
1026 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1027 pub coins_to_merge: Vec<Argument>,
1028}
1029
1030/// Command to publish a new move package
1031///
1032/// # BCS
1033///
1034/// The BCS serialized form for this type is defined by the following ABNF:
1035///
1036/// ```text
1037/// publish = (vector bytes) ; the serialized move modules
1038/// (vector address) ; the set of package dependencies
1039/// ```
1040#[derive(Clone, Debug, PartialEq, Eq)]
1041#[cfg_attr(
1042 feature = "serde",
1043 derive(serde_derive::Serialize, serde_derive::Deserialize)
1044)]
1045#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1046pub struct Publish {
1047 /// The serialized move modules
1048 #[cfg_attr(
1049 feature = "serde",
1050 serde(
1051 with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
1052 )
1053 )]
1054 pub modules: Vec<Vec<u8>>,
1055
1056 /// Set of packages that the to-be published package depends on
1057 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1058 pub dependencies: Vec<Address>,
1059}
1060
1061/// Command to build a move vector out of a set of individual elements
1062///
1063/// # BCS
1064///
1065/// The BCS serialized form for this type is defined by the following ABNF:
1066///
1067/// ```text
1068/// make-move-vector = (option type-tag) (vector argument)
1069/// ```
1070#[derive(Clone, Debug, PartialEq, Eq)]
1071#[cfg_attr(
1072 feature = "serde",
1073 derive(serde_derive::Serialize, serde_derive::Deserialize)
1074)]
1075#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1076pub struct MakeMoveVector {
1077 /// Type of the individual elements
1078 ///
1079 /// This is required to be set when the type can't be inferred, for example when the set of
1080 /// provided arguments are all pure input values.
1081 #[cfg_attr(feature = "serde", serde(rename = "type"))]
1082 pub type_: Option<TypeTag>,
1083
1084 /// The set individual elements to build the vector with
1085 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1086 pub elements: Vec<Argument>,
1087}
1088
1089/// Command to upgrade an already published package
1090///
1091/// # BCS
1092///
1093/// The BCS serialized form for this type is defined by the following ABNF:
1094///
1095/// ```text
1096/// upgrade = (vector bytes) ; move modules
1097/// (vector address) ; dependencies
1098/// address ; package-id of the package
1099/// argument ; upgrade ticket
1100/// ```
1101#[derive(Clone, Debug, PartialEq, Eq)]
1102#[cfg_attr(
1103 feature = "serde",
1104 derive(serde_derive::Serialize, serde_derive::Deserialize)
1105)]
1106#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1107pub struct Upgrade {
1108 /// The serialized move modules
1109 #[cfg_attr(
1110 feature = "serde",
1111 serde(
1112 with = "::serde_with::As::<Vec<::serde_with::IfIsHumanReadable<crate::_serde::Base64Encoded, ::serde_with::Bytes>>>"
1113 )
1114 )]
1115 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
1116 pub modules: Vec<Vec<u8>>,
1117
1118 /// Set of packages that the to-be published package depends on
1119 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1120 pub dependencies: Vec<Address>,
1121
1122 /// Package id of the package to upgrade
1123 pub package: Address,
1124
1125 /// Ticket authorizing the upgrade
1126 pub ticket: Argument,
1127}
1128
1129/// An argument to a programmable transaction command
1130///
1131/// # BCS
1132///
1133/// The BCS serialized form for this type is defined by the following ABNF:
1134///
1135/// ```text
1136/// argument = argument-gas
1137/// =/ argument-input
1138/// =/ argument-result
1139/// =/ argument-nested-result
1140///
1141/// argument-gas = %x00
1142/// argument-input = %x01 u16
1143/// argument-result = %x02 u16
1144/// argument-nested-result = %x03 u16 u16
1145/// ```
1146#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1147#[cfg_attr(
1148 feature = "serde",
1149 derive(serde_derive::Serialize, serde_derive::Deserialize)
1150)]
1151#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1152pub enum Argument {
1153 /// The gas coin. The gas coin can only be used by-ref, except for with
1154 /// `TransferObjects`, which can use it by-value.
1155 Gas,
1156
1157 /// One of the input objects or primitive values (from
1158 /// `ProgrammableTransaction` inputs)
1159 Input(u16),
1160
1161 /// The result of another command (from `ProgrammableTransaction` commands)
1162 Result(u16),
1163
1164 /// Like a `Result` but it accesses a nested result. Currently, the only usage
1165 /// of this is to access a value from a Move call with multiple return values.
1166 // (command index, subresult index)
1167 NestedResult(u16, u16),
1168}
1169
1170impl Argument {
1171 /// Turn a Result into a NestedResult. If the argument is not a Result, returns None.
1172 pub fn nested(&self, ix: u16) -> Option<Argument> {
1173 match self {
1174 Argument::Result(i) => Some(Argument::NestedResult(*i, ix)),
1175 _ => None,
1176 }
1177 }
1178}
1179
1180/// Command to call a move function
1181///
1182/// Functions that can be called by a `MoveCall` command are those that have a function signature
1183/// that is either `entry` or `public` (which don't have a reference return type).
1184///
1185/// # BCS
1186///
1187/// The BCS serialized form for this type is defined by the following ABNF:
1188///
1189/// ```text
1190/// move-call = address ; package id
1191/// identifier ; module name
1192/// identifier ; function name
1193/// (vector type-tag) ; type arguments, if any
1194/// (vector argument) ; input arguments
1195/// ```
1196#[derive(Clone, Debug, PartialEq, Eq)]
1197#[cfg_attr(
1198 feature = "serde",
1199 derive(serde_derive::Serialize, serde_derive::Deserialize)
1200)]
1201#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
1202pub struct MoveCall {
1203 /// The package containing the module and function.
1204 pub package: Address,
1205
1206 /// The specific module in the package containing the function.
1207 pub module: Identifier,
1208
1209 /// The function to be called.
1210 pub function: Identifier,
1211
1212 /// The type arguments to the function.
1213 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1214 pub type_arguments: Vec<TypeTag>,
1215
1216 /// The arguments to the function.
1217 #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
1218 pub arguments: Vec<Argument>,
1219}