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