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