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