use super::Address;
use super::Digest;
use super::Identifier;
use super::ObjectId;
#[derive(Eq, PartialEq, Clone, Debug)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub enum ExecutionStatus {
Success,
Failure {
error: ExecutionError,
#[cfg_attr(test, map(|x: Option<u16>| x.map(Into::into)))]
command: Option<u64>,
},
}
pub type TypeParameterIndex = u16;
#[derive(Eq, PartialEq, Clone, Debug)]
#[cfg_attr(
feature = "schemars",
derive(schemars::JsonSchema),
schemars(tag = "error", rename_all = "snake_case")
)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub enum ExecutionError {
InsufficientGas,
InvalidGasObject,
InvariantViolation,
FeatureNotYetSupported,
ObjectTooBig {
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
object_size: u64,
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
max_object_size: u64,
},
PackageTooBig {
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
object_size: u64,
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
max_object_size: u64,
},
CircularObjectOwnership { object: ObjectId },
InsufficientCoinBalance,
CoinBalanceOverflow,
PublishErrorNonZeroAddress,
SuiMoveVerificationError,
MovePrimitiveRuntimeError { location: Option<MoveLocation> },
MoveAbort {
location: MoveLocation,
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
code: u64,
},
VmVerificationOrDeserializationError,
VmInvariantViolation,
FunctionNotFound,
ArityMismatch,
TypeArityMismatch,
NonEntryFunctionInvoked,
CommandArgumentError {
argument: u16,
kind: CommandArgumentError,
},
TypeArgumentError {
type_argument: TypeParameterIndex,
kind: TypeArgumentError,
},
UnusedValueWithoutDrop { result: u16, subresult: u16 },
InvalidPublicFunctionReturnType { index: u16 },
InvalidTransferObject,
EffectsTooLarge {
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
current_size: u64,
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
max_size: u64,
},
PublishUpgradeMissingDependency,
PublishUpgradeDependencyDowngrade,
#[cfg_attr(feature = "schemars", schemars(title = "PackageUpgradeError"))]
PackageUpgradeError { kind: PackageUpgradeError },
WrittenObjectsTooLarge {
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
object_size: u64,
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
max_object_size: u64,
},
CertificateDenied,
SuiMoveVerificationTimedout,
SharedObjectOperationNotAllowed,
InputObjectDeleted,
ExecutionCancelledDueToSharedObjectCongestion { congested_objects: Vec<ObjectId> },
AddressDeniedForCoin { address: Address, coin_type: String },
CoinTypeGlobalPause { coin_type: String },
ExecutionCancelledDueToRandomnessUnavailable,
}
#[derive(Eq, PartialEq, Clone, Debug)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub struct MoveLocation {
pub package: ObjectId,
pub module: Identifier,
pub function: u16,
pub instruction: u16,
pub function_name: Option<Identifier>,
}
#[derive(Eq, PartialEq, Clone, Debug)]
#[cfg_attr(
feature = "schemars",
derive(schemars::JsonSchema),
schemars(tag = "kind", rename_all = "snake_case")
)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub enum CommandArgumentError {
TypeMismatch,
InvalidBcsBytes,
InvalidUsageOfPureArgument,
InvalidArgumentToPrivateEntryFunction,
IndexOutOfBounds { index: u16 },
SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
InvalidResultArity { result: u16 },
InvalidGasCoinUsage,
InvalidValueUsage,
InvalidObjectByValue,
InvalidObjectByMutRef,
SharedObjectOperationNotAllowed,
}
#[derive(Eq, PartialEq, Clone, Debug)]
#[cfg_attr(
feature = "schemars",
derive(schemars::JsonSchema),
schemars(tag = "kind", rename_all = "snake_case")
)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub enum PackageUpgradeError {
UnableToFetchPackage { package_id: ObjectId },
NotAPackage { object_id: ObjectId },
IncompatibleUpgrade,
DigestDoesNotMatch { digest: Digest },
UnknownUpgradePolicy { policy: u8 },
PackageIdDoesNotMatch {
package_id: ObjectId,
ticket_id: ObjectId,
},
}
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize),
serde(rename_all = "snake_case")
)]
#[cfg_attr(
feature = "schemars",
derive(schemars::JsonSchema),
schemars(rename_all = "snake_case")
)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub enum TypeArgumentError {
TypeNotFound,
ConstraintNotSatisfied,
}
#[cfg(feature = "serde")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
mod serialization {
use super::*;
use serde::Deserialize;
use serde::Deserializer;
use serde::Serialize;
use serde::Serializer;
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(rename = "ExecutionStatus")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
struct ReadableExecutionStatus {
success: bool,
#[serde(skip_serializing_if = "Option::is_none")]
status: Option<FailureStatus>,
}
#[cfg(feature = "schemars")]
impl schemars::JsonSchema for ExecutionStatus {
fn schema_name() -> String {
ReadableExecutionStatus::schema_name()
}
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
ReadableExecutionStatus::json_schema(gen)
}
}
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
struct FailureStatus {
error: ExecutionError,
#[serde(skip_serializing_if = "Option::is_none")]
command: Option<u16>,
}
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
enum BinaryExecutionStatus {
Success,
Failure {
error: ExecutionError,
command: Option<u64>,
},
}
impl Serialize for ExecutionStatus {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if serializer.is_human_readable() {
let readable = match self.clone() {
ExecutionStatus::Success => ReadableExecutionStatus {
success: true,
status: None,
},
ExecutionStatus::Failure { error, command } => ReadableExecutionStatus {
success: false,
status: Some(FailureStatus {
error,
command: command.map(|c| c as u16),
}),
},
};
readable.serialize(serializer)
} else {
let binary = match self.clone() {
ExecutionStatus::Success => BinaryExecutionStatus::Success,
ExecutionStatus::Failure { error, command } => {
BinaryExecutionStatus::Failure { error, command }
}
};
binary.serialize(serializer)
}
}
}
impl<'de> Deserialize<'de> for ExecutionStatus {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
if deserializer.is_human_readable() {
let ReadableExecutionStatus { success, status } =
Deserialize::deserialize(deserializer)?;
match (success, status) {
(true, None) => Ok(ExecutionStatus::Success),
(false, Some(FailureStatus { error, command })) => {
Ok(ExecutionStatus::Failure {
error,
command: command.map(Into::into),
})
}
(true, Some(_)) | (false, None) => {
Err(serde::de::Error::custom("invalid execution status"))
}
}
} else {
BinaryExecutionStatus::deserialize(deserializer).map(|readable| match readable {
BinaryExecutionStatus::Success => Self::Success,
BinaryExecutionStatus::Failure { error, command } => {
Self::Failure { error, command }
}
})
}
}
}
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(tag = "error", rename_all = "snake_case")]
enum ReadableExecutionError {
InsufficientGas,
InvalidGasObject,
InvariantViolation,
FeatureNotYetSupported,
ObjectTooBig {
#[serde(with = "crate::_serde::ReadableDisplay")]
object_size: u64,
#[serde(with = "crate::_serde::ReadableDisplay")]
max_object_size: u64,
},
PackageTooBig {
#[serde(with = "crate::_serde::ReadableDisplay")]
object_size: u64,
#[serde(with = "crate::_serde::ReadableDisplay")]
max_object_size: u64,
},
CircularObjectOwnership {
object: ObjectId,
},
InsufficientCoinBalance,
CoinBalanceOverflow,
PublishErrorNonZeroAddress,
SuiMoveVerificationError,
MovePrimitiveRuntimeError {
location: Option<MoveLocation>,
},
MoveAbort {
location: MoveLocation,
#[serde(with = "crate::_serde::ReadableDisplay")]
code: u64,
},
VmVerificationOrDeserializationError,
VmInvariantViolation,
FunctionNotFound,
ArityMismatch,
TypeArityMismatch,
NonEntryFunctionInvoked,
CommandArgumentError {
argument: u16,
kind: CommandArgumentError,
},
TypeArgumentError {
type_argument: TypeParameterIndex,
kind: TypeArgumentError,
},
UnusedValueWithoutDrop {
result: u16,
subresult: u16,
},
InvalidPublicFunctionReturnType {
index: u16,
},
InvalidTransferObject,
EffectsTooLarge {
#[serde(with = "crate::_serde::ReadableDisplay")]
current_size: u64,
#[serde(with = "crate::_serde::ReadableDisplay")]
max_size: u64,
},
PublishUpgradeMissingDependency,
PublishUpgradeDependencyDowngrade,
PackageUpgradeError {
kind: PackageUpgradeError,
},
WrittenObjectsTooLarge {
#[serde(with = "crate::_serde::ReadableDisplay")]
object_size: u64,
#[serde(with = "crate::_serde::ReadableDisplay")]
max_object_size: u64,
},
CertificateDenied,
SuiMoveVerificationTimedout,
SharedObjectOperationNotAllowed,
InputObjectDeleted,
ExecutionCancelledDueToSharedObjectCongestion {
congested_objects: Vec<ObjectId>,
},
AddressDeniedForCoin {
address: Address,
coin_type: String,
},
CoinTypeGlobalPause {
coin_type: String,
},
ExecutionCancelledDueToRandomnessUnavailable,
}
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
enum BinaryExecutionError {
InsufficientGas,
InvalidGasObject,
InvariantViolation,
FeatureNotYetSupported,
ObjectTooBig {
object_size: u64,
max_object_size: u64,
},
PackageTooBig {
object_size: u64,
max_object_size: u64,
},
CircularObjectOwnership {
object: ObjectId,
},
InsufficientCoinBalance,
CoinBalanceOverflow,
PublishErrorNonZeroAddress,
SuiMoveVerificationError,
MovePrimitiveRuntimeError {
location: Option<MoveLocation>,
},
MoveAbort {
location: MoveLocation,
code: u64,
},
VmVerificationOrDeserializationError,
VmInvariantViolation,
FunctionNotFound,
ArityMismatch,
TypeArityMismatch,
NonEntryFunctionInvoked,
CommandArgumentError {
argument: u16,
kind: CommandArgumentError,
},
TypeArgumentError {
type_argument: TypeParameterIndex,
kind: TypeArgumentError,
},
UnusedValueWithoutDrop {
result: u16,
subresult: u16,
},
InvalidPublicFunctionReturnType {
index: u16,
},
InvalidTransferObject,
EffectsTooLarge {
current_size: u64,
max_size: u64,
},
PublishUpgradeMissingDependency,
PublishUpgradeDependencyDowngrade,
PackageUpgradeError {
kind: PackageUpgradeError,
},
WrittenObjectsTooLarge {
object_size: u64,
max_object_size: u64,
},
CertificateDenied,
SuiMoveVerificationTimedout,
SharedObjectOperationNotAllowed,
InputObjectDeleted,
ExecutionCancelledDueToSharedObjectCongestion {
congested_objects: Vec<ObjectId>,
},
AddressDeniedForCoin {
address: Address,
coin_type: String,
},
CoinTypeGlobalPause {
coin_type: String,
},
ExecutionCancelledDueToRandomnessUnavailable,
}
impl Serialize for ExecutionError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if serializer.is_human_readable() {
let readable = match self.clone() {
Self::InsufficientGas => ReadableExecutionError::InsufficientGas,
Self::InvalidGasObject => ReadableExecutionError::InvalidGasObject,
Self::InvariantViolation => ReadableExecutionError::InvariantViolation,
Self::FeatureNotYetSupported => ReadableExecutionError::FeatureNotYetSupported,
Self::ObjectTooBig {
object_size,
max_object_size,
} => ReadableExecutionError::ObjectTooBig {
object_size,
max_object_size,
},
Self::PackageTooBig {
object_size,
max_object_size,
} => ReadableExecutionError::PackageTooBig {
object_size,
max_object_size,
},
Self::CircularObjectOwnership { object } => {
ReadableExecutionError::CircularObjectOwnership { object }
}
Self::InsufficientCoinBalance => {
ReadableExecutionError::InsufficientCoinBalance
}
Self::CoinBalanceOverflow => ReadableExecutionError::CoinBalanceOverflow,
Self::PublishErrorNonZeroAddress => {
ReadableExecutionError::PublishErrorNonZeroAddress
}
Self::SuiMoveVerificationError => {
ReadableExecutionError::SuiMoveVerificationError
}
Self::MovePrimitiveRuntimeError { location } => {
ReadableExecutionError::MovePrimitiveRuntimeError { location }
}
Self::MoveAbort { location, code } => {
ReadableExecutionError::MoveAbort { location, code }
}
Self::VmVerificationOrDeserializationError => {
ReadableExecutionError::VmVerificationOrDeserializationError
}
Self::VmInvariantViolation => ReadableExecutionError::VmInvariantViolation,
Self::FunctionNotFound => ReadableExecutionError::FunctionNotFound,
Self::ArityMismatch => ReadableExecutionError::ArityMismatch,
Self::TypeArityMismatch => ReadableExecutionError::TypeArityMismatch,
Self::NonEntryFunctionInvoked => {
ReadableExecutionError::NonEntryFunctionInvoked
}
Self::CommandArgumentError { argument, kind } => {
ReadableExecutionError::CommandArgumentError { argument, kind }
}
Self::TypeArgumentError {
type_argument,
kind,
} => ReadableExecutionError::TypeArgumentError {
type_argument,
kind,
},
Self::UnusedValueWithoutDrop { result, subresult } => {
ReadableExecutionError::UnusedValueWithoutDrop { result, subresult }
}
Self::InvalidPublicFunctionReturnType { index } => {
ReadableExecutionError::InvalidPublicFunctionReturnType { index }
}
Self::InvalidTransferObject => ReadableExecutionError::InvalidTransferObject,
Self::EffectsTooLarge {
current_size,
max_size,
} => ReadableExecutionError::EffectsTooLarge {
current_size,
max_size,
},
Self::PublishUpgradeMissingDependency => {
ReadableExecutionError::PublishUpgradeMissingDependency
}
Self::PublishUpgradeDependencyDowngrade => {
ReadableExecutionError::PublishUpgradeDependencyDowngrade
}
Self::PackageUpgradeError { kind } => {
ReadableExecutionError::PackageUpgradeError { kind }
}
Self::WrittenObjectsTooLarge {
object_size,
max_object_size,
} => ReadableExecutionError::WrittenObjectsTooLarge {
object_size,
max_object_size,
},
Self::CertificateDenied => ReadableExecutionError::CertificateDenied,
Self::SuiMoveVerificationTimedout => {
ReadableExecutionError::SuiMoveVerificationTimedout
}
Self::SharedObjectOperationNotAllowed => {
ReadableExecutionError::SharedObjectOperationNotAllowed
}
Self::InputObjectDeleted => ReadableExecutionError::InputObjectDeleted,
Self::ExecutionCancelledDueToSharedObjectCongestion { congested_objects } => {
ReadableExecutionError::ExecutionCancelledDueToSharedObjectCongestion {
congested_objects,
}
}
Self::AddressDeniedForCoin { address, coin_type } => {
ReadableExecutionError::AddressDeniedForCoin { address, coin_type }
}
Self::CoinTypeGlobalPause { coin_type } => {
ReadableExecutionError::CoinTypeGlobalPause { coin_type }
}
Self::ExecutionCancelledDueToRandomnessUnavailable => {
ReadableExecutionError::ExecutionCancelledDueToRandomnessUnavailable
}
};
readable.serialize(serializer)
} else {
let binary = match self.clone() {
Self::InsufficientGas => BinaryExecutionError::InsufficientGas,
Self::InvalidGasObject => BinaryExecutionError::InvalidGasObject,
Self::InvariantViolation => BinaryExecutionError::InvariantViolation,
Self::FeatureNotYetSupported => BinaryExecutionError::FeatureNotYetSupported,
Self::ObjectTooBig {
object_size,
max_object_size,
} => BinaryExecutionError::ObjectTooBig {
object_size,
max_object_size,
},
Self::PackageTooBig {
object_size,
max_object_size,
} => BinaryExecutionError::PackageTooBig {
object_size,
max_object_size,
},
Self::CircularObjectOwnership { object } => {
BinaryExecutionError::CircularObjectOwnership { object }
}
Self::InsufficientCoinBalance => BinaryExecutionError::InsufficientCoinBalance,
Self::CoinBalanceOverflow => BinaryExecutionError::CoinBalanceOverflow,
Self::PublishErrorNonZeroAddress => {
BinaryExecutionError::PublishErrorNonZeroAddress
}
Self::SuiMoveVerificationError => {
BinaryExecutionError::SuiMoveVerificationError
}
Self::MovePrimitiveRuntimeError { location } => {
BinaryExecutionError::MovePrimitiveRuntimeError { location }
}
Self::MoveAbort { location, code } => {
BinaryExecutionError::MoveAbort { location, code }
}
Self::VmVerificationOrDeserializationError => {
BinaryExecutionError::VmVerificationOrDeserializationError
}
Self::VmInvariantViolation => BinaryExecutionError::VmInvariantViolation,
Self::FunctionNotFound => BinaryExecutionError::FunctionNotFound,
Self::ArityMismatch => BinaryExecutionError::ArityMismatch,
Self::TypeArityMismatch => BinaryExecutionError::TypeArityMismatch,
Self::NonEntryFunctionInvoked => BinaryExecutionError::NonEntryFunctionInvoked,
Self::CommandArgumentError { argument, kind } => {
BinaryExecutionError::CommandArgumentError { argument, kind }
}
Self::TypeArgumentError {
type_argument,
kind,
} => BinaryExecutionError::TypeArgumentError {
type_argument,
kind,
},
Self::UnusedValueWithoutDrop { result, subresult } => {
BinaryExecutionError::UnusedValueWithoutDrop { result, subresult }
}
Self::InvalidPublicFunctionReturnType { index } => {
BinaryExecutionError::InvalidPublicFunctionReturnType { index }
}
Self::InvalidTransferObject => BinaryExecutionError::InvalidTransferObject,
Self::EffectsTooLarge {
current_size,
max_size,
} => BinaryExecutionError::EffectsTooLarge {
current_size,
max_size,
},
Self::PublishUpgradeMissingDependency => {
BinaryExecutionError::PublishUpgradeMissingDependency
}
Self::PublishUpgradeDependencyDowngrade => {
BinaryExecutionError::PublishUpgradeDependencyDowngrade
}
Self::PackageUpgradeError { kind } => {
BinaryExecutionError::PackageUpgradeError { kind }
}
Self::WrittenObjectsTooLarge {
object_size,
max_object_size,
} => BinaryExecutionError::WrittenObjectsTooLarge {
object_size,
max_object_size,
},
Self::CertificateDenied => BinaryExecutionError::CertificateDenied,
Self::SuiMoveVerificationTimedout => {
BinaryExecutionError::SuiMoveVerificationTimedout
}
Self::SharedObjectOperationNotAllowed => {
BinaryExecutionError::SharedObjectOperationNotAllowed
}
Self::InputObjectDeleted => BinaryExecutionError::InputObjectDeleted,
Self::ExecutionCancelledDueToSharedObjectCongestion { congested_objects } => {
BinaryExecutionError::ExecutionCancelledDueToSharedObjectCongestion {
congested_objects,
}
}
Self::AddressDeniedForCoin { address, coin_type } => {
BinaryExecutionError::AddressDeniedForCoin { address, coin_type }
}
Self::CoinTypeGlobalPause { coin_type } => {
BinaryExecutionError::CoinTypeGlobalPause { coin_type }
}
Self::ExecutionCancelledDueToRandomnessUnavailable => {
BinaryExecutionError::ExecutionCancelledDueToRandomnessUnavailable
}
};
binary.serialize(serializer)
}
}
}
impl<'de> Deserialize<'de> for ExecutionError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
if deserializer.is_human_readable() {
ReadableExecutionError::deserialize(deserializer).map(|readable| match readable {
ReadableExecutionError::InsufficientGas => Self::InsufficientGas,
ReadableExecutionError::InvalidGasObject => Self::InvalidGasObject,
ReadableExecutionError::InvariantViolation => Self::InvariantViolation,
ReadableExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
ReadableExecutionError::ObjectTooBig {
object_size,
max_object_size,
} => Self::ObjectTooBig {
object_size,
max_object_size,
},
ReadableExecutionError::PackageTooBig {
object_size,
max_object_size,
} => Self::PackageTooBig {
object_size,
max_object_size,
},
ReadableExecutionError::CircularObjectOwnership { object } => {
Self::CircularObjectOwnership { object }
}
ReadableExecutionError::InsufficientCoinBalance => {
Self::InsufficientCoinBalance
}
ReadableExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
ReadableExecutionError::PublishErrorNonZeroAddress => {
Self::PublishErrorNonZeroAddress
}
ReadableExecutionError::SuiMoveVerificationError => {
Self::SuiMoveVerificationError
}
ReadableExecutionError::MovePrimitiveRuntimeError { location } => {
Self::MovePrimitiveRuntimeError { location }
}
ReadableExecutionError::MoveAbort { location, code } => {
Self::MoveAbort { location, code }
}
ReadableExecutionError::VmVerificationOrDeserializationError => {
Self::VmVerificationOrDeserializationError
}
ReadableExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
ReadableExecutionError::FunctionNotFound => Self::FunctionNotFound,
ReadableExecutionError::ArityMismatch => Self::ArityMismatch,
ReadableExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
ReadableExecutionError::NonEntryFunctionInvoked => {
Self::NonEntryFunctionInvoked
}
ReadableExecutionError::CommandArgumentError { argument, kind } => {
Self::CommandArgumentError { argument, kind }
}
ReadableExecutionError::TypeArgumentError {
type_argument,
kind,
} => Self::TypeArgumentError {
type_argument,
kind,
},
ReadableExecutionError::UnusedValueWithoutDrop { result, subresult } => {
Self::UnusedValueWithoutDrop { result, subresult }
}
ReadableExecutionError::InvalidPublicFunctionReturnType { index } => {
Self::InvalidPublicFunctionReturnType { index }
}
ReadableExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
ReadableExecutionError::EffectsTooLarge {
current_size,
max_size,
} => Self::EffectsTooLarge {
current_size,
max_size,
},
ReadableExecutionError::PublishUpgradeMissingDependency => {
Self::PublishUpgradeMissingDependency
}
ReadableExecutionError::PublishUpgradeDependencyDowngrade => {
Self::PublishUpgradeDependencyDowngrade
}
ReadableExecutionError::PackageUpgradeError { kind } => {
Self::PackageUpgradeError { kind }
}
ReadableExecutionError::WrittenObjectsTooLarge {
object_size,
max_object_size,
} => Self::WrittenObjectsTooLarge {
object_size,
max_object_size,
},
ReadableExecutionError::CertificateDenied => Self::CertificateDenied,
ReadableExecutionError::SuiMoveVerificationTimedout => {
Self::SuiMoveVerificationTimedout
}
ReadableExecutionError::SharedObjectOperationNotAllowed => {
Self::SharedObjectOperationNotAllowed
}
ReadableExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
ReadableExecutionError::ExecutionCancelledDueToSharedObjectCongestion {
congested_objects,
} => Self::ExecutionCancelledDueToSharedObjectCongestion { congested_objects },
ReadableExecutionError::AddressDeniedForCoin { address, coin_type } => {
Self::AddressDeniedForCoin { address, coin_type }
}
ReadableExecutionError::CoinTypeGlobalPause { coin_type } => {
Self::CoinTypeGlobalPause { coin_type }
}
ReadableExecutionError::ExecutionCancelledDueToRandomnessUnavailable => {
Self::ExecutionCancelledDueToRandomnessUnavailable
}
})
} else {
BinaryExecutionError::deserialize(deserializer).map(|binary| match binary {
BinaryExecutionError::InsufficientGas => Self::InsufficientGas,
BinaryExecutionError::InvalidGasObject => Self::InvalidGasObject,
BinaryExecutionError::InvariantViolation => Self::InvariantViolation,
BinaryExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
BinaryExecutionError::ObjectTooBig {
object_size,
max_object_size,
} => Self::ObjectTooBig {
object_size,
max_object_size,
},
BinaryExecutionError::PackageTooBig {
object_size,
max_object_size,
} => Self::PackageTooBig {
object_size,
max_object_size,
},
BinaryExecutionError::CircularObjectOwnership { object } => {
Self::CircularObjectOwnership { object }
}
BinaryExecutionError::InsufficientCoinBalance => Self::InsufficientCoinBalance,
BinaryExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
BinaryExecutionError::PublishErrorNonZeroAddress => {
Self::PublishErrorNonZeroAddress
}
BinaryExecutionError::SuiMoveVerificationError => {
Self::SuiMoveVerificationError
}
BinaryExecutionError::MovePrimitiveRuntimeError { location } => {
Self::MovePrimitiveRuntimeError { location }
}
BinaryExecutionError::MoveAbort { location, code } => {
Self::MoveAbort { location, code }
}
BinaryExecutionError::VmVerificationOrDeserializationError => {
Self::VmVerificationOrDeserializationError
}
BinaryExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
BinaryExecutionError::FunctionNotFound => Self::FunctionNotFound,
BinaryExecutionError::ArityMismatch => Self::ArityMismatch,
BinaryExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
BinaryExecutionError::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
BinaryExecutionError::CommandArgumentError { argument, kind } => {
Self::CommandArgumentError { argument, kind }
}
BinaryExecutionError::TypeArgumentError {
type_argument,
kind,
} => Self::TypeArgumentError {
type_argument,
kind,
},
BinaryExecutionError::UnusedValueWithoutDrop { result, subresult } => {
Self::UnusedValueWithoutDrop { result, subresult }
}
BinaryExecutionError::InvalidPublicFunctionReturnType { index } => {
Self::InvalidPublicFunctionReturnType { index }
}
BinaryExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
BinaryExecutionError::EffectsTooLarge {
current_size,
max_size,
} => Self::EffectsTooLarge {
current_size,
max_size,
},
BinaryExecutionError::PublishUpgradeMissingDependency => {
Self::PublishUpgradeMissingDependency
}
BinaryExecutionError::PublishUpgradeDependencyDowngrade => {
Self::PublishUpgradeDependencyDowngrade
}
BinaryExecutionError::PackageUpgradeError { kind } => {
Self::PackageUpgradeError { kind }
}
BinaryExecutionError::WrittenObjectsTooLarge {
object_size,
max_object_size,
} => Self::WrittenObjectsTooLarge {
object_size,
max_object_size,
},
BinaryExecutionError::CertificateDenied => Self::CertificateDenied,
BinaryExecutionError::SuiMoveVerificationTimedout => {
Self::SuiMoveVerificationTimedout
}
BinaryExecutionError::SharedObjectOperationNotAllowed => {
Self::SharedObjectOperationNotAllowed
}
BinaryExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
BinaryExecutionError::ExecutionCancelledDueToSharedObjectCongestion {
congested_objects,
} => Self::ExecutionCancelledDueToSharedObjectCongestion { congested_objects },
BinaryExecutionError::AddressDeniedForCoin { address, coin_type } => {
Self::AddressDeniedForCoin { address, coin_type }
}
BinaryExecutionError::CoinTypeGlobalPause { coin_type } => {
Self::CoinTypeGlobalPause { coin_type }
}
BinaryExecutionError::ExecutionCancelledDueToRandomnessUnavailable => {
Self::ExecutionCancelledDueToRandomnessUnavailable
}
})
}
}
}
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
enum ReadableCommandArgumentError {
TypeMismatch,
InvalidBcsBytes,
InvalidUsageOfPureArgument,
InvalidArgumentToPrivateEntryFunction,
IndexOutOfBounds { index: u16 },
SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
InvalidResultArity { result: u16 },
InvalidGasCoinUsage,
InvalidValueUsage,
InvalidObjectByValue,
InvalidObjectByMutRef,
SharedObjectOperationNotAllowed,
}
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
enum BinaryCommandArgumentError {
TypeMismatch,
InvalidBcsBytes,
InvalidUsageOfPureArgument,
InvalidArgumentToPrivateEntryFunction,
IndexOutOfBounds { index: u16 },
SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
InvalidResultArity { result: u16 },
InvalidGasCoinUsage,
InvalidValueUsage,
InvalidObjectByValue,
InvalidObjectByMutRef,
SharedObjectOperationNotAllowed,
}
impl Serialize for CommandArgumentError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if serializer.is_human_readable() {
let readable = match self.clone() {
Self::TypeMismatch => ReadableCommandArgumentError::TypeMismatch,
Self::InvalidBcsBytes => ReadableCommandArgumentError::InvalidBcsBytes,
Self::InvalidUsageOfPureArgument => {
ReadableCommandArgumentError::InvalidUsageOfPureArgument
}
Self::InvalidArgumentToPrivateEntryFunction => {
ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction
}
Self::IndexOutOfBounds { index } => {
ReadableCommandArgumentError::IndexOutOfBounds { index }
}
Self::SecondaryIndexOutOfBounds { result, subresult } => {
ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
result,
subresult,
}
}
Self::InvalidResultArity { result } => {
ReadableCommandArgumentError::InvalidResultArity { result }
}
Self::InvalidGasCoinUsage => ReadableCommandArgumentError::InvalidGasCoinUsage,
Self::InvalidValueUsage => ReadableCommandArgumentError::InvalidValueUsage,
Self::InvalidObjectByValue => {
ReadableCommandArgumentError::InvalidObjectByValue
}
Self::InvalidObjectByMutRef => {
ReadableCommandArgumentError::InvalidObjectByMutRef
}
Self::SharedObjectOperationNotAllowed => {
ReadableCommandArgumentError::SharedObjectOperationNotAllowed
}
};
readable.serialize(serializer)
} else {
let binary = match self.clone() {
Self::TypeMismatch => BinaryCommandArgumentError::TypeMismatch,
Self::InvalidBcsBytes => BinaryCommandArgumentError::InvalidBcsBytes,
Self::InvalidUsageOfPureArgument => {
BinaryCommandArgumentError::InvalidUsageOfPureArgument
}
Self::InvalidArgumentToPrivateEntryFunction => {
BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction
}
Self::IndexOutOfBounds { index } => {
BinaryCommandArgumentError::IndexOutOfBounds { index }
}
Self::SecondaryIndexOutOfBounds { result, subresult } => {
BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult }
}
Self::InvalidResultArity { result } => {
BinaryCommandArgumentError::InvalidResultArity { result }
}
Self::InvalidGasCoinUsage => BinaryCommandArgumentError::InvalidGasCoinUsage,
Self::InvalidValueUsage => BinaryCommandArgumentError::InvalidValueUsage,
Self::InvalidObjectByValue => BinaryCommandArgumentError::InvalidObjectByValue,
Self::InvalidObjectByMutRef => {
BinaryCommandArgumentError::InvalidObjectByMutRef
}
Self::SharedObjectOperationNotAllowed => {
BinaryCommandArgumentError::SharedObjectOperationNotAllowed
}
};
binary.serialize(serializer)
}
}
}
impl<'de> Deserialize<'de> for CommandArgumentError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
if deserializer.is_human_readable() {
ReadableCommandArgumentError::deserialize(deserializer).map(|readable| {
match readable {
ReadableCommandArgumentError::TypeMismatch => Self::TypeMismatch,
ReadableCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
ReadableCommandArgumentError::InvalidUsageOfPureArgument => {
Self::InvalidUsageOfPureArgument
}
ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
Self::InvalidArgumentToPrivateEntryFunction
}
ReadableCommandArgumentError::IndexOutOfBounds { index } => {
Self::IndexOutOfBounds { index }
}
ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
result,
subresult,
} => Self::SecondaryIndexOutOfBounds { result, subresult },
ReadableCommandArgumentError::InvalidResultArity { result } => {
Self::InvalidResultArity { result }
}
ReadableCommandArgumentError::InvalidGasCoinUsage => {
Self::InvalidGasCoinUsage
}
ReadableCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
ReadableCommandArgumentError::InvalidObjectByValue => {
Self::InvalidObjectByValue
}
ReadableCommandArgumentError::InvalidObjectByMutRef => {
Self::InvalidObjectByMutRef
}
ReadableCommandArgumentError::SharedObjectOperationNotAllowed => {
Self::SharedObjectOperationNotAllowed
}
}
})
} else {
BinaryCommandArgumentError::deserialize(deserializer).map(|binary| match binary {
BinaryCommandArgumentError::TypeMismatch => Self::TypeMismatch,
BinaryCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
BinaryCommandArgumentError::InvalidUsageOfPureArgument => {
Self::InvalidUsageOfPureArgument
}
BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
Self::InvalidArgumentToPrivateEntryFunction
}
BinaryCommandArgumentError::IndexOutOfBounds { index } => {
Self::IndexOutOfBounds { index }
}
BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult } => {
Self::SecondaryIndexOutOfBounds { result, subresult }
}
BinaryCommandArgumentError::InvalidResultArity { result } => {
Self::InvalidResultArity { result }
}
BinaryCommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
BinaryCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
BinaryCommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
BinaryCommandArgumentError::InvalidObjectByMutRef => {
Self::InvalidObjectByMutRef
}
BinaryCommandArgumentError::SharedObjectOperationNotAllowed => {
Self::SharedObjectOperationNotAllowed
}
})
}
}
}
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
enum ReadablePackageUpgradeError {
UnableToFetchPackage {
package_id: ObjectId,
},
NotAPackage {
object_id: ObjectId,
},
IncompatibleUpgrade,
DigestDoesNotMatch {
digest: Digest,
},
UnknownUpgradePolicy {
policy: u8,
},
PackageIdDoesNotMatch {
package_id: ObjectId,
ticket_id: ObjectId,
},
}
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
enum BinaryPackageUpgradeError {
UnableToFetchPackage {
package_id: ObjectId,
},
NotAPackage {
object_id: ObjectId,
},
IncompatibleUpgrade,
DigestDoesNotMatch {
digest: Digest,
},
UnknownUpgradePolicy {
policy: u8,
},
PackageIdDoesNotMatch {
package_id: ObjectId,
ticket_id: ObjectId,
},
}
impl Serialize for PackageUpgradeError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if serializer.is_human_readable() {
let readable = match self.clone() {
Self::UnableToFetchPackage { package_id } => {
ReadablePackageUpgradeError::UnableToFetchPackage { package_id }
}
Self::NotAPackage { object_id } => {
ReadablePackageUpgradeError::NotAPackage { object_id }
}
Self::IncompatibleUpgrade => ReadablePackageUpgradeError::IncompatibleUpgrade,
Self::DigestDoesNotMatch { digest } => {
ReadablePackageUpgradeError::DigestDoesNotMatch { digest }
}
Self::UnknownUpgradePolicy { policy } => {
ReadablePackageUpgradeError::UnknownUpgradePolicy { policy }
}
Self::PackageIdDoesNotMatch {
package_id,
ticket_id,
} => ReadablePackageUpgradeError::PackageIdDoesNotMatch {
package_id,
ticket_id,
},
};
readable.serialize(serializer)
} else {
let binary = match self.clone() {
Self::UnableToFetchPackage { package_id } => {
BinaryPackageUpgradeError::UnableToFetchPackage { package_id }
}
Self::NotAPackage { object_id } => {
BinaryPackageUpgradeError::NotAPackage { object_id }
}
Self::IncompatibleUpgrade => BinaryPackageUpgradeError::IncompatibleUpgrade,
Self::DigestDoesNotMatch { digest } => {
BinaryPackageUpgradeError::DigestDoesNotMatch { digest }
}
Self::UnknownUpgradePolicy { policy } => {
BinaryPackageUpgradeError::UnknownUpgradePolicy { policy }
}
Self::PackageIdDoesNotMatch {
package_id,
ticket_id,
} => BinaryPackageUpgradeError::PackageIdDoesNotMatch {
package_id,
ticket_id,
},
};
binary.serialize(serializer)
}
}
}
impl<'de> Deserialize<'de> for PackageUpgradeError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
if deserializer.is_human_readable() {
ReadablePackageUpgradeError::deserialize(deserializer).map(
|readable| match readable {
ReadablePackageUpgradeError::UnableToFetchPackage { package_id } => {
Self::UnableToFetchPackage { package_id }
}
ReadablePackageUpgradeError::NotAPackage { object_id } => {
Self::NotAPackage { object_id }
}
ReadablePackageUpgradeError::IncompatibleUpgrade => {
Self::IncompatibleUpgrade
}
ReadablePackageUpgradeError::DigestDoesNotMatch { digest } => {
Self::DigestDoesNotMatch { digest }
}
ReadablePackageUpgradeError::UnknownUpgradePolicy { policy } => {
Self::UnknownUpgradePolicy { policy }
}
ReadablePackageUpgradeError::PackageIdDoesNotMatch {
package_id,
ticket_id,
} => Self::PackageIdDoesNotMatch {
package_id,
ticket_id,
},
},
)
} else {
BinaryPackageUpgradeError::deserialize(deserializer).map(|binary| match binary {
BinaryPackageUpgradeError::UnableToFetchPackage { package_id } => {
Self::UnableToFetchPackage { package_id }
}
BinaryPackageUpgradeError::NotAPackage { object_id } => {
Self::NotAPackage { object_id }
}
BinaryPackageUpgradeError::IncompatibleUpgrade => Self::IncompatibleUpgrade,
BinaryPackageUpgradeError::DigestDoesNotMatch { digest } => {
Self::DigestDoesNotMatch { digest }
}
BinaryPackageUpgradeError::UnknownUpgradePolicy { policy } => {
Self::UnknownUpgradePolicy { policy }
}
BinaryPackageUpgradeError::PackageIdDoesNotMatch {
package_id,
ticket_id,
} => Self::PackageIdDoesNotMatch {
package_id,
ticket_id,
},
})
}
}
}
}