iota_sdk_types/
execution_status.rs

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