Skip to main content

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