sui_sdk_types/
execution_status.rs

1use super::Address;
2use super::Digest;
3use super::Identifier;
4use super::ObjectId;
5
6/// The status of an executed Transaction
7///
8/// # BCS
9///
10/// The BCS serialized form for this type is defined by the following ABNF:
11///
12/// ```text
13/// execution-status = success / failure
14/// success = %x00
15/// failure = %x01 execution-error (option u64)
16/// ```
17#[derive(Eq, PartialEq, Clone, Debug)]
18#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
19pub enum ExecutionStatus {
20    /// The Transaction successfully executed.
21    Success,
22
23    /// The Transaction didn't execute successfully.
24    ///
25    /// Failed transactions are still committed to the blockchain but any intended effects are
26    /// rolled back to prior to this transaction executing with the caveat that gas objects are
27    /// still smashed and gas usage is still charged.
28    Failure {
29        /// The error encountered during execution.
30        error: ExecutionError,
31        /// The command, if any, during which the error occurred.
32        #[cfg_attr(feature = "proptest", map(|x: Option<u16>| x.map(Into::into)))]
33        command: Option<u64>,
34    },
35}
36
37/// An error that can occur during the execution of a transaction
38///
39/// # BCS
40///
41/// The BCS serialized form for this type is defined by the following ABNF:
42///
43/// ```text
44/// execution-error =  insufficient-gas
45///                 =/ invalid-gas-object
46///                 =/ invariant-violation
47///                 =/ feature-not-yet-supported
48///                 =/ object-too-big
49///                 =/ package-too-big
50///                 =/ circular-object-ownership
51///                 =/ insufficient-coin-balance
52///                 =/ coin-balance-overflow
53///                 =/ publish-error-non-zero-address
54///                 =/ sui-move-verification-error
55///                 =/ move-primitive-runtime-error
56///                 =/ move-abort
57///                 =/ vm-verification-or-deserialization-error
58///                 =/ vm-invariant-violation
59///                 =/ function-not-found
60///                 =/ arity-mismatch
61///                 =/ type-arity-mismatch
62///                 =/ non-entry-function-invoked
63///                 =/ command-argument-error
64///                 =/ type-argument-error
65///                 =/ unused-value-without-drop
66///                 =/ invalid-public-function-return-type
67///                 =/ invalid-transfer-object
68///                 =/ effects-too-large
69///                 =/ publish-upgrade-missing-dependency
70///                 =/ publish-upgrade-dependency-downgrade
71///                 =/ package-upgrade-error
72///                 =/ written-objects-too-large
73///                 =/ certificate-denied
74///                 =/ sui-move-verification-timedout
75///                 =/ shared-object-operation-not-allowed
76///                 =/ input-object-deleted
77///                 =/ execution-canceled-due-to-shared-object-congestion
78///                 =/ address-denied-for-coin
79///                 =/ coin-type-global-pause
80///                 =/ execution-canceled-due-to-randomness-unavailable
81///
82/// insufficient-gas                                    = %x00
83/// invalid-gas-object                                  = %x01
84/// invariant-violation                                 = %x02
85/// feature-not-yet-supported                           = %x03
86/// object-too-big                                      = %x04 u64 u64
87/// package-too-big                                     = %x05 u64 u64
88/// circular-object-ownership                           = %x06 object-id
89/// insufficient-coin-balance                           = %x07
90/// coin-balance-overflow                               = %x08
91/// publish-error-non-zero-address                      = %x09
92/// sui-move-verification-error                         = %x0a
93/// move-primitive-runtime-error                        = %x0b (option move-location)
94/// move-abort                                          = %x0c move-location u64
95/// vm-verification-or-deserialization-error            = %x0d
96/// vm-invariant-violation                              = %x0e
97/// function-not-found                                  = %x0f
98/// arity-mismatch                                      = %x10
99/// type-arity-mismatch                                 = %x11
100/// non-entry-function-invoked                          = %x12
101/// command-argument-error                              = %x13 u16 command-argument-error
102/// type-argument-error                                 = %x14 u16 type-argument-error
103/// unused-value-without-drop                           = %x15 u16 u16
104/// invalid-public-function-return-type                 = %x16 u16
105/// invalid-transfer-object                             = %x17
106/// effects-too-large                                   = %x18 u64 u64
107/// publish-upgrade-missing-dependency                  = %x19
108/// publish-upgrade-dependency-downgrade                = %x1a
109/// package-upgrade-error                               = %x1b package-upgrade-error
110/// written-objects-too-large                           = %x1c u64 u64
111/// certificate-denied                                  = %x1d
112/// sui-move-verification-timedout                      = %x1e
113/// shared-object-operation-not-allowed                 = %x1f
114/// input-object-deleted                                = %x20
115/// execution-canceled-due-to-shared-object-congestion = %x21 (vector object-id)
116/// address-denied-for-coin                             = %x22 address string
117/// coin-type-global-pause                              = %x23 string
118/// execution-canceled-due-to-randomness-unavailable   = %x24
119/// ```
120#[derive(Eq, PartialEq, Clone, Debug)]
121#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
122pub enum ExecutionError {
123    //
124    // General transaction errors
125    //
126    /// Insufficient Gas
127    InsufficientGas,
128    /// Invalid Gas Object.
129    InvalidGasObject,
130    /// Invariant Violation
131    InvariantViolation,
132    /// Attempted to used feature that is not supported yet
133    FeatureNotYetSupported,
134    /// Move object is larger than the maximum allowed size
135    ObjectTooBig {
136        object_size: u64,
137        max_object_size: u64,
138    },
139    /// Package is larger than the maximum allowed size
140    PackageTooBig {
141        object_size: u64,
142        max_object_size: u64,
143    },
144    /// Circular Object Ownership
145    CircularObjectOwnership { object: ObjectId },
146
147    //
148    // Coin errors
149    //
150    /// Insufficient coin balance for requested operation
151    InsufficientCoinBalance,
152    /// Coin balance overflowed an u64
153    CoinBalanceOverflow,
154
155    //
156    // Publish/Upgrade errors
157    //
158    /// Publish Error, Non-zero Address.
159    /// The modules in the package must have their self-addresses set to zero.
160    PublishErrorNonZeroAddress,
161
162    /// Sui Move Bytecode Verification Error.
163    SuiMoveVerificationError,
164
165    //
166    // MoveVm Errors
167    //
168    /// Error from a non-abort instruction.
169    /// Possible causes:
170    ///     Arithmetic error, stack overflow, max value depth, etc."
171    MovePrimitiveRuntimeError { location: Option<MoveLocation> },
172    /// Move runtime abort
173    MoveAbort { location: MoveLocation, code: u64 },
174    /// Bytecode verification error.
175    VmVerificationOrDeserializationError,
176    /// MoveVm invariant violation
177    VmInvariantViolation,
178
179    //
180    // Programmable Transaction Errors
181    //
182    /// Function not found
183    FunctionNotFound,
184    /// Arity mismatch for Move function.
185    /// The number of arguments does not match the number of parameters
186    ArityMismatch,
187    /// Type arity mismatch for Move function.
188    /// Mismatch between the number of actual versus expected type arguments.
189    TypeArityMismatch,
190    /// Non Entry Function Invoked. Move Call must start with an entry function.
191    NonEntryFunctionInvoked,
192    /// Invalid command argument
193    CommandArgumentError {
194        argument: u16,
195        kind: CommandArgumentError,
196    },
197    /// Type argument error
198    TypeArgumentError {
199        /// Index of the problematic type argument
200        type_argument: u16,
201        kind: TypeArgumentError,
202    },
203    /// Unused result without the drop ability.
204    UnusedValueWithoutDrop { result: u16, subresult: u16 },
205    /// Invalid public Move function signature.
206    /// Unsupported return type for return value
207    InvalidPublicFunctionReturnType { index: u16 },
208    /// Invalid Transfer Object, object does not have public transfer.
209    InvalidTransferObject,
210
211    //
212    // Post-execution errors
213    //
214    /// Effects from the transaction are too large
215    EffectsTooLarge { current_size: u64, max_size: u64 },
216
217    /// Publish or Upgrade is missing dependency
218    PublishUpgradeMissingDependency,
219
220    /// Publish or Upgrade dependency downgrade.
221    ///
222    /// Indirect (transitive) dependency of published or upgraded package has been assigned an
223    /// on-chain version that is less than the version required by one of the package's
224    /// transitive dependencies.
225    PublishUpgradeDependencyDowngrade,
226
227    /// Invalid package upgrade
228    PackageUpgradeError { kind: PackageUpgradeError },
229
230    /// Indicates the transaction tried to write objects too large to storage
231    WrittenObjectsTooLarge {
232        object_size: u64,
233        max_object_size: u64,
234    },
235
236    /// Certificate is on the deny list
237    CertificateDenied,
238
239    /// Sui Move Bytecode verification timed out.
240    SuiMoveVerificationTimedout,
241
242    /// The requested shared object operation is not allowed
243    SharedObjectOperationNotAllowed,
244
245    /// Requested shared object has been deleted
246    InputObjectDeleted,
247
248    /// Certificate is canceled due to congestion on shared objects
249    ExecutionCanceledDueToSharedObjectCongestion { congested_objects: Vec<ObjectId> },
250
251    /// Address is denied for this coin type
252    AddressDeniedForCoin { address: Address, coin_type: String },
253
254    /// Coin type is globally paused for use
255    CoinTypeGlobalPause { coin_type: String },
256
257    /// Certificate is canceled because randomness could not be generated this epoch
258    ExecutionCanceledDueToRandomnessUnavailable,
259
260    /// Move vector element (passed to MakeMoveVec) with size {value_size} is larger \
261    /// than the maximum size {max_scaled_size}. Note that this maximum is scaled based on the \
262    /// type of the vector element.
263    MoveVectorElemTooBig {
264        value_size: u64,
265        max_scaled_size: u64,
266    },
267
268    /// Move value (possibly an upgrade ticket or a dev-inspect value) with size {value_size} \
269    /// is larger than the maximum size  {max_scaled_size}. Note that this maximum is scaled based \
270    /// on the type of the value.
271    MoveRawValueTooBig {
272        value_size: u64,
273        max_scaled_size: u64,
274    },
275
276    /// A valid linkage was unable to be determined for the transaction or one of its commands.
277    InvalidLinkage,
278}
279
280/// Location in move bytecode where an error occurred
281///
282/// # BCS
283///
284/// The BCS serialized form for this type is defined by the following ABNF:
285///
286/// ```text
287/// move-location = object-id identifier u16 u16 (option identifier)
288/// ```
289#[derive(Eq, PartialEq, Clone, Debug)]
290#[cfg_attr(
291    feature = "serde",
292    derive(serde_derive::Serialize, serde_derive::Deserialize)
293)]
294#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
295pub struct MoveLocation {
296    /// The package id
297    pub package: ObjectId,
298
299    /// The module name
300    pub module: Identifier,
301
302    /// The function index
303    pub function: u16,
304
305    /// Index into the code stream for a jump. The offset is relative to the beginning of
306    /// the instruction stream.
307    pub instruction: u16,
308
309    /// The name of the function if available
310    pub function_name: Option<Identifier>,
311}
312
313/// An error with an argument to a command
314///
315/// # BCS
316///
317/// The BCS serialized form for this type is defined by the following ABNF:
318///
319/// ```text
320/// command-argument-error =  type-mismatch
321///                        =/ invalid-bcs-bytes
322///                        =/ invalid-usage-of-pure-argument
323///                        =/ invalid-argument-to-private-entry-function
324///                        =/ index-out-of-bounds
325///                        =/ secondary-index-out-of-bound
326///                        =/ invalid-result-arity
327///                        =/ invalid-gas-coin-usage
328///                        =/ invalid-value-usage
329///                        =/ invalid-object-by-value
330///                        =/ invalid-object-by-mut-ref
331///                        =/ shared-object-operation-not-allowed
332///
333/// type-mismatch                               = %x00
334/// invalid-bcs-bytes                           = %x01
335/// invalid-usage-of-pure-argument              = %x02
336/// invalid-argument-to-private-entry-function  = %x03
337/// index-out-of-bounds                         = %x04 u16
338/// secondary-index-out-of-bound                = %x05 u16 u16
339/// invalid-result-arity                        = %x06 u16
340/// invalid-gas-coin-usage                      = %x07
341/// invalid-value-usage                         = %x08
342/// invalid-object-by-value                     = %x09
343/// invalid-object-by-mut-ref                   = %x0a
344/// shared-object-operation-not-allowed         = %x0b
345/// ```
346#[derive(Eq, PartialEq, Clone, Debug)]
347#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
348pub enum CommandArgumentError {
349    /// The type of the value does not match the expected type
350    TypeMismatch,
351
352    /// The argument cannot be deserialized into a value of the specified type
353    InvalidBcsBytes,
354
355    /// The argument cannot be instantiated from raw bytes
356    InvalidUsageOfPureArgument,
357
358    /// Invalid argument to private entry function.
359    /// Private entry functions cannot take arguments from other Move functions.
360    InvalidArgumentToPrivateEntryFunction,
361
362    /// Out of bounds access to input or results
363    IndexOutOfBounds { index: u16 },
364
365    /// Out of bounds access to subresult
366    SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
367
368    /// Invalid usage of result.
369    /// Expected a single result but found either no return value or multiple.
370    InvalidResultArity { result: u16 },
371
372    /// Invalid usage of Gas coin.
373    /// The Gas coin can only be used by-value with a TransferObjects command.
374    InvalidGasCoinUsage,
375
376    /// Invalid usage of move value.
377    //     Mutably borrowed values require unique usage.
378    //     Immutably borrowed values cannot be taken or borrowed mutably.
379    //     Taken values cannot be used again.
380    InvalidValueUsage,
381
382    /// Immutable objects cannot be passed by-value.
383    InvalidObjectByValue,
384
385    /// Immutable objects cannot be passed by mutable reference, &mut.
386    InvalidObjectByMutRef,
387
388    /// Shared object operations such a wrapping, freezing, or converting to owned are not
389    /// allowed.
390    SharedObjectOperationNotAllowed,
391
392    /// Invalid argument arity. Expected a single argument but found a result that expanded to
393    /// multiple arguments.
394    InvalidArgumentArity,
395}
396
397/// An error with a upgrading a package
398///
399/// # BCS
400///
401/// The BCS serialized form for this type is defined by the following ABNF:
402///
403/// ```text
404/// package-upgrade-error = unable-to-fetch-package /
405///                         not-a-package           /
406///                         incompatible-upgrade    /
407///                         digest-does-not-match   /
408///                         unknown-upgrade-policy  /
409///                         package-id-does-not-match
410///
411/// unable-to-fetch-package     = %x00 object-id
412/// not-a-package               = %x01 object-id
413/// incompatible-upgrade        = %x02
414/// digest-does-not-match       = %x03 digest
415/// unknown-upgrade-policy      = %x04 u8
416/// package-id-does-not-match   = %x05 object-id object-id
417/// ```
418#[derive(Eq, PartialEq, Clone, Debug)]
419#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
420pub enum PackageUpgradeError {
421    /// Unable to fetch package
422    UnableToFetchPackage { package_id: ObjectId },
423
424    /// Object is not a package
425    NotAPackage { object_id: ObjectId },
426
427    /// Package upgrade is incompatible with previous version
428    IncompatibleUpgrade,
429
430    /// Digest in upgrade ticket and computed digest differ
431    DigestDoesNotMatch { digest: Digest },
432
433    /// Upgrade policy is not valid
434    UnknownUpgradePolicy { policy: u8 },
435
436    /// PackageId does not matach PackageId in upgrade ticket
437    PackageIdDoesNotMatch {
438        package_id: ObjectId,
439        ticket_id: ObjectId,
440    },
441}
442
443/// An error with a type argument
444///
445/// # BCS
446///
447/// The BCS serialized form for this type is defined by the following ABNF:
448///
449/// ```text
450/// type-argument-error = type-not-found / constraint-not-satisfied
451/// type-not-found = %x00
452/// constraint-not-satisfied = %x01
453/// ```
454#[derive(Eq, PartialEq, Clone, Copy, Debug)]
455#[cfg_attr(
456    feature = "serde",
457    derive(serde_derive::Serialize, serde_derive::Deserialize),
458    serde(rename_all = "snake_case")
459)]
460#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
461pub enum TypeArgumentError {
462    /// A type was not found in the module specified
463    TypeNotFound,
464
465    /// A type provided did not match the specified constraint
466    ConstraintNotSatisfied,
467}
468
469#[cfg(feature = "serde")]
470#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
471mod serialization {
472    use super::*;
473
474    use serde::Deserialize;
475    use serde::Deserializer;
476    use serde::Serialize;
477    use serde::Serializer;
478
479    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
480    #[serde(rename = "ExecutionStatus")]
481    struct ReadableExecutionStatus {
482        success: bool,
483        #[serde(skip_serializing_if = "Option::is_none")]
484        status: Option<FailureStatus>,
485    }
486
487    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
488    struct FailureStatus {
489        error: ExecutionError,
490        #[serde(skip_serializing_if = "Option::is_none")]
491        command: Option<u16>,
492    }
493
494    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
495    enum BinaryExecutionStatus {
496        Success,
497        Failure {
498            error: ExecutionError,
499            command: Option<u64>,
500        },
501    }
502
503    impl Serialize for ExecutionStatus {
504        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
505        where
506            S: Serializer,
507        {
508            if serializer.is_human_readable() {
509                let readable = match self.clone() {
510                    ExecutionStatus::Success => ReadableExecutionStatus {
511                        success: true,
512                        status: None,
513                    },
514                    ExecutionStatus::Failure { error, command } => ReadableExecutionStatus {
515                        success: false,
516                        status: Some(FailureStatus {
517                            error,
518                            command: command.map(|c| c as u16),
519                        }),
520                    },
521                };
522                readable.serialize(serializer)
523            } else {
524                let binary = match self.clone() {
525                    ExecutionStatus::Success => BinaryExecutionStatus::Success,
526                    ExecutionStatus::Failure { error, command } => {
527                        BinaryExecutionStatus::Failure { error, command }
528                    }
529                };
530                binary.serialize(serializer)
531            }
532        }
533    }
534
535    impl<'de> Deserialize<'de> for ExecutionStatus {
536        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
537        where
538            D: Deserializer<'de>,
539        {
540            if deserializer.is_human_readable() {
541                let ReadableExecutionStatus { success, status } =
542                    Deserialize::deserialize(deserializer)?;
543                match (success, status) {
544                    (true, None) => Ok(ExecutionStatus::Success),
545                    (false, Some(FailureStatus { error, command })) => {
546                        Ok(ExecutionStatus::Failure {
547                            error,
548                            command: command.map(Into::into),
549                        })
550                    }
551                    // invalid cases
552                    (true, Some(_)) | (false, None) => {
553                        Err(serde::de::Error::custom("invalid execution status"))
554                    }
555                }
556            } else {
557                BinaryExecutionStatus::deserialize(deserializer).map(|readable| match readable {
558                    BinaryExecutionStatus::Success => Self::Success,
559                    BinaryExecutionStatus::Failure { error, command } => {
560                        Self::Failure { error, command }
561                    }
562                })
563            }
564        }
565    }
566
567    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
568    #[serde(tag = "error", rename_all = "snake_case")]
569    enum ReadableExecutionError {
570        InsufficientGas,
571        InvalidGasObject,
572        InvariantViolation,
573        FeatureNotYetSupported,
574        ObjectTooBig {
575            #[serde(with = "crate::_serde::ReadableDisplay")]
576            object_size: u64,
577            #[serde(with = "crate::_serde::ReadableDisplay")]
578            max_object_size: u64,
579        },
580        PackageTooBig {
581            #[serde(with = "crate::_serde::ReadableDisplay")]
582            object_size: u64,
583            #[serde(with = "crate::_serde::ReadableDisplay")]
584            max_object_size: u64,
585        },
586        CircularObjectOwnership {
587            object: ObjectId,
588        },
589        InsufficientCoinBalance,
590        CoinBalanceOverflow,
591        PublishErrorNonZeroAddress,
592        SuiMoveVerificationError,
593        MovePrimitiveRuntimeError {
594            location: Option<MoveLocation>,
595        },
596        MoveAbort {
597            location: MoveLocation,
598            #[serde(with = "crate::_serde::ReadableDisplay")]
599            code: u64,
600        },
601        VmVerificationOrDeserializationError,
602        VmInvariantViolation,
603        FunctionNotFound,
604        ArityMismatch,
605        TypeArityMismatch,
606        NonEntryFunctionInvoked,
607        CommandArgumentError {
608            argument: u16,
609            kind: CommandArgumentError,
610        },
611        TypeArgumentError {
612            type_argument: u16,
613            kind: TypeArgumentError,
614        },
615        UnusedValueWithoutDrop {
616            result: u16,
617            subresult: u16,
618        },
619        InvalidPublicFunctionReturnType {
620            index: u16,
621        },
622        InvalidTransferObject,
623        EffectsTooLarge {
624            #[serde(with = "crate::_serde::ReadableDisplay")]
625            current_size: u64,
626            #[serde(with = "crate::_serde::ReadableDisplay")]
627            max_size: u64,
628        },
629        PublishUpgradeMissingDependency,
630        PublishUpgradeDependencyDowngrade,
631        PackageUpgradeError {
632            kind: PackageUpgradeError,
633        },
634        WrittenObjectsTooLarge {
635            #[serde(with = "crate::_serde::ReadableDisplay")]
636            object_size: u64,
637            #[serde(with = "crate::_serde::ReadableDisplay")]
638            max_object_size: u64,
639        },
640        CertificateDenied,
641        SuiMoveVerificationTimedout,
642        SharedObjectOperationNotAllowed,
643        InputObjectDeleted,
644        ExecutionCanceledDueToSharedObjectCongestion {
645            congested_objects: Vec<ObjectId>,
646        },
647
648        AddressDeniedForCoin {
649            address: Address,
650            coin_type: String,
651        },
652
653        CoinTypeGlobalPause {
654            coin_type: String,
655        },
656
657        ExecutionCanceledDueToRandomnessUnavailable,
658
659        MoveVectorElemTooBig {
660            value_size: u64,
661            max_scaled_size: u64,
662        },
663
664        MoveRawValueTooBig {
665            value_size: u64,
666            max_scaled_size: u64,
667        },
668
669        InvalidLinkage,
670    }
671
672    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
673    enum BinaryExecutionError {
674        InsufficientGas,
675        InvalidGasObject,
676        InvariantViolation,
677        FeatureNotYetSupported,
678        ObjectTooBig {
679            object_size: u64,
680            max_object_size: u64,
681        },
682        PackageTooBig {
683            object_size: u64,
684            max_object_size: u64,
685        },
686        CircularObjectOwnership {
687            object: ObjectId,
688        },
689        InsufficientCoinBalance,
690        CoinBalanceOverflow,
691        PublishErrorNonZeroAddress,
692        SuiMoveVerificationError,
693        MovePrimitiveRuntimeError {
694            location: Option<MoveLocation>,
695        },
696        MoveAbort {
697            location: MoveLocation,
698            code: u64,
699        },
700        VmVerificationOrDeserializationError,
701        VmInvariantViolation,
702        FunctionNotFound,
703        ArityMismatch,
704        TypeArityMismatch,
705        NonEntryFunctionInvoked,
706        CommandArgumentError {
707            argument: u16,
708            kind: CommandArgumentError,
709        },
710        TypeArgumentError {
711            type_argument: u16,
712            kind: TypeArgumentError,
713        },
714        UnusedValueWithoutDrop {
715            result: u16,
716            subresult: u16,
717        },
718        InvalidPublicFunctionReturnType {
719            index: u16,
720        },
721        InvalidTransferObject,
722        EffectsTooLarge {
723            current_size: u64,
724            max_size: u64,
725        },
726        PublishUpgradeMissingDependency,
727        PublishUpgradeDependencyDowngrade,
728        PackageUpgradeError {
729            kind: PackageUpgradeError,
730        },
731        WrittenObjectsTooLarge {
732            object_size: u64,
733            max_object_size: u64,
734        },
735        CertificateDenied,
736        SuiMoveVerificationTimedout,
737        SharedObjectOperationNotAllowed,
738        InputObjectDeleted,
739        ExecutionCanceledDueToSharedObjectCongestion {
740            congested_objects: Vec<ObjectId>,
741        },
742
743        AddressDeniedForCoin {
744            address: Address,
745            coin_type: String,
746        },
747
748        CoinTypeGlobalPause {
749            coin_type: String,
750        },
751
752        ExecutionCanceledDueToRandomnessUnavailable,
753
754        MoveVectorElemTooBig {
755            value_size: u64,
756            max_scaled_size: u64,
757        },
758
759        MoveRawValueTooBig {
760            value_size: u64,
761            max_scaled_size: u64,
762        },
763
764        InvalidLinkage,
765    }
766
767    impl Serialize for ExecutionError {
768        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
769        where
770            S: Serializer,
771        {
772            if serializer.is_human_readable() {
773                let readable = match self.clone() {
774                    Self::InsufficientGas => ReadableExecutionError::InsufficientGas,
775                    Self::InvalidGasObject => ReadableExecutionError::InvalidGasObject,
776                    Self::InvariantViolation => ReadableExecutionError::InvariantViolation,
777                    Self::FeatureNotYetSupported => ReadableExecutionError::FeatureNotYetSupported,
778                    Self::ObjectTooBig {
779                        object_size,
780                        max_object_size,
781                    } => ReadableExecutionError::ObjectTooBig {
782                        object_size,
783                        max_object_size,
784                    },
785                    Self::PackageTooBig {
786                        object_size,
787                        max_object_size,
788                    } => ReadableExecutionError::PackageTooBig {
789                        object_size,
790                        max_object_size,
791                    },
792                    Self::CircularObjectOwnership { object } => {
793                        ReadableExecutionError::CircularObjectOwnership { object }
794                    }
795                    Self::InsufficientCoinBalance => {
796                        ReadableExecutionError::InsufficientCoinBalance
797                    }
798                    Self::CoinBalanceOverflow => ReadableExecutionError::CoinBalanceOverflow,
799                    Self::PublishErrorNonZeroAddress => {
800                        ReadableExecutionError::PublishErrorNonZeroAddress
801                    }
802                    Self::SuiMoveVerificationError => {
803                        ReadableExecutionError::SuiMoveVerificationError
804                    }
805                    Self::MovePrimitiveRuntimeError { location } => {
806                        ReadableExecutionError::MovePrimitiveRuntimeError { location }
807                    }
808                    Self::MoveAbort { location, code } => {
809                        ReadableExecutionError::MoveAbort { location, code }
810                    }
811                    Self::VmVerificationOrDeserializationError => {
812                        ReadableExecutionError::VmVerificationOrDeserializationError
813                    }
814                    Self::VmInvariantViolation => ReadableExecutionError::VmInvariantViolation,
815                    Self::FunctionNotFound => ReadableExecutionError::FunctionNotFound,
816                    Self::ArityMismatch => ReadableExecutionError::ArityMismatch,
817                    Self::TypeArityMismatch => ReadableExecutionError::TypeArityMismatch,
818                    Self::NonEntryFunctionInvoked => {
819                        ReadableExecutionError::NonEntryFunctionInvoked
820                    }
821                    Self::CommandArgumentError { argument, kind } => {
822                        ReadableExecutionError::CommandArgumentError { argument, kind }
823                    }
824                    Self::TypeArgumentError {
825                        type_argument,
826                        kind,
827                    } => ReadableExecutionError::TypeArgumentError {
828                        type_argument,
829                        kind,
830                    },
831                    Self::UnusedValueWithoutDrop { result, subresult } => {
832                        ReadableExecutionError::UnusedValueWithoutDrop { result, subresult }
833                    }
834                    Self::InvalidPublicFunctionReturnType { index } => {
835                        ReadableExecutionError::InvalidPublicFunctionReturnType { index }
836                    }
837                    Self::InvalidTransferObject => ReadableExecutionError::InvalidTransferObject,
838                    Self::EffectsTooLarge {
839                        current_size,
840                        max_size,
841                    } => ReadableExecutionError::EffectsTooLarge {
842                        current_size,
843                        max_size,
844                    },
845                    Self::PublishUpgradeMissingDependency => {
846                        ReadableExecutionError::PublishUpgradeMissingDependency
847                    }
848                    Self::PublishUpgradeDependencyDowngrade => {
849                        ReadableExecutionError::PublishUpgradeDependencyDowngrade
850                    }
851                    Self::PackageUpgradeError { kind } => {
852                        ReadableExecutionError::PackageUpgradeError { kind }
853                    }
854                    Self::WrittenObjectsTooLarge {
855                        object_size,
856                        max_object_size,
857                    } => ReadableExecutionError::WrittenObjectsTooLarge {
858                        object_size,
859                        max_object_size,
860                    },
861                    Self::CertificateDenied => ReadableExecutionError::CertificateDenied,
862                    Self::SuiMoveVerificationTimedout => {
863                        ReadableExecutionError::SuiMoveVerificationTimedout
864                    }
865                    Self::SharedObjectOperationNotAllowed => {
866                        ReadableExecutionError::SharedObjectOperationNotAllowed
867                    }
868                    Self::InputObjectDeleted => ReadableExecutionError::InputObjectDeleted,
869                    Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects } => {
870                        ReadableExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
871                            congested_objects,
872                        }
873                    }
874                    Self::AddressDeniedForCoin { address, coin_type } => {
875                        ReadableExecutionError::AddressDeniedForCoin { address, coin_type }
876                    }
877                    Self::CoinTypeGlobalPause { coin_type } => {
878                        ReadableExecutionError::CoinTypeGlobalPause { coin_type }
879                    }
880                    Self::ExecutionCanceledDueToRandomnessUnavailable => {
881                        ReadableExecutionError::ExecutionCanceledDueToRandomnessUnavailable
882                    }
883                    Self::MoveVectorElemTooBig {
884                        value_size,
885                        max_scaled_size,
886                    } => ReadableExecutionError::MoveVectorElemTooBig {
887                        value_size,
888                        max_scaled_size,
889                    },
890                    Self::MoveRawValueTooBig {
891                        value_size,
892                        max_scaled_size,
893                    } => ReadableExecutionError::MoveRawValueTooBig {
894                        value_size,
895                        max_scaled_size,
896                    },
897                    Self::InvalidLinkage => ReadableExecutionError::InvalidLinkage,
898                };
899                readable.serialize(serializer)
900            } else {
901                let binary = match self.clone() {
902                    Self::InsufficientGas => BinaryExecutionError::InsufficientGas,
903                    Self::InvalidGasObject => BinaryExecutionError::InvalidGasObject,
904                    Self::InvariantViolation => BinaryExecutionError::InvariantViolation,
905                    Self::FeatureNotYetSupported => BinaryExecutionError::FeatureNotYetSupported,
906                    Self::ObjectTooBig {
907                        object_size,
908                        max_object_size,
909                    } => BinaryExecutionError::ObjectTooBig {
910                        object_size,
911                        max_object_size,
912                    },
913                    Self::PackageTooBig {
914                        object_size,
915                        max_object_size,
916                    } => BinaryExecutionError::PackageTooBig {
917                        object_size,
918                        max_object_size,
919                    },
920                    Self::CircularObjectOwnership { object } => {
921                        BinaryExecutionError::CircularObjectOwnership { object }
922                    }
923                    Self::InsufficientCoinBalance => BinaryExecutionError::InsufficientCoinBalance,
924                    Self::CoinBalanceOverflow => BinaryExecutionError::CoinBalanceOverflow,
925                    Self::PublishErrorNonZeroAddress => {
926                        BinaryExecutionError::PublishErrorNonZeroAddress
927                    }
928                    Self::SuiMoveVerificationError => {
929                        BinaryExecutionError::SuiMoveVerificationError
930                    }
931                    Self::MovePrimitiveRuntimeError { location } => {
932                        BinaryExecutionError::MovePrimitiveRuntimeError { location }
933                    }
934                    Self::MoveAbort { location, code } => {
935                        BinaryExecutionError::MoveAbort { location, code }
936                    }
937                    Self::VmVerificationOrDeserializationError => {
938                        BinaryExecutionError::VmVerificationOrDeserializationError
939                    }
940                    Self::VmInvariantViolation => BinaryExecutionError::VmInvariantViolation,
941                    Self::FunctionNotFound => BinaryExecutionError::FunctionNotFound,
942                    Self::ArityMismatch => BinaryExecutionError::ArityMismatch,
943                    Self::TypeArityMismatch => BinaryExecutionError::TypeArityMismatch,
944                    Self::NonEntryFunctionInvoked => BinaryExecutionError::NonEntryFunctionInvoked,
945                    Self::CommandArgumentError { argument, kind } => {
946                        BinaryExecutionError::CommandArgumentError { argument, kind }
947                    }
948                    Self::TypeArgumentError {
949                        type_argument,
950                        kind,
951                    } => BinaryExecutionError::TypeArgumentError {
952                        type_argument,
953                        kind,
954                    },
955                    Self::UnusedValueWithoutDrop { result, subresult } => {
956                        BinaryExecutionError::UnusedValueWithoutDrop { result, subresult }
957                    }
958                    Self::InvalidPublicFunctionReturnType { index } => {
959                        BinaryExecutionError::InvalidPublicFunctionReturnType { index }
960                    }
961                    Self::InvalidTransferObject => BinaryExecutionError::InvalidTransferObject,
962                    Self::EffectsTooLarge {
963                        current_size,
964                        max_size,
965                    } => BinaryExecutionError::EffectsTooLarge {
966                        current_size,
967                        max_size,
968                    },
969                    Self::PublishUpgradeMissingDependency => {
970                        BinaryExecutionError::PublishUpgradeMissingDependency
971                    }
972                    Self::PublishUpgradeDependencyDowngrade => {
973                        BinaryExecutionError::PublishUpgradeDependencyDowngrade
974                    }
975                    Self::PackageUpgradeError { kind } => {
976                        BinaryExecutionError::PackageUpgradeError { kind }
977                    }
978                    Self::WrittenObjectsTooLarge {
979                        object_size,
980                        max_object_size,
981                    } => BinaryExecutionError::WrittenObjectsTooLarge {
982                        object_size,
983                        max_object_size,
984                    },
985                    Self::CertificateDenied => BinaryExecutionError::CertificateDenied,
986                    Self::SuiMoveVerificationTimedout => {
987                        BinaryExecutionError::SuiMoveVerificationTimedout
988                    }
989                    Self::SharedObjectOperationNotAllowed => {
990                        BinaryExecutionError::SharedObjectOperationNotAllowed
991                    }
992                    Self::InputObjectDeleted => BinaryExecutionError::InputObjectDeleted,
993                    Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects } => {
994                        BinaryExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
995                            congested_objects,
996                        }
997                    }
998                    Self::AddressDeniedForCoin { address, coin_type } => {
999                        BinaryExecutionError::AddressDeniedForCoin { address, coin_type }
1000                    }
1001                    Self::CoinTypeGlobalPause { coin_type } => {
1002                        BinaryExecutionError::CoinTypeGlobalPause { coin_type }
1003                    }
1004                    Self::ExecutionCanceledDueToRandomnessUnavailable => {
1005                        BinaryExecutionError::ExecutionCanceledDueToRandomnessUnavailable
1006                    }
1007                    Self::MoveVectorElemTooBig {
1008                        value_size,
1009                        max_scaled_size,
1010                    } => BinaryExecutionError::MoveVectorElemTooBig {
1011                        value_size,
1012                        max_scaled_size,
1013                    },
1014                    Self::MoveRawValueTooBig {
1015                        value_size,
1016                        max_scaled_size,
1017                    } => BinaryExecutionError::MoveRawValueTooBig {
1018                        value_size,
1019                        max_scaled_size,
1020                    },
1021                    Self::InvalidLinkage => BinaryExecutionError::InvalidLinkage,
1022                };
1023                binary.serialize(serializer)
1024            }
1025        }
1026    }
1027
1028    impl<'de> Deserialize<'de> for ExecutionError {
1029        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1030        where
1031            D: Deserializer<'de>,
1032        {
1033            if deserializer.is_human_readable() {
1034                ReadableExecutionError::deserialize(deserializer).map(|readable| match readable {
1035                    ReadableExecutionError::InsufficientGas => Self::InsufficientGas,
1036                    ReadableExecutionError::InvalidGasObject => Self::InvalidGasObject,
1037                    ReadableExecutionError::InvariantViolation => Self::InvariantViolation,
1038                    ReadableExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
1039                    ReadableExecutionError::ObjectTooBig {
1040                        object_size,
1041                        max_object_size,
1042                    } => Self::ObjectTooBig {
1043                        object_size,
1044                        max_object_size,
1045                    },
1046                    ReadableExecutionError::PackageTooBig {
1047                        object_size,
1048                        max_object_size,
1049                    } => Self::PackageTooBig {
1050                        object_size,
1051                        max_object_size,
1052                    },
1053                    ReadableExecutionError::CircularObjectOwnership { object } => {
1054                        Self::CircularObjectOwnership { object }
1055                    }
1056                    ReadableExecutionError::InsufficientCoinBalance => {
1057                        Self::InsufficientCoinBalance
1058                    }
1059                    ReadableExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
1060                    ReadableExecutionError::PublishErrorNonZeroAddress => {
1061                        Self::PublishErrorNonZeroAddress
1062                    }
1063                    ReadableExecutionError::SuiMoveVerificationError => {
1064                        Self::SuiMoveVerificationError
1065                    }
1066                    ReadableExecutionError::MovePrimitiveRuntimeError { location } => {
1067                        Self::MovePrimitiveRuntimeError { location }
1068                    }
1069                    ReadableExecutionError::MoveAbort { location, code } => {
1070                        Self::MoveAbort { location, code }
1071                    }
1072                    ReadableExecutionError::VmVerificationOrDeserializationError => {
1073                        Self::VmVerificationOrDeserializationError
1074                    }
1075                    ReadableExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
1076                    ReadableExecutionError::FunctionNotFound => Self::FunctionNotFound,
1077                    ReadableExecutionError::ArityMismatch => Self::ArityMismatch,
1078                    ReadableExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1079                    ReadableExecutionError::NonEntryFunctionInvoked => {
1080                        Self::NonEntryFunctionInvoked
1081                    }
1082                    ReadableExecutionError::CommandArgumentError { argument, kind } => {
1083                        Self::CommandArgumentError { argument, kind }
1084                    }
1085                    ReadableExecutionError::TypeArgumentError {
1086                        type_argument,
1087                        kind,
1088                    } => Self::TypeArgumentError {
1089                        type_argument,
1090                        kind,
1091                    },
1092                    ReadableExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1093                        Self::UnusedValueWithoutDrop { result, subresult }
1094                    }
1095                    ReadableExecutionError::InvalidPublicFunctionReturnType { index } => {
1096                        Self::InvalidPublicFunctionReturnType { index }
1097                    }
1098                    ReadableExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1099                    ReadableExecutionError::EffectsTooLarge {
1100                        current_size,
1101                        max_size,
1102                    } => Self::EffectsTooLarge {
1103                        current_size,
1104                        max_size,
1105                    },
1106                    ReadableExecutionError::PublishUpgradeMissingDependency => {
1107                        Self::PublishUpgradeMissingDependency
1108                    }
1109                    ReadableExecutionError::PublishUpgradeDependencyDowngrade => {
1110                        Self::PublishUpgradeDependencyDowngrade
1111                    }
1112                    ReadableExecutionError::PackageUpgradeError { kind } => {
1113                        Self::PackageUpgradeError { kind }
1114                    }
1115                    ReadableExecutionError::WrittenObjectsTooLarge {
1116                        object_size,
1117                        max_object_size,
1118                    } => Self::WrittenObjectsTooLarge {
1119                        object_size,
1120                        max_object_size,
1121                    },
1122                    ReadableExecutionError::CertificateDenied => Self::CertificateDenied,
1123                    ReadableExecutionError::SuiMoveVerificationTimedout => {
1124                        Self::SuiMoveVerificationTimedout
1125                    }
1126                    ReadableExecutionError::SharedObjectOperationNotAllowed => {
1127                        Self::SharedObjectOperationNotAllowed
1128                    }
1129                    ReadableExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1130                    ReadableExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
1131                        congested_objects,
1132                    } => Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects },
1133                    ReadableExecutionError::AddressDeniedForCoin { address, coin_type } => {
1134                        Self::AddressDeniedForCoin { address, coin_type }
1135                    }
1136                    ReadableExecutionError::CoinTypeGlobalPause { coin_type } => {
1137                        Self::CoinTypeGlobalPause { coin_type }
1138                    }
1139                    ReadableExecutionError::ExecutionCanceledDueToRandomnessUnavailable => {
1140                        Self::ExecutionCanceledDueToRandomnessUnavailable
1141                    }
1142                    ReadableExecutionError::MoveVectorElemTooBig {
1143                        value_size,
1144                        max_scaled_size,
1145                    } => Self::MoveVectorElemTooBig {
1146                        value_size,
1147                        max_scaled_size,
1148                    },
1149                    ReadableExecutionError::MoveRawValueTooBig {
1150                        value_size,
1151                        max_scaled_size,
1152                    } => Self::MoveRawValueTooBig {
1153                        value_size,
1154                        max_scaled_size,
1155                    },
1156                    ReadableExecutionError::InvalidLinkage => Self::InvalidLinkage,
1157                })
1158            } else {
1159                BinaryExecutionError::deserialize(deserializer).map(|binary| match binary {
1160                    BinaryExecutionError::InsufficientGas => Self::InsufficientGas,
1161                    BinaryExecutionError::InvalidGasObject => Self::InvalidGasObject,
1162                    BinaryExecutionError::InvariantViolation => Self::InvariantViolation,
1163                    BinaryExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
1164                    BinaryExecutionError::ObjectTooBig {
1165                        object_size,
1166                        max_object_size,
1167                    } => Self::ObjectTooBig {
1168                        object_size,
1169                        max_object_size,
1170                    },
1171                    BinaryExecutionError::PackageTooBig {
1172                        object_size,
1173                        max_object_size,
1174                    } => Self::PackageTooBig {
1175                        object_size,
1176                        max_object_size,
1177                    },
1178                    BinaryExecutionError::CircularObjectOwnership { object } => {
1179                        Self::CircularObjectOwnership { object }
1180                    }
1181                    BinaryExecutionError::InsufficientCoinBalance => Self::InsufficientCoinBalance,
1182                    BinaryExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
1183                    BinaryExecutionError::PublishErrorNonZeroAddress => {
1184                        Self::PublishErrorNonZeroAddress
1185                    }
1186                    BinaryExecutionError::SuiMoveVerificationError => {
1187                        Self::SuiMoveVerificationError
1188                    }
1189                    BinaryExecutionError::MovePrimitiveRuntimeError { location } => {
1190                        Self::MovePrimitiveRuntimeError { location }
1191                    }
1192                    BinaryExecutionError::MoveAbort { location, code } => {
1193                        Self::MoveAbort { location, code }
1194                    }
1195                    BinaryExecutionError::VmVerificationOrDeserializationError => {
1196                        Self::VmVerificationOrDeserializationError
1197                    }
1198                    BinaryExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
1199                    BinaryExecutionError::FunctionNotFound => Self::FunctionNotFound,
1200                    BinaryExecutionError::ArityMismatch => Self::ArityMismatch,
1201                    BinaryExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1202                    BinaryExecutionError::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
1203                    BinaryExecutionError::CommandArgumentError { argument, kind } => {
1204                        Self::CommandArgumentError { argument, kind }
1205                    }
1206                    BinaryExecutionError::TypeArgumentError {
1207                        type_argument,
1208                        kind,
1209                    } => Self::TypeArgumentError {
1210                        type_argument,
1211                        kind,
1212                    },
1213                    BinaryExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1214                        Self::UnusedValueWithoutDrop { result, subresult }
1215                    }
1216                    BinaryExecutionError::InvalidPublicFunctionReturnType { index } => {
1217                        Self::InvalidPublicFunctionReturnType { index }
1218                    }
1219                    BinaryExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1220                    BinaryExecutionError::EffectsTooLarge {
1221                        current_size,
1222                        max_size,
1223                    } => Self::EffectsTooLarge {
1224                        current_size,
1225                        max_size,
1226                    },
1227                    BinaryExecutionError::PublishUpgradeMissingDependency => {
1228                        Self::PublishUpgradeMissingDependency
1229                    }
1230                    BinaryExecutionError::PublishUpgradeDependencyDowngrade => {
1231                        Self::PublishUpgradeDependencyDowngrade
1232                    }
1233                    BinaryExecutionError::PackageUpgradeError { kind } => {
1234                        Self::PackageUpgradeError { kind }
1235                    }
1236                    BinaryExecutionError::WrittenObjectsTooLarge {
1237                        object_size,
1238                        max_object_size,
1239                    } => Self::WrittenObjectsTooLarge {
1240                        object_size,
1241                        max_object_size,
1242                    },
1243                    BinaryExecutionError::CertificateDenied => Self::CertificateDenied,
1244                    BinaryExecutionError::SuiMoveVerificationTimedout => {
1245                        Self::SuiMoveVerificationTimedout
1246                    }
1247                    BinaryExecutionError::SharedObjectOperationNotAllowed => {
1248                        Self::SharedObjectOperationNotAllowed
1249                    }
1250                    BinaryExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1251                    BinaryExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
1252                        congested_objects,
1253                    } => Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects },
1254                    BinaryExecutionError::AddressDeniedForCoin { address, coin_type } => {
1255                        Self::AddressDeniedForCoin { address, coin_type }
1256                    }
1257                    BinaryExecutionError::CoinTypeGlobalPause { coin_type } => {
1258                        Self::CoinTypeGlobalPause { coin_type }
1259                    }
1260                    BinaryExecutionError::ExecutionCanceledDueToRandomnessUnavailable => {
1261                        Self::ExecutionCanceledDueToRandomnessUnavailable
1262                    }
1263                    BinaryExecutionError::MoveVectorElemTooBig {
1264                        value_size,
1265                        max_scaled_size,
1266                    } => Self::MoveVectorElemTooBig {
1267                        value_size,
1268                        max_scaled_size,
1269                    },
1270                    BinaryExecutionError::MoveRawValueTooBig {
1271                        value_size,
1272                        max_scaled_size,
1273                    } => Self::MoveRawValueTooBig {
1274                        value_size,
1275                        max_scaled_size,
1276                    },
1277                    BinaryExecutionError::InvalidLinkage => Self::InvalidLinkage,
1278                })
1279            }
1280        }
1281    }
1282
1283    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1284    #[serde(tag = "kind", rename_all = "snake_case")]
1285    enum ReadableCommandArgumentError {
1286        TypeMismatch,
1287        InvalidBcsBytes,
1288        InvalidUsageOfPureArgument,
1289        InvalidArgumentToPrivateEntryFunction,
1290        IndexOutOfBounds { index: u16 },
1291        SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
1292        InvalidResultArity { result: u16 },
1293        InvalidGasCoinUsage,
1294        InvalidValueUsage,
1295        InvalidObjectByValue,
1296        InvalidObjectByMutRef,
1297        SharedObjectOperationNotAllowed,
1298        InvalidArgumentArity,
1299    }
1300
1301    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1302    enum BinaryCommandArgumentError {
1303        TypeMismatch,
1304        InvalidBcsBytes,
1305        InvalidUsageOfPureArgument,
1306        InvalidArgumentToPrivateEntryFunction,
1307        IndexOutOfBounds { index: u16 },
1308        SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
1309        InvalidResultArity { result: u16 },
1310        InvalidGasCoinUsage,
1311        InvalidValueUsage,
1312        InvalidObjectByValue,
1313        InvalidObjectByMutRef,
1314        SharedObjectOperationNotAllowed,
1315        InvalidArgumentArity,
1316    }
1317
1318    impl Serialize for CommandArgumentError {
1319        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1320        where
1321            S: Serializer,
1322        {
1323            if serializer.is_human_readable() {
1324                let readable = match self.clone() {
1325                    Self::TypeMismatch => ReadableCommandArgumentError::TypeMismatch,
1326                    Self::InvalidBcsBytes => ReadableCommandArgumentError::InvalidBcsBytes,
1327                    Self::InvalidUsageOfPureArgument => {
1328                        ReadableCommandArgumentError::InvalidUsageOfPureArgument
1329                    }
1330                    Self::InvalidArgumentToPrivateEntryFunction => {
1331                        ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction
1332                    }
1333                    Self::IndexOutOfBounds { index } => {
1334                        ReadableCommandArgumentError::IndexOutOfBounds { index }
1335                    }
1336                    Self::SecondaryIndexOutOfBounds { result, subresult } => {
1337                        ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
1338                            result,
1339                            subresult,
1340                        }
1341                    }
1342                    Self::InvalidResultArity { result } => {
1343                        ReadableCommandArgumentError::InvalidResultArity { result }
1344                    }
1345                    Self::InvalidGasCoinUsage => ReadableCommandArgumentError::InvalidGasCoinUsage,
1346                    Self::InvalidValueUsage => ReadableCommandArgumentError::InvalidValueUsage,
1347                    Self::InvalidObjectByValue => {
1348                        ReadableCommandArgumentError::InvalidObjectByValue
1349                    }
1350                    Self::InvalidObjectByMutRef => {
1351                        ReadableCommandArgumentError::InvalidObjectByMutRef
1352                    }
1353                    Self::SharedObjectOperationNotAllowed => {
1354                        ReadableCommandArgumentError::SharedObjectOperationNotAllowed
1355                    }
1356                    Self::InvalidArgumentArity => {
1357                        ReadableCommandArgumentError::InvalidArgumentArity
1358                    }
1359                };
1360                readable.serialize(serializer)
1361            } else {
1362                let binary = match self.clone() {
1363                    Self::TypeMismatch => BinaryCommandArgumentError::TypeMismatch,
1364                    Self::InvalidBcsBytes => BinaryCommandArgumentError::InvalidBcsBytes,
1365                    Self::InvalidUsageOfPureArgument => {
1366                        BinaryCommandArgumentError::InvalidUsageOfPureArgument
1367                    }
1368                    Self::InvalidArgumentToPrivateEntryFunction => {
1369                        BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction
1370                    }
1371                    Self::IndexOutOfBounds { index } => {
1372                        BinaryCommandArgumentError::IndexOutOfBounds { index }
1373                    }
1374                    Self::SecondaryIndexOutOfBounds { result, subresult } => {
1375                        BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult }
1376                    }
1377                    Self::InvalidResultArity { result } => {
1378                        BinaryCommandArgumentError::InvalidResultArity { result }
1379                    }
1380                    Self::InvalidGasCoinUsage => BinaryCommandArgumentError::InvalidGasCoinUsage,
1381                    Self::InvalidValueUsage => BinaryCommandArgumentError::InvalidValueUsage,
1382                    Self::InvalidObjectByValue => BinaryCommandArgumentError::InvalidObjectByValue,
1383                    Self::InvalidObjectByMutRef => {
1384                        BinaryCommandArgumentError::InvalidObjectByMutRef
1385                    }
1386                    Self::SharedObjectOperationNotAllowed => {
1387                        BinaryCommandArgumentError::SharedObjectOperationNotAllowed
1388                    }
1389                    Self::InvalidArgumentArity => BinaryCommandArgumentError::InvalidArgumentArity,
1390                };
1391                binary.serialize(serializer)
1392            }
1393        }
1394    }
1395
1396    impl<'de> Deserialize<'de> for CommandArgumentError {
1397        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1398        where
1399            D: Deserializer<'de>,
1400        {
1401            if deserializer.is_human_readable() {
1402                ReadableCommandArgumentError::deserialize(deserializer).map(|readable| {
1403                    match readable {
1404                        ReadableCommandArgumentError::TypeMismatch => Self::TypeMismatch,
1405                        ReadableCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
1406                        ReadableCommandArgumentError::InvalidUsageOfPureArgument => {
1407                            Self::InvalidUsageOfPureArgument
1408                        }
1409                        ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
1410                            Self::InvalidArgumentToPrivateEntryFunction
1411                        }
1412                        ReadableCommandArgumentError::IndexOutOfBounds { index } => {
1413                            Self::IndexOutOfBounds { index }
1414                        }
1415                        ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
1416                            result,
1417                            subresult,
1418                        } => Self::SecondaryIndexOutOfBounds { result, subresult },
1419                        ReadableCommandArgumentError::InvalidResultArity { result } => {
1420                            Self::InvalidResultArity { result }
1421                        }
1422                        ReadableCommandArgumentError::InvalidGasCoinUsage => {
1423                            Self::InvalidGasCoinUsage
1424                        }
1425                        ReadableCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
1426                        ReadableCommandArgumentError::InvalidObjectByValue => {
1427                            Self::InvalidObjectByValue
1428                        }
1429                        ReadableCommandArgumentError::InvalidObjectByMutRef => {
1430                            Self::InvalidObjectByMutRef
1431                        }
1432                        ReadableCommandArgumentError::SharedObjectOperationNotAllowed => {
1433                            Self::SharedObjectOperationNotAllowed
1434                        }
1435                        ReadableCommandArgumentError::InvalidArgumentArity => {
1436                            Self::InvalidArgumentArity
1437                        }
1438                    }
1439                })
1440            } else {
1441                BinaryCommandArgumentError::deserialize(deserializer).map(|binary| match binary {
1442                    BinaryCommandArgumentError::TypeMismatch => Self::TypeMismatch,
1443                    BinaryCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
1444                    BinaryCommandArgumentError::InvalidUsageOfPureArgument => {
1445                        Self::InvalidUsageOfPureArgument
1446                    }
1447                    BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
1448                        Self::InvalidArgumentToPrivateEntryFunction
1449                    }
1450                    BinaryCommandArgumentError::IndexOutOfBounds { index } => {
1451                        Self::IndexOutOfBounds { index }
1452                    }
1453                    BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult } => {
1454                        Self::SecondaryIndexOutOfBounds { result, subresult }
1455                    }
1456                    BinaryCommandArgumentError::InvalidResultArity { result } => {
1457                        Self::InvalidResultArity { result }
1458                    }
1459                    BinaryCommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
1460                    BinaryCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
1461                    BinaryCommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
1462                    BinaryCommandArgumentError::InvalidObjectByMutRef => {
1463                        Self::InvalidObjectByMutRef
1464                    }
1465                    BinaryCommandArgumentError::SharedObjectOperationNotAllowed => {
1466                        Self::SharedObjectOperationNotAllowed
1467                    }
1468                    BinaryCommandArgumentError::InvalidArgumentArity => Self::InvalidArgumentArity,
1469                })
1470            }
1471        }
1472    }
1473
1474    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1475    #[serde(tag = "kind", rename_all = "snake_case")]
1476    enum ReadablePackageUpgradeError {
1477        UnableToFetchPackage {
1478            package_id: ObjectId,
1479        },
1480        NotAPackage {
1481            object_id: ObjectId,
1482        },
1483        IncompatibleUpgrade,
1484        DigestDoesNotMatch {
1485            digest: Digest,
1486        },
1487        UnknownUpgradePolicy {
1488            policy: u8,
1489        },
1490        PackageIdDoesNotMatch {
1491            package_id: ObjectId,
1492            ticket_id: ObjectId,
1493        },
1494    }
1495
1496    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1497    enum BinaryPackageUpgradeError {
1498        UnableToFetchPackage {
1499            package_id: ObjectId,
1500        },
1501        NotAPackage {
1502            object_id: ObjectId,
1503        },
1504        IncompatibleUpgrade,
1505        DigestDoesNotMatch {
1506            digest: Digest,
1507        },
1508        UnknownUpgradePolicy {
1509            policy: u8,
1510        },
1511        PackageIdDoesNotMatch {
1512            package_id: ObjectId,
1513            ticket_id: ObjectId,
1514        },
1515    }
1516
1517    impl Serialize for PackageUpgradeError {
1518        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1519        where
1520            S: Serializer,
1521        {
1522            if serializer.is_human_readable() {
1523                let readable = match self.clone() {
1524                    Self::UnableToFetchPackage { package_id } => {
1525                        ReadablePackageUpgradeError::UnableToFetchPackage { package_id }
1526                    }
1527                    Self::NotAPackage { object_id } => {
1528                        ReadablePackageUpgradeError::NotAPackage { object_id }
1529                    }
1530                    Self::IncompatibleUpgrade => ReadablePackageUpgradeError::IncompatibleUpgrade,
1531                    Self::DigestDoesNotMatch { digest } => {
1532                        ReadablePackageUpgradeError::DigestDoesNotMatch { digest }
1533                    }
1534                    Self::UnknownUpgradePolicy { policy } => {
1535                        ReadablePackageUpgradeError::UnknownUpgradePolicy { policy }
1536                    }
1537                    Self::PackageIdDoesNotMatch {
1538                        package_id,
1539                        ticket_id,
1540                    } => ReadablePackageUpgradeError::PackageIdDoesNotMatch {
1541                        package_id,
1542                        ticket_id,
1543                    },
1544                };
1545                readable.serialize(serializer)
1546            } else {
1547                let binary = match self.clone() {
1548                    Self::UnableToFetchPackage { package_id } => {
1549                        BinaryPackageUpgradeError::UnableToFetchPackage { package_id }
1550                    }
1551                    Self::NotAPackage { object_id } => {
1552                        BinaryPackageUpgradeError::NotAPackage { object_id }
1553                    }
1554                    Self::IncompatibleUpgrade => BinaryPackageUpgradeError::IncompatibleUpgrade,
1555                    Self::DigestDoesNotMatch { digest } => {
1556                        BinaryPackageUpgradeError::DigestDoesNotMatch { digest }
1557                    }
1558                    Self::UnknownUpgradePolicy { policy } => {
1559                        BinaryPackageUpgradeError::UnknownUpgradePolicy { policy }
1560                    }
1561                    Self::PackageIdDoesNotMatch {
1562                        package_id,
1563                        ticket_id,
1564                    } => BinaryPackageUpgradeError::PackageIdDoesNotMatch {
1565                        package_id,
1566                        ticket_id,
1567                    },
1568                };
1569                binary.serialize(serializer)
1570            }
1571        }
1572    }
1573
1574    impl<'de> Deserialize<'de> for PackageUpgradeError {
1575        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1576        where
1577            D: Deserializer<'de>,
1578        {
1579            if deserializer.is_human_readable() {
1580                ReadablePackageUpgradeError::deserialize(deserializer).map(
1581                    |readable| match readable {
1582                        ReadablePackageUpgradeError::UnableToFetchPackage { package_id } => {
1583                            Self::UnableToFetchPackage { package_id }
1584                        }
1585                        ReadablePackageUpgradeError::NotAPackage { object_id } => {
1586                            Self::NotAPackage { object_id }
1587                        }
1588                        ReadablePackageUpgradeError::IncompatibleUpgrade => {
1589                            Self::IncompatibleUpgrade
1590                        }
1591                        ReadablePackageUpgradeError::DigestDoesNotMatch { digest } => {
1592                            Self::DigestDoesNotMatch { digest }
1593                        }
1594                        ReadablePackageUpgradeError::UnknownUpgradePolicy { policy } => {
1595                            Self::UnknownUpgradePolicy { policy }
1596                        }
1597                        ReadablePackageUpgradeError::PackageIdDoesNotMatch {
1598                            package_id,
1599                            ticket_id,
1600                        } => Self::PackageIdDoesNotMatch {
1601                            package_id,
1602                            ticket_id,
1603                        },
1604                    },
1605                )
1606            } else {
1607                BinaryPackageUpgradeError::deserialize(deserializer).map(|binary| match binary {
1608                    BinaryPackageUpgradeError::UnableToFetchPackage { package_id } => {
1609                        Self::UnableToFetchPackage { package_id }
1610                    }
1611                    BinaryPackageUpgradeError::NotAPackage { object_id } => {
1612                        Self::NotAPackage { object_id }
1613                    }
1614                    BinaryPackageUpgradeError::IncompatibleUpgrade => Self::IncompatibleUpgrade,
1615                    BinaryPackageUpgradeError::DigestDoesNotMatch { digest } => {
1616                        Self::DigestDoesNotMatch { digest }
1617                    }
1618                    BinaryPackageUpgradeError::UnknownUpgradePolicy { policy } => {
1619                        Self::UnknownUpgradePolicy { policy }
1620                    }
1621                    BinaryPackageUpgradeError::PackageIdDoesNotMatch {
1622                        package_id,
1623                        ticket_id,
1624                    } => Self::PackageIdDoesNotMatch {
1625                        package_id,
1626                        ticket_id,
1627                    },
1628                })
1629            }
1630        }
1631    }
1632}