1use super::Address;
2use super::Digest;
3use super::Identifier;
4use super::ObjectId;
5
6#[derive(Eq, PartialEq, Clone, Debug)]
18#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
19pub enum ExecutionStatus {
20 Success,
22
23 Failure {
29 error: ExecutionError,
31 #[cfg_attr(feature = "proptest", map(|x: Option<u16>| x.map(Into::into)))]
33 command: Option<u64>,
34 },
35}
36
37#[derive(Eq, PartialEq, Clone, Debug)]
121#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
122pub enum ExecutionError {
123 InsufficientGas,
128 InvalidGasObject,
130 InvariantViolation,
132 FeatureNotYetSupported,
134 ObjectTooBig {
136 object_size: u64,
137 max_object_size: u64,
138 },
139 PackageTooBig {
141 object_size: u64,
142 max_object_size: u64,
143 },
144 CircularObjectOwnership { object: ObjectId },
146
147 InsufficientCoinBalance,
152 CoinBalanceOverflow,
154
155 PublishErrorNonZeroAddress,
161
162 SuiMoveVerificationError,
164
165 MovePrimitiveRuntimeError { location: Option<MoveLocation> },
172 MoveAbort { location: MoveLocation, code: u64 },
174 VmVerificationOrDeserializationError,
176 VmInvariantViolation,
178
179 FunctionNotFound,
184 ArityMismatch,
187 TypeArityMismatch,
190 NonEntryFunctionInvoked,
192 CommandArgumentError {
194 argument: u16,
195 kind: CommandArgumentError,
196 },
197 TypeArgumentError {
199 type_argument: u16,
201 kind: TypeArgumentError,
202 },
203 UnusedValueWithoutDrop { result: u16, subresult: u16 },
205 InvalidPublicFunctionReturnType { index: u16 },
208 InvalidTransferObject,
210
211 EffectsTooLarge { current_size: u64, max_size: u64 },
216
217 PublishUpgradeMissingDependency,
219
220 PublishUpgradeDependencyDowngrade,
226
227 PackageUpgradeError { kind: PackageUpgradeError },
229
230 WrittenObjectsTooLarge {
232 object_size: u64,
233 max_object_size: u64,
234 },
235
236 CertificateDenied,
238
239 SuiMoveVerificationTimedout,
241
242 SharedObjectOperationNotAllowed,
244
245 InputObjectDeleted,
247
248 ExecutionCanceledDueToSharedObjectCongestion { congested_objects: Vec<ObjectId> },
250
251 AddressDeniedForCoin { address: Address, coin_type: String },
253
254 CoinTypeGlobalPause { coin_type: String },
256
257 ExecutionCanceledDueToRandomnessUnavailable,
259}
260
261#[derive(Eq, PartialEq, Clone, Debug)]
271#[cfg_attr(
272 feature = "serde",
273 derive(serde_derive::Serialize, serde_derive::Deserialize)
274)]
275#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
276pub struct MoveLocation {
277 pub package: ObjectId,
279
280 pub module: Identifier,
282
283 pub function: u16,
285
286 pub instruction: u16,
289
290 pub function_name: Option<Identifier>,
292}
293
294#[derive(Eq, PartialEq, Clone, Debug)]
328#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
329pub enum CommandArgumentError {
330 TypeMismatch,
332
333 InvalidBcsBytes,
335
336 InvalidUsageOfPureArgument,
338
339 InvalidArgumentToPrivateEntryFunction,
342
343 IndexOutOfBounds { index: u16 },
345
346 SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
348
349 InvalidResultArity { result: u16 },
352
353 InvalidGasCoinUsage,
356
357 InvalidValueUsage,
362
363 InvalidObjectByValue,
365
366 InvalidObjectByMutRef,
368
369 SharedObjectOperationNotAllowed,
372}
373
374#[derive(Eq, PartialEq, Clone, Debug)]
396#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
397pub enum PackageUpgradeError {
398 UnableToFetchPackage { package_id: ObjectId },
400
401 NotAPackage { object_id: ObjectId },
403
404 IncompatibleUpgrade,
406
407 DigestDoesNotMatch { digest: Digest },
409
410 UnknownUpgradePolicy { policy: u8 },
412
413 PackageIdDoesNotMatch {
415 package_id: ObjectId,
416 ticket_id: ObjectId,
417 },
418}
419
420#[derive(Eq, PartialEq, Clone, Copy, Debug)]
432#[cfg_attr(
433 feature = "serde",
434 derive(serde_derive::Serialize, serde_derive::Deserialize),
435 serde(rename_all = "snake_case")
436)]
437#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
438pub enum TypeArgumentError {
439 TypeNotFound,
441
442 ConstraintNotSatisfied,
444}
445
446#[cfg(feature = "serde")]
447#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
448mod serialization {
449 use super::*;
450
451 use serde::Deserialize;
452 use serde::Deserializer;
453 use serde::Serialize;
454 use serde::Serializer;
455
456 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
457 #[serde(rename = "ExecutionStatus")]
458 struct ReadableExecutionStatus {
459 success: bool,
460 #[serde(skip_serializing_if = "Option::is_none")]
461 status: Option<FailureStatus>,
462 }
463
464 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
465 struct FailureStatus {
466 error: ExecutionError,
467 #[serde(skip_serializing_if = "Option::is_none")]
468 command: Option<u16>,
469 }
470
471 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
472 enum BinaryExecutionStatus {
473 Success,
474 Failure {
475 error: ExecutionError,
476 command: Option<u64>,
477 },
478 }
479
480 impl Serialize for ExecutionStatus {
481 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
482 where
483 S: Serializer,
484 {
485 if serializer.is_human_readable() {
486 let readable = match self.clone() {
487 ExecutionStatus::Success => ReadableExecutionStatus {
488 success: true,
489 status: None,
490 },
491 ExecutionStatus::Failure { error, command } => ReadableExecutionStatus {
492 success: false,
493 status: Some(FailureStatus {
494 error,
495 command: command.map(|c| c as u16),
496 }),
497 },
498 };
499 readable.serialize(serializer)
500 } else {
501 let binary = match self.clone() {
502 ExecutionStatus::Success => BinaryExecutionStatus::Success,
503 ExecutionStatus::Failure { error, command } => {
504 BinaryExecutionStatus::Failure { error, command }
505 }
506 };
507 binary.serialize(serializer)
508 }
509 }
510 }
511
512 impl<'de> Deserialize<'de> for ExecutionStatus {
513 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
514 where
515 D: Deserializer<'de>,
516 {
517 if deserializer.is_human_readable() {
518 let ReadableExecutionStatus { success, status } =
519 Deserialize::deserialize(deserializer)?;
520 match (success, status) {
521 (true, None) => Ok(ExecutionStatus::Success),
522 (false, Some(FailureStatus { error, command })) => {
523 Ok(ExecutionStatus::Failure {
524 error,
525 command: command.map(Into::into),
526 })
527 }
528 (true, Some(_)) | (false, None) => {
530 Err(serde::de::Error::custom("invalid execution status"))
531 }
532 }
533 } else {
534 BinaryExecutionStatus::deserialize(deserializer).map(|readable| match readable {
535 BinaryExecutionStatus::Success => Self::Success,
536 BinaryExecutionStatus::Failure { error, command } => {
537 Self::Failure { error, command }
538 }
539 })
540 }
541 }
542 }
543
544 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
545 #[serde(tag = "error", rename_all = "snake_case")]
546 enum ReadableExecutionError {
547 InsufficientGas,
548 InvalidGasObject,
549 InvariantViolation,
550 FeatureNotYetSupported,
551 ObjectTooBig {
552 #[serde(with = "crate::_serde::ReadableDisplay")]
553 object_size: u64,
554 #[serde(with = "crate::_serde::ReadableDisplay")]
555 max_object_size: u64,
556 },
557 PackageTooBig {
558 #[serde(with = "crate::_serde::ReadableDisplay")]
559 object_size: u64,
560 #[serde(with = "crate::_serde::ReadableDisplay")]
561 max_object_size: u64,
562 },
563 CircularObjectOwnership {
564 object: ObjectId,
565 },
566 InsufficientCoinBalance,
567 CoinBalanceOverflow,
568 PublishErrorNonZeroAddress,
569 SuiMoveVerificationError,
570 MovePrimitiveRuntimeError {
571 location: Option<MoveLocation>,
572 },
573 MoveAbort {
574 location: MoveLocation,
575 #[serde(with = "crate::_serde::ReadableDisplay")]
576 code: u64,
577 },
578 VmVerificationOrDeserializationError,
579 VmInvariantViolation,
580 FunctionNotFound,
581 ArityMismatch,
582 TypeArityMismatch,
583 NonEntryFunctionInvoked,
584 CommandArgumentError {
585 argument: u16,
586 kind: CommandArgumentError,
587 },
588 TypeArgumentError {
589 type_argument: u16,
590 kind: TypeArgumentError,
591 },
592 UnusedValueWithoutDrop {
593 result: u16,
594 subresult: u16,
595 },
596 InvalidPublicFunctionReturnType {
597 index: u16,
598 },
599 InvalidTransferObject,
600 EffectsTooLarge {
601 #[serde(with = "crate::_serde::ReadableDisplay")]
602 current_size: u64,
603 #[serde(with = "crate::_serde::ReadableDisplay")]
604 max_size: u64,
605 },
606 PublishUpgradeMissingDependency,
607 PublishUpgradeDependencyDowngrade,
608 PackageUpgradeError {
609 kind: PackageUpgradeError,
610 },
611 WrittenObjectsTooLarge {
612 #[serde(with = "crate::_serde::ReadableDisplay")]
613 object_size: u64,
614 #[serde(with = "crate::_serde::ReadableDisplay")]
615 max_object_size: u64,
616 },
617 CertificateDenied,
618 SuiMoveVerificationTimedout,
619 SharedObjectOperationNotAllowed,
620 InputObjectDeleted,
621 ExecutionCanceledDueToSharedObjectCongestion {
622 congested_objects: Vec<ObjectId>,
623 },
624
625 AddressDeniedForCoin {
626 address: Address,
627 coin_type: String,
628 },
629
630 CoinTypeGlobalPause {
631 coin_type: String,
632 },
633
634 ExecutionCanceledDueToRandomnessUnavailable,
635 }
636
637 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
638 enum BinaryExecutionError {
639 InsufficientGas,
640 InvalidGasObject,
641 InvariantViolation,
642 FeatureNotYetSupported,
643 ObjectTooBig {
644 object_size: u64,
645 max_object_size: u64,
646 },
647 PackageTooBig {
648 object_size: u64,
649 max_object_size: u64,
650 },
651 CircularObjectOwnership {
652 object: ObjectId,
653 },
654 InsufficientCoinBalance,
655 CoinBalanceOverflow,
656 PublishErrorNonZeroAddress,
657 SuiMoveVerificationError,
658 MovePrimitiveRuntimeError {
659 location: Option<MoveLocation>,
660 },
661 MoveAbort {
662 location: MoveLocation,
663 code: u64,
664 },
665 VmVerificationOrDeserializationError,
666 VmInvariantViolation,
667 FunctionNotFound,
668 ArityMismatch,
669 TypeArityMismatch,
670 NonEntryFunctionInvoked,
671 CommandArgumentError {
672 argument: u16,
673 kind: CommandArgumentError,
674 },
675 TypeArgumentError {
676 type_argument: u16,
677 kind: TypeArgumentError,
678 },
679 UnusedValueWithoutDrop {
680 result: u16,
681 subresult: u16,
682 },
683 InvalidPublicFunctionReturnType {
684 index: u16,
685 },
686 InvalidTransferObject,
687 EffectsTooLarge {
688 current_size: u64,
689 max_size: u64,
690 },
691 PublishUpgradeMissingDependency,
692 PublishUpgradeDependencyDowngrade,
693 PackageUpgradeError {
694 kind: PackageUpgradeError,
695 },
696 WrittenObjectsTooLarge {
697 object_size: u64,
698 max_object_size: u64,
699 },
700 CertificateDenied,
701 SuiMoveVerificationTimedout,
702 SharedObjectOperationNotAllowed,
703 InputObjectDeleted,
704 ExecutionCanceledDueToSharedObjectCongestion {
705 congested_objects: Vec<ObjectId>,
706 },
707
708 AddressDeniedForCoin {
709 address: Address,
710 coin_type: String,
711 },
712
713 CoinTypeGlobalPause {
714 coin_type: String,
715 },
716
717 ExecutionCanceledDueToRandomnessUnavailable,
718 }
719
720 impl Serialize for ExecutionError {
721 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
722 where
723 S: Serializer,
724 {
725 if serializer.is_human_readable() {
726 let readable = match self.clone() {
727 Self::InsufficientGas => ReadableExecutionError::InsufficientGas,
728 Self::InvalidGasObject => ReadableExecutionError::InvalidGasObject,
729 Self::InvariantViolation => ReadableExecutionError::InvariantViolation,
730 Self::FeatureNotYetSupported => ReadableExecutionError::FeatureNotYetSupported,
731 Self::ObjectTooBig {
732 object_size,
733 max_object_size,
734 } => ReadableExecutionError::ObjectTooBig {
735 object_size,
736 max_object_size,
737 },
738 Self::PackageTooBig {
739 object_size,
740 max_object_size,
741 } => ReadableExecutionError::PackageTooBig {
742 object_size,
743 max_object_size,
744 },
745 Self::CircularObjectOwnership { object } => {
746 ReadableExecutionError::CircularObjectOwnership { object }
747 }
748 Self::InsufficientCoinBalance => {
749 ReadableExecutionError::InsufficientCoinBalance
750 }
751 Self::CoinBalanceOverflow => ReadableExecutionError::CoinBalanceOverflow,
752 Self::PublishErrorNonZeroAddress => {
753 ReadableExecutionError::PublishErrorNonZeroAddress
754 }
755 Self::SuiMoveVerificationError => {
756 ReadableExecutionError::SuiMoveVerificationError
757 }
758 Self::MovePrimitiveRuntimeError { location } => {
759 ReadableExecutionError::MovePrimitiveRuntimeError { location }
760 }
761 Self::MoveAbort { location, code } => {
762 ReadableExecutionError::MoveAbort { location, code }
763 }
764 Self::VmVerificationOrDeserializationError => {
765 ReadableExecutionError::VmVerificationOrDeserializationError
766 }
767 Self::VmInvariantViolation => ReadableExecutionError::VmInvariantViolation,
768 Self::FunctionNotFound => ReadableExecutionError::FunctionNotFound,
769 Self::ArityMismatch => ReadableExecutionError::ArityMismatch,
770 Self::TypeArityMismatch => ReadableExecutionError::TypeArityMismatch,
771 Self::NonEntryFunctionInvoked => {
772 ReadableExecutionError::NonEntryFunctionInvoked
773 }
774 Self::CommandArgumentError { argument, kind } => {
775 ReadableExecutionError::CommandArgumentError { argument, kind }
776 }
777 Self::TypeArgumentError {
778 type_argument,
779 kind,
780 } => ReadableExecutionError::TypeArgumentError {
781 type_argument,
782 kind,
783 },
784 Self::UnusedValueWithoutDrop { result, subresult } => {
785 ReadableExecutionError::UnusedValueWithoutDrop { result, subresult }
786 }
787 Self::InvalidPublicFunctionReturnType { index } => {
788 ReadableExecutionError::InvalidPublicFunctionReturnType { index }
789 }
790 Self::InvalidTransferObject => ReadableExecutionError::InvalidTransferObject,
791 Self::EffectsTooLarge {
792 current_size,
793 max_size,
794 } => ReadableExecutionError::EffectsTooLarge {
795 current_size,
796 max_size,
797 },
798 Self::PublishUpgradeMissingDependency => {
799 ReadableExecutionError::PublishUpgradeMissingDependency
800 }
801 Self::PublishUpgradeDependencyDowngrade => {
802 ReadableExecutionError::PublishUpgradeDependencyDowngrade
803 }
804 Self::PackageUpgradeError { kind } => {
805 ReadableExecutionError::PackageUpgradeError { kind }
806 }
807 Self::WrittenObjectsTooLarge {
808 object_size,
809 max_object_size,
810 } => ReadableExecutionError::WrittenObjectsTooLarge {
811 object_size,
812 max_object_size,
813 },
814 Self::CertificateDenied => ReadableExecutionError::CertificateDenied,
815 Self::SuiMoveVerificationTimedout => {
816 ReadableExecutionError::SuiMoveVerificationTimedout
817 }
818 Self::SharedObjectOperationNotAllowed => {
819 ReadableExecutionError::SharedObjectOperationNotAllowed
820 }
821 Self::InputObjectDeleted => ReadableExecutionError::InputObjectDeleted,
822 Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects } => {
823 ReadableExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
824 congested_objects,
825 }
826 }
827 Self::AddressDeniedForCoin { address, coin_type } => {
828 ReadableExecutionError::AddressDeniedForCoin { address, coin_type }
829 }
830 Self::CoinTypeGlobalPause { coin_type } => {
831 ReadableExecutionError::CoinTypeGlobalPause { coin_type }
832 }
833 Self::ExecutionCanceledDueToRandomnessUnavailable => {
834 ReadableExecutionError::ExecutionCanceledDueToRandomnessUnavailable
835 }
836 };
837 readable.serialize(serializer)
838 } else {
839 let binary = match self.clone() {
840 Self::InsufficientGas => BinaryExecutionError::InsufficientGas,
841 Self::InvalidGasObject => BinaryExecutionError::InvalidGasObject,
842 Self::InvariantViolation => BinaryExecutionError::InvariantViolation,
843 Self::FeatureNotYetSupported => BinaryExecutionError::FeatureNotYetSupported,
844 Self::ObjectTooBig {
845 object_size,
846 max_object_size,
847 } => BinaryExecutionError::ObjectTooBig {
848 object_size,
849 max_object_size,
850 },
851 Self::PackageTooBig {
852 object_size,
853 max_object_size,
854 } => BinaryExecutionError::PackageTooBig {
855 object_size,
856 max_object_size,
857 },
858 Self::CircularObjectOwnership { object } => {
859 BinaryExecutionError::CircularObjectOwnership { object }
860 }
861 Self::InsufficientCoinBalance => BinaryExecutionError::InsufficientCoinBalance,
862 Self::CoinBalanceOverflow => BinaryExecutionError::CoinBalanceOverflow,
863 Self::PublishErrorNonZeroAddress => {
864 BinaryExecutionError::PublishErrorNonZeroAddress
865 }
866 Self::SuiMoveVerificationError => {
867 BinaryExecutionError::SuiMoveVerificationError
868 }
869 Self::MovePrimitiveRuntimeError { location } => {
870 BinaryExecutionError::MovePrimitiveRuntimeError { location }
871 }
872 Self::MoveAbort { location, code } => {
873 BinaryExecutionError::MoveAbort { location, code }
874 }
875 Self::VmVerificationOrDeserializationError => {
876 BinaryExecutionError::VmVerificationOrDeserializationError
877 }
878 Self::VmInvariantViolation => BinaryExecutionError::VmInvariantViolation,
879 Self::FunctionNotFound => BinaryExecutionError::FunctionNotFound,
880 Self::ArityMismatch => BinaryExecutionError::ArityMismatch,
881 Self::TypeArityMismatch => BinaryExecutionError::TypeArityMismatch,
882 Self::NonEntryFunctionInvoked => BinaryExecutionError::NonEntryFunctionInvoked,
883 Self::CommandArgumentError { argument, kind } => {
884 BinaryExecutionError::CommandArgumentError { argument, kind }
885 }
886 Self::TypeArgumentError {
887 type_argument,
888 kind,
889 } => BinaryExecutionError::TypeArgumentError {
890 type_argument,
891 kind,
892 },
893 Self::UnusedValueWithoutDrop { result, subresult } => {
894 BinaryExecutionError::UnusedValueWithoutDrop { result, subresult }
895 }
896 Self::InvalidPublicFunctionReturnType { index } => {
897 BinaryExecutionError::InvalidPublicFunctionReturnType { index }
898 }
899 Self::InvalidTransferObject => BinaryExecutionError::InvalidTransferObject,
900 Self::EffectsTooLarge {
901 current_size,
902 max_size,
903 } => BinaryExecutionError::EffectsTooLarge {
904 current_size,
905 max_size,
906 },
907 Self::PublishUpgradeMissingDependency => {
908 BinaryExecutionError::PublishUpgradeMissingDependency
909 }
910 Self::PublishUpgradeDependencyDowngrade => {
911 BinaryExecutionError::PublishUpgradeDependencyDowngrade
912 }
913 Self::PackageUpgradeError { kind } => {
914 BinaryExecutionError::PackageUpgradeError { kind }
915 }
916 Self::WrittenObjectsTooLarge {
917 object_size,
918 max_object_size,
919 } => BinaryExecutionError::WrittenObjectsTooLarge {
920 object_size,
921 max_object_size,
922 },
923 Self::CertificateDenied => BinaryExecutionError::CertificateDenied,
924 Self::SuiMoveVerificationTimedout => {
925 BinaryExecutionError::SuiMoveVerificationTimedout
926 }
927 Self::SharedObjectOperationNotAllowed => {
928 BinaryExecutionError::SharedObjectOperationNotAllowed
929 }
930 Self::InputObjectDeleted => BinaryExecutionError::InputObjectDeleted,
931 Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects } => {
932 BinaryExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
933 congested_objects,
934 }
935 }
936 Self::AddressDeniedForCoin { address, coin_type } => {
937 BinaryExecutionError::AddressDeniedForCoin { address, coin_type }
938 }
939 Self::CoinTypeGlobalPause { coin_type } => {
940 BinaryExecutionError::CoinTypeGlobalPause { coin_type }
941 }
942 Self::ExecutionCanceledDueToRandomnessUnavailable => {
943 BinaryExecutionError::ExecutionCanceledDueToRandomnessUnavailable
944 }
945 };
946 binary.serialize(serializer)
947 }
948 }
949 }
950
951 impl<'de> Deserialize<'de> for ExecutionError {
952 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
953 where
954 D: Deserializer<'de>,
955 {
956 if deserializer.is_human_readable() {
957 ReadableExecutionError::deserialize(deserializer).map(|readable| match readable {
958 ReadableExecutionError::InsufficientGas => Self::InsufficientGas,
959 ReadableExecutionError::InvalidGasObject => Self::InvalidGasObject,
960 ReadableExecutionError::InvariantViolation => Self::InvariantViolation,
961 ReadableExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
962 ReadableExecutionError::ObjectTooBig {
963 object_size,
964 max_object_size,
965 } => Self::ObjectTooBig {
966 object_size,
967 max_object_size,
968 },
969 ReadableExecutionError::PackageTooBig {
970 object_size,
971 max_object_size,
972 } => Self::PackageTooBig {
973 object_size,
974 max_object_size,
975 },
976 ReadableExecutionError::CircularObjectOwnership { object } => {
977 Self::CircularObjectOwnership { object }
978 }
979 ReadableExecutionError::InsufficientCoinBalance => {
980 Self::InsufficientCoinBalance
981 }
982 ReadableExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
983 ReadableExecutionError::PublishErrorNonZeroAddress => {
984 Self::PublishErrorNonZeroAddress
985 }
986 ReadableExecutionError::SuiMoveVerificationError => {
987 Self::SuiMoveVerificationError
988 }
989 ReadableExecutionError::MovePrimitiveRuntimeError { location } => {
990 Self::MovePrimitiveRuntimeError { location }
991 }
992 ReadableExecutionError::MoveAbort { location, code } => {
993 Self::MoveAbort { location, code }
994 }
995 ReadableExecutionError::VmVerificationOrDeserializationError => {
996 Self::VmVerificationOrDeserializationError
997 }
998 ReadableExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
999 ReadableExecutionError::FunctionNotFound => Self::FunctionNotFound,
1000 ReadableExecutionError::ArityMismatch => Self::ArityMismatch,
1001 ReadableExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1002 ReadableExecutionError::NonEntryFunctionInvoked => {
1003 Self::NonEntryFunctionInvoked
1004 }
1005 ReadableExecutionError::CommandArgumentError { argument, kind } => {
1006 Self::CommandArgumentError { argument, kind }
1007 }
1008 ReadableExecutionError::TypeArgumentError {
1009 type_argument,
1010 kind,
1011 } => Self::TypeArgumentError {
1012 type_argument,
1013 kind,
1014 },
1015 ReadableExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1016 Self::UnusedValueWithoutDrop { result, subresult }
1017 }
1018 ReadableExecutionError::InvalidPublicFunctionReturnType { index } => {
1019 Self::InvalidPublicFunctionReturnType { index }
1020 }
1021 ReadableExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1022 ReadableExecutionError::EffectsTooLarge {
1023 current_size,
1024 max_size,
1025 } => Self::EffectsTooLarge {
1026 current_size,
1027 max_size,
1028 },
1029 ReadableExecutionError::PublishUpgradeMissingDependency => {
1030 Self::PublishUpgradeMissingDependency
1031 }
1032 ReadableExecutionError::PublishUpgradeDependencyDowngrade => {
1033 Self::PublishUpgradeDependencyDowngrade
1034 }
1035 ReadableExecutionError::PackageUpgradeError { kind } => {
1036 Self::PackageUpgradeError { kind }
1037 }
1038 ReadableExecutionError::WrittenObjectsTooLarge {
1039 object_size,
1040 max_object_size,
1041 } => Self::WrittenObjectsTooLarge {
1042 object_size,
1043 max_object_size,
1044 },
1045 ReadableExecutionError::CertificateDenied => Self::CertificateDenied,
1046 ReadableExecutionError::SuiMoveVerificationTimedout => {
1047 Self::SuiMoveVerificationTimedout
1048 }
1049 ReadableExecutionError::SharedObjectOperationNotAllowed => {
1050 Self::SharedObjectOperationNotAllowed
1051 }
1052 ReadableExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1053 ReadableExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
1054 congested_objects,
1055 } => Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects },
1056 ReadableExecutionError::AddressDeniedForCoin { address, coin_type } => {
1057 Self::AddressDeniedForCoin { address, coin_type }
1058 }
1059 ReadableExecutionError::CoinTypeGlobalPause { coin_type } => {
1060 Self::CoinTypeGlobalPause { coin_type }
1061 }
1062 ReadableExecutionError::ExecutionCanceledDueToRandomnessUnavailable => {
1063 Self::ExecutionCanceledDueToRandomnessUnavailable
1064 }
1065 })
1066 } else {
1067 BinaryExecutionError::deserialize(deserializer).map(|binary| match binary {
1068 BinaryExecutionError::InsufficientGas => Self::InsufficientGas,
1069 BinaryExecutionError::InvalidGasObject => Self::InvalidGasObject,
1070 BinaryExecutionError::InvariantViolation => Self::InvariantViolation,
1071 BinaryExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
1072 BinaryExecutionError::ObjectTooBig {
1073 object_size,
1074 max_object_size,
1075 } => Self::ObjectTooBig {
1076 object_size,
1077 max_object_size,
1078 },
1079 BinaryExecutionError::PackageTooBig {
1080 object_size,
1081 max_object_size,
1082 } => Self::PackageTooBig {
1083 object_size,
1084 max_object_size,
1085 },
1086 BinaryExecutionError::CircularObjectOwnership { object } => {
1087 Self::CircularObjectOwnership { object }
1088 }
1089 BinaryExecutionError::InsufficientCoinBalance => Self::InsufficientCoinBalance,
1090 BinaryExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
1091 BinaryExecutionError::PublishErrorNonZeroAddress => {
1092 Self::PublishErrorNonZeroAddress
1093 }
1094 BinaryExecutionError::SuiMoveVerificationError => {
1095 Self::SuiMoveVerificationError
1096 }
1097 BinaryExecutionError::MovePrimitiveRuntimeError { location } => {
1098 Self::MovePrimitiveRuntimeError { location }
1099 }
1100 BinaryExecutionError::MoveAbort { location, code } => {
1101 Self::MoveAbort { location, code }
1102 }
1103 BinaryExecutionError::VmVerificationOrDeserializationError => {
1104 Self::VmVerificationOrDeserializationError
1105 }
1106 BinaryExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
1107 BinaryExecutionError::FunctionNotFound => Self::FunctionNotFound,
1108 BinaryExecutionError::ArityMismatch => Self::ArityMismatch,
1109 BinaryExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1110 BinaryExecutionError::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
1111 BinaryExecutionError::CommandArgumentError { argument, kind } => {
1112 Self::CommandArgumentError { argument, kind }
1113 }
1114 BinaryExecutionError::TypeArgumentError {
1115 type_argument,
1116 kind,
1117 } => Self::TypeArgumentError {
1118 type_argument,
1119 kind,
1120 },
1121 BinaryExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1122 Self::UnusedValueWithoutDrop { result, subresult }
1123 }
1124 BinaryExecutionError::InvalidPublicFunctionReturnType { index } => {
1125 Self::InvalidPublicFunctionReturnType { index }
1126 }
1127 BinaryExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1128 BinaryExecutionError::EffectsTooLarge {
1129 current_size,
1130 max_size,
1131 } => Self::EffectsTooLarge {
1132 current_size,
1133 max_size,
1134 },
1135 BinaryExecutionError::PublishUpgradeMissingDependency => {
1136 Self::PublishUpgradeMissingDependency
1137 }
1138 BinaryExecutionError::PublishUpgradeDependencyDowngrade => {
1139 Self::PublishUpgradeDependencyDowngrade
1140 }
1141 BinaryExecutionError::PackageUpgradeError { kind } => {
1142 Self::PackageUpgradeError { kind }
1143 }
1144 BinaryExecutionError::WrittenObjectsTooLarge {
1145 object_size,
1146 max_object_size,
1147 } => Self::WrittenObjectsTooLarge {
1148 object_size,
1149 max_object_size,
1150 },
1151 BinaryExecutionError::CertificateDenied => Self::CertificateDenied,
1152 BinaryExecutionError::SuiMoveVerificationTimedout => {
1153 Self::SuiMoveVerificationTimedout
1154 }
1155 BinaryExecutionError::SharedObjectOperationNotAllowed => {
1156 Self::SharedObjectOperationNotAllowed
1157 }
1158 BinaryExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1159 BinaryExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
1160 congested_objects,
1161 } => Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects },
1162 BinaryExecutionError::AddressDeniedForCoin { address, coin_type } => {
1163 Self::AddressDeniedForCoin { address, coin_type }
1164 }
1165 BinaryExecutionError::CoinTypeGlobalPause { coin_type } => {
1166 Self::CoinTypeGlobalPause { coin_type }
1167 }
1168 BinaryExecutionError::ExecutionCanceledDueToRandomnessUnavailable => {
1169 Self::ExecutionCanceledDueToRandomnessUnavailable
1170 }
1171 })
1172 }
1173 }
1174 }
1175
1176 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1177 #[serde(tag = "kind", rename_all = "snake_case")]
1178 enum ReadableCommandArgumentError {
1179 TypeMismatch,
1180 InvalidBcsBytes,
1181 InvalidUsageOfPureArgument,
1182 InvalidArgumentToPrivateEntryFunction,
1183 IndexOutOfBounds { index: u16 },
1184 SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
1185 InvalidResultArity { result: u16 },
1186 InvalidGasCoinUsage,
1187 InvalidValueUsage,
1188 InvalidObjectByValue,
1189 InvalidObjectByMutRef,
1190 SharedObjectOperationNotAllowed,
1191 }
1192
1193 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1194 enum BinaryCommandArgumentError {
1195 TypeMismatch,
1196 InvalidBcsBytes,
1197 InvalidUsageOfPureArgument,
1198 InvalidArgumentToPrivateEntryFunction,
1199 IndexOutOfBounds { index: u16 },
1200 SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
1201 InvalidResultArity { result: u16 },
1202 InvalidGasCoinUsage,
1203 InvalidValueUsage,
1204 InvalidObjectByValue,
1205 InvalidObjectByMutRef,
1206 SharedObjectOperationNotAllowed,
1207 }
1208
1209 impl Serialize for CommandArgumentError {
1210 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1211 where
1212 S: Serializer,
1213 {
1214 if serializer.is_human_readable() {
1215 let readable = match self.clone() {
1216 Self::TypeMismatch => ReadableCommandArgumentError::TypeMismatch,
1217 Self::InvalidBcsBytes => ReadableCommandArgumentError::InvalidBcsBytes,
1218 Self::InvalidUsageOfPureArgument => {
1219 ReadableCommandArgumentError::InvalidUsageOfPureArgument
1220 }
1221 Self::InvalidArgumentToPrivateEntryFunction => {
1222 ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction
1223 }
1224 Self::IndexOutOfBounds { index } => {
1225 ReadableCommandArgumentError::IndexOutOfBounds { index }
1226 }
1227 Self::SecondaryIndexOutOfBounds { result, subresult } => {
1228 ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
1229 result,
1230 subresult,
1231 }
1232 }
1233 Self::InvalidResultArity { result } => {
1234 ReadableCommandArgumentError::InvalidResultArity { result }
1235 }
1236 Self::InvalidGasCoinUsage => ReadableCommandArgumentError::InvalidGasCoinUsage,
1237 Self::InvalidValueUsage => ReadableCommandArgumentError::InvalidValueUsage,
1238 Self::InvalidObjectByValue => {
1239 ReadableCommandArgumentError::InvalidObjectByValue
1240 }
1241 Self::InvalidObjectByMutRef => {
1242 ReadableCommandArgumentError::InvalidObjectByMutRef
1243 }
1244 Self::SharedObjectOperationNotAllowed => {
1245 ReadableCommandArgumentError::SharedObjectOperationNotAllowed
1246 }
1247 };
1248 readable.serialize(serializer)
1249 } else {
1250 let binary = match self.clone() {
1251 Self::TypeMismatch => BinaryCommandArgumentError::TypeMismatch,
1252 Self::InvalidBcsBytes => BinaryCommandArgumentError::InvalidBcsBytes,
1253 Self::InvalidUsageOfPureArgument => {
1254 BinaryCommandArgumentError::InvalidUsageOfPureArgument
1255 }
1256 Self::InvalidArgumentToPrivateEntryFunction => {
1257 BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction
1258 }
1259 Self::IndexOutOfBounds { index } => {
1260 BinaryCommandArgumentError::IndexOutOfBounds { index }
1261 }
1262 Self::SecondaryIndexOutOfBounds { result, subresult } => {
1263 BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult }
1264 }
1265 Self::InvalidResultArity { result } => {
1266 BinaryCommandArgumentError::InvalidResultArity { result }
1267 }
1268 Self::InvalidGasCoinUsage => BinaryCommandArgumentError::InvalidGasCoinUsage,
1269 Self::InvalidValueUsage => BinaryCommandArgumentError::InvalidValueUsage,
1270 Self::InvalidObjectByValue => BinaryCommandArgumentError::InvalidObjectByValue,
1271 Self::InvalidObjectByMutRef => {
1272 BinaryCommandArgumentError::InvalidObjectByMutRef
1273 }
1274 Self::SharedObjectOperationNotAllowed => {
1275 BinaryCommandArgumentError::SharedObjectOperationNotAllowed
1276 }
1277 };
1278 binary.serialize(serializer)
1279 }
1280 }
1281 }
1282
1283 impl<'de> Deserialize<'de> for CommandArgumentError {
1284 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1285 where
1286 D: Deserializer<'de>,
1287 {
1288 if deserializer.is_human_readable() {
1289 ReadableCommandArgumentError::deserialize(deserializer).map(|readable| {
1290 match readable {
1291 ReadableCommandArgumentError::TypeMismatch => Self::TypeMismatch,
1292 ReadableCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
1293 ReadableCommandArgumentError::InvalidUsageOfPureArgument => {
1294 Self::InvalidUsageOfPureArgument
1295 }
1296 ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
1297 Self::InvalidArgumentToPrivateEntryFunction
1298 }
1299 ReadableCommandArgumentError::IndexOutOfBounds { index } => {
1300 Self::IndexOutOfBounds { index }
1301 }
1302 ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
1303 result,
1304 subresult,
1305 } => Self::SecondaryIndexOutOfBounds { result, subresult },
1306 ReadableCommandArgumentError::InvalidResultArity { result } => {
1307 Self::InvalidResultArity { result }
1308 }
1309 ReadableCommandArgumentError::InvalidGasCoinUsage => {
1310 Self::InvalidGasCoinUsage
1311 }
1312 ReadableCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
1313 ReadableCommandArgumentError::InvalidObjectByValue => {
1314 Self::InvalidObjectByValue
1315 }
1316 ReadableCommandArgumentError::InvalidObjectByMutRef => {
1317 Self::InvalidObjectByMutRef
1318 }
1319 ReadableCommandArgumentError::SharedObjectOperationNotAllowed => {
1320 Self::SharedObjectOperationNotAllowed
1321 }
1322 }
1323 })
1324 } else {
1325 BinaryCommandArgumentError::deserialize(deserializer).map(|binary| match binary {
1326 BinaryCommandArgumentError::TypeMismatch => Self::TypeMismatch,
1327 BinaryCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
1328 BinaryCommandArgumentError::InvalidUsageOfPureArgument => {
1329 Self::InvalidUsageOfPureArgument
1330 }
1331 BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
1332 Self::InvalidArgumentToPrivateEntryFunction
1333 }
1334 BinaryCommandArgumentError::IndexOutOfBounds { index } => {
1335 Self::IndexOutOfBounds { index }
1336 }
1337 BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult } => {
1338 Self::SecondaryIndexOutOfBounds { result, subresult }
1339 }
1340 BinaryCommandArgumentError::InvalidResultArity { result } => {
1341 Self::InvalidResultArity { result }
1342 }
1343 BinaryCommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
1344 BinaryCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
1345 BinaryCommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
1346 BinaryCommandArgumentError::InvalidObjectByMutRef => {
1347 Self::InvalidObjectByMutRef
1348 }
1349 BinaryCommandArgumentError::SharedObjectOperationNotAllowed => {
1350 Self::SharedObjectOperationNotAllowed
1351 }
1352 })
1353 }
1354 }
1355 }
1356
1357 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1358 #[serde(tag = "kind", rename_all = "snake_case")]
1359 enum ReadablePackageUpgradeError {
1360 UnableToFetchPackage {
1361 package_id: ObjectId,
1362 },
1363 NotAPackage {
1364 object_id: ObjectId,
1365 },
1366 IncompatibleUpgrade,
1367 DigestDoesNotMatch {
1368 digest: Digest,
1369 },
1370 UnknownUpgradePolicy {
1371 policy: u8,
1372 },
1373 PackageIdDoesNotMatch {
1374 package_id: ObjectId,
1375 ticket_id: ObjectId,
1376 },
1377 }
1378
1379 #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1380 enum BinaryPackageUpgradeError {
1381 UnableToFetchPackage {
1382 package_id: ObjectId,
1383 },
1384 NotAPackage {
1385 object_id: ObjectId,
1386 },
1387 IncompatibleUpgrade,
1388 DigestDoesNotMatch {
1389 digest: Digest,
1390 },
1391 UnknownUpgradePolicy {
1392 policy: u8,
1393 },
1394 PackageIdDoesNotMatch {
1395 package_id: ObjectId,
1396 ticket_id: ObjectId,
1397 },
1398 }
1399
1400 impl Serialize for PackageUpgradeError {
1401 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1402 where
1403 S: Serializer,
1404 {
1405 if serializer.is_human_readable() {
1406 let readable = match self.clone() {
1407 Self::UnableToFetchPackage { package_id } => {
1408 ReadablePackageUpgradeError::UnableToFetchPackage { package_id }
1409 }
1410 Self::NotAPackage { object_id } => {
1411 ReadablePackageUpgradeError::NotAPackage { object_id }
1412 }
1413 Self::IncompatibleUpgrade => ReadablePackageUpgradeError::IncompatibleUpgrade,
1414 Self::DigestDoesNotMatch { digest } => {
1415 ReadablePackageUpgradeError::DigestDoesNotMatch { digest }
1416 }
1417 Self::UnknownUpgradePolicy { policy } => {
1418 ReadablePackageUpgradeError::UnknownUpgradePolicy { policy }
1419 }
1420 Self::PackageIdDoesNotMatch {
1421 package_id,
1422 ticket_id,
1423 } => ReadablePackageUpgradeError::PackageIdDoesNotMatch {
1424 package_id,
1425 ticket_id,
1426 },
1427 };
1428 readable.serialize(serializer)
1429 } else {
1430 let binary = match self.clone() {
1431 Self::UnableToFetchPackage { package_id } => {
1432 BinaryPackageUpgradeError::UnableToFetchPackage { package_id }
1433 }
1434 Self::NotAPackage { object_id } => {
1435 BinaryPackageUpgradeError::NotAPackage { object_id }
1436 }
1437 Self::IncompatibleUpgrade => BinaryPackageUpgradeError::IncompatibleUpgrade,
1438 Self::DigestDoesNotMatch { digest } => {
1439 BinaryPackageUpgradeError::DigestDoesNotMatch { digest }
1440 }
1441 Self::UnknownUpgradePolicy { policy } => {
1442 BinaryPackageUpgradeError::UnknownUpgradePolicy { policy }
1443 }
1444 Self::PackageIdDoesNotMatch {
1445 package_id,
1446 ticket_id,
1447 } => BinaryPackageUpgradeError::PackageIdDoesNotMatch {
1448 package_id,
1449 ticket_id,
1450 },
1451 };
1452 binary.serialize(serializer)
1453 }
1454 }
1455 }
1456
1457 impl<'de> Deserialize<'de> for PackageUpgradeError {
1458 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1459 where
1460 D: Deserializer<'de>,
1461 {
1462 if deserializer.is_human_readable() {
1463 ReadablePackageUpgradeError::deserialize(deserializer).map(
1464 |readable| match readable {
1465 ReadablePackageUpgradeError::UnableToFetchPackage { package_id } => {
1466 Self::UnableToFetchPackage { package_id }
1467 }
1468 ReadablePackageUpgradeError::NotAPackage { object_id } => {
1469 Self::NotAPackage { object_id }
1470 }
1471 ReadablePackageUpgradeError::IncompatibleUpgrade => {
1472 Self::IncompatibleUpgrade
1473 }
1474 ReadablePackageUpgradeError::DigestDoesNotMatch { digest } => {
1475 Self::DigestDoesNotMatch { digest }
1476 }
1477 ReadablePackageUpgradeError::UnknownUpgradePolicy { policy } => {
1478 Self::UnknownUpgradePolicy { policy }
1479 }
1480 ReadablePackageUpgradeError::PackageIdDoesNotMatch {
1481 package_id,
1482 ticket_id,
1483 } => Self::PackageIdDoesNotMatch {
1484 package_id,
1485 ticket_id,
1486 },
1487 },
1488 )
1489 } else {
1490 BinaryPackageUpgradeError::deserialize(deserializer).map(|binary| match binary {
1491 BinaryPackageUpgradeError::UnableToFetchPackage { package_id } => {
1492 Self::UnableToFetchPackage { package_id }
1493 }
1494 BinaryPackageUpgradeError::NotAPackage { object_id } => {
1495 Self::NotAPackage { object_id }
1496 }
1497 BinaryPackageUpgradeError::IncompatibleUpgrade => Self::IncompatibleUpgrade,
1498 BinaryPackageUpgradeError::DigestDoesNotMatch { digest } => {
1499 Self::DigestDoesNotMatch { digest }
1500 }
1501 BinaryPackageUpgradeError::UnknownUpgradePolicy { policy } => {
1502 Self::UnknownUpgradePolicy { policy }
1503 }
1504 BinaryPackageUpgradeError::PackageIdDoesNotMatch {
1505 package_id,
1506 ticket_id,
1507 } => Self::PackageIdDoesNotMatch {
1508 package_id,
1509 ticket_id,
1510 },
1511 })
1512 }
1513 }
1514 }
1515}