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