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