Skip to main content

sui_types/
sui_sdk_types_conversions.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Module for conversions between sui-core types and sui-sdk types
5//!
6//! For now this module makes heavy use of the `bcs_convert_impl` macro to implement the `From` trait
7//! for converting between core and external sdk types, relying on the fact that the BCS format of
8//! these types are strictly identical. As time goes on we'll slowly hand implement these impls
9//! directly to avoid going through the BCS machinery.
10
11use fastcrypto::traits::ToFromBytes;
12use nonempty::NonEmpty;
13use sui_sdk_types::{
14    self, AccumulatorWrite, ActiveJwk, Address, Argument, AuthenticatorStateExpire, Bitmap,
15    Bls12381PublicKey, Bls12381Signature, CanceledTransaction, CanceledTransactionV2, ChangeEpoch,
16    CheckpointCommitment, CheckpointContents, CheckpointData, CheckpointSummary, Command,
17    CommandArgumentError, ConsensusDeterminedVersionAssignments, Digest, Ed25519PublicKey,
18    Ed25519Signature, EndOfEpochTransactionKind, Event, ExecutionError, ExecutionStatus,
19    ExecutionTimeObservationKey, ExecutionTimeObservations, FundsWithdrawal, IdOperation,
20    Identifier, Input, Jwk, JwkId, MakeMoveVector, MergeCoins, MlDsa65PublicKey, MlDsa65Signature,
21    MoveCall, MoveLocation, MovePackage, MultisigMemberPublicKey, MultisigMemberSignature,
22    Mutability, Object, ObjectIn, ObjectOut, ObjectReference, Owner, PackageUpgradeError,
23    PasskeyAuthenticator, PasskeyPublicKey, Publish, Secp256k1PublicKey, Secp256k1Signature,
24    Secp256r1PublicKey, Secp256r1Signature, SharedInput, SignatureScheme, SignedCheckpointSummary,
25    SignedTransaction, SimpleSignature, SplitCoins, StructTag, SystemPackage, Transaction,
26    TransactionEffects, TransactionEffectsV1, TransactionEffectsV2, TransactionEvents,
27    TransactionExpiration, TransactionKind, TransferObjects, TypeArgumentError, TypeParseError,
28    TypeTag, UnchangedConsensusKind, Upgrade, UserSignature, ValidatorAggregatedSignature,
29    ValidatorCommittee, ValidatorCommitteeMember, ValidatorExecutionTimeObservation,
30    VersionAssignment, VersionAssignmentV2, ZkLoginAuthenticator, ZkLoginPublicIdentifier,
31};
32use tap::Pipe;
33
34use crate::crypto::SuiSignature as _;
35use crate::execution_status::ExecutionFailure;
36
37#[derive(Debug)]
38pub struct SdkTypeConversionError(String);
39
40impl std::fmt::Display for SdkTypeConversionError {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        f.write_str(&self.0)
43    }
44}
45
46impl std::error::Error for SdkTypeConversionError {}
47
48impl From<TypeParseError> for SdkTypeConversionError {
49    fn from(value: TypeParseError) -> Self {
50        Self(value.to_string())
51    }
52}
53
54impl From<anyhow::Error> for SdkTypeConversionError {
55    fn from(value: anyhow::Error) -> Self {
56        Self(value.to_string())
57    }
58}
59
60impl From<bcs::Error> for SdkTypeConversionError {
61    fn from(value: bcs::Error) -> Self {
62        Self(value.to_string())
63    }
64}
65
66impl From<std::array::TryFromSliceError> for SdkTypeConversionError {
67    fn from(value: std::array::TryFromSliceError) -> Self {
68        Self(value.to_string())
69    }
70}
71
72macro_rules! bcs_convert_impl {
73    ($core:ty, $external:ty) => {
74        impl TryFrom<$core> for $external {
75            type Error = bcs::Error;
76
77            fn try_from(value: $core) -> Result<Self, Self::Error> {
78                let bytes = bcs::to_bytes(&value)?;
79                bcs::from_bytes(&bytes)
80            }
81        }
82
83        impl TryFrom<$external> for $core {
84            type Error = bcs::Error;
85
86            fn try_from(value: $external) -> Result<Self, Self::Error> {
87                let bytes = bcs::to_bytes(&value)?;
88                bcs::from_bytes(&bytes)
89            }
90        }
91    };
92}
93
94bcs_convert_impl!(crate::object::Object, Object);
95bcs_convert_impl!(crate::transaction::TransactionData, Transaction);
96bcs_convert_impl!(crate::effects::TransactionEffectsV1, TransactionEffectsV1);
97bcs_convert_impl!(crate::effects::TransactionEffectsV2, TransactionEffectsV2);
98bcs_convert_impl!(
99    crate::messages_checkpoint::CheckpointSummary,
100    CheckpointSummary
101);
102bcs_convert_impl!(
103    crate::messages_checkpoint::CertifiedCheckpointSummary,
104    SignedCheckpointSummary
105);
106bcs_convert_impl!(
107    crate::messages_checkpoint::CheckpointContents,
108    CheckpointContents
109);
110bcs_convert_impl!(
111    crate::full_checkpoint_content::CheckpointData,
112    CheckpointData
113);
114bcs_convert_impl!(crate::signature::GenericSignature, UserSignature);
115bcs_convert_impl!(
116    crate::crypto::ZkLoginPublicIdentifier,
117    ZkLoginPublicIdentifier
118);
119bcs_convert_impl!(
120    crate::crypto::ZkLoginAuthenticatorAsBytes,
121    ZkLoginAuthenticator
122);
123bcs_convert_impl!(
124    crate::zk_login_authenticator::ZkLoginAuthenticator,
125    ZkLoginAuthenticator
126);
127bcs_convert_impl!(
128    crate::crypto::PasskeyAuthenticatorAsBytes,
129    PasskeyAuthenticator
130);
131bcs_convert_impl!(
132    crate::passkey_authenticator::PasskeyAuthenticator,
133    PasskeyAuthenticator
134);
135bcs_convert_impl!(crate::event::Event, Event);
136bcs_convert_impl!(crate::effects::TransactionEvents, TransactionEvents);
137bcs_convert_impl!(crate::transaction::TransactionKind, TransactionKind);
138bcs_convert_impl!(crate::move_package::MovePackage, MovePackage);
139
140impl<const T: bool> From<crate::crypto::AuthorityQuorumSignInfo<T>>
141    for ValidatorAggregatedSignature
142{
143    fn from(value: crate::crypto::AuthorityQuorumSignInfo<T>) -> Self {
144        let crate::crypto::AuthorityQuorumSignInfo {
145            epoch,
146            signature,
147            signers_map,
148        } = value;
149
150        Self {
151            epoch,
152            signature: Bls12381Signature::from_bytes(signature.as_ref()).unwrap(),
153            bitmap: Bitmap::from_iter(signers_map),
154        }
155    }
156}
157
158impl<const T: bool> From<ValidatorAggregatedSignature>
159    for crate::crypto::AuthorityQuorumSignInfo<T>
160{
161    fn from(value: ValidatorAggregatedSignature) -> Self {
162        let ValidatorAggregatedSignature {
163            epoch,
164            signature,
165            bitmap,
166        } = value;
167
168        Self {
169            epoch,
170            signature: crate::crypto::AggregateAuthoritySignature::from_bytes(signature.as_bytes())
171                .unwrap(),
172            signers_map: roaring::RoaringBitmap::from_iter(bitmap.iter()),
173        }
174    }
175}
176
177impl From<crate::object::Owner> for Owner {
178    fn from(value: crate::object::Owner) -> Self {
179        match value {
180            crate::object::Owner::AddressOwner(address) => Self::Address(address.into()),
181            crate::object::Owner::ObjectOwner(object_id) => Self::Object(object_id.into()),
182            crate::object::Owner::Shared {
183                initial_shared_version,
184            } => Self::Shared(initial_shared_version.value()),
185            crate::object::Owner::Immutable => Self::Immutable,
186            crate::object::Owner::ConsensusAddressOwner {
187                start_version,
188                owner,
189            } => Self::ConsensusAddress {
190                start_version: start_version.value(),
191                owner: owner.into(),
192            },
193            // TODO(Party WIP)
194            crate::object::Owner::Party { .. } => todo!("Party WIP"),
195        }
196    }
197}
198
199impl From<Owner> for crate::object::Owner {
200    fn from(value: Owner) -> Self {
201        match value {
202            Owner::Address(address) => crate::object::Owner::AddressOwner(address.into()),
203            Owner::Object(object_id) => crate::object::Owner::ObjectOwner(object_id.into()),
204            Owner::Shared(initial_shared_version) => crate::object::Owner::Shared {
205                initial_shared_version: initial_shared_version.into(),
206            },
207            Owner::Immutable => crate::object::Owner::Immutable,
208            Owner::ConsensusAddress {
209                start_version,
210                owner,
211            } => crate::object::Owner::ConsensusAddressOwner {
212                start_version: start_version.into(),
213                owner: owner.into(),
214            },
215            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
216        }
217    }
218}
219
220impl From<crate::base_types::SuiAddress> for Address {
221    fn from(value: crate::base_types::SuiAddress) -> Self {
222        Self::new(value.to_inner())
223    }
224}
225
226impl From<Address> for crate::base_types::SuiAddress {
227    fn from(value: Address) -> Self {
228        crate::base_types::ObjectID::new(value.into_inner()).into()
229    }
230}
231
232impl From<crate::base_types::ObjectID> for Address {
233    fn from(value: crate::base_types::ObjectID) -> Self {
234        Self::new(value.into_bytes())
235    }
236}
237
238impl From<Address> for crate::base_types::ObjectID {
239    fn from(value: Address) -> Self {
240        Self::new(value.into_inner())
241    }
242}
243
244impl TryFrom<crate::transaction::SenderSignedData> for SignedTransaction {
245    type Error = SdkTypeConversionError;
246
247    fn try_from(value: crate::transaction::SenderSignedData) -> Result<Self, Self::Error> {
248        let crate::transaction::SenderSignedTransaction {
249            intent_message,
250            tx_signatures,
251        } = value.into_inner();
252
253        Self {
254            transaction: intent_message.value.try_into()?,
255            signatures: tx_signatures
256                .into_iter()
257                .map(TryInto::try_into)
258                .collect::<Result<_, _>>()?,
259        }
260        .pipe(Ok)
261    }
262}
263
264impl TryFrom<SignedTransaction> for crate::transaction::SenderSignedData {
265    type Error = SdkTypeConversionError;
266
267    fn try_from(value: SignedTransaction) -> Result<Self, Self::Error> {
268        let SignedTransaction {
269            transaction,
270            signatures,
271        } = value;
272
273        Self::new(
274            transaction.try_into()?,
275            signatures
276                .into_iter()
277                .map(TryInto::try_into)
278                .collect::<Result<_, _>>()?,
279        )
280        .pipe(Ok)
281    }
282}
283
284impl TryFrom<crate::transaction::Transaction> for SignedTransaction {
285    type Error = SdkTypeConversionError;
286
287    fn try_from(value: crate::transaction::Transaction) -> Result<Self, Self::Error> {
288        value.into_data().try_into()
289    }
290}
291
292impl TryFrom<SignedTransaction> for crate::transaction::Transaction {
293    type Error = SdkTypeConversionError;
294
295    fn try_from(value: SignedTransaction) -> Result<Self, Self::Error> {
296        Ok(Self::new(value.try_into()?))
297    }
298}
299
300pub fn type_tag_core_to_sdk(
301    value: move_core_types::language_storage::TypeTag,
302) -> Result<TypeTag, SdkTypeConversionError> {
303    match value {
304        move_core_types::language_storage::TypeTag::Bool => TypeTag::Bool,
305        move_core_types::language_storage::TypeTag::U8 => TypeTag::U8,
306        move_core_types::language_storage::TypeTag::U64 => TypeTag::U64,
307        move_core_types::language_storage::TypeTag::U128 => TypeTag::U128,
308        move_core_types::language_storage::TypeTag::Address => TypeTag::Address,
309        move_core_types::language_storage::TypeTag::Signer => TypeTag::Signer,
310        move_core_types::language_storage::TypeTag::Vector(type_tag) => {
311            TypeTag::Vector(Box::new(type_tag_core_to_sdk(*type_tag)?))
312        }
313        move_core_types::language_storage::TypeTag::Struct(struct_tag) => {
314            TypeTag::Struct(Box::new(struct_tag_core_to_sdk(*struct_tag)?))
315        }
316        move_core_types::language_storage::TypeTag::U16 => TypeTag::U16,
317        move_core_types::language_storage::TypeTag::U32 => TypeTag::U32,
318        move_core_types::language_storage::TypeTag::U256 => TypeTag::U256,
319    }
320    .pipe(Ok)
321}
322
323pub fn struct_tag_core_to_sdk(
324    value: move_core_types::language_storage::StructTag,
325) -> Result<StructTag, SdkTypeConversionError> {
326    let move_core_types::language_storage::StructTag {
327        address,
328        module,
329        name,
330        type_params,
331    } = value;
332
333    let address = Address::new(address.into_bytes());
334    let module = Identifier::new(module.as_str())?;
335    let name = Identifier::new(name.as_str())?;
336    let type_params = type_params
337        .into_iter()
338        .map(type_tag_core_to_sdk)
339        .collect::<Result<_, _>>()?;
340    StructTag::new(address, module, name, type_params).pipe(Ok)
341}
342
343pub fn type_tag_sdk_to_core(
344    value: TypeTag,
345) -> Result<move_core_types::language_storage::TypeTag, SdkTypeConversionError> {
346    match value {
347        TypeTag::Bool => move_core_types::language_storage::TypeTag::Bool,
348        TypeTag::U8 => move_core_types::language_storage::TypeTag::U8,
349        TypeTag::U64 => move_core_types::language_storage::TypeTag::U64,
350        TypeTag::U128 => move_core_types::language_storage::TypeTag::U128,
351        TypeTag::Address => move_core_types::language_storage::TypeTag::Address,
352        TypeTag::Signer => move_core_types::language_storage::TypeTag::Signer,
353        TypeTag::Vector(type_tag) => move_core_types::language_storage::TypeTag::Vector(Box::new(
354            type_tag_sdk_to_core(*type_tag)?,
355        )),
356        TypeTag::Struct(struct_tag) => move_core_types::language_storage::TypeTag::Struct(
357            Box::new(struct_tag_sdk_to_core(*struct_tag)?),
358        ),
359        TypeTag::U16 => move_core_types::language_storage::TypeTag::U16,
360        TypeTag::U32 => move_core_types::language_storage::TypeTag::U32,
361        TypeTag::U256 => move_core_types::language_storage::TypeTag::U256,
362    }
363    .pipe(Ok)
364}
365
366pub fn struct_tag_sdk_to_core(
367    value: StructTag,
368) -> Result<move_core_types::language_storage::StructTag, SdkTypeConversionError> {
369    let address = value.address();
370    let module = value.module();
371    let name = value.name();
372    let type_params = value.type_params();
373
374    let address = move_core_types::account_address::AccountAddress::new(address.into_inner());
375    let module = move_core_types::identifier::Identifier::new(module.as_str())?;
376    let name = move_core_types::identifier::Identifier::new(name.as_str())?;
377    let type_params = type_params
378        .iter()
379        .cloned()
380        .map(type_tag_sdk_to_core)
381        .collect::<Result<_, _>>()?;
382    move_core_types::language_storage::StructTag {
383        address,
384        module,
385        name,
386        type_params,
387    }
388    .pipe(Ok)
389}
390
391impl TryFrom<crate::type_input::TypeInput> for TypeTag {
392    type Error = SdkTypeConversionError;
393
394    fn try_from(value: crate::type_input::TypeInput) -> Result<Self, Self::Error> {
395        match value {
396            crate::type_input::TypeInput::Bool => Self::Bool,
397            crate::type_input::TypeInput::U8 => Self::U8,
398            crate::type_input::TypeInput::U64 => Self::U64,
399            crate::type_input::TypeInput::U128 => Self::U128,
400            crate::type_input::TypeInput::Address => Self::Address,
401            crate::type_input::TypeInput::Signer => Self::Signer,
402            crate::type_input::TypeInput::Vector(type_input) => {
403                Self::Vector(Box::new((*type_input).try_into()?))
404            }
405            crate::type_input::TypeInput::Struct(struct_input) => {
406                Self::Struct(Box::new((*struct_input).try_into()?))
407            }
408            crate::type_input::TypeInput::U16 => Self::U16,
409            crate::type_input::TypeInput::U32 => Self::U32,
410            crate::type_input::TypeInput::U256 => Self::U256,
411        }
412        .pipe(Ok)
413    }
414}
415
416impl TryFrom<crate::type_input::StructInput> for StructTag {
417    type Error = SdkTypeConversionError;
418
419    fn try_from(value: crate::type_input::StructInput) -> Result<Self, Self::Error> {
420        Self::new(
421            Address::new(value.address.into_bytes()),
422            Identifier::new(value.module)?,
423            Identifier::new(value.name)?,
424            value
425                .type_params
426                .into_iter()
427                .map(TryInto::try_into)
428                .collect::<Result<_, _>>()?,
429        )
430        .pipe(Ok)
431    }
432}
433
434impl From<TypeTag> for crate::type_input::TypeInput {
435    fn from(value: TypeTag) -> Self {
436        match value {
437            TypeTag::U8 => Self::U8,
438            TypeTag::U16 => Self::U16,
439            TypeTag::U32 => Self::U32,
440            TypeTag::U64 => Self::U64,
441            TypeTag::U128 => Self::U128,
442            TypeTag::U256 => Self::U256,
443            TypeTag::Bool => Self::Bool,
444            TypeTag::Address => Self::Address,
445            TypeTag::Signer => Self::Signer,
446            TypeTag::Vector(type_tag) => Self::Vector(Box::new((*type_tag).into())),
447            TypeTag::Struct(struct_tag) => Self::Struct(Box::new((*struct_tag).into())),
448        }
449    }
450}
451
452impl From<StructTag> for crate::type_input::StructInput {
453    fn from(value: StructTag) -> Self {
454        Self {
455            address: move_core_types::account_address::AccountAddress::new(
456                value.address().into_inner(),
457            ),
458            module: value.module().as_str().into(),
459            name: value.name().as_str().into(),
460            type_params: value
461                .type_params()
462                .iter()
463                .cloned()
464                .map(crate::type_input::TypeInput::from)
465                .collect(),
466        }
467    }
468}
469
470impl From<crate::digests::ObjectDigest> for Digest {
471    fn from(value: crate::digests::ObjectDigest) -> Self {
472        Self::new(value.into_inner())
473    }
474}
475
476impl From<Digest> for crate::digests::ObjectDigest {
477    fn from(value: Digest) -> Self {
478        Self::new(value.into_inner())
479    }
480}
481
482impl From<crate::digests::TransactionDigest> for Digest {
483    fn from(value: crate::digests::TransactionDigest) -> Self {
484        Self::new(value.into_inner())
485    }
486}
487
488impl From<Digest> for crate::digests::TransactionDigest {
489    fn from(value: Digest) -> Self {
490        Self::new(value.into_inner())
491    }
492}
493
494impl From<crate::messages_checkpoint::CheckpointDigest> for Digest {
495    fn from(value: crate::messages_checkpoint::CheckpointDigest) -> Self {
496        Self::new(value.into_inner())
497    }
498}
499
500impl From<Digest> for crate::messages_checkpoint::CheckpointDigest {
501    fn from(value: Digest) -> Self {
502        Self::new(value.into_inner())
503    }
504}
505
506impl From<crate::digests::Digest> for Digest {
507    fn from(value: crate::digests::Digest) -> Self {
508        Self::new(value.into_inner())
509    }
510}
511
512impl From<Digest> for crate::digests::Digest {
513    fn from(value: Digest) -> Self {
514        Self::new(value.into_inner())
515    }
516}
517
518impl From<crate::digests::CheckpointArtifactsDigest> for Digest {
519    fn from(value: crate::digests::CheckpointArtifactsDigest) -> Self {
520        Self::new(value.into_inner())
521    }
522}
523
524impl From<Digest> for crate::digests::CheckpointArtifactsDigest {
525    fn from(value: Digest) -> Self {
526        Self::new(value.into_inner())
527    }
528}
529
530impl From<crate::committee::Committee> for ValidatorCommittee {
531    fn from(value: crate::committee::Committee) -> Self {
532        Self {
533            epoch: value.epoch(),
534            members: value
535                .voting_rights
536                .into_iter()
537                .map(|(name, stake)| ValidatorCommitteeMember {
538                    public_key: name.into(),
539                    stake,
540                })
541                .collect(),
542        }
543    }
544}
545
546impl From<ValidatorCommittee> for crate::committee::Committee {
547    fn from(value: ValidatorCommittee) -> Self {
548        let ValidatorCommittee { epoch, members } = value;
549
550        Self::new(
551            epoch,
552            members
553                .into_iter()
554                .map(|member| (member.public_key.into(), member.stake))
555                .collect(),
556        )
557    }
558}
559
560impl From<crate::crypto::AuthorityPublicKeyBytes> for Bls12381PublicKey {
561    fn from(value: crate::crypto::AuthorityPublicKeyBytes) -> Self {
562        Self::new(value.0)
563    }
564}
565
566impl From<Bls12381PublicKey> for crate::crypto::AuthorityPublicKeyBytes {
567    fn from(value: Bls12381PublicKey) -> Self {
568        Self::new(value.into_inner())
569    }
570}
571
572impl From<UnchangedConsensusKind> for crate::effects::UnchangedConsensusKind {
573    fn from(value: UnchangedConsensusKind) -> Self {
574        match value {
575            UnchangedConsensusKind::ReadOnlyRoot { version, digest } => {
576                Self::ReadOnlyRoot((version.into(), digest.into()))
577            }
578            UnchangedConsensusKind::MutateDeleted { version } => {
579                Self::MutateConsensusStreamEnded(version.into())
580            }
581            UnchangedConsensusKind::ReadDeleted { version } => {
582                Self::ReadConsensusStreamEnded(version.into())
583            }
584            UnchangedConsensusKind::Canceled { version } => Self::Cancelled(version.into()),
585            UnchangedConsensusKind::PerEpochConfig => Self::PerEpochConfig,
586            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
587        }
588    }
589}
590
591impl From<crate::effects::UnchangedConsensusKind> for UnchangedConsensusKind {
592    fn from(value: crate::effects::UnchangedConsensusKind) -> Self {
593        match value {
594            crate::effects::UnchangedConsensusKind::ReadOnlyRoot((version, digest)) => {
595                Self::ReadOnlyRoot {
596                    version: version.into(),
597                    digest: digest.into(),
598                }
599            }
600            crate::effects::UnchangedConsensusKind::MutateConsensusStreamEnded(version) => {
601                Self::MutateDeleted {
602                    version: version.into(),
603                }
604            }
605            crate::effects::UnchangedConsensusKind::ReadConsensusStreamEnded(version) => {
606                Self::ReadDeleted {
607                    version: version.into(),
608                }
609            }
610            crate::effects::UnchangedConsensusKind::Cancelled(version) => Self::Canceled {
611                version: version.into(),
612            },
613            crate::effects::UnchangedConsensusKind::PerEpochConfig => Self::PerEpochConfig,
614        }
615    }
616}
617
618impl From<crate::effects::ObjectIn> for ObjectIn {
619    fn from(value: crate::effects::ObjectIn) -> Self {
620        match value {
621            crate::effects::ObjectIn::NotExist => Self::NotExist,
622            crate::effects::ObjectIn::Exist(((version, digest), owner)) => Self::Exist {
623                version: version.value(),
624                digest: digest.into(),
625                owner: owner.into(),
626            },
627        }
628    }
629}
630
631impl From<crate::effects::ObjectOut> for ObjectOut {
632    fn from(value: crate::effects::ObjectOut) -> Self {
633        match value {
634            crate::effects::ObjectOut::NotExist => Self::NotExist,
635            crate::effects::ObjectOut::ObjectWrite((digest, owner)) => Self::ObjectWrite {
636                digest: digest.into(),
637                owner: owner.into(),
638            },
639            crate::effects::ObjectOut::PackageWrite((version, digest)) => Self::PackageWrite {
640                version: version.value(),
641                digest: digest.into(),
642            },
643
644            crate::effects::ObjectOut::AccumulatorWriteV1(accumulator_write) => {
645                Self::AccumulatorWrite(accumulator_write.into())
646            }
647        }
648    }
649}
650
651impl From<crate::effects::AccumulatorWriteV1> for AccumulatorWrite {
652    fn from(value: crate::effects::AccumulatorWriteV1) -> Self {
653        let operation = match value.operation {
654            crate::effects::AccumulatorOperation::Merge => {
655                sui_sdk_types::AccumulatorOperation::Merge
656            }
657            crate::effects::AccumulatorOperation::Split => {
658                sui_sdk_types::AccumulatorOperation::Split
659            }
660        };
661        Self::new(
662            value.address.address.into(),
663            type_tag_core_to_sdk(value.address.ty).unwrap(),
664            operation,
665            match value.value {
666                crate::effects::AccumulatorValue::Integer(value) => {
667                    sui_sdk_types::AccumulatorValue::Integer(value)
668                }
669                crate::effects::AccumulatorValue::IntegerTuple(a, b) => {
670                    sui_sdk_types::AccumulatorValue::IntegerTuple(a, b)
671                }
672                crate::effects::AccumulatorValue::EventDigest(digests) => {
673                    sui_sdk_types::AccumulatorValue::EventDigest(
674                        digests
675                            .into_iter()
676                            .map(|(idx, digest)| (idx, digest.into()))
677                            .collect(),
678                    )
679                }
680            },
681        )
682    }
683}
684
685impl From<crate::effects::IDOperation> for IdOperation {
686    fn from(value: crate::effects::IDOperation) -> Self {
687        match value {
688            crate::effects::IDOperation::None => Self::None,
689            crate::effects::IDOperation::Created => Self::Created,
690            crate::effects::IDOperation::Deleted => Self::Deleted,
691        }
692    }
693}
694
695impl From<crate::transaction::TransactionExpiration> for TransactionExpiration {
696    fn from(value: crate::transaction::TransactionExpiration) -> Self {
697        match value {
698            crate::transaction::TransactionExpiration::None => Self::None,
699            crate::transaction::TransactionExpiration::Epoch(epoch) => Self::Epoch(epoch),
700            crate::transaction::TransactionExpiration::ValidDuring {
701                min_epoch,
702                max_epoch,
703                min_timestamp,
704                max_timestamp,
705                chain,
706                nonce,
707            } => Self::ValidDuring {
708                min_epoch,
709                max_epoch,
710                min_timestamp,
711                max_timestamp,
712                chain: Digest::new(*chain.as_bytes()),
713                nonce,
714            },
715            crate::transaction::TransactionExpiration::Validity {
716                min_epoch,
717                max_epoch,
718                min_timestamp,
719                max_timestamp,
720                chain,
721                nonce,
722                allowed_proposers,
723            } => Self::Validity {
724                min_epoch,
725                max_epoch,
726                min_timestamp,
727                max_timestamp,
728                chain: Digest::new(*chain.as_bytes()),
729                nonce,
730                allowed_proposers: allowed_proposers.map(|allowed| {
731                    sui_sdk_types::AllowedProposers {
732                        epoch: allowed.epoch,
733                        proposers: allowed.proposers.into(),
734                    }
735                }),
736            },
737        }
738    }
739}
740
741impl From<TransactionExpiration> for crate::transaction::TransactionExpiration {
742    fn from(value: TransactionExpiration) -> Self {
743        match value {
744            TransactionExpiration::None => Self::None,
745            TransactionExpiration::Epoch(epoch) => Self::Epoch(epoch),
746            TransactionExpiration::ValidDuring {
747                min_epoch,
748                max_epoch,
749                min_timestamp,
750                max_timestamp,
751                chain,
752                nonce,
753            } => Self::ValidDuring {
754                min_epoch,
755                max_epoch,
756                min_timestamp,
757                max_timestamp,
758                chain: crate::digests::CheckpointDigest::from(chain).into(),
759                nonce,
760            },
761            TransactionExpiration::Validity {
762                min_epoch,
763                max_epoch,
764                min_timestamp,
765                max_timestamp,
766                chain,
767                nonce,
768                allowed_proposers,
769            } => Self::Validity {
770                min_epoch,
771                max_epoch,
772                min_timestamp,
773                max_timestamp,
774                chain: crate::digests::CheckpointDigest::from(chain).into(),
775                nonce,
776                // An empty set is rejected by the sdk's deserializer, so it can only appear on a
777                // value built in memory; drop the restriction rather than fabricating one.
778                allowed_proposers: allowed_proposers.and_then(|allowed| {
779                    Some(crate::transaction::AllowedProposers {
780                        epoch: allowed.epoch,
781                        proposers: NonEmpty::from_vec(allowed.proposers)?,
782                    })
783                }),
784            },
785            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
786        }
787    }
788}
789
790impl From<crate::execution_status::TypeArgumentError> for TypeArgumentError {
791    fn from(value: crate::execution_status::TypeArgumentError) -> Self {
792        match value {
793            crate::execution_status::TypeArgumentError::TypeNotFound => Self::TypeNotFound,
794            crate::execution_status::TypeArgumentError::ConstraintNotSatisfied => {
795                Self::ConstraintNotSatisfied
796            }
797        }
798    }
799}
800
801impl From<TypeArgumentError> for crate::execution_status::TypeArgumentError {
802    fn from(value: TypeArgumentError) -> Self {
803        match value {
804            TypeArgumentError::TypeNotFound => Self::TypeNotFound,
805            TypeArgumentError::ConstraintNotSatisfied => Self::ConstraintNotSatisfied,
806            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
807        }
808    }
809}
810
811impl From<crate::execution_status::PackageUpgradeError> for PackageUpgradeError {
812    fn from(value: crate::execution_status::PackageUpgradeError) -> Self {
813        match value {
814            crate::execution_status::PackageUpgradeError::UnableToFetchPackage { package_id } => {
815                Self::UnableToFetchPackage {
816                    package_id: package_id.into(),
817                }
818            }
819            crate::execution_status::PackageUpgradeError::NotAPackage { object_id } => {
820                Self::NotAPackage {
821                    object_id: object_id.into(),
822                }
823            }
824            crate::execution_status::PackageUpgradeError::IncompatibleUpgrade => {
825                Self::IncompatibleUpgrade
826            }
827            crate::execution_status::PackageUpgradeError::DigestDoesNotMatch { digest } => {
828                Self::DigestDoesNotMatch {
829                    digest: Digest::from_bytes(digest).unwrap(),
830                }
831            }
832            crate::execution_status::PackageUpgradeError::UnknownUpgradePolicy { policy } => {
833                Self::UnknownUpgradePolicy { policy }
834            }
835            crate::execution_status::PackageUpgradeError::PackageIDDoesNotMatch {
836                package_id,
837                ticket_id,
838            } => Self::PackageIdDoesNotMatch {
839                package_id: package_id.into(),
840                ticket_id: ticket_id.into(),
841            },
842        }
843    }
844}
845
846impl From<PackageUpgradeError> for crate::execution_status::PackageUpgradeError {
847    fn from(value: PackageUpgradeError) -> Self {
848        match value {
849            PackageUpgradeError::UnableToFetchPackage { package_id } => {
850                Self::UnableToFetchPackage {
851                    package_id: package_id.into(),
852                }
853            }
854            PackageUpgradeError::NotAPackage { object_id } => Self::NotAPackage {
855                object_id: object_id.into(),
856            },
857            PackageUpgradeError::IncompatibleUpgrade => Self::IncompatibleUpgrade,
858            PackageUpgradeError::DigestDoesNotMatch { digest } => Self::DigestDoesNotMatch {
859                digest: digest.into_inner().to_vec(),
860            },
861            PackageUpgradeError::UnknownUpgradePolicy { policy } => {
862                Self::UnknownUpgradePolicy { policy }
863            }
864            PackageUpgradeError::PackageIdDoesNotMatch {
865                package_id,
866                ticket_id,
867            } => Self::PackageIDDoesNotMatch {
868                package_id: package_id.into(),
869                ticket_id: ticket_id.into(),
870            },
871            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
872        }
873    }
874}
875
876impl From<crate::execution_status::CommandArgumentError> for CommandArgumentError {
877    fn from(value: crate::execution_status::CommandArgumentError) -> Self {
878        match value {
879            crate::execution_status::CommandArgumentError::TypeMismatch => Self::TypeMismatch,
880            crate::execution_status::CommandArgumentError::InvalidBCSBytes => Self::InvalidBcsBytes,
881            crate::execution_status::CommandArgumentError::InvalidUsageOfPureArg => Self::InvalidUsageOfPureArgument,
882            crate::execution_status::CommandArgumentError::InvalidArgumentToPrivateEntryFunction => Self::InvalidArgumentToPrivateEntryFunction,
883            crate::execution_status::CommandArgumentError::IndexOutOfBounds { idx } => Self::IndexOutOfBounds { index: idx },
884            crate::execution_status::CommandArgumentError::SecondaryIndexOutOfBounds { result_idx, secondary_idx } => Self::SecondaryIndexOutOfBounds { result: result_idx, subresult: secondary_idx },
885            crate::execution_status::CommandArgumentError::InvalidResultArity { result_idx } => Self::InvalidResultArity { result: result_idx },
886            crate::execution_status::CommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
887            crate::execution_status::CommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
888            crate::execution_status::CommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
889            crate::execution_status::CommandArgumentError::InvalidObjectByMutRef => Self::InvalidObjectByMutRef,
890            crate::execution_status::CommandArgumentError::SharedObjectOperationNotAllowed => Self::ConsensusObjectOperationNotAllowed,
891            crate::execution_status::CommandArgumentError::InvalidArgumentArity => Self::InvalidArgumentArity,
892            crate::execution_status::CommandArgumentError::InvalidTransferObject  => Self::InvalidTransferObject,
893            crate::execution_status::CommandArgumentError::InvalidMakeMoveVecNonObjectArgument =>
894                Self::InvalidMakeMoveVecNonObjectArgument,
895            crate::execution_status::CommandArgumentError::ArgumentWithoutValue  =>
896                Self::ArgumentWithoutValue,
897            crate::execution_status::CommandArgumentError::CannotMoveBorrowedValue =>
898                Self::CannotMoveBorrowedValue,
899            crate::execution_status::CommandArgumentError::CannotWriteToExtendedReference =>
900                Self::CannotWriteToExtendedReference,
901            crate::execution_status::CommandArgumentError::InvalidReferenceArgument =>
902                Self::InvalidReferenceArgument,
903            crate::execution_status::CommandArgumentError::InvalidTxContext =>
904                Self::InvalidTxContext,
905        }
906    }
907}
908
909impl From<CommandArgumentError> for crate::execution_status::CommandArgumentError {
910    fn from(value: CommandArgumentError) -> Self {
911        match value {
912            CommandArgumentError::TypeMismatch => Self::TypeMismatch,
913            CommandArgumentError::InvalidBcsBytes => Self::InvalidBCSBytes,
914            CommandArgumentError::InvalidUsageOfPureArgument => Self::InvalidUsageOfPureArg,
915            CommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
916                Self::InvalidArgumentToPrivateEntryFunction
917            }
918            CommandArgumentError::IndexOutOfBounds { index } => {
919                Self::IndexOutOfBounds { idx: index }
920            }
921            CommandArgumentError::SecondaryIndexOutOfBounds { result, subresult } => {
922                Self::SecondaryIndexOutOfBounds {
923                    result_idx: result,
924                    secondary_idx: subresult,
925                }
926            }
927            CommandArgumentError::InvalidResultArity { result } => {
928                Self::InvalidResultArity { result_idx: result }
929            }
930            CommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
931            CommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
932            CommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
933            CommandArgumentError::InvalidObjectByMutRef => Self::InvalidObjectByMutRef,
934            CommandArgumentError::ConsensusObjectOperationNotAllowed => {
935                Self::SharedObjectOperationNotAllowed
936            }
937            CommandArgumentError::InvalidArgumentArity => Self::InvalidArgumentArity,
938            CommandArgumentError::InvalidTransferObject => Self::InvalidTransferObject,
939            CommandArgumentError::InvalidMakeMoveVecNonObjectArgument => {
940                Self::InvalidMakeMoveVecNonObjectArgument
941            }
942            CommandArgumentError::ArgumentWithoutValue => Self::ArgumentWithoutValue,
943            CommandArgumentError::CannotMoveBorrowedValue => Self::CannotMoveBorrowedValue,
944            CommandArgumentError::CannotWriteToExtendedReference => {
945                Self::CannotWriteToExtendedReference
946            }
947            CommandArgumentError::InvalidReferenceArgument => Self::InvalidReferenceArgument,
948            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
949        }
950    }
951}
952
953impl From<crate::execution_status::ExecutionErrorKind> for ExecutionError {
954    fn from(value: crate::execution_status::ExecutionErrorKind) -> Self {
955        match value {
956            crate::execution_status::ExecutionErrorKind::InsufficientGas => Self::InsufficientGas,
957            crate::execution_status::ExecutionErrorKind::InvalidGasObject => Self::InvalidGasObject,
958            crate::execution_status::ExecutionErrorKind::InvariantViolation => Self::InvariantViolation,
959            crate::execution_status::ExecutionErrorKind::FeatureNotYetSupported => Self::FeatureNotYetSupported,
960            crate::execution_status::ExecutionErrorKind::MoveObjectTooBig { object_size, max_object_size } => Self::ObjectTooBig { object_size, max_object_size },
961            crate::execution_status::ExecutionErrorKind::MovePackageTooBig { object_size, max_object_size } => Self::PackageTooBig { object_size, max_object_size },
962            crate::execution_status::ExecutionErrorKind::CircularObjectOwnership { object } => Self::CircularObjectOwnership { object: object.into() },
963            crate::execution_status::ExecutionErrorKind::InsufficientCoinBalance => Self::InsufficientCoinBalance,
964            crate::execution_status::ExecutionErrorKind::CoinBalanceOverflow => Self::CoinBalanceOverflow,
965            crate::execution_status::ExecutionErrorKind::PublishErrorNonZeroAddress => Self::PublishErrorNonZeroAddress,
966            crate::execution_status::ExecutionErrorKind::SuiMoveVerificationError => Self::SuiMoveVerificationError,
967            crate::execution_status::ExecutionErrorKind::MovePrimitiveRuntimeError(move_location_opt) => Self::MovePrimitiveRuntimeError { location: move_location_opt.0.map(Into::into) },
968            crate::execution_status::ExecutionErrorKind::MoveAbort(move_location, code) => Self::MoveAbort { location: move_location.into(), code },
969            crate::execution_status::ExecutionErrorKind::VMVerificationOrDeserializationError => Self::VmVerificationOrDeserializationError,
970            crate::execution_status::ExecutionErrorKind::VMInvariantViolation => Self::VmInvariantViolation,
971            crate::execution_status::ExecutionErrorKind::FunctionNotFound => Self::FunctionNotFound,
972            crate::execution_status::ExecutionErrorKind::ArityMismatch => Self::ArityMismatch,
973            crate::execution_status::ExecutionErrorKind::TypeArityMismatch => Self::TypeArityMismatch,
974            crate::execution_status::ExecutionErrorKind::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
975            crate::execution_status::ExecutionErrorKind::CommandArgumentError { arg_idx, kind } => Self::CommandArgumentError { argument: arg_idx, kind: kind.into() },
976            crate::execution_status::ExecutionErrorKind::TypeArgumentError { argument_idx, kind } => Self::TypeArgumentError { type_argument: argument_idx, kind: kind.into() },
977            crate::execution_status::ExecutionErrorKind::UnusedValueWithoutDrop { result_idx, secondary_idx } => Self::UnusedValueWithoutDrop { result: result_idx, subresult: secondary_idx },
978            crate::execution_status::ExecutionErrorKind::InvalidPublicFunctionReturnType { idx } => Self::InvalidPublicFunctionReturnType { index: idx },
979            crate::execution_status::ExecutionErrorKind::InvalidTransferObject => Self::InvalidTransferObject,
980            crate::execution_status::ExecutionErrorKind::EffectsTooLarge { current_size, max_size } => Self::EffectsTooLarge { current_size, max_size },
981            crate::execution_status::ExecutionErrorKind::PublishUpgradeMissingDependency => Self::PublishUpgradeMissingDependency,
982            crate::execution_status::ExecutionErrorKind::PublishUpgradeDependencyDowngrade => Self::PublishUpgradeDependencyDowngrade,
983            crate::execution_status::ExecutionErrorKind::PackageUpgradeError { upgrade_error } => Self::PackageUpgradeError { kind: upgrade_error.into() },
984            crate::execution_status::ExecutionErrorKind::WrittenObjectsTooLarge { current_size, max_size } => Self::WrittenObjectsTooLarge { object_size: current_size, max_object_size:max_size },
985            crate::execution_status::ExecutionErrorKind::CertificateDenied => Self::CertificateDenied,
986            crate::execution_status::ExecutionErrorKind::SuiMoveVerificationTimedout => Self::SuiMoveVerificationTimedout,
987            crate::execution_status::ExecutionErrorKind::SharedObjectOperationNotAllowed => Self::ConsensusObjectOperationNotAllowed,
988            crate::execution_status::ExecutionErrorKind::InputObjectDeleted => Self::InputObjectDeleted,
989            crate::execution_status::ExecutionErrorKind::ExecutionCancelledDueToSharedObjectCongestion { congested_objects } => Self::ExecutionCanceledDueToConsensusObjectCongestion { congested_objects: congested_objects.0.into_iter().map(Into::into).collect() },
990            crate::execution_status::ExecutionErrorKind::AddressDeniedForCoin { address, coin_type } => Self::AddressDeniedForCoin { address: address.into(), coin_type },
991            crate::execution_status::ExecutionErrorKind::CoinTypeGlobalPause { coin_type } => Self::CoinTypeGlobalPause { coin_type },
992            crate::execution_status::ExecutionErrorKind::ExecutionCancelledDueToRandomnessUnavailable => Self::ExecutionCanceledDueToRandomnessUnavailable,
993            crate::execution_status::ExecutionErrorKind::MoveVectorElemTooBig { value_size, max_scaled_size } => Self::MoveVectorElemTooBig { value_size, max_scaled_size },
994            crate::execution_status::ExecutionErrorKind::MoveRawValueTooBig { value_size, max_scaled_size } => Self::MoveRawValueTooBig { value_size, max_scaled_size },
995            crate::execution_status::ExecutionErrorKind::InvalidLinkage => Self::InvalidLinkage,
996            crate::execution_status::ExecutionErrorKind::InsufficientFundsForWithdraw => {
997                Self::InsufficientFundsForWithdraw
998            }
999            crate::execution_status::ExecutionErrorKind::NonExclusiveWriteInputObjectModified { id } => {
1000                Self::NonExclusiveWriteInputObjectModified { object: id.into() }
1001            }
1002            crate::execution_status::ExecutionErrorKind::TransactionExpired => {
1003                Self::TransactionExpired
1004            }
1005        }
1006    }
1007}
1008
1009impl From<ExecutionError> for crate::execution_status::ExecutionErrorKind {
1010    fn from(value: ExecutionError) -> Self {
1011        match value {
1012            ExecutionError::InsufficientGas => Self::InsufficientGas,
1013            ExecutionError::InvalidGasObject => Self::InvalidGasObject,
1014            ExecutionError::InvariantViolation => Self::InvariantViolation,
1015            ExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
1016            ExecutionError::ObjectTooBig {
1017                object_size,
1018                max_object_size,
1019            } => Self::MoveObjectTooBig {
1020                object_size,
1021                max_object_size,
1022            },
1023            ExecutionError::PackageTooBig {
1024                object_size,
1025                max_object_size,
1026            } => Self::MovePackageTooBig {
1027                object_size,
1028                max_object_size,
1029            },
1030            ExecutionError::CircularObjectOwnership { object } => Self::CircularObjectOwnership {
1031                object: object.into(),
1032            },
1033            ExecutionError::InsufficientCoinBalance => Self::InsufficientCoinBalance,
1034            ExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
1035            ExecutionError::PublishErrorNonZeroAddress => Self::PublishErrorNonZeroAddress,
1036            ExecutionError::SuiMoveVerificationError => Self::SuiMoveVerificationError,
1037            ExecutionError::MovePrimitiveRuntimeError { location } => {
1038                Self::MovePrimitiveRuntimeError(crate::execution_status::MoveLocationOpt(
1039                    location.map(Into::into),
1040                ))
1041            }
1042            ExecutionError::MoveAbort { location, code } => Self::MoveAbort(location.into(), code),
1043            ExecutionError::VmVerificationOrDeserializationError => {
1044                Self::VMVerificationOrDeserializationError
1045            }
1046            ExecutionError::VmInvariantViolation => Self::VMInvariantViolation,
1047            ExecutionError::FunctionNotFound => Self::FunctionNotFound,
1048            ExecutionError::ArityMismatch => Self::ArityMismatch,
1049            ExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1050            ExecutionError::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
1051            ExecutionError::CommandArgumentError { argument, kind } => Self::CommandArgumentError {
1052                arg_idx: argument,
1053                kind: kind.into(),
1054            },
1055            ExecutionError::TypeArgumentError {
1056                type_argument,
1057                kind,
1058            } => Self::TypeArgumentError {
1059                argument_idx: type_argument,
1060                kind: kind.into(),
1061            },
1062            ExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1063                Self::UnusedValueWithoutDrop {
1064                    result_idx: result,
1065                    secondary_idx: subresult,
1066                }
1067            }
1068            ExecutionError::InvalidPublicFunctionReturnType { index } => {
1069                Self::InvalidPublicFunctionReturnType { idx: index }
1070            }
1071            ExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1072            ExecutionError::EffectsTooLarge {
1073                current_size,
1074                max_size,
1075            } => Self::EffectsTooLarge {
1076                current_size,
1077                max_size,
1078            },
1079            ExecutionError::PublishUpgradeMissingDependency => {
1080                Self::PublishUpgradeMissingDependency
1081            }
1082            ExecutionError::PublishUpgradeDependencyDowngrade => {
1083                Self::PublishUpgradeDependencyDowngrade
1084            }
1085            ExecutionError::PackageUpgradeError { kind } => Self::PackageUpgradeError {
1086                upgrade_error: kind.into(),
1087            },
1088            ExecutionError::WrittenObjectsTooLarge {
1089                object_size,
1090                max_object_size,
1091            } => Self::WrittenObjectsTooLarge {
1092                current_size: object_size,
1093                max_size: max_object_size,
1094            },
1095            ExecutionError::CertificateDenied => Self::CertificateDenied,
1096            ExecutionError::SuiMoveVerificationTimedout => Self::SuiMoveVerificationTimedout,
1097            ExecutionError::ConsensusObjectOperationNotAllowed => {
1098                Self::SharedObjectOperationNotAllowed
1099            }
1100            ExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1101            ExecutionError::ExecutionCanceledDueToConsensusObjectCongestion {
1102                congested_objects,
1103            } => Self::ExecutionCancelledDueToSharedObjectCongestion {
1104                congested_objects: crate::execution_status::CongestedObjects(
1105                    congested_objects.into_iter().map(Into::into).collect(),
1106                ),
1107            },
1108            ExecutionError::AddressDeniedForCoin { address, coin_type } => {
1109                Self::AddressDeniedForCoin {
1110                    address: address.into(),
1111                    coin_type,
1112                }
1113            }
1114            ExecutionError::CoinTypeGlobalPause { coin_type } => {
1115                Self::CoinTypeGlobalPause { coin_type }
1116            }
1117            ExecutionError::ExecutionCanceledDueToRandomnessUnavailable => {
1118                Self::ExecutionCancelledDueToRandomnessUnavailable
1119            }
1120            ExecutionError::MoveVectorElemTooBig {
1121                value_size,
1122                max_scaled_size,
1123            } => Self::MoveVectorElemTooBig {
1124                value_size,
1125                max_scaled_size,
1126            },
1127            ExecutionError::MoveRawValueTooBig {
1128                value_size,
1129                max_scaled_size,
1130            } => Self::MoveRawValueTooBig {
1131                value_size,
1132                max_scaled_size,
1133            },
1134            ExecutionError::InvalidLinkage => Self::InvalidLinkage,
1135            ExecutionError::InsufficientFundsForWithdraw => Self::InsufficientFundsForWithdraw,
1136            ExecutionError::NonExclusiveWriteInputObjectModified { object } => {
1137                Self::NonExclusiveWriteInputObjectModified { id: object.into() }
1138            }
1139            ExecutionError::TransactionExpired => Self::TransactionExpired,
1140            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
1141        }
1142    }
1143}
1144
1145impl From<crate::execution_status::MoveLocation> for MoveLocation {
1146    fn from(value: crate::execution_status::MoveLocation) -> Self {
1147        Self {
1148            package: Address::new(value.module.address().into_bytes()),
1149            module: Identifier::new(value.module.name().as_str()).unwrap(),
1150            function: value.function,
1151            instruction: value.instruction,
1152            function_name: value
1153                .function_name
1154                .map(|name| Identifier::new(name).unwrap()),
1155        }
1156    }
1157}
1158
1159impl From<MoveLocation> for crate::execution_status::MoveLocation {
1160    fn from(value: MoveLocation) -> Self {
1161        Self {
1162            module: move_core_types::language_storage::ModuleId::new(
1163                move_core_types::account_address::AccountAddress::new(value.package.into_inner()),
1164                move_core_types::identifier::Identifier::new(value.module.as_str()).unwrap(),
1165            ),
1166            function: value.function,
1167            instruction: value.instruction,
1168            function_name: value.function_name.map(|ident| ident.as_str().into()),
1169        }
1170    }
1171}
1172
1173impl From<crate::execution_status::ExecutionStatus> for ExecutionStatus {
1174    fn from(value: crate::execution_status::ExecutionStatus) -> Self {
1175        match value {
1176            crate::execution_status::ExecutionStatus::Success => Self::Success,
1177            crate::execution_status::ExecutionStatus::Failure(ExecutionFailure {
1178                error,
1179                command,
1180            }) => Self::Failure {
1181                error: error.into(),
1182                command: command.map(|c| c as u64),
1183            },
1184        }
1185    }
1186}
1187
1188impl From<crate::messages_checkpoint::CheckpointCommitment> for CheckpointCommitment {
1189    fn from(value: crate::messages_checkpoint::CheckpointCommitment) -> Self {
1190        match value {
1191            crate::messages_checkpoint::CheckpointCommitment::ECMHLiveObjectSetDigest(digest) => {
1192                Self::EcmhLiveObjectSet {
1193                    digest: digest.digest.into(),
1194                }
1195            }
1196            crate::messages_checkpoint::CheckpointCommitment::CheckpointArtifactsDigest(digest) => {
1197                Self::CheckpointArtifacts {
1198                    digest: digest.into(),
1199                }
1200            }
1201        }
1202    }
1203}
1204
1205impl TryFrom<crate::crypto::PublicKey> for MultisigMemberPublicKey {
1206    type Error = SdkTypeConversionError;
1207
1208    fn try_from(value: crate::crypto::PublicKey) -> Result<Self, Self::Error> {
1209        match value {
1210            crate::crypto::PublicKey::Ed25519(bytes_representation) => {
1211                Self::Ed25519(Ed25519PublicKey::new(bytes_representation.0))
1212            }
1213            crate::crypto::PublicKey::Secp256k1(bytes_representation) => {
1214                Self::Secp256k1(Secp256k1PublicKey::new(bytes_representation.0))
1215            }
1216            crate::crypto::PublicKey::Secp256r1(bytes_representation) => {
1217                Self::Secp256r1(Secp256r1PublicKey::new(bytes_representation.0))
1218            }
1219            crate::crypto::PublicKey::ZkLogin(z) => Self::ZkLogin(z.try_into()?),
1220            crate::crypto::PublicKey::Passkey(p) => {
1221                Self::Passkey(PasskeyPublicKey::new(Secp256r1PublicKey::new(p.0)))
1222            }
1223            crate::crypto::PublicKey::MLDSA65(pk) => {
1224                Self::MlDsa65(Box::new(MlDsa65PublicKey::from_bytes(&pk.0)?))
1225            }
1226        }
1227        .pipe(Ok)
1228    }
1229}
1230
1231impl TryFrom<crate::crypto::CompressedSignature> for MultisigMemberSignature {
1232    type Error = SdkTypeConversionError;
1233
1234    fn try_from(value: crate::crypto::CompressedSignature) -> Result<Self, Self::Error> {
1235        match value {
1236            crate::crypto::CompressedSignature::Ed25519(bytes_representation) => {
1237                Self::Ed25519(Ed25519Signature::new(bytes_representation.0))
1238            }
1239            crate::crypto::CompressedSignature::Secp256k1(bytes_representation) => {
1240                Self::Secp256k1(Secp256k1Signature::new(bytes_representation.0))
1241            }
1242            crate::crypto::CompressedSignature::Secp256r1(bytes_representation) => {
1243                Self::Secp256r1(Secp256r1Signature::new(bytes_representation.0))
1244            }
1245            crate::crypto::CompressedSignature::ZkLogin(z) => {
1246                Self::ZkLogin(Box::new(z.try_into()?))
1247            }
1248            crate::crypto::CompressedSignature::Passkey(p) => Self::Passkey(p.try_into()?),
1249            crate::crypto::CompressedSignature::MLDSA65(s) => {
1250                Self::MlDsa65(Box::new(MlDsa65Signature::from_bytes(&s.0)?))
1251            }
1252        }
1253        .pipe(Ok)
1254    }
1255}
1256
1257impl TryFrom<crate::crypto::Signature> for SimpleSignature {
1258    type Error = SdkTypeConversionError;
1259
1260    fn try_from(value: crate::crypto::Signature) -> Result<Self, Self::Error> {
1261        match value {
1262            crate::crypto::Signature::Ed25519SuiSignature(ed25519_sui_signature) => Self::Ed25519 {
1263                signature: Ed25519Signature::from_bytes(ed25519_sui_signature.signature_bytes())?,
1264                public_key: Ed25519PublicKey::from_bytes(ed25519_sui_signature.public_key_bytes())?,
1265            },
1266            crate::crypto::Signature::Secp256k1SuiSignature(secp256k1_sui_signature) => {
1267                Self::Secp256k1 {
1268                    signature: Secp256k1Signature::from_bytes(
1269                        secp256k1_sui_signature.signature_bytes(),
1270                    )?,
1271                    public_key: Secp256k1PublicKey::from_bytes(
1272                        secp256k1_sui_signature.public_key_bytes(),
1273                    )?,
1274                }
1275            }
1276
1277            crate::crypto::Signature::Secp256r1SuiSignature(secp256r1_sui_signature) => {
1278                Self::Secp256r1 {
1279                    signature: Secp256r1Signature::from_bytes(
1280                        secp256r1_sui_signature.signature_bytes(),
1281                    )?,
1282                    public_key: Secp256r1PublicKey::from_bytes(
1283                        secp256r1_sui_signature.public_key_bytes(),
1284                    )?,
1285                }
1286            }
1287            crate::crypto::Signature::MLDSA65SuiSignature(s) => Self::MlDsa65 {
1288                signature: Box::new(MlDsa65Signature::from_bytes(s.signature_bytes())?),
1289                public_key: Box::new(MlDsa65PublicKey::from_bytes(s.public_key_bytes())?),
1290            },
1291        }
1292        .pipe(Ok)
1293    }
1294}
1295
1296impl TryFrom<crate::crypto::SignatureScheme> for SignatureScheme {
1297    type Error = SdkTypeConversionError;
1298
1299    fn try_from(value: crate::crypto::SignatureScheme) -> Result<Self, Self::Error> {
1300        match value {
1301            crate::crypto::SignatureScheme::ED25519 => Ok(Self::Ed25519),
1302            crate::crypto::SignatureScheme::Secp256k1 => Ok(Self::Secp256k1),
1303            crate::crypto::SignatureScheme::Secp256r1 => Ok(Self::Secp256r1),
1304            crate::crypto::SignatureScheme::BLS12381 => Ok(Self::Bls12381),
1305            crate::crypto::SignatureScheme::MultiSig => Ok(Self::Multisig),
1306            crate::crypto::SignatureScheme::ZkLoginAuthenticator => Ok(Self::ZkLogin),
1307            crate::crypto::SignatureScheme::PasskeyAuthenticator => Ok(Self::Passkey),
1308            crate::crypto::SignatureScheme::MLDSA65 => Ok(Self::MlDsa65),
1309        }
1310    }
1311}
1312
1313impl From<crate::transaction::SharedObjectMutability> for Mutability {
1314    fn from(value: crate::transaction::SharedObjectMutability) -> Self {
1315        match value {
1316            crate::transaction::SharedObjectMutability::Immutable => Self::Immutable,
1317            crate::transaction::SharedObjectMutability::Mutable => Self::Mutable,
1318            crate::transaction::SharedObjectMutability::NonExclusiveWrite => {
1319                Self::NonExclusiveWrite
1320            }
1321        }
1322    }
1323}
1324
1325impl From<crate::transaction::CallArg> for Input {
1326    fn from(value: crate::transaction::CallArg) -> Self {
1327        match value {
1328            crate::transaction::CallArg::Pure(value) => Self::Pure(value),
1329            crate::transaction::CallArg::Object(object_arg) => match object_arg {
1330                crate::transaction::ObjectArg::ImmOrOwnedObject((id, version, digest)) => {
1331                    Self::ImmutableOrOwned(ObjectReference::new(
1332                        id.into(),
1333                        version.value(),
1334                        digest.into(),
1335                    ))
1336                }
1337                crate::transaction::ObjectArg::SharedObject {
1338                    id,
1339                    initial_shared_version,
1340                    mutability,
1341                } => Self::Shared(SharedInput::new(
1342                    id.into(),
1343                    initial_shared_version.value(),
1344                    mutability,
1345                )),
1346                crate::transaction::ObjectArg::Receiving((id, version, digest)) => Self::Receiving(
1347                    ObjectReference::new(id.into(), version.value(), digest.into()),
1348                ),
1349            },
1350            crate::transaction::CallArg::FundsWithdrawal(withdrawal) => {
1351                let crate::transaction::Reservation::MaxAmountU64(amount) = withdrawal.reservation;
1352                let crate::transaction::WithdrawalTypeArg::Balance(coin_type) = withdrawal.type_arg;
1353                let source = match withdrawal.withdraw_from {
1354                    crate::transaction::WithdrawFrom::Sender => sui_sdk_types::WithdrawFrom::Sender,
1355                    crate::transaction::WithdrawFrom::Sponsor => {
1356                        sui_sdk_types::WithdrawFrom::Sponsor
1357                    }
1358                    crate::transaction::WithdrawFrom::SenderAllowance { funder, allowance } => {
1359                        sui_sdk_types::WithdrawFrom::SenderAllowance {
1360                            funder: funder.into(),
1361                            allowance: allowance.into(),
1362                        }
1363                    }
1364                    crate::transaction::WithdrawFrom::FrozenAddress {
1365                        seized_from,
1366                        seize_auth,
1367                    } => sui_sdk_types::WithdrawFrom::FrozenAddress {
1368                        seized_from: seized_from.into(),
1369                        seize_auth: seize_auth.into(),
1370                    },
1371                };
1372
1373                Self::FundsWithdrawal(FundsWithdrawal::new(
1374                    amount,
1375                    type_tag_core_to_sdk(coin_type).unwrap(),
1376                    source,
1377                ))
1378            }
1379        }
1380    }
1381}
1382
1383impl From<Input> for crate::transaction::CallArg {
1384    fn from(value: Input) -> Self {
1385        use crate::transaction::ObjectArg;
1386
1387        match value {
1388            Input::Pure(value) => Self::Pure(value),
1389            Input::ImmutableOrOwned(object_reference) => {
1390                let (id, version, digest) = object_reference.into_parts();
1391                Self::Object(ObjectArg::ImmOrOwnedObject((
1392                    id.into(),
1393                    version.into(),
1394                    digest.into(),
1395                )))
1396            }
1397            Input::Shared(shared_input) => Self::Object(ObjectArg::SharedObject {
1398                id: shared_input.object_id().into(),
1399                initial_shared_version: shared_input.version().into(),
1400                mutability: match shared_input.mutability() {
1401                    Mutability::Immutable => crate::transaction::SharedObjectMutability::Immutable,
1402                    Mutability::Mutable => crate::transaction::SharedObjectMutability::Mutable,
1403                    Mutability::NonExclusiveWrite => {
1404                        crate::transaction::SharedObjectMutability::NonExclusiveWrite
1405                    }
1406                },
1407            }),
1408            Input::Receiving(object_reference) => {
1409                let (id, version, digest) = object_reference.into_parts();
1410                Self::Object(ObjectArg::Receiving((
1411                    id.into(),
1412                    version.into(),
1413                    digest.into(),
1414                )))
1415            }
1416            Input::FundsWithdrawal(withdrawal) => {
1417                Self::FundsWithdrawal(crate::transaction::FundsWithdrawalArg {
1418                    reservation: withdrawal
1419                        .amount()
1420                        .map(crate::transaction::Reservation::MaxAmountU64)
1421                        .unwrap(),
1422                    type_arg: crate::transaction::WithdrawalTypeArg::Balance(
1423                        type_tag_sdk_to_core(withdrawal.coin_type().to_owned()).unwrap(),
1424                    ),
1425                    withdraw_from: match withdrawal.source() {
1426                        sui_sdk_types::WithdrawFrom::Sender => {
1427                            crate::transaction::WithdrawFrom::Sender
1428                        }
1429                        sui_sdk_types::WithdrawFrom::Sponsor => {
1430                            crate::transaction::WithdrawFrom::Sponsor
1431                        }
1432                        sui_sdk_types::WithdrawFrom::SenderAllowance { funder, allowance } => {
1433                            crate::transaction::WithdrawFrom::SenderAllowance {
1434                                funder: funder.into(),
1435                                allowance: allowance.into(),
1436                            }
1437                        }
1438                        sui_sdk_types::WithdrawFrom::FrozenAddress {
1439                            seized_from,
1440                            seize_auth,
1441                        } => crate::transaction::WithdrawFrom::FrozenAddress {
1442                            seized_from: seized_from.into(),
1443                            seize_auth: seize_auth.into(),
1444                        },
1445                        _ => {
1446                            unreachable!("sdk shouldn't have a variant that the mono repo doesn't")
1447                        }
1448                    },
1449                })
1450            }
1451            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
1452        }
1453    }
1454}
1455
1456impl From<crate::transaction::Argument> for Argument {
1457    fn from(value: crate::transaction::Argument) -> Self {
1458        match value {
1459            crate::transaction::Argument::GasCoin => Self::Gas,
1460            crate::transaction::Argument::Input(idx) => Self::Input(idx),
1461            crate::transaction::Argument::Result(idx) => Self::Result(idx),
1462            crate::transaction::Argument::NestedResult(idx, sub_idx) => {
1463                Self::NestedResult(idx, sub_idx)
1464            }
1465        }
1466    }
1467}
1468
1469impl From<Argument> for crate::transaction::Argument {
1470    fn from(value: Argument) -> Self {
1471        match value {
1472            Argument::Gas => Self::GasCoin,
1473            Argument::Input(idx) => Self::Input(idx),
1474            Argument::Result(idx) => Self::Result(idx),
1475            Argument::NestedResult(idx, sub_idx) => Self::NestedResult(idx, sub_idx),
1476        }
1477    }
1478}
1479
1480impl TryFrom<TransactionEffects> for crate::effects::TransactionEffects {
1481    type Error = SdkTypeConversionError;
1482
1483    fn try_from(value: TransactionEffects) -> Result<Self, Self::Error> {
1484        match value {
1485            TransactionEffects::V1(v1) => Self::V1((*v1).try_into()?),
1486            TransactionEffects::V2(v2) => Self::V2((*v2).try_into()?),
1487        }
1488        .pipe(Ok)
1489    }
1490}
1491
1492impl TryFrom<crate::effects::TransactionEffects> for TransactionEffects {
1493    type Error = SdkTypeConversionError;
1494
1495    fn try_from(value: crate::effects::TransactionEffects) -> Result<Self, Self::Error> {
1496        match value {
1497            crate::effects::TransactionEffects::V1(v1) => Self::V1(Box::new(v1.try_into()?)),
1498            crate::effects::TransactionEffects::V2(v2) => Self::V2(Box::new(v2.try_into()?)),
1499        }
1500        .pipe(Ok)
1501    }
1502}
1503
1504impl TryFrom<crate::transaction::Command> for Command {
1505    type Error = SdkTypeConversionError;
1506
1507    fn try_from(value: crate::transaction::Command) -> Result<Self, Self::Error> {
1508        match value {
1509            crate::transaction::Command::MoveCall(programmable_move_call) => {
1510                Self::MoveCall((*programmable_move_call).try_into()?)
1511            }
1512            crate::transaction::Command::TransferObjects(vec, argument) => {
1513                Self::TransferObjects(TransferObjects {
1514                    objects: vec.into_iter().map(Into::into).collect(),
1515                    address: argument.into(),
1516                })
1517            }
1518            crate::transaction::Command::SplitCoins(argument, vec) => {
1519                Self::SplitCoins(SplitCoins {
1520                    coin: argument.into(),
1521                    amounts: vec.into_iter().map(Into::into).collect(),
1522                })
1523            }
1524            crate::transaction::Command::MergeCoins(argument, vec) => {
1525                Self::MergeCoins(MergeCoins {
1526                    coin: argument.into(),
1527                    coins_to_merge: vec.into_iter().map(Into::into).collect(),
1528                })
1529            }
1530            crate::transaction::Command::Publish(vec, vec1) => Self::Publish(Publish {
1531                modules: vec,
1532                dependencies: vec1.into_iter().map(Into::into).collect(),
1533            }),
1534            crate::transaction::Command::MakeMoveVec(type_input, elements) => {
1535                Self::MakeMoveVector(MakeMoveVector {
1536                    type_: type_input.map(TryInto::try_into).transpose()?,
1537                    elements: elements.into_iter().map(Into::into).collect(),
1538                })
1539            }
1540            crate::transaction::Command::Upgrade(modules, deps, object_id, ticket) => {
1541                Self::Upgrade(Upgrade {
1542                    modules,
1543                    dependencies: deps.into_iter().map(Into::into).collect(),
1544                    package: object_id.into(),
1545                    ticket: ticket.into(),
1546                })
1547            }
1548        }
1549        .pipe(Ok)
1550    }
1551}
1552
1553impl TryFrom<crate::transaction::ProgrammableMoveCall> for MoveCall {
1554    type Error = SdkTypeConversionError;
1555
1556    fn try_from(value: crate::transaction::ProgrammableMoveCall) -> Result<Self, Self::Error> {
1557        Self {
1558            package: value.package.into(),
1559            module: Identifier::new(value.module)?,
1560            function: Identifier::new(value.function)?,
1561            type_arguments: value
1562                .type_arguments
1563                .into_iter()
1564                .map(TryInto::try_into)
1565                .collect::<Result<_, _>>()?,
1566            arguments: value.arguments.into_iter().map(Into::into).collect(),
1567        }
1568        .pipe(Ok)
1569    }
1570}
1571
1572impl From<MoveCall> for crate::transaction::ProgrammableMoveCall {
1573    fn from(value: MoveCall) -> Self {
1574        Self {
1575            package: value.package.into(),
1576            module: value.module.as_str().into(),
1577            function: value.function.as_str().into(),
1578            type_arguments: value.type_arguments.into_iter().map(Into::into).collect(),
1579            arguments: value.arguments.into_iter().map(Into::into).collect(),
1580        }
1581    }
1582}
1583
1584impl From<Command> for crate::transaction::Command {
1585    fn from(value: Command) -> Self {
1586        match value {
1587            Command::MoveCall(move_call) => Self::MoveCall(Box::new(move_call.into())),
1588            Command::TransferObjects(TransferObjects { objects, address }) => {
1589                Self::TransferObjects(
1590                    objects.into_iter().map(Into::into).collect(),
1591                    address.into(),
1592                )
1593            }
1594            Command::SplitCoins(SplitCoins { coin, amounts }) => {
1595                Self::SplitCoins(coin.into(), amounts.into_iter().map(Into::into).collect())
1596            }
1597            Command::MergeCoins(MergeCoins {
1598                coin,
1599                coins_to_merge,
1600            }) => Self::MergeCoins(
1601                coin.into(),
1602                coins_to_merge.into_iter().map(Into::into).collect(),
1603            ),
1604            Command::Publish(Publish {
1605                modules,
1606                dependencies,
1607            }) => Self::Publish(modules, dependencies.into_iter().map(Into::into).collect()),
1608            Command::MakeMoveVector(MakeMoveVector { type_, elements }) => Self::MakeMoveVec(
1609                type_.map(Into::into),
1610                elements.into_iter().map(Into::into).collect(),
1611            ),
1612            Command::Upgrade(Upgrade {
1613                modules,
1614                dependencies,
1615                package,
1616                ticket,
1617            }) => Self::Upgrade(
1618                modules,
1619                dependencies.into_iter().map(Into::into).collect(),
1620                package.into(),
1621                ticket.into(),
1622            ),
1623            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
1624        }
1625    }
1626}
1627
1628impl From<crate::transaction::StoredExecutionTimeObservations> for ExecutionTimeObservations {
1629    fn from(value: crate::transaction::StoredExecutionTimeObservations) -> Self {
1630        match value {
1631            crate::transaction::StoredExecutionTimeObservations::V1(vec) => Self::V1(
1632                vec.into_iter()
1633                    .map(|(key, value)| {
1634                        (
1635                            key.into(),
1636                            value
1637                                .into_iter()
1638                                .map(|(name, duration)| ValidatorExecutionTimeObservation {
1639                                    validator: name.into(),
1640                                    duration,
1641                                })
1642                                .collect(),
1643                        )
1644                    })
1645                    .collect(),
1646            ),
1647        }
1648    }
1649}
1650
1651impl From<crate::execution::ExecutionTimeObservationKey> for ExecutionTimeObservationKey {
1652    fn from(value: crate::execution::ExecutionTimeObservationKey) -> Self {
1653        match value {
1654            crate::execution::ExecutionTimeObservationKey::MoveEntryPoint {
1655                package,
1656                module,
1657                function,
1658                type_arguments,
1659            } => Self::MoveEntryPoint {
1660                package: package.into(),
1661                module,
1662                function,
1663                type_arguments: type_arguments
1664                    .into_iter()
1665                    .map(TryInto::try_into)
1666                    .collect::<Result<_, _>>()
1667                    .unwrap(),
1668            },
1669            crate::execution::ExecutionTimeObservationKey::TransferObjects => Self::TransferObjects,
1670            crate::execution::ExecutionTimeObservationKey::SplitCoins => Self::SplitCoins,
1671            crate::execution::ExecutionTimeObservationKey::MergeCoins => Self::MergeCoins,
1672            crate::execution::ExecutionTimeObservationKey::Publish => Self::Publish,
1673            crate::execution::ExecutionTimeObservationKey::MakeMoveVec => Self::MakeMoveVec,
1674            crate::execution::ExecutionTimeObservationKey::Upgrade => Self::Upgrade,
1675        }
1676    }
1677}
1678
1679impl From<crate::transaction::EndOfEpochTransactionKind> for EndOfEpochTransactionKind {
1680    fn from(value: crate::transaction::EndOfEpochTransactionKind) -> Self {
1681        match value {
1682            crate::transaction::EndOfEpochTransactionKind::ChangeEpoch(change_epoch) => {
1683                Self::ChangeEpoch(change_epoch.into())
1684            }
1685            crate::transaction::EndOfEpochTransactionKind::AuthenticatorStateCreate => {
1686                Self::AuthenticatorStateCreate
1687            }
1688            crate::transaction::EndOfEpochTransactionKind::AuthenticatorStateExpire(
1689                authenticator_state_expire,
1690            ) => Self::AuthenticatorStateExpire(authenticator_state_expire.into()),
1691            crate::transaction::EndOfEpochTransactionKind::RandomnessStateCreate => {
1692                Self::RandomnessStateCreate
1693            }
1694            crate::transaction::EndOfEpochTransactionKind::DenyListStateCreate => {
1695                Self::DenyListStateCreate
1696            }
1697            crate::transaction::EndOfEpochTransactionKind::BridgeStateCreate(chain_identifier) => {
1698                Self::BridgeStateCreate {
1699                    chain_id: Digest::new(chain_identifier.as_bytes().to_owned()),
1700                }
1701            }
1702            crate::transaction::EndOfEpochTransactionKind::BridgeCommitteeInit(sequence_number) => {
1703                Self::BridgeCommitteeInit {
1704                    bridge_object_version: sequence_number.value(),
1705                }
1706            }
1707            crate::transaction::EndOfEpochTransactionKind::StoreExecutionTimeObservations(
1708                stored_execution_time_observations,
1709            ) => Self::StoreExecutionTimeObservations(stored_execution_time_observations.into()),
1710            crate::transaction::EndOfEpochTransactionKind::AccumulatorRootCreate => {
1711                Self::AccumulatorRootCreate
1712            }
1713            crate::transaction::EndOfEpochTransactionKind::CoinRegistryCreate => {
1714                Self::CoinRegistryCreate
1715            }
1716            crate::transaction::EndOfEpochTransactionKind::DisplayRegistryCreate => {
1717                Self::DisplayRegistryCreate
1718            }
1719            crate::transaction::EndOfEpochTransactionKind::AddressAliasStateCreate => {
1720                Self::AddressAliasStateCreate
1721            }
1722            crate::transaction::EndOfEpochTransactionKind::WriteAccumulatorStorageCost(
1723                storage_cost,
1724            ) => Self::WriteAccumulatorStorageCost {
1725                storage_cost: storage_cost.storage_cost,
1726            },
1727            crate::transaction::EndOfEpochTransactionKind::ForwardingAddressRegistryCreate => {
1728                Self::ForwardingAddressRegistryCreate
1729            }
1730            crate::transaction::EndOfEpochTransactionKind::FreezeListCreate => {
1731                Self::FreezeListCreate
1732            }
1733        }
1734    }
1735}
1736
1737impl From<crate::transaction::ChangeEpoch> for ChangeEpoch {
1738    fn from(
1739        crate::transaction::ChangeEpoch {
1740            epoch,
1741            protocol_version,
1742            storage_charge,
1743            computation_charge,
1744            storage_rebate,
1745            non_refundable_storage_fee,
1746            epoch_start_timestamp_ms,
1747            system_packages,
1748        }: crate::transaction::ChangeEpoch,
1749    ) -> Self {
1750        Self {
1751            epoch,
1752            protocol_version: protocol_version.as_u64(),
1753            storage_charge,
1754            computation_charge,
1755            storage_rebate,
1756            non_refundable_storage_fee,
1757            epoch_start_timestamp_ms,
1758            system_packages: system_packages
1759                .into_iter()
1760                .map(|(version, modules, dependencies)| SystemPackage {
1761                    version: version.value(),
1762                    modules,
1763                    dependencies: dependencies.into_iter().map(Into::into).collect(),
1764                })
1765                .collect(),
1766        }
1767    }
1768}
1769
1770impl From<crate::transaction::AuthenticatorStateExpire> for AuthenticatorStateExpire {
1771    fn from(value: crate::transaction::AuthenticatorStateExpire) -> Self {
1772        Self {
1773            min_epoch: value.min_epoch,
1774            authenticator_object_initial_shared_version: value
1775                .authenticator_obj_initial_shared_version
1776                .value(),
1777        }
1778    }
1779}
1780
1781impl From<crate::messages_consensus::ConsensusDeterminedVersionAssignments>
1782    for ConsensusDeterminedVersionAssignments
1783{
1784    fn from(value: crate::messages_consensus::ConsensusDeterminedVersionAssignments) -> Self {
1785        use crate::messages_consensus::ConsensusDeterminedVersionAssignments::*;
1786        match value {
1787            CancelledTransactions(vec) => Self::CanceledTransactions {
1788                canceled_transactions: vec
1789                    .into_iter()
1790                    .map(|(digest, assignments)| CanceledTransaction {
1791                        digest: digest.into(),
1792                        version_assignments: assignments
1793                            .into_iter()
1794                            .map(|(id, version)| VersionAssignment {
1795                                object_id: id.into(),
1796                                version: version.value(),
1797                            })
1798                            .collect(),
1799                    })
1800                    .collect(),
1801            },
1802            CancelledTransactionsV2(canceled_transactions) => Self::CanceledTransactionsV2 {
1803                canceled_transactions: canceled_transactions
1804                    .into_iter()
1805                    .map(|(digest, assignments)| CanceledTransactionV2 {
1806                        digest: digest.into(),
1807                        version_assignments: assignments
1808                            .into_iter()
1809                            .map(|((id, start_version), version)| VersionAssignmentV2 {
1810                                object_id: id.into(),
1811                                start_version: start_version.value(),
1812                                version: version.value(),
1813                            })
1814                            .collect(),
1815                    })
1816                    .collect(),
1817            },
1818        }
1819    }
1820}
1821
1822impl From<crate::authenticator_state::ActiveJwk> for ActiveJwk {
1823    fn from(value: crate::authenticator_state::ActiveJwk) -> Self {
1824        let crate::authenticator_state::ActiveJwk { jwk_id, jwk, epoch } = value;
1825        Self {
1826            jwk_id: JwkId {
1827                iss: jwk_id.iss,
1828                kid: jwk_id.kid,
1829            },
1830            jwk: Jwk {
1831                kty: jwk.kty,
1832                e: jwk.e,
1833                n: jwk.n,
1834                alg: jwk.alg,
1835            },
1836            epoch,
1837        }
1838    }
1839}
1840
1841// TODO remaining set of enums to add impls for to ensure new additions are caught during review
1842//
1843// impl From<crate::transaction::TransactionKind> for TransactionKind {
1844//     fn from(value: crate::transaction::TransactionKind) -> Self {
1845//         todo!()
1846//     }
1847// }
1848// src/object.rs:pub enum ObjectData {