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