1use crate::crypto::SuiSignature;
7
8fn ms_to_timestamp(ms: u64) -> prost_types::Timestamp {
9 prost_types::Timestamp {
10 seconds: (ms / 1000) as _,
11 nanos: ((ms % 1000) * 1_000_000) as _,
12 }
13}
14use crate::message_envelope::Message as _;
15use fastcrypto::traits::ToFromBytes;
16use sui_rpc::field::FieldMaskTree;
17use sui_rpc::merge::Merge;
18use sui_rpc::proto::TryFromProtoError;
19use sui_rpc::proto::sui::rpc::v2::*;
20
21impl Merge<&crate::full_checkpoint_content::Checkpoint> for Checkpoint {
26 fn merge(&mut self, source: &crate::full_checkpoint_content::Checkpoint, mask: &FieldMaskTree) {
27 let sequence_number = source.summary.sequence_number;
28 let timestamp_ms = source.summary.timestamp_ms;
29
30 let summary = source.summary.data();
31 let signature = source.summary.auth_sig();
32
33 self.merge(summary, mask);
34 self.merge(signature.clone(), mask);
35
36 if mask.contains(Checkpoint::CONTENTS_FIELD.name) {
37 self.merge(&source.contents, mask);
38 }
39
40 if let Some(submask) = mask
41 .subtree(Checkpoint::OBJECTS_FIELD)
42 .and_then(|submask| submask.subtree(ObjectSet::OBJECTS_FIELD))
43 {
44 let set = source
45 .object_set
46 .iter()
47 .map(|o| sui_rpc::proto::sui::rpc::v2::Object::merge_from(o, &submask))
48 .collect();
49 self.objects = Some(ObjectSet::default().with_objects(set));
50 }
51
52 if let Some(submask) = mask.subtree(Checkpoint::TRANSACTIONS_FIELD.name) {
53 self.transactions = source
54 .transactions
55 .iter()
56 .map(|t| {
57 let mut transaction = ExecutedTransaction::merge_from(t, &submask);
58 transaction.checkpoint = submask
59 .contains(ExecutedTransaction::CHECKPOINT_FIELD)
60 .then_some(sequence_number);
61 transaction.timestamp = submask
62 .contains(ExecutedTransaction::TIMESTAMP_FIELD)
63 .then(|| sui_rpc::proto::timestamp_ms_to_proto(timestamp_ms));
64 transaction
65 })
66 .collect();
67 }
68 }
69}
70
71impl Merge<&crate::full_checkpoint_content::ExecutedTransaction> for ExecutedTransaction {
72 fn merge(
73 &mut self,
74 source: &crate::full_checkpoint_content::ExecutedTransaction,
75 mask: &FieldMaskTree,
76 ) {
77 if mask.contains(ExecutedTransaction::DIGEST_FIELD) {
78 self.digest = Some(source.transaction.digest().to_string());
79 }
80
81 if let Some(submask) = mask.subtree(ExecutedTransaction::TRANSACTION_FIELD) {
82 self.transaction = Some(Transaction::merge_from(&source.transaction, &submask));
83 }
84
85 if let Some(submask) = mask.subtree(ExecutedTransaction::SIGNATURES_FIELD) {
86 self.signatures = source
87 .signatures
88 .iter()
89 .map(|s| UserSignature::merge_from(s, &submask))
90 .collect();
91 }
92
93 if let Some(submask) = mask.subtree(ExecutedTransaction::EFFECTS_FIELD) {
94 let mut effects = TransactionEffects::merge_from(&source.effects, &submask);
95 if submask.contains(TransactionEffects::UNCHANGED_LOADED_RUNTIME_OBJECTS_FIELD) {
96 effects.set_unchanged_loaded_runtime_objects(
97 source
98 .unchanged_loaded_runtime_objects
99 .iter()
100 .map(Into::into)
101 .collect(),
102 );
103 }
104 self.effects = Some(effects);
105 }
106
107 if let Some(submask) = mask.subtree(ExecutedTransaction::EVENTS_FIELD) {
108 self.events = source
109 .events
110 .as_ref()
111 .map(|events| TransactionEvents::merge_from(events, &submask));
112 }
113 }
114}
115
116impl TryFrom<&Checkpoint> for crate::full_checkpoint_content::Checkpoint {
117 type Error = TryFromProtoError;
118
119 fn try_from(checkpoint: &Checkpoint) -> Result<Self, Self::Error> {
120 let summary = checkpoint
121 .summary()
122 .bcs()
123 .deserialize()
124 .map_err(|e| TryFromProtoError::invalid("summary.bcs", e))?;
125
126 let signature =
127 crate::crypto::AuthorityStrongQuorumSignInfo::try_from(checkpoint.signature())?;
128
129 let summary = crate::messages_checkpoint::CertifiedCheckpointSummary::new_from_data_and_sig(
130 summary, signature,
131 );
132
133 let contents = checkpoint
134 .contents()
135 .bcs()
136 .deserialize()
137 .map_err(|e| TryFromProtoError::invalid("contents.bcs", e))?;
138
139 let transactions = checkpoint
140 .transactions()
141 .iter()
142 .map(TryInto::try_into)
143 .collect::<Result<_, _>>()?;
144
145 let object_set = checkpoint.objects().try_into()?;
146
147 Ok(Self {
148 summary,
149 contents,
150 transactions,
151 object_set,
152 })
153 }
154}
155
156impl TryFrom<&ExecutedTransaction> for crate::full_checkpoint_content::ExecutedTransaction {
157 type Error = TryFromProtoError;
158
159 fn try_from(value: &ExecutedTransaction) -> Result<Self, Self::Error> {
160 Ok(Self {
161 transaction: value
162 .transaction()
163 .bcs()
164 .deserialize()
165 .map_err(|e| TryFromProtoError::invalid("transaction.bcs", e))?,
166 signatures: value
167 .signatures()
168 .iter()
169 .map(|sig| {
170 crate::signature::GenericSignature::from_bytes(sig.bcs().value())
171 .map_err(|e| TryFromProtoError::invalid("signature.bcs", e))
172 })
173 .collect::<Result<_, _>>()?,
174 effects: value
175 .effects()
176 .bcs()
177 .deserialize()
178 .map_err(|e| TryFromProtoError::invalid("effects.bcs", e))?,
179 events: value
180 .events_opt()
181 .map(|events| {
182 events
183 .bcs()
184 .deserialize()
185 .map_err(|e| TryFromProtoError::invalid("effects.bcs", e))
186 })
187 .transpose()?,
188 unchanged_loaded_runtime_objects: value
189 .effects()
190 .unchanged_loaded_runtime_objects()
191 .iter()
192 .map(TryInto::try_into)
193 .collect::<Result<_, _>>()?,
194 })
195 }
196}
197
198impl TryFrom<&ObjectReference> for crate::storage::ObjectKey {
199 type Error = TryFromProtoError;
200
201 fn try_from(value: &ObjectReference) -> Result<Self, Self::Error> {
202 Ok(Self(
203 value
204 .object_id()
205 .parse()
206 .map_err(|e| TryFromProtoError::invalid("object_id", e))?,
207 value.version().into(),
208 ))
209 }
210}
211
212impl From<crate::messages_checkpoint::CheckpointSummary> for CheckpointSummary {
217 fn from(summary: crate::messages_checkpoint::CheckpointSummary) -> Self {
218 Self::merge_from(summary, &FieldMaskTree::new_wildcard())
219 }
220}
221
222impl Merge<crate::messages_checkpoint::CheckpointSummary> for CheckpointSummary {
223 fn merge(
224 &mut self,
225 source: crate::messages_checkpoint::CheckpointSummary,
226 mask: &FieldMaskTree,
227 ) {
228 if mask.contains(Self::BCS_FIELD) {
229 let mut bcs = Bcs::serialize(&source).unwrap();
230 bcs.name = Some("CheckpointSummary".to_owned());
231 self.bcs = Some(bcs);
232 }
233
234 if mask.contains(Self::DIGEST_FIELD) {
235 self.digest = Some(source.digest().to_string());
236 }
237
238 let crate::messages_checkpoint::CheckpointSummary {
239 epoch,
240 sequence_number,
241 network_total_transactions,
242 content_digest,
243 previous_digest,
244 epoch_rolling_gas_cost_summary,
245 timestamp_ms,
246 checkpoint_commitments,
247 end_of_epoch_data,
248 version_specific_data,
249 } = source;
250
251 if mask.contains(Self::EPOCH_FIELD) {
252 self.epoch = Some(epoch);
253 }
254
255 if mask.contains(Self::SEQUENCE_NUMBER_FIELD) {
256 self.sequence_number = Some(sequence_number);
257 }
258
259 if mask.contains(Self::TOTAL_NETWORK_TRANSACTIONS_FIELD) {
260 self.total_network_transactions = Some(network_total_transactions);
261 }
262
263 if mask.contains(Self::CONTENT_DIGEST_FIELD) {
264 self.content_digest = Some(content_digest.to_string());
265 }
266
267 if mask.contains(Self::PREVIOUS_DIGEST_FIELD) {
268 self.previous_digest = previous_digest.map(|d| d.to_string());
269 }
270
271 if mask.contains(Self::EPOCH_ROLLING_GAS_COST_SUMMARY_FIELD) {
272 self.epoch_rolling_gas_cost_summary = Some(epoch_rolling_gas_cost_summary.into());
273 }
274
275 if mask.contains(Self::TIMESTAMP_FIELD) {
276 self.timestamp = Some(sui_rpc::proto::timestamp_ms_to_proto(timestamp_ms));
277 }
278
279 if mask.contains(Self::COMMITMENTS_FIELD) {
280 self.commitments = checkpoint_commitments.into_iter().map(Into::into).collect();
281 }
282
283 if mask.contains(Self::END_OF_EPOCH_DATA_FIELD) {
284 self.end_of_epoch_data = end_of_epoch_data.map(Into::into);
285 }
286
287 if mask.contains(Self::VERSION_SPECIFIC_DATA_FIELD) {
288 self.version_specific_data = Some(version_specific_data.into());
289 }
290 }
291}
292
293impl From<crate::gas::GasCostSummary> for GasCostSummary {
298 fn from(
299 crate::gas::GasCostSummary {
300 computation_cost,
301 storage_cost,
302 storage_rebate,
303 non_refundable_storage_fee,
304 }: crate::gas::GasCostSummary,
305 ) -> Self {
306 let mut message = Self::default();
307 message.computation_cost = Some(computation_cost);
308 message.storage_cost = Some(storage_cost);
309 message.storage_rebate = Some(storage_rebate);
310 message.non_refundable_storage_fee = Some(non_refundable_storage_fee);
311 message
312 }
313}
314
315impl From<crate::messages_checkpoint::CheckpointCommitment> for CheckpointCommitment {
320 fn from(value: crate::messages_checkpoint::CheckpointCommitment) -> Self {
321 use checkpoint_commitment::CheckpointCommitmentKind;
322
323 let mut message = Self::default();
324
325 let kind = match value {
326 crate::messages_checkpoint::CheckpointCommitment::ECMHLiveObjectSetDigest(digest) => {
327 message.digest = Some(digest.digest.to_string());
328 CheckpointCommitmentKind::EcmhLiveObjectSet
329 }
330 crate::messages_checkpoint::CheckpointCommitment::CheckpointArtifactsDigest(digest) => {
331 message.digest = Some(digest.to_string());
332 CheckpointCommitmentKind::CheckpointArtifacts
333 }
334 };
335
336 message.set_kind(kind);
337 message
338 }
339}
340
341impl From<crate::messages_checkpoint::EndOfEpochData> for EndOfEpochData {
346 fn from(
347 crate::messages_checkpoint::EndOfEpochData {
348 next_epoch_committee,
349 next_epoch_protocol_version,
350 epoch_commitments,
351 }: crate::messages_checkpoint::EndOfEpochData,
352 ) -> Self {
353 let mut message = Self::default();
354
355 message.next_epoch_committee = next_epoch_committee
356 .into_iter()
357 .map(|(name, weight)| {
358 let mut member = ValidatorCommitteeMember::default();
359 member.public_key = Some(name.0.to_vec().into());
360 member.weight = Some(weight);
361 member
362 })
363 .collect();
364 message.next_epoch_protocol_version = Some(next_epoch_protocol_version.as_u64());
365 message.epoch_commitments = epoch_commitments.into_iter().map(Into::into).collect();
366
367 message
368 }
369}
370
371impl From<crate::messages_checkpoint::CheckpointContents> for CheckpointContents {
376 fn from(value: crate::messages_checkpoint::CheckpointContents) -> Self {
377 Self::merge_from(value, &FieldMaskTree::new_wildcard())
378 }
379}
380
381impl Merge<crate::messages_checkpoint::CheckpointContents> for CheckpointContents {
382 fn merge(
383 &mut self,
384 source: crate::messages_checkpoint::CheckpointContents,
385 mask: &FieldMaskTree,
386 ) {
387 if mask.contains(Self::BCS_FIELD) {
388 let mut bcs = Bcs::serialize(&source).unwrap();
389 bcs.name = Some("CheckpointContents".to_owned());
390 self.bcs = Some(bcs);
391 }
392
393 if mask.contains(Self::DIGEST_FIELD) {
394 self.digest = Some(source.digest().to_string());
395 }
396
397 if mask.contains(Self::VERSION_FIELD) {
398 self.set_version(match &source {
399 crate::messages_checkpoint::CheckpointContents::V1(_) => 1,
400 crate::messages_checkpoint::CheckpointContents::V2(_) => 2,
401 });
402 }
403
404 if mask.contains(Self::TRANSACTIONS_FIELD) {
405 self.transactions = source
406 .inner()
407 .iter()
408 .map(|(digests, sigs)| {
409 let mut info = CheckpointedTransactionInfo::default();
410 info.transaction = Some(digests.transaction.to_string());
411 info.effects = Some(digests.effects.to_string());
412 let (signatures, versions) = sigs
413 .map(|(s, v)| {
414 (s.into(), {
415 let mut message = AddressAliasesVersion::default();
416 message.version = v.map(Into::into);
417 message
418 })
419 })
420 .unzip();
421 info.signatures = signatures;
422 info.address_aliases_versions = versions;
423 info
424 })
425 .collect();
426 }
427 }
428}
429
430impl Merge<&crate::messages_checkpoint::CheckpointContents> for Checkpoint {
431 fn merge(
432 &mut self,
433 source: &crate::messages_checkpoint::CheckpointContents,
434 mask: &FieldMaskTree,
435 ) {
436 if let Some(submask) = mask.subtree(Self::CONTENTS_FIELD.name) {
437 self.contents = Some(CheckpointContents::merge_from(source.to_owned(), &submask));
438 }
439 }
440}
441
442impl Merge<&crate::messages_checkpoint::CheckpointSummary> for Checkpoint {
447 fn merge(
448 &mut self,
449 source: &crate::messages_checkpoint::CheckpointSummary,
450 mask: &FieldMaskTree,
451 ) {
452 if mask.contains(Self::SEQUENCE_NUMBER_FIELD) {
453 self.sequence_number = Some(source.sequence_number);
454 }
455
456 if mask.contains(Self::DIGEST_FIELD) {
457 self.digest = Some(source.digest().to_string());
458 }
459
460 if let Some(submask) = mask.subtree(Self::SUMMARY_FIELD) {
461 self.summary = Some(CheckpointSummary::merge_from(source.clone(), &submask));
462 }
463 }
464}
465
466impl<const T: bool> Merge<crate::crypto::AuthorityQuorumSignInfo<T>> for Checkpoint {
467 fn merge(&mut self, source: crate::crypto::AuthorityQuorumSignInfo<T>, mask: &FieldMaskTree) {
468 if mask.contains(Self::SIGNATURE_FIELD) {
469 self.signature = Some(source.into());
470 }
471 }
472}
473
474impl Merge<crate::messages_checkpoint::CheckpointContents> for Checkpoint {
475 fn merge(
476 &mut self,
477 source: crate::messages_checkpoint::CheckpointContents,
478 mask: &FieldMaskTree,
479 ) {
480 if let Some(submask) = mask.subtree(Self::CONTENTS_FIELD) {
481 self.contents = Some(CheckpointContents::merge_from(source, &submask));
482 }
483 }
484}
485
486impl From<crate::event::Event> for Event {
491 fn from(value: crate::event::Event) -> Self {
492 Self::merge_from(&value, &FieldMaskTree::new_wildcard())
493 }
494}
495
496impl Merge<&crate::event::Event> for Event {
497 fn merge(&mut self, source: &crate::event::Event, mask: &FieldMaskTree) {
498 if mask.contains(Self::PACKAGE_ID_FIELD) {
499 self.package_id = Some(source.package_id.to_canonical_string(true));
500 }
501
502 if mask.contains(Self::MODULE_FIELD) {
503 self.module = Some(source.transaction_module.to_string());
504 }
505
506 if mask.contains(Self::SENDER_FIELD) {
507 self.sender = Some(source.sender.to_string());
508 }
509
510 if mask.contains(Self::EVENT_TYPE_FIELD) {
511 self.event_type = Some(source.type_.to_canonical_string(true));
512 }
513
514 if mask.contains(Self::CONTENTS_FIELD) {
515 let mut bcs = Bcs::from(source.contents.clone());
516 bcs.name = Some(source.type_.to_canonical_string(true));
517 self.contents = Some(bcs);
518 }
519 }
520}
521
522impl From<crate::effects::TransactionEvents> for TransactionEvents {
527 fn from(value: crate::effects::TransactionEvents) -> Self {
528 Self::merge_from(&value, &FieldMaskTree::new_wildcard())
529 }
530}
531
532impl Merge<&crate::effects::TransactionEvents> for TransactionEvents {
533 fn merge(&mut self, source: &crate::effects::TransactionEvents, mask: &FieldMaskTree) {
534 if mask.contains(Self::BCS_FIELD) {
535 let mut bcs = Bcs::serialize(&source).unwrap();
536 bcs.name = Some("TransactionEvents".to_owned());
537 self.bcs = Some(bcs);
538 }
539
540 if mask.contains(Self::DIGEST_FIELD) {
541 self.digest = Some(source.digest().to_string());
542 }
543
544 if let Some(events_mask) = mask.subtree(Self::EVENTS_FIELD) {
545 self.events = source
546 .data
547 .iter()
548 .map(|event| Event::merge_from(event, &events_mask))
549 .collect();
550 }
551 }
552}
553
554impl From<crate::sui_system_state::SuiSystemState> for SystemState {
559 fn from(value: crate::sui_system_state::SuiSystemState) -> Self {
560 match value {
561 crate::sui_system_state::SuiSystemState::V1(v1) => v1.into(),
562 crate::sui_system_state::SuiSystemState::V2(v2) => v2.into(),
563
564 #[allow(unreachable_patterns)]
565 _ => Self::default(),
566 }
567 }
568}
569
570impl From<crate::sui_system_state::sui_system_state_inner_v1::SuiSystemStateInnerV1>
571 for SystemState
572{
573 fn from(
574 crate::sui_system_state::sui_system_state_inner_v1::SuiSystemStateInnerV1 {
575 epoch,
576 protocol_version,
577 system_state_version,
578 validators,
579 storage_fund,
580 parameters,
581 reference_gas_price,
582 validator_report_records,
583 stake_subsidy,
584 safe_mode,
585 safe_mode_storage_rewards,
586 safe_mode_computation_rewards,
587 safe_mode_storage_rebates,
588 safe_mode_non_refundable_storage_fee,
589 epoch_start_timestamp_ms,
590 extra_fields,
591 }: crate::sui_system_state::sui_system_state_inner_v1::SuiSystemStateInnerV1,
592 ) -> Self {
593 let validator_report_records = validator_report_records
594 .contents
595 .into_iter()
596 .map(|entry| {
597 let mut record = ValidatorReportRecord::default();
598 record.reported = Some(entry.key.to_string());
599 record.reporters = entry
600 .value
601 .contents
602 .iter()
603 .map(ToString::to_string)
604 .collect();
605 record
606 })
607 .collect();
608
609 let mut message = Self::default();
610
611 message.version = Some(system_state_version);
612 message.epoch = Some(epoch);
613 message.protocol_version = Some(protocol_version);
614 message.validators = Some(validators.into());
615 message.storage_fund = Some(storage_fund.into());
616 message.parameters = Some(parameters.into());
617 message.reference_gas_price = Some(reference_gas_price);
618 message.validator_report_records = validator_report_records;
619 message.stake_subsidy = Some(stake_subsidy.into());
620 message.safe_mode = Some(safe_mode);
621 message.safe_mode_storage_rewards = Some(safe_mode_storage_rewards.value());
622 message.safe_mode_computation_rewards = Some(safe_mode_computation_rewards.value());
623 message.safe_mode_storage_rebates = Some(safe_mode_storage_rebates);
624 message.safe_mode_non_refundable_storage_fee = Some(safe_mode_non_refundable_storage_fee);
625 message.epoch_start_timestamp_ms = Some(epoch_start_timestamp_ms);
626 message.extra_fields = Some(extra_fields.into());
627 message
628 }
629}
630
631impl From<crate::sui_system_state::sui_system_state_inner_v2::SuiSystemStateInnerV2>
632 for SystemState
633{
634 fn from(
635 crate::sui_system_state::sui_system_state_inner_v2::SuiSystemStateInnerV2 {
636 epoch,
637 protocol_version,
638 system_state_version,
639 validators,
640 storage_fund,
641 parameters,
642 reference_gas_price,
643 validator_report_records,
644 stake_subsidy,
645 safe_mode,
646 safe_mode_storage_rewards,
647 safe_mode_computation_rewards,
648 safe_mode_storage_rebates,
649 safe_mode_non_refundable_storage_fee,
650 epoch_start_timestamp_ms,
651 extra_fields,
652 }: crate::sui_system_state::sui_system_state_inner_v2::SuiSystemStateInnerV2,
653 ) -> Self {
654 let validator_report_records = validator_report_records
655 .contents
656 .into_iter()
657 .map(|entry| {
658 let mut record = ValidatorReportRecord::default();
659 record.reported = Some(entry.key.to_string());
660 record.reporters = entry
661 .value
662 .contents
663 .iter()
664 .map(ToString::to_string)
665 .collect();
666 record
667 })
668 .collect();
669
670 let mut message = Self::default();
671
672 message.version = Some(system_state_version);
673 message.epoch = Some(epoch);
674 message.protocol_version = Some(protocol_version);
675 message.validators = Some(validators.into());
676 message.storage_fund = Some(storage_fund.into());
677 message.parameters = Some(parameters.into());
678 message.reference_gas_price = Some(reference_gas_price);
679 message.validator_report_records = validator_report_records;
680 message.stake_subsidy = Some(stake_subsidy.into());
681 message.safe_mode = Some(safe_mode);
682 message.safe_mode_storage_rewards = Some(safe_mode_storage_rewards.value());
683 message.safe_mode_computation_rewards = Some(safe_mode_computation_rewards.value());
684 message.safe_mode_storage_rebates = Some(safe_mode_storage_rebates);
685 message.safe_mode_non_refundable_storage_fee = Some(safe_mode_non_refundable_storage_fee);
686 message.epoch_start_timestamp_ms = Some(epoch_start_timestamp_ms);
687 message.extra_fields = Some(extra_fields.into());
688 message
689 }
690}
691
692impl From<crate::collection_types::Bag> for MoveTable {
693 fn from(crate::collection_types::Bag { id, size }: crate::collection_types::Bag) -> Self {
694 let mut message = Self::default();
695 message.id = Some(id.id.bytes.to_canonical_string(true));
696 message.size = Some(size);
697 message
698 }
699}
700
701impl From<crate::collection_types::Table> for MoveTable {
702 fn from(crate::collection_types::Table { id, size }: crate::collection_types::Table) -> Self {
703 let mut message = Self::default();
704 message.id = Some(id.to_canonical_string(true));
705 message.size = Some(size);
706 message
707 }
708}
709
710impl From<crate::collection_types::TableVec> for MoveTable {
711 fn from(value: crate::collection_types::TableVec) -> Self {
712 value.contents.into()
713 }
714}
715
716impl From<crate::sui_system_state::sui_system_state_inner_v1::StakeSubsidyV1> for StakeSubsidy {
717 fn from(
718 crate::sui_system_state::sui_system_state_inner_v1::StakeSubsidyV1 {
719 balance,
720 distribution_counter,
721 current_distribution_amount,
722 stake_subsidy_period_length,
723 stake_subsidy_decrease_rate,
724 extra_fields,
725 }: crate::sui_system_state::sui_system_state_inner_v1::StakeSubsidyV1,
726 ) -> Self {
727 let mut message = Self::default();
728 message.balance = Some(balance.value());
729 message.distribution_counter = Some(distribution_counter);
730 message.current_distribution_amount = Some(current_distribution_amount);
731 message.stake_subsidy_period_length = Some(stake_subsidy_period_length);
732 message.stake_subsidy_decrease_rate = Some(stake_subsidy_decrease_rate.into());
733 message.extra_fields = Some(extra_fields.into());
734 message
735 }
736}
737
738impl From<crate::sui_system_state::sui_system_state_inner_v1::SystemParametersV1>
739 for SystemParameters
740{
741 fn from(
742 crate::sui_system_state::sui_system_state_inner_v1::SystemParametersV1 {
743 epoch_duration_ms,
744 stake_subsidy_start_epoch,
745 max_validator_count,
746 min_validator_joining_stake,
747 validator_low_stake_threshold,
748 validator_very_low_stake_threshold,
749 validator_low_stake_grace_period,
750 extra_fields,
751 }: crate::sui_system_state::sui_system_state_inner_v1::SystemParametersV1,
752 ) -> Self {
753 let mut message = Self::default();
754 message.epoch_duration_ms = Some(epoch_duration_ms);
755 message.stake_subsidy_start_epoch = Some(stake_subsidy_start_epoch);
756 message.min_validator_count = None;
757 message.max_validator_count = Some(max_validator_count);
758 message.min_validator_joining_stake = Some(min_validator_joining_stake);
759 message.validator_low_stake_threshold = Some(validator_low_stake_threshold);
760 message.validator_very_low_stake_threshold = Some(validator_very_low_stake_threshold);
761 message.validator_low_stake_grace_period = Some(validator_low_stake_grace_period);
762 message.extra_fields = Some(extra_fields.into());
763 message
764 }
765}
766
767impl From<crate::sui_system_state::sui_system_state_inner_v2::SystemParametersV2>
768 for SystemParameters
769{
770 fn from(
771 crate::sui_system_state::sui_system_state_inner_v2::SystemParametersV2 {
772 epoch_duration_ms,
773 stake_subsidy_start_epoch,
774 min_validator_count,
775 max_validator_count,
776 min_validator_joining_stake,
777 validator_low_stake_threshold,
778 validator_very_low_stake_threshold,
779 validator_low_stake_grace_period,
780 extra_fields,
781 }: crate::sui_system_state::sui_system_state_inner_v2::SystemParametersV2,
782 ) -> Self {
783 let mut message = Self::default();
784 message.epoch_duration_ms = Some(epoch_duration_ms);
785 message.stake_subsidy_start_epoch = Some(stake_subsidy_start_epoch);
786 message.min_validator_count = Some(min_validator_count);
787 message.max_validator_count = Some(max_validator_count);
788 message.min_validator_joining_stake = Some(min_validator_joining_stake);
789 message.validator_low_stake_threshold = Some(validator_low_stake_threshold);
790 message.validator_very_low_stake_threshold = Some(validator_very_low_stake_threshold);
791 message.validator_low_stake_grace_period = Some(validator_low_stake_grace_period);
792 message.extra_fields = Some(extra_fields.into());
793 message
794 }
795}
796
797impl From<crate::sui_system_state::sui_system_state_inner_v1::StorageFundV1> for StorageFund {
798 fn from(
799 crate::sui_system_state::sui_system_state_inner_v1::StorageFundV1 {
800 total_object_storage_rebates,
801 non_refundable_balance,
802 }: crate::sui_system_state::sui_system_state_inner_v1::StorageFundV1,
803 ) -> Self {
804 let mut message = Self::default();
805 message.total_object_storage_rebates = Some(total_object_storage_rebates.value());
806 message.non_refundable_balance = Some(non_refundable_balance.value());
807 message
808 }
809}
810
811impl From<crate::sui_system_state::sui_system_state_inner_v1::ValidatorSetV1> for ValidatorSet {
812 fn from(
813 crate::sui_system_state::sui_system_state_inner_v1::ValidatorSetV1 {
814 total_stake,
815 active_validators,
816 pending_active_validators,
817 pending_removals,
818 staking_pool_mappings,
819 inactive_validators,
820 validator_candidates,
821 at_risk_validators,
822 extra_fields,
823 }: crate::sui_system_state::sui_system_state_inner_v1::ValidatorSetV1,
824 ) -> Self {
825 let at_risk_validators = at_risk_validators
826 .contents
827 .into_iter()
828 .map(|entry| (entry.key.to_string(), entry.value))
829 .collect();
830
831 let mut message = Self::default();
832 message.total_stake = Some(total_stake);
833 message.active_validators = active_validators.into_iter().map(Into::into).collect();
834 message.pending_active_validators = Some(pending_active_validators.into());
835 message.pending_removals = pending_removals;
836 message.staking_pool_mappings = Some(staking_pool_mappings.into());
837 message.inactive_validators = Some(inactive_validators.into());
838 message.validator_candidates = Some(validator_candidates.into());
839 message.at_risk_validators = at_risk_validators;
840 message.extra_fields = Some(extra_fields.into());
841 message
842 }
843}
844
845impl From<crate::sui_system_state::sui_system_state_inner_v1::StakingPoolV1> for StakingPool {
846 fn from(
847 crate::sui_system_state::sui_system_state_inner_v1::StakingPoolV1 {
848 id,
849 activation_epoch,
850 deactivation_epoch,
851 sui_balance,
852 rewards_pool,
853 pool_token_balance,
854 exchange_rates,
855 pending_stake,
856 pending_total_sui_withdraw,
857 pending_pool_token_withdraw,
858 extra_fields,
859 }: crate::sui_system_state::sui_system_state_inner_v1::StakingPoolV1,
860 ) -> Self {
861 let mut message = Self::default();
862 message.id = Some(id.to_canonical_string(true));
863 message.activation_epoch = activation_epoch;
864 message.deactivation_epoch = deactivation_epoch;
865 message.sui_balance = Some(sui_balance);
866 message.rewards_pool = Some(rewards_pool.value());
867 message.pool_token_balance = Some(pool_token_balance);
868 message.exchange_rates = Some(exchange_rates.into());
869 message.pending_stake = Some(pending_stake);
870 message.pending_total_sui_withdraw = Some(pending_total_sui_withdraw);
871 message.pending_pool_token_withdraw = Some(pending_pool_token_withdraw);
872 message.extra_fields = Some(extra_fields.into());
873 message
874 }
875}
876
877impl From<crate::sui_system_state::sui_system_state_inner_v1::ValidatorV1> for Validator {
878 fn from(
879 crate::sui_system_state::sui_system_state_inner_v1::ValidatorV1 {
880 metadata:
881 crate::sui_system_state::sui_system_state_inner_v1::ValidatorMetadataV1 {
882 sui_address,
883 protocol_pubkey_bytes,
884 network_pubkey_bytes,
885 worker_pubkey_bytes,
886 proof_of_possession_bytes,
887 name,
888 description,
889 image_url,
890 project_url,
891 net_address,
892 p2p_address,
893 primary_address,
894 worker_address,
895 next_epoch_protocol_pubkey_bytes,
896 next_epoch_proof_of_possession,
897 next_epoch_network_pubkey_bytes,
898 next_epoch_worker_pubkey_bytes,
899 next_epoch_net_address,
900 next_epoch_p2p_address,
901 next_epoch_primary_address,
902 next_epoch_worker_address,
903 extra_fields: metadata_extra_fields,
904 },
905 voting_power,
906 operation_cap_id,
907 gas_price,
908 staking_pool,
909 commission_rate,
910 next_epoch_stake,
911 next_epoch_gas_price,
912 next_epoch_commission_rate,
913 extra_fields,
914 ..
915 }: crate::sui_system_state::sui_system_state_inner_v1::ValidatorV1,
916 ) -> Self {
917 let mut message = Self::default();
918 message.name = Some(name);
919 message.address = Some(sui_address.to_string());
920 message.description = Some(description);
921 message.image_url = Some(image_url);
922 message.project_url = Some(project_url);
923 message.protocol_public_key = Some(protocol_pubkey_bytes.into());
924 message.proof_of_possession = Some(proof_of_possession_bytes.into());
925 message.network_public_key = Some(network_pubkey_bytes.into());
926 message.worker_public_key = Some(worker_pubkey_bytes.into());
927 message.network_address = Some(net_address);
928 message.p2p_address = Some(p2p_address);
929 message.primary_address = Some(primary_address);
930 message.worker_address = Some(worker_address);
931 message.next_epoch_protocol_public_key = next_epoch_protocol_pubkey_bytes.map(Into::into);
932 message.next_epoch_proof_of_possession = next_epoch_proof_of_possession.map(Into::into);
933 message.next_epoch_network_public_key = next_epoch_network_pubkey_bytes.map(Into::into);
934 message.next_epoch_worker_public_key = next_epoch_worker_pubkey_bytes.map(Into::into);
935 message.next_epoch_network_address = next_epoch_net_address;
936 message.next_epoch_p2p_address = next_epoch_p2p_address;
937 message.next_epoch_primary_address = next_epoch_primary_address;
938 message.next_epoch_worker_address = next_epoch_worker_address;
939 message.metadata_extra_fields = Some(metadata_extra_fields.into());
940 message.voting_power = Some(voting_power);
941 message.operation_cap_id = Some(operation_cap_id.bytes.to_canonical_string(true));
942 message.gas_price = Some(gas_price);
943 message.staking_pool = Some(staking_pool.into());
944 message.commission_rate = Some(commission_rate);
945 message.next_epoch_stake = Some(next_epoch_stake);
946 message.next_epoch_gas_price = Some(next_epoch_gas_price);
947 message.next_epoch_commission_rate = Some(next_epoch_commission_rate);
948 message.extra_fields = Some(extra_fields.into());
949 message
950 }
951}
952
953impl From<crate::execution_status::ExecutionStatus> for ExecutionStatus {
958 fn from(value: crate::execution_status::ExecutionStatus) -> Self {
959 let mut message = Self::default();
960 match value {
961 crate::execution_status::ExecutionStatus::Success => {
962 message.success = Some(true);
963 }
964 crate::execution_status::ExecutionStatus::Failure { error, command } => {
965 let description = if let Some(command) = command {
966 format!("{error:?} in command {command}")
967 } else {
968 format!("{error:?}")
969 };
970 let mut error_message = ExecutionError::from(error);
971 error_message.command = command.map(|i| i as u64);
972 error_message.description = Some(description);
973
974 message.success = Some(false);
975 message.error = Some(error_message);
976 }
977 }
978
979 message
980 }
981}
982
983fn size_error(size: u64, max_size: u64) -> SizeError {
988 let mut message = SizeError::default();
989 message.size = Some(size);
990 message.max_size = Some(max_size);
991 message
992}
993
994fn index_error(index: u32, secondary_idx: Option<u32>) -> IndexError {
995 let mut message = IndexError::default();
996 message.index = Some(index);
997 message.subresult = secondary_idx;
998 message
999}
1000
1001impl From<crate::execution_status::ExecutionFailureStatus> for ExecutionError {
1002 fn from(value: crate::execution_status::ExecutionFailureStatus) -> Self {
1003 use crate::execution_status::ExecutionFailureStatus as E;
1004 use execution_error::ErrorDetails;
1005 use execution_error::ExecutionErrorKind;
1006
1007 let mut message = Self::default();
1008
1009 let kind = match value {
1010 E::InsufficientGas => ExecutionErrorKind::InsufficientGas,
1011 E::InvalidGasObject => ExecutionErrorKind::InvalidGasObject,
1012 E::InvariantViolation => ExecutionErrorKind::InvariantViolation,
1013 E::FeatureNotYetSupported => ExecutionErrorKind::FeatureNotYetSupported,
1014 E::MoveObjectTooBig {
1015 object_size,
1016 max_object_size,
1017 } => {
1018 message.error_details = Some(ErrorDetails::SizeError(size_error(
1019 object_size,
1020 max_object_size,
1021 )));
1022 ExecutionErrorKind::ObjectTooBig
1023 }
1024 E::MovePackageTooBig {
1025 object_size,
1026 max_object_size,
1027 } => {
1028 message.error_details = Some(ErrorDetails::SizeError(size_error(
1029 object_size,
1030 max_object_size,
1031 )));
1032 ExecutionErrorKind::PackageTooBig
1033 }
1034 E::CircularObjectOwnership { object } => {
1035 message.error_details =
1036 Some(ErrorDetails::ObjectId(object.to_canonical_string(true)));
1037 ExecutionErrorKind::CircularObjectOwnership
1038 }
1039 E::InsufficientCoinBalance => ExecutionErrorKind::InsufficientCoinBalance,
1040 E::CoinBalanceOverflow => ExecutionErrorKind::CoinBalanceOverflow,
1041 E::PublishErrorNonZeroAddress => ExecutionErrorKind::PublishErrorNonZeroAddress,
1042 E::SuiMoveVerificationError => ExecutionErrorKind::SuiMoveVerificationError,
1043 E::MovePrimitiveRuntimeError(location) => {
1044 message.error_details = location.0.map(|l| {
1045 let mut abort = MoveAbort::default();
1046 abort.location = Some(l.into());
1047 ErrorDetails::Abort(abort)
1048 });
1049 ExecutionErrorKind::MovePrimitiveRuntimeError
1050 }
1051 E::MoveAbort(location, code) => {
1052 let mut abort = MoveAbort::default();
1053 abort.abort_code = Some(code);
1054 abort.location = Some(location.into());
1055 message.error_details = Some(ErrorDetails::Abort(abort));
1056 ExecutionErrorKind::MoveAbort
1057 }
1058 E::VMVerificationOrDeserializationError => {
1059 ExecutionErrorKind::VmVerificationOrDeserializationError
1060 }
1061 E::VMInvariantViolation => ExecutionErrorKind::VmInvariantViolation,
1062 E::FunctionNotFound => ExecutionErrorKind::FunctionNotFound,
1063 E::ArityMismatch => ExecutionErrorKind::ArityMismatch,
1064 E::TypeArityMismatch => ExecutionErrorKind::TypeArityMismatch,
1065 E::NonEntryFunctionInvoked => ExecutionErrorKind::NonEntryFunctionInvoked,
1066 E::CommandArgumentError { arg_idx, kind } => {
1067 let mut command_argument_error = CommandArgumentError::from(kind);
1068 command_argument_error.argument = Some(arg_idx.into());
1069 message.error_details =
1070 Some(ErrorDetails::CommandArgumentError(command_argument_error));
1071 ExecutionErrorKind::CommandArgumentError
1072 }
1073 E::TypeArgumentError { argument_idx, kind } => {
1074 let mut type_argument_error = TypeArgumentError::default();
1075 type_argument_error.type_argument = Some(argument_idx.into());
1076 type_argument_error.kind =
1077 Some(type_argument_error::TypeArgumentErrorKind::from(kind).into());
1078 message.error_details = Some(ErrorDetails::TypeArgumentError(type_argument_error));
1079 ExecutionErrorKind::TypeArgumentError
1080 }
1081 E::UnusedValueWithoutDrop {
1082 result_idx,
1083 secondary_idx,
1084 } => {
1085 message.error_details = Some(ErrorDetails::IndexError(index_error(
1086 result_idx.into(),
1087 Some(secondary_idx.into()),
1088 )));
1089 ExecutionErrorKind::UnusedValueWithoutDrop
1090 }
1091 E::InvalidPublicFunctionReturnType { idx } => {
1092 message.error_details =
1093 Some(ErrorDetails::IndexError(index_error(idx.into(), None)));
1094 ExecutionErrorKind::InvalidPublicFunctionReturnType
1095 }
1096 E::InvalidTransferObject => ExecutionErrorKind::InvalidTransferObject,
1097 E::EffectsTooLarge {
1098 current_size,
1099 max_size,
1100 } => {
1101 message.error_details =
1102 Some(ErrorDetails::SizeError(size_error(current_size, max_size)));
1103 ExecutionErrorKind::EffectsTooLarge
1104 }
1105 E::PublishUpgradeMissingDependency => {
1106 ExecutionErrorKind::PublishUpgradeMissingDependency
1107 }
1108 E::PublishUpgradeDependencyDowngrade => {
1109 ExecutionErrorKind::PublishUpgradeDependencyDowngrade
1110 }
1111 E::PackageUpgradeError { upgrade_error } => {
1112 message.error_details =
1113 Some(ErrorDetails::PackageUpgradeError(upgrade_error.into()));
1114 ExecutionErrorKind::PackageUpgradeError
1115 }
1116 E::WrittenObjectsTooLarge {
1117 current_size,
1118 max_size,
1119 } => {
1120 message.error_details =
1121 Some(ErrorDetails::SizeError(size_error(current_size, max_size)));
1122
1123 ExecutionErrorKind::WrittenObjectsTooLarge
1124 }
1125 E::CertificateDenied => ExecutionErrorKind::CertificateDenied,
1126 E::SuiMoveVerificationTimedout => ExecutionErrorKind::SuiMoveVerificationTimedout,
1127 E::SharedObjectOperationNotAllowed => {
1128 ExecutionErrorKind::ConsensusObjectOperationNotAllowed
1129 }
1130 E::InputObjectDeleted => ExecutionErrorKind::InputObjectDeleted,
1131 E::ExecutionCancelledDueToSharedObjectCongestion { congested_objects } => {
1132 message.error_details = Some(ErrorDetails::CongestedObjects({
1133 let mut message = CongestedObjects::default();
1134 message.objects = congested_objects
1135 .0
1136 .iter()
1137 .map(|o| o.to_canonical_string(true))
1138 .collect();
1139 message
1140 }));
1141
1142 ExecutionErrorKind::ExecutionCanceledDueToConsensusObjectCongestion
1143 }
1144 E::AddressDeniedForCoin { address, coin_type } => {
1145 message.error_details = Some(ErrorDetails::CoinDenyListError({
1146 let mut message = CoinDenyListError::default();
1147 message.address = Some(address.to_string());
1148 message.coin_type = Some(coin_type);
1149 message
1150 }));
1151 ExecutionErrorKind::AddressDeniedForCoin
1152 }
1153 E::CoinTypeGlobalPause { coin_type } => {
1154 message.error_details = Some(ErrorDetails::CoinDenyListError({
1155 let mut message = CoinDenyListError::default();
1156 message.coin_type = Some(coin_type);
1157 message
1158 }));
1159 ExecutionErrorKind::CoinTypeGlobalPause
1160 }
1161 E::ExecutionCancelledDueToRandomnessUnavailable => {
1162 ExecutionErrorKind::ExecutionCanceledDueToRandomnessUnavailable
1163 }
1164 E::MoveVectorElemTooBig {
1165 value_size,
1166 max_scaled_size,
1167 } => {
1168 message.error_details = Some(ErrorDetails::SizeError(size_error(
1169 value_size,
1170 max_scaled_size,
1171 )));
1172
1173 ExecutionErrorKind::MoveVectorElemTooBig
1174 }
1175 E::MoveRawValueTooBig {
1176 value_size,
1177 max_scaled_size,
1178 } => {
1179 message.error_details = Some(ErrorDetails::SizeError(size_error(
1180 value_size,
1181 max_scaled_size,
1182 )));
1183 ExecutionErrorKind::MoveRawValueTooBig
1184 }
1185 E::InvalidLinkage => ExecutionErrorKind::InvalidLinkage,
1186 E::InsufficientFundsForWithdraw => ExecutionErrorKind::InsufficientFundsForWithdraw,
1187 E::NonExclusiveWriteInputObjectModified { id } => {
1188 message.set_object_id(id.to_canonical_string(true));
1189 ExecutionErrorKind::NonExclusiveWriteInputObjectModified
1190 }
1191 };
1192
1193 message.set_kind(kind);
1194 message
1195 }
1196}
1197
1198impl From<crate::execution_status::CommandArgumentError> for CommandArgumentError {
1203 fn from(value: crate::execution_status::CommandArgumentError) -> Self {
1204 use crate::execution_status::CommandArgumentError as E;
1205 use command_argument_error::CommandArgumentErrorKind;
1206
1207 let mut message = Self::default();
1208
1209 let kind = match value {
1210 E::TypeMismatch => CommandArgumentErrorKind::TypeMismatch,
1211 E::InvalidBCSBytes => CommandArgumentErrorKind::InvalidBcsBytes,
1212 E::InvalidUsageOfPureArg => CommandArgumentErrorKind::InvalidUsageOfPureArgument,
1213 E::InvalidArgumentToPrivateEntryFunction => {
1214 CommandArgumentErrorKind::InvalidArgumentToPrivateEntryFunction
1215 }
1216 E::IndexOutOfBounds { idx } => {
1217 message.index_error = Some(index_error(idx.into(), None));
1218 CommandArgumentErrorKind::IndexOutOfBounds
1219 }
1220 E::SecondaryIndexOutOfBounds {
1221 result_idx,
1222 secondary_idx,
1223 } => {
1224 message.index_error =
1225 Some(index_error(result_idx.into(), Some(secondary_idx.into())));
1226 CommandArgumentErrorKind::SecondaryIndexOutOfBounds
1227 }
1228 E::InvalidResultArity { result_idx } => {
1229 message.index_error = Some(index_error(result_idx.into(), None));
1230 CommandArgumentErrorKind::InvalidResultArity
1231 }
1232 E::InvalidGasCoinUsage => CommandArgumentErrorKind::InvalidGasCoinUsage,
1233 E::InvalidValueUsage => CommandArgumentErrorKind::InvalidValueUsage,
1234 E::InvalidObjectByValue => CommandArgumentErrorKind::InvalidObjectByValue,
1235 E::InvalidObjectByMutRef => CommandArgumentErrorKind::InvalidObjectByMutRef,
1236 E::SharedObjectOperationNotAllowed => {
1237 CommandArgumentErrorKind::ConsensusObjectOperationNotAllowed
1238 }
1239 E::InvalidArgumentArity => CommandArgumentErrorKind::InvalidArgumentArity,
1240
1241 E::InvalidTransferObject => CommandArgumentErrorKind::InvalidTransferObject,
1242 E::InvalidMakeMoveVecNonObjectArgument => {
1243 CommandArgumentErrorKind::InvalidMakeMoveVecNonObjectArgument
1244 }
1245 E::ArgumentWithoutValue => CommandArgumentErrorKind::ArgumentWithoutValue,
1246 E::CannotMoveBorrowedValue => CommandArgumentErrorKind::CannotMoveBorrowedValue,
1247 E::CannotWriteToExtendedReference => {
1248 CommandArgumentErrorKind::CannotWriteToExtendedReference
1249 }
1250 E::InvalidReferenceArgument => CommandArgumentErrorKind::InvalidReferenceArgument,
1251 };
1252
1253 message.set_kind(kind);
1254 message
1255 }
1256}
1257
1258impl From<crate::execution_status::TypeArgumentError>
1263 for type_argument_error::TypeArgumentErrorKind
1264{
1265 fn from(value: crate::execution_status::TypeArgumentError) -> Self {
1266 use crate::execution_status::TypeArgumentError::*;
1267
1268 match value {
1269 TypeNotFound => Self::TypeNotFound,
1270 ConstraintNotSatisfied => Self::ConstraintNotSatisfied,
1271 }
1272 }
1273}
1274
1275impl From<crate::execution_status::PackageUpgradeError> for PackageUpgradeError {
1280 fn from(value: crate::execution_status::PackageUpgradeError) -> Self {
1281 use crate::execution_status::PackageUpgradeError as E;
1282 use package_upgrade_error::PackageUpgradeErrorKind;
1283
1284 let mut message = Self::default();
1285
1286 let kind = match value {
1287 E::UnableToFetchPackage { package_id } => {
1288 message.package_id = Some(package_id.to_canonical_string(true));
1289 PackageUpgradeErrorKind::UnableToFetchPackage
1290 }
1291 E::NotAPackage { object_id } => {
1292 message.package_id = Some(object_id.to_canonical_string(true));
1293 PackageUpgradeErrorKind::NotAPackage
1294 }
1295 E::IncompatibleUpgrade => PackageUpgradeErrorKind::IncompatibleUpgrade,
1296 E::DigestDoesNotMatch { digest } => {
1297 message.digest = crate::digests::Digest::try_from(digest)
1298 .ok()
1299 .map(|d| d.to_string());
1300 PackageUpgradeErrorKind::DigestDoesNotMatch
1301 }
1302 E::UnknownUpgradePolicy { policy } => {
1303 message.policy = Some(policy.into());
1304 PackageUpgradeErrorKind::UnknownUpgradePolicy
1305 }
1306 E::PackageIDDoesNotMatch {
1307 package_id,
1308 ticket_id,
1309 } => {
1310 message.package_id = Some(package_id.to_canonical_string(true));
1311 message.ticket_id = Some(ticket_id.to_canonical_string(true));
1312 PackageUpgradeErrorKind::PackageIdDoesNotMatch
1313 }
1314 };
1315
1316 message.set_kind(kind);
1317 message
1318 }
1319}
1320
1321impl From<crate::execution_status::MoveLocation> for MoveLocation {
1326 fn from(value: crate::execution_status::MoveLocation) -> Self {
1327 let mut message = Self::default();
1328 message.package = Some(value.module.address().to_canonical_string(true));
1329 message.module = Some(value.module.name().to_string());
1330 message.function = Some(value.function.into());
1331 message.instruction = Some(value.instruction.into());
1332 message.function_name = value.function_name.map(|name| name.to_string());
1333 message
1334 }
1335}
1336
1337impl<const T: bool> From<crate::crypto::AuthorityQuorumSignInfo<T>>
1342 for ValidatorAggregatedSignature
1343{
1344 fn from(value: crate::crypto::AuthorityQuorumSignInfo<T>) -> Self {
1345 let mut bitmap = Vec::new();
1346 value.signers_map.serialize_into(&mut bitmap).unwrap();
1347
1348 Self::default()
1349 .with_epoch(value.epoch)
1350 .with_signature(value.signature.as_ref().to_vec())
1351 .with_bitmap(bitmap)
1352 }
1353}
1354
1355impl<const T: bool> TryFrom<&ValidatorAggregatedSignature>
1356 for crate::crypto::AuthorityQuorumSignInfo<T>
1357{
1358 type Error = TryFromProtoError;
1359
1360 fn try_from(value: &ValidatorAggregatedSignature) -> Result<Self, Self::Error> {
1361 Ok(Self {
1362 epoch: value.epoch(),
1363 signature: crate::crypto::AggregateAuthoritySignature::from_bytes(value.signature())
1364 .map_err(|e| TryFromProtoError::invalid("signature", e))?,
1365 signers_map: crate::sui_serde::deserialize_sui_bitmap(value.bitmap())
1366 .map_err(|e| TryFromProtoError::invalid("bitmap", e))?,
1367 })
1368 }
1369}
1370
1371impl From<crate::committee::Committee> for ValidatorCommittee {
1376 fn from(value: crate::committee::Committee) -> Self {
1377 let mut message = Self::default();
1378 message.epoch = Some(value.epoch);
1379 message.members = value
1380 .voting_rights
1381 .into_iter()
1382 .map(|(name, weight)| {
1383 let mut member = ValidatorCommitteeMember::default();
1384 member.public_key = Some(name.0.to_vec().into());
1385 member.weight = Some(weight);
1386 member
1387 })
1388 .collect();
1389 message
1390 }
1391}
1392
1393impl From<&crate::zk_login_authenticator::ZkLoginAuthenticator> for ZkLoginAuthenticator {
1398 fn from(value: &crate::zk_login_authenticator::ZkLoginAuthenticator) -> Self {
1399 let mut inputs = ZkLoginInputs::default();
1401 inputs.address_seed = Some(value.inputs.get_address_seed().to_string());
1402 let mut message = Self::default();
1403 message.inputs = Some(inputs);
1404 message.max_epoch = Some(value.get_max_epoch());
1405 message.signature = Some(value.user_signature.clone().into());
1406
1407 sui_sdk_types::ZkLoginAuthenticator::try_from(value.clone())
1408 .map(Into::into)
1409 .ok()
1410 .unwrap_or(message)
1411 }
1412}
1413
1414impl From<&crate::crypto::ZkLoginPublicIdentifier> for ZkLoginPublicIdentifier {
1419 fn from(value: &crate::crypto::ZkLoginPublicIdentifier) -> Self {
1420 sui_sdk_types::ZkLoginPublicIdentifier::try_from(value.to_owned())
1422 .map(|id| (&id).into())
1423 .ok()
1424 .unwrap_or_default()
1425 }
1426}
1427
1428impl From<crate::crypto::SignatureScheme> for SignatureScheme {
1433 fn from(value: crate::crypto::SignatureScheme) -> Self {
1434 use crate::crypto::SignatureScheme as S;
1435
1436 match value {
1437 S::ED25519 => Self::Ed25519,
1438 S::Secp256k1 => Self::Secp256k1,
1439 S::Secp256r1 => Self::Secp256r1,
1440 S::BLS12381 => Self::Bls12381,
1441 S::MultiSig => Self::Multisig,
1442 S::ZkLoginAuthenticator => Self::Zklogin,
1443 S::PasskeyAuthenticator => Self::Passkey,
1444 }
1445 }
1446}
1447
1448impl From<crate::crypto::Signature> for SimpleSignature {
1453 fn from(value: crate::crypto::Signature) -> Self {
1454 Self::from(&value)
1455 }
1456}
1457
1458impl From<&crate::crypto::Signature> for SimpleSignature {
1459 fn from(value: &crate::crypto::Signature) -> Self {
1460 let scheme: SignatureScheme = value.scheme().into();
1461 let signature = value.signature_bytes();
1462 let public_key = value.public_key_bytes();
1463
1464 let mut message = Self::default();
1465 message.scheme = Some(scheme.into());
1466 message.signature = Some(signature.to_vec().into());
1467 message.public_key = Some(public_key.to_vec().into());
1468 message
1469 }
1470}
1471
1472impl From<&crate::passkey_authenticator::PasskeyAuthenticator> for PasskeyAuthenticator {
1477 fn from(value: &crate::passkey_authenticator::PasskeyAuthenticator) -> Self {
1478 let mut message = Self::default();
1479 message.authenticator_data = Some(value.authenticator_data().to_vec().into());
1480 message.client_data_json = Some(value.client_data_json().to_owned());
1481 message.signature = Some(value.signature().into());
1482 message
1483 }
1484}
1485
1486impl From<&crate::crypto::PublicKey> for MultisigMemberPublicKey {
1491 fn from(value: &crate::crypto::PublicKey) -> Self {
1492 let mut message = Self::default();
1493
1494 match value {
1495 crate::crypto::PublicKey::Ed25519(_)
1496 | crate::crypto::PublicKey::Secp256k1(_)
1497 | crate::crypto::PublicKey::Secp256r1(_)
1498 | crate::crypto::PublicKey::Passkey(_) => {
1499 message.public_key = Some(value.as_ref().to_vec().into());
1500 }
1501 crate::crypto::PublicKey::ZkLogin(z) => {
1502 message.zklogin = Some(z.into());
1503 }
1504 }
1505
1506 message.set_scheme(value.scheme().into());
1507 message
1508 }
1509}
1510
1511impl From<&crate::multisig::MultiSigPublicKey> for MultisigCommittee {
1516 fn from(value: &crate::multisig::MultiSigPublicKey) -> Self {
1517 let mut message = Self::default();
1518 message.members = value
1519 .pubkeys()
1520 .iter()
1521 .map(|(pk, weight)| {
1522 let mut member = MultisigMember::default();
1523 member.public_key = Some(pk.into());
1524 member.weight = Some((*weight).into());
1525 member
1526 })
1527 .collect();
1528 message.threshold = Some((*value.threshold()).into());
1529 message
1530 }
1531}
1532
1533impl From<&crate::multisig_legacy::MultiSigPublicKeyLegacy> for MultisigCommittee {
1534 fn from(value: &crate::multisig_legacy::MultiSigPublicKeyLegacy) -> Self {
1535 let mut message = Self::default();
1536 message.members = value
1537 .pubkeys()
1538 .iter()
1539 .map(|(pk, weight)| {
1540 let mut member = MultisigMember::default();
1541 member.public_key = Some(pk.into());
1542 member.weight = Some((*weight).into());
1543 member
1544 })
1545 .collect();
1546 message.threshold = Some((*value.threshold()).into());
1547 message
1548 }
1549}
1550
1551impl From<&crate::crypto::CompressedSignature> for MultisigMemberSignature {
1556 fn from(value: &crate::crypto::CompressedSignature) -> Self {
1557 let mut message = Self::default();
1558
1559 let scheme = match value {
1560 crate::crypto::CompressedSignature::Ed25519(b) => {
1561 message.signature = Some(b.0.to_vec().into());
1562 SignatureScheme::Ed25519
1563 }
1564 crate::crypto::CompressedSignature::Secp256k1(b) => {
1565 message.signature = Some(b.0.to_vec().into());
1566 SignatureScheme::Secp256k1
1567 }
1568 crate::crypto::CompressedSignature::Secp256r1(b) => {
1569 message.signature = Some(b.0.to_vec().into());
1570 SignatureScheme::Secp256r1
1571 }
1572 crate::crypto::CompressedSignature::ZkLogin(_z) => {
1573 SignatureScheme::Zklogin
1575 }
1576 crate::crypto::CompressedSignature::Passkey(_p) => {
1577 SignatureScheme::Passkey
1579 }
1580 };
1581
1582 message.set_scheme(scheme);
1583 message
1584 }
1585}
1586
1587impl From<&crate::multisig_legacy::MultiSigLegacy> for MultisigAggregatedSignature {
1592 fn from(value: &crate::multisig_legacy::MultiSigLegacy) -> Self {
1593 let mut legacy_bitmap = Vec::new();
1594 value
1595 .get_bitmap()
1596 .serialize_into(&mut legacy_bitmap)
1597 .unwrap();
1598
1599 Self::default()
1600 .with_signatures(value.get_sigs().iter().map(Into::into).collect())
1601 .with_legacy_bitmap(legacy_bitmap)
1602 .with_committee(value.get_pk())
1603 }
1604}
1605
1606impl From<&crate::multisig::MultiSig> for MultisigAggregatedSignature {
1607 fn from(value: &crate::multisig::MultiSig) -> Self {
1608 let mut message = Self::default();
1609 message.signatures = value.get_sigs().iter().map(Into::into).collect();
1610 message.bitmap = Some(value.get_bitmap().into());
1611 message.committee = Some(value.get_pk().into());
1612 message
1613 }
1614}
1615
1616impl From<&crate::signature::GenericSignature> for UserSignature {
1621 fn from(value: &crate::signature::GenericSignature) -> Self {
1622 Self::merge_from(value, &FieldMaskTree::new_wildcard())
1623 }
1624}
1625
1626impl Merge<&crate::signature::GenericSignature> for UserSignature {
1627 fn merge(&mut self, source: &crate::signature::GenericSignature, mask: &FieldMaskTree) {
1628 use user_signature::Signature;
1629
1630 if mask.contains(Self::BCS_FIELD) {
1631 let mut bcs = Bcs::from(source.as_ref().to_vec());
1632 bcs.name = Some("UserSignatureBytes".to_owned());
1633 self.bcs = Some(bcs);
1634 }
1635
1636 let scheme = match source {
1637 crate::signature::GenericSignature::MultiSig(multi_sig) => {
1638 if mask.contains(Self::MULTISIG_FIELD) {
1639 self.signature = Some(Signature::Multisig(multi_sig.into()));
1640 }
1641 SignatureScheme::Multisig
1642 }
1643 crate::signature::GenericSignature::MultiSigLegacy(multi_sig_legacy) => {
1644 if mask.contains(Self::MULTISIG_FIELD) {
1645 self.signature = Some(Signature::Multisig(multi_sig_legacy.into()));
1646 }
1647 SignatureScheme::Multisig
1648 }
1649 crate::signature::GenericSignature::Signature(signature) => {
1650 let scheme = signature.scheme().into();
1651 if mask.contains(Self::SIMPLE_FIELD) {
1652 self.signature = Some(Signature::Simple(signature.into()));
1653 }
1654 scheme
1655 }
1656 crate::signature::GenericSignature::ZkLoginAuthenticator(z) => {
1657 if mask.contains(Self::ZKLOGIN_FIELD) {
1658 self.signature = Some(Signature::Zklogin(z.into()));
1659 }
1660 SignatureScheme::Zklogin
1661 }
1662 crate::signature::GenericSignature::PasskeyAuthenticator(p) => {
1663 if mask.contains(Self::PASSKEY_FIELD) {
1664 self.signature = Some(Signature::Passkey(p.into()));
1665 }
1666 SignatureScheme::Passkey
1667 }
1668 };
1669
1670 if mask.contains(Self::SCHEME_FIELD) {
1671 self.set_scheme(scheme);
1672 }
1673 }
1674}
1675
1676impl From<crate::balance_change::BalanceChange> for BalanceChange {
1681 fn from(value: crate::balance_change::BalanceChange) -> Self {
1682 let mut message = Self::default();
1683 message.address = Some(value.address.to_string());
1684 message.coin_type = Some(value.coin_type.to_canonical_string(true));
1685 message.amount = Some(value.amount.to_string());
1686 message
1687 }
1688}
1689
1690impl TryFrom<&BalanceChange> for crate::balance_change::BalanceChange {
1691 type Error = TryFromProtoError;
1692
1693 fn try_from(value: &BalanceChange) -> Result<Self, Self::Error> {
1694 Ok(Self {
1695 address: value
1696 .address()
1697 .parse()
1698 .map_err(|e| TryFromProtoError::invalid(BalanceChange::ADDRESS_FIELD, e))?,
1699 coin_type: value
1700 .coin_type()
1701 .parse()
1702 .map_err(|e| TryFromProtoError::invalid(BalanceChange::COIN_TYPE_FIELD, e))?,
1703 amount: value
1704 .amount()
1705 .parse()
1706 .map_err(|e| TryFromProtoError::invalid(BalanceChange::AMOUNT_FIELD, e))?,
1707 })
1708 }
1709}
1710
1711pub const PACKAGE_TYPE: &str = "package";
1716
1717impl From<crate::object::Object> for Object {
1718 fn from(value: crate::object::Object) -> Self {
1719 Self::merge_from(&value, &FieldMaskTree::new_wildcard())
1720 }
1721}
1722
1723impl Merge<&crate::object::Object> for Object {
1724 fn merge(&mut self, source: &crate::object::Object, mask: &FieldMaskTree) {
1725 if mask.contains(Self::BCS_FIELD.name) {
1726 let mut bcs = Bcs::serialize(&source).unwrap();
1727 bcs.name = Some("Object".to_owned());
1728 self.bcs = Some(bcs);
1729 }
1730
1731 if mask.contains(Self::DIGEST_FIELD.name) {
1732 self.digest = Some(source.digest().to_string());
1733 }
1734
1735 if mask.contains(Self::OBJECT_ID_FIELD.name) {
1736 self.object_id = Some(source.id().to_canonical_string(true));
1737 }
1738
1739 if mask.contains(Self::VERSION_FIELD.name) {
1740 self.version = Some(source.version().value());
1741 }
1742
1743 if mask.contains(Self::OWNER_FIELD.name) {
1744 self.owner = Some(source.owner().to_owned().into());
1745 }
1746
1747 if mask.contains(Self::PREVIOUS_TRANSACTION_FIELD.name) {
1748 self.previous_transaction = Some(source.previous_transaction.to_string());
1749 }
1750
1751 if mask.contains(Self::STORAGE_REBATE_FIELD.name) {
1752 self.storage_rebate = Some(source.storage_rebate);
1753 }
1754
1755 if mask.contains(Self::BALANCE_FIELD) {
1756 self.balance = source.as_coin_maybe().map(|coin| coin.balance.value());
1757 }
1758
1759 self.merge(&source.data, mask);
1760 }
1761}
1762
1763impl Merge<&crate::object::MoveObject> for Object {
1764 fn merge(&mut self, source: &crate::object::MoveObject, mask: &FieldMaskTree) {
1765 self.object_id = Some(source.id().to_canonical_string(true));
1766 self.version = Some(source.version().value());
1767
1768 if mask.contains(Self::OBJECT_TYPE_FIELD.name) {
1769 self.object_type = Some(source.type_().to_canonical_string(true));
1770 }
1771
1772 if mask.contains(Self::HAS_PUBLIC_TRANSFER_FIELD.name) {
1773 self.has_public_transfer = Some(source.has_public_transfer());
1774 }
1775
1776 if mask.contains(Self::CONTENTS_FIELD.name) {
1777 let mut bcs = Bcs::from(source.contents().to_vec());
1778 bcs.name = Some(source.type_().to_canonical_string(true));
1779 self.contents = Some(bcs);
1780 }
1781 }
1782}
1783
1784impl Merge<&crate::move_package::MovePackage> for Object {
1785 fn merge(&mut self, source: &crate::move_package::MovePackage, mask: &FieldMaskTree) {
1786 self.object_id = Some(source.id().to_canonical_string(true));
1787 self.version = Some(source.version().value());
1788
1789 if mask.contains(Self::OBJECT_TYPE_FIELD.name) {
1790 self.object_type = Some(PACKAGE_TYPE.to_owned());
1791 }
1792
1793 if mask.contains(Self::PACKAGE_FIELD.name) {
1794 let mut package = Package::default();
1795 package.modules = source
1796 .serialized_module_map()
1797 .iter()
1798 .map(|(name, contents)| {
1799 let mut module = Module::default();
1800 module.name = Some(name.to_string());
1801 module.contents = Some(contents.clone().into());
1802 module
1803 })
1804 .collect();
1805 package.type_origins = source
1806 .type_origin_table()
1807 .clone()
1808 .into_iter()
1809 .map(Into::into)
1810 .collect();
1811 package.linkage = source
1812 .linkage_table()
1813 .iter()
1814 .map(
1815 |(
1816 original_id,
1817 crate::move_package::UpgradeInfo {
1818 upgraded_id,
1819 upgraded_version,
1820 },
1821 )| {
1822 let mut linkage = Linkage::default();
1823 linkage.original_id = Some(original_id.to_canonical_string(true));
1824 linkage.upgraded_id = Some(upgraded_id.to_canonical_string(true));
1825 linkage.upgraded_version = Some(upgraded_version.value());
1826 linkage
1827 },
1828 )
1829 .collect();
1830
1831 self.package = Some(package);
1832 }
1833 }
1834}
1835
1836impl Merge<&crate::object::Data> for Object {
1837 fn merge(&mut self, source: &crate::object::Data, mask: &FieldMaskTree) {
1838 match source {
1839 crate::object::Data::Move(object) => self.merge(object, mask),
1840 crate::object::Data::Package(package) => self.merge(package, mask),
1841 }
1842 }
1843}
1844
1845impl From<crate::move_package::TypeOrigin> for TypeOrigin {
1850 fn from(value: crate::move_package::TypeOrigin) -> Self {
1851 let mut message = Self::default();
1852 message.module_name = Some(value.module_name.to_string());
1853 message.datatype_name = Some(value.datatype_name.to_string());
1854 message.package_id = Some(value.package.to_canonical_string(true));
1855 message
1856 }
1857}
1858
1859impl From<crate::transaction::GenesisObject> for Object {
1864 fn from(value: crate::transaction::GenesisObject) -> Self {
1865 let crate::transaction::GenesisObject::RawObject { data, owner } = value;
1866 let mut message = Self::default();
1867 message.owner = Some(owner.into());
1868
1869 message.merge(&data, &FieldMaskTree::new_wildcard());
1870
1871 message
1872 }
1873}
1874
1875pub trait ObjectRefExt {
1880 fn to_proto(self) -> ObjectReference;
1881}
1882
1883pub trait ObjectReferenceExt {
1884 fn try_to_object_ref(&self) -> Result<crate::base_types::ObjectRef, anyhow::Error>;
1885}
1886
1887impl ObjectRefExt for crate::base_types::ObjectRef {
1888 fn to_proto(self) -> ObjectReference {
1889 let (object_id, version, digest) = self;
1890 let mut message = ObjectReference::default();
1891 message.object_id = Some(object_id.to_canonical_string(true));
1892 message.version = Some(version.value());
1893 message.digest = Some(digest.to_string());
1894 message
1895 }
1896}
1897
1898impl ObjectReferenceExt for ObjectReference {
1899 fn try_to_object_ref(&self) -> Result<crate::base_types::ObjectRef, anyhow::Error> {
1900 use anyhow::Context;
1901
1902 let object_id = self
1903 .object_id_opt()
1904 .ok_or_else(|| anyhow::anyhow!("missing object_id"))?;
1905 let object_id = crate::base_types::ObjectID::from_hex_literal(object_id)
1906 .with_context(|| format!("Failed to parse object_id: {}", object_id))?;
1907
1908 let version = self
1909 .version_opt()
1910 .ok_or_else(|| anyhow::anyhow!("missing version"))?;
1911 let version = crate::base_types::SequenceNumber::from(version);
1912
1913 let digest = self
1914 .digest_opt()
1915 .ok_or_else(|| anyhow::anyhow!("missing digest"))?;
1916 let digest = digest
1917 .parse::<crate::digests::ObjectDigest>()
1918 .with_context(|| format!("Failed to parse digest: {}", digest))?;
1919
1920 Ok((object_id, version, digest))
1921 }
1922}
1923
1924impl From<&crate::storage::ObjectKey> for ObjectReference {
1925 fn from(value: &crate::storage::ObjectKey) -> Self {
1926 Self::default()
1927 .with_object_id(value.0.to_canonical_string(true))
1928 .with_version(value.1.value())
1929 }
1930}
1931
1932impl From<crate::object::Owner> for Owner {
1937 fn from(value: crate::object::Owner) -> Self {
1938 use crate::object::Owner as O;
1939 use owner::OwnerKind;
1940
1941 let mut message = Self::default();
1942
1943 let kind = match value {
1944 O::AddressOwner(address) => {
1945 message.address = Some(address.to_string());
1946 OwnerKind::Address
1947 }
1948 O::ObjectOwner(address) => {
1949 message.address = Some(address.to_string());
1950 OwnerKind::Object
1951 }
1952 O::Shared {
1953 initial_shared_version,
1954 } => {
1955 message.version = Some(initial_shared_version.value());
1956 OwnerKind::Shared
1957 }
1958 O::Immutable => OwnerKind::Immutable,
1959 O::ConsensusAddressOwner {
1960 start_version,
1961 owner,
1962 } => {
1963 message.version = Some(start_version.value());
1964 message.address = Some(owner.to_string());
1965 OwnerKind::ConsensusAddress
1966 }
1967 };
1968
1969 message.set_kind(kind);
1970 message
1971 }
1972}
1973
1974impl From<crate::transaction::TransactionData> for Transaction {
1979 fn from(value: crate::transaction::TransactionData) -> Self {
1980 Self::merge_from(&value, &FieldMaskTree::new_wildcard())
1981 }
1982}
1983
1984impl Merge<&crate::transaction::TransactionData> for Transaction {
1985 fn merge(&mut self, source: &crate::transaction::TransactionData, mask: &FieldMaskTree) {
1986 if mask.contains(Self::BCS_FIELD.name) {
1987 let mut bcs = Bcs::serialize(&source).unwrap();
1988 bcs.name = Some("TransactionData".to_owned());
1989 self.bcs = Some(bcs);
1990 }
1991
1992 if mask.contains(Self::DIGEST_FIELD.name) {
1993 self.digest = Some(source.digest().to_string());
1994 }
1995
1996 if mask.contains(Self::VERSION_FIELD.name) {
1997 self.version = Some(1);
1998 }
1999
2000 let crate::transaction::TransactionData::V1(source) = source;
2001
2002 if mask.contains(Self::KIND_FIELD.name) {
2003 self.kind = Some(source.kind.clone().into());
2004 }
2005
2006 if mask.contains(Self::SENDER_FIELD.name) {
2007 self.sender = Some(source.sender.to_string());
2008 }
2009
2010 if mask.contains(Self::GAS_PAYMENT_FIELD.name) {
2011 self.gas_payment = Some((&source.gas_data).into());
2012 }
2013
2014 if mask.contains(Self::EXPIRATION_FIELD.name) {
2015 self.expiration = Some(source.expiration.into());
2016 }
2017 }
2018}
2019
2020impl From<&crate::transaction::GasData> for GasPayment {
2025 fn from(value: &crate::transaction::GasData) -> Self {
2026 let mut message = Self::default();
2027 message.objects = value
2028 .payment
2029 .iter()
2030 .map(|obj_ref| obj_ref.to_proto())
2031 .collect();
2032 message.owner = Some(value.owner.to_string());
2033 message.price = Some(value.price);
2034 message.budget = Some(value.budget);
2035 message
2036 }
2037}
2038
2039impl From<crate::transaction::TransactionExpiration> for TransactionExpiration {
2044 fn from(value: crate::transaction::TransactionExpiration) -> Self {
2045 use crate::transaction::TransactionExpiration as E;
2046 use transaction_expiration::TransactionExpirationKind;
2047
2048 let mut message = Self::default();
2049
2050 let kind = match value {
2051 E::None => TransactionExpirationKind::None,
2052 E::Epoch(epoch) => {
2053 message.epoch = Some(epoch);
2054 TransactionExpirationKind::Epoch
2055 }
2056 E::ValidDuring {
2057 min_epoch,
2058 max_epoch,
2059 min_timestamp,
2060 max_timestamp,
2061 chain,
2062 nonce,
2063 } => {
2064 message.epoch = max_epoch;
2065 message.min_epoch = min_epoch;
2066 message.min_timestamp = min_timestamp.map(ms_to_timestamp);
2067 message.max_timestamp = max_timestamp.map(ms_to_timestamp);
2068 message.set_chain(sui_sdk_types::Digest::new(*chain.as_bytes()));
2069 message.set_nonce(nonce);
2070
2071 TransactionExpirationKind::ValidDuring
2072 }
2073 };
2074
2075 message.set_kind(kind);
2076 message
2077 }
2078}
2079
2080impl TryFrom<&TransactionExpiration> for crate::transaction::TransactionExpiration {
2081 type Error = &'static str;
2082
2083 fn try_from(value: &TransactionExpiration) -> Result<Self, Self::Error> {
2084 use transaction_expiration::TransactionExpirationKind;
2085
2086 Ok(match value.kind() {
2087 TransactionExpirationKind::None => Self::None,
2088 TransactionExpirationKind::Epoch => Self::Epoch(value.epoch()),
2089 TransactionExpirationKind::Unknown | _ => {
2090 return Err("unknown TransactionExpirationKind");
2091 }
2092 })
2093 }
2094}
2095
2096impl From<crate::transaction::TransactionKind> for TransactionKind {
2101 fn from(value: crate::transaction::TransactionKind) -> Self {
2102 use crate::transaction::TransactionKind as K;
2103 use transaction_kind::Kind;
2104
2105 let message = Self::default();
2106
2107 match value {
2108 K::ProgrammableTransaction(ptb) => message
2109 .with_programmable_transaction(ptb)
2110 .with_kind(Kind::ProgrammableTransaction),
2111 K::ChangeEpoch(change_epoch) => message
2112 .with_change_epoch(change_epoch)
2113 .with_kind(Kind::ChangeEpoch),
2114 K::Genesis(genesis) => message.with_genesis(genesis).with_kind(Kind::Genesis),
2115 K::ConsensusCommitPrologue(prologue) => message
2116 .with_consensus_commit_prologue(prologue)
2117 .with_kind(Kind::ConsensusCommitPrologueV1),
2118 K::AuthenticatorStateUpdate(update) => message
2119 .with_authenticator_state_update(update)
2120 .with_kind(Kind::AuthenticatorStateUpdate),
2121 K::EndOfEpochTransaction(transactions) => message
2122 .with_end_of_epoch({
2123 EndOfEpochTransaction::default()
2124 .with_transactions(transactions.into_iter().map(Into::into).collect())
2125 })
2126 .with_kind(Kind::EndOfEpoch),
2127 K::RandomnessStateUpdate(update) => message
2128 .with_randomness_state_update(update)
2129 .with_kind(Kind::RandomnessStateUpdate),
2130 K::ConsensusCommitPrologueV2(prologue) => message
2131 .with_consensus_commit_prologue(prologue)
2132 .with_kind(Kind::ConsensusCommitPrologueV2),
2133 K::ConsensusCommitPrologueV3(prologue) => message
2134 .with_consensus_commit_prologue(prologue)
2135 .with_kind(Kind::ConsensusCommitPrologueV3),
2136 K::ConsensusCommitPrologueV4(prologue) => message
2137 .with_consensus_commit_prologue(prologue)
2138 .with_kind(Kind::ConsensusCommitPrologueV4),
2139 K::ProgrammableSystemTransaction(_) => message,
2140 }
2144 }
2145}
2146
2147impl From<crate::messages_consensus::ConsensusCommitPrologue> for ConsensusCommitPrologue {
2152 fn from(value: crate::messages_consensus::ConsensusCommitPrologue) -> Self {
2153 let mut message = Self::default();
2154 message.epoch = Some(value.epoch);
2155 message.round = Some(value.round);
2156 message.commit_timestamp = Some(sui_rpc::proto::timestamp_ms_to_proto(
2157 value.commit_timestamp_ms,
2158 ));
2159 message
2160 }
2161}
2162
2163impl From<crate::messages_consensus::ConsensusCommitPrologueV2> for ConsensusCommitPrologue {
2164 fn from(value: crate::messages_consensus::ConsensusCommitPrologueV2) -> Self {
2165 let mut message = Self::default();
2166 message.epoch = Some(value.epoch);
2167 message.round = Some(value.round);
2168 message.commit_timestamp = Some(sui_rpc::proto::timestamp_ms_to_proto(
2169 value.commit_timestamp_ms,
2170 ));
2171 message.consensus_commit_digest = Some(value.consensus_commit_digest.to_string());
2172 message
2173 }
2174}
2175
2176impl From<crate::messages_consensus::ConsensusCommitPrologueV3> for ConsensusCommitPrologue {
2177 fn from(value: crate::messages_consensus::ConsensusCommitPrologueV3) -> Self {
2178 let mut message = Self::default();
2179 message.epoch = Some(value.epoch);
2180 message.round = Some(value.round);
2181 message.commit_timestamp = Some(sui_rpc::proto::timestamp_ms_to_proto(
2182 value.commit_timestamp_ms,
2183 ));
2184 message.consensus_commit_digest = Some(value.consensus_commit_digest.to_string());
2185 message.sub_dag_index = value.sub_dag_index;
2186 message.consensus_determined_version_assignments =
2187 Some(value.consensus_determined_version_assignments.into());
2188 message
2189 }
2190}
2191
2192impl From<crate::messages_consensus::ConsensusCommitPrologueV4> for ConsensusCommitPrologue {
2193 fn from(
2194 crate::messages_consensus::ConsensusCommitPrologueV4 {
2195 epoch,
2196 round,
2197 sub_dag_index,
2198 commit_timestamp_ms,
2199 consensus_commit_digest,
2200 consensus_determined_version_assignments,
2201 additional_state_digest,
2202 }: crate::messages_consensus::ConsensusCommitPrologueV4,
2203 ) -> Self {
2204 let mut message = Self::default();
2205 message.epoch = Some(epoch);
2206 message.round = Some(round);
2207 message.commit_timestamp = Some(sui_rpc::proto::timestamp_ms_to_proto(commit_timestamp_ms));
2208 message.consensus_commit_digest = Some(consensus_commit_digest.to_string());
2209 message.sub_dag_index = sub_dag_index;
2210 message.consensus_determined_version_assignments =
2211 Some(consensus_determined_version_assignments.into());
2212 message.additional_state_digest = Some(additional_state_digest.to_string());
2213 message
2214 }
2215}
2216
2217impl From<crate::messages_consensus::ConsensusDeterminedVersionAssignments>
2222 for ConsensusDeterminedVersionAssignments
2223{
2224 fn from(value: crate::messages_consensus::ConsensusDeterminedVersionAssignments) -> Self {
2225 use crate::messages_consensus::ConsensusDeterminedVersionAssignments as A;
2226
2227 let mut message = Self::default();
2228
2229 let version = match value {
2230 A::CancelledTransactions(canceled_transactions) => {
2231 message.canceled_transactions = canceled_transactions
2232 .into_iter()
2233 .map(|(tx_digest, assignments)| {
2234 let mut message = CanceledTransaction::default();
2235 message.digest = Some(tx_digest.to_string());
2236 message.version_assignments = assignments
2237 .into_iter()
2238 .map(|(id, version)| {
2239 let mut message = VersionAssignment::default();
2240 message.object_id = Some(id.to_canonical_string(true));
2241 message.version = Some(version.value());
2242 message
2243 })
2244 .collect();
2245 message
2246 })
2247 .collect();
2248 1
2249 }
2250 A::CancelledTransactionsV2(canceled_transactions) => {
2251 message.canceled_transactions = canceled_transactions
2252 .into_iter()
2253 .map(|(tx_digest, assignments)| {
2254 let mut message = CanceledTransaction::default();
2255 message.digest = Some(tx_digest.to_string());
2256 message.version_assignments = assignments
2257 .into_iter()
2258 .map(|((id, start_version), version)| {
2259 let mut message = VersionAssignment::default();
2260 message.object_id = Some(id.to_canonical_string(true));
2261 message.start_version = Some(start_version.value());
2262 message.version = Some(version.value());
2263 message
2264 })
2265 .collect();
2266 message
2267 })
2268 .collect();
2269 2
2270 }
2271 };
2272
2273 message.version = Some(version);
2274 message
2275 }
2276}
2277
2278impl From<crate::transaction::GenesisTransaction> for GenesisTransaction {
2283 fn from(value: crate::transaction::GenesisTransaction) -> Self {
2284 let mut message = Self::default();
2285 message.objects = value.objects.into_iter().map(Into::into).collect();
2286 message
2287 }
2288}
2289
2290impl From<crate::transaction::RandomnessStateUpdate> for RandomnessStateUpdate {
2295 fn from(value: crate::transaction::RandomnessStateUpdate) -> Self {
2296 let mut message = Self::default();
2297 message.epoch = Some(value.epoch);
2298 message.randomness_round = Some(value.randomness_round.0);
2299 message.random_bytes = Some(value.random_bytes.into());
2300 message.randomness_object_initial_shared_version =
2301 Some(value.randomness_obj_initial_shared_version.value());
2302 message
2303 }
2304}
2305
2306impl From<crate::transaction::AuthenticatorStateUpdate> for AuthenticatorStateUpdate {
2311 fn from(value: crate::transaction::AuthenticatorStateUpdate) -> Self {
2312 let mut message = Self::default();
2313 message.epoch = Some(value.epoch);
2314 message.round = Some(value.round);
2315 message.new_active_jwks = value.new_active_jwks.into_iter().map(Into::into).collect();
2316 message.authenticator_object_initial_shared_version =
2317 Some(value.authenticator_obj_initial_shared_version.value());
2318 message
2319 }
2320}
2321
2322impl From<crate::authenticator_state::ActiveJwk> for ActiveJwk {
2327 fn from(value: crate::authenticator_state::ActiveJwk) -> Self {
2328 let mut jwk_id = JwkId::default();
2329 jwk_id.iss = Some(value.jwk_id.iss);
2330 jwk_id.kid = Some(value.jwk_id.kid);
2331
2332 let mut jwk = Jwk::default();
2333 jwk.kty = Some(value.jwk.kty);
2334 jwk.e = Some(value.jwk.e);
2335 jwk.n = Some(value.jwk.n);
2336 jwk.alg = Some(value.jwk.alg);
2337
2338 let mut message = Self::default();
2339 message.id = Some(jwk_id);
2340 message.jwk = Some(jwk);
2341 message.epoch = Some(value.epoch);
2342 message
2343 }
2344}
2345
2346impl From<crate::transaction::ChangeEpoch> for ChangeEpoch {
2351 fn from(value: crate::transaction::ChangeEpoch) -> Self {
2352 let mut message = Self::default();
2353 message.epoch = Some(value.epoch);
2354 message.protocol_version = Some(value.protocol_version.as_u64());
2355 message.storage_charge = Some(value.storage_charge);
2356 message.computation_charge = Some(value.computation_charge);
2357 message.storage_rebate = Some(value.storage_rebate);
2358 message.non_refundable_storage_fee = Some(value.non_refundable_storage_fee);
2359 message.epoch_start_timestamp = Some(sui_rpc::proto::timestamp_ms_to_proto(
2360 value.epoch_start_timestamp_ms,
2361 ));
2362 message.system_packages = value
2363 .system_packages
2364 .into_iter()
2365 .map(|(version, modules, dependencies)| {
2366 let mut message = SystemPackage::default();
2367 message.version = Some(version.value());
2368 message.modules = modules.into_iter().map(Into::into).collect();
2369 message.dependencies = dependencies
2370 .iter()
2371 .map(|d| d.to_canonical_string(true))
2372 .collect();
2373 message
2374 })
2375 .collect();
2376 message
2377 }
2378}
2379
2380impl From<crate::transaction::EndOfEpochTransactionKind> for EndOfEpochTransactionKind {
2385 fn from(value: crate::transaction::EndOfEpochTransactionKind) -> Self {
2386 use crate::transaction::EndOfEpochTransactionKind as K;
2387 use end_of_epoch_transaction_kind::Kind;
2388
2389 let message = Self::default();
2390
2391 match value {
2392 K::ChangeEpoch(change_epoch) => message
2393 .with_change_epoch(change_epoch)
2394 .with_kind(Kind::ChangeEpoch),
2395 K::AuthenticatorStateCreate => message.with_kind(Kind::AuthenticatorStateCreate),
2396 K::AuthenticatorStateExpire(expire) => message
2397 .with_authenticator_state_expire(expire)
2398 .with_kind(Kind::AuthenticatorStateExpire),
2399 K::RandomnessStateCreate => message.with_kind(Kind::RandomnessStateCreate),
2400 K::DenyListStateCreate => message.with_kind(Kind::DenyListStateCreate),
2401 K::BridgeStateCreate(chain_id) => message
2402 .with_bridge_chain_id(chain_id.to_string())
2403 .with_kind(Kind::BridgeStateCreate),
2404 K::BridgeCommitteeInit(bridge_object_version) => message
2405 .with_bridge_object_version(bridge_object_version.into())
2406 .with_kind(Kind::BridgeCommitteeInit),
2407 K::StoreExecutionTimeObservations(observations) => message
2408 .with_execution_time_observations(observations)
2409 .with_kind(Kind::StoreExecutionTimeObservations),
2410 K::AccumulatorRootCreate => message.with_kind(Kind::AccumulatorRootCreate),
2411 K::CoinRegistryCreate => message.with_kind(Kind::CoinRegistryCreate),
2412 K::DisplayRegistryCreate => message.with_kind(Kind::DisplayRegistryCreate),
2413 K::AddressAliasStateCreate => message.with_kind(Kind::AddressAliasStateCreate),
2414 K::WriteAccumulatorStorageCost(_) => {
2415 todo!("WriteAccumulatorStorageCost needs to be added to proto in sui-apis")
2416 }
2417 }
2418 }
2419}
2420
2421impl From<crate::transaction::AuthenticatorStateExpire> for AuthenticatorStateExpire {
2426 fn from(value: crate::transaction::AuthenticatorStateExpire) -> Self {
2427 let mut message = Self::default();
2428 message.min_epoch = Some(value.min_epoch);
2429 message.authenticator_object_initial_shared_version =
2430 Some(value.authenticator_obj_initial_shared_version.value());
2431 message
2432 }
2433}
2434
2435impl From<crate::transaction::StoredExecutionTimeObservations> for ExecutionTimeObservations {
2438 fn from(value: crate::transaction::StoredExecutionTimeObservations) -> Self {
2439 let mut message = Self::default();
2440 match value {
2441 crate::transaction::StoredExecutionTimeObservations::V1(vec) => {
2442 message.version = Some(1);
2443 message.observations = vec
2444 .into_iter()
2445 .map(|(key, observation)| {
2446 use crate::execution::ExecutionTimeObservationKey as K;
2447 use execution_time_observation::ExecutionTimeObservationKind;
2448
2449 let mut message = ExecutionTimeObservation::default();
2450
2451 let kind = match key {
2452 K::MoveEntryPoint {
2453 package,
2454 module,
2455 function,
2456 type_arguments,
2457 } => {
2458 message.move_entry_point = Some({
2459 let mut message = MoveCall::default();
2460 message.package = Some(package.to_canonical_string(true));
2461 message.module = Some(module);
2462 message.function = Some(function);
2463 message.type_arguments = type_arguments
2464 .into_iter()
2465 .map(|ty| ty.to_canonical_string(true))
2466 .collect();
2467 message
2468 });
2469 ExecutionTimeObservationKind::MoveEntryPoint
2470 }
2471 K::TransferObjects => ExecutionTimeObservationKind::TransferObjects,
2472 K::SplitCoins => ExecutionTimeObservationKind::SplitCoins,
2473 K::MergeCoins => ExecutionTimeObservationKind::MergeCoins,
2474 K::Publish => ExecutionTimeObservationKind::Publish,
2475 K::MakeMoveVec => ExecutionTimeObservationKind::MakeMoveVector,
2476 K::Upgrade => ExecutionTimeObservationKind::Upgrade,
2477 };
2478
2479 message.validator_observations = observation
2480 .into_iter()
2481 .map(|(name, duration)| {
2482 let mut message = ValidatorExecutionTimeObservation::default();
2483 message.validator = Some(name.0.to_vec().into());
2484 message.duration = Some(prost_types::Duration {
2485 seconds: duration.as_secs() as i64,
2486 nanos: duration.subsec_nanos() as i32,
2487 });
2488 message
2489 })
2490 .collect();
2491
2492 message.set_kind(kind);
2493 message
2494 })
2495 .collect();
2496 }
2497 }
2498
2499 message
2500 }
2501}
2502
2503impl From<crate::transaction::ProgrammableTransaction> for ProgrammableTransaction {
2508 fn from(value: crate::transaction::ProgrammableTransaction) -> Self {
2509 let mut message = Self::default();
2510 message.inputs = value.inputs.into_iter().map(Into::into).collect();
2511 message.commands = value.commands.into_iter().map(Into::into).collect();
2512 message
2513 }
2514}
2515
2516impl From<crate::transaction::CallArg> for Input {
2521 fn from(value: crate::transaction::CallArg) -> Self {
2522 use crate::transaction::CallArg as I;
2523 use crate::transaction::ObjectArg as O;
2524 use input::InputKind;
2525 use input::Mutability;
2526
2527 let mut message = Self::default();
2528
2529 let kind = match value {
2530 I::Pure(value) => {
2531 message.pure = Some(value.into());
2532 InputKind::Pure
2533 }
2534 I::Object(o) => match o {
2535 O::ImmOrOwnedObject((id, version, digest)) => {
2536 message.object_id = Some(id.to_canonical_string(true));
2537 message.version = Some(version.value());
2538 message.digest = Some(digest.to_string());
2539 InputKind::ImmutableOrOwned
2540 }
2541 O::SharedObject {
2542 id,
2543 initial_shared_version,
2544 mutability,
2545 } => {
2546 message.object_id = Some(id.to_canonical_string(true));
2547 message.version = Some(initial_shared_version.value());
2548 message.mutable = Some(mutability.is_exclusive());
2549 message.set_mutability(match mutability {
2550 crate::transaction::SharedObjectMutability::Immutable => {
2551 Mutability::Immutable
2552 }
2553 crate::transaction::SharedObjectMutability::Mutable => Mutability::Mutable,
2554 crate::transaction::SharedObjectMutability::NonExclusiveWrite => {
2555 Mutability::NonExclusiveWrite
2556 }
2557 });
2558 InputKind::Shared
2559 }
2560 O::Receiving((id, version, digest)) => {
2561 message.object_id = Some(id.to_canonical_string(true));
2562 message.version = Some(version.value());
2563 message.digest = Some(digest.to_string());
2564 InputKind::Receiving
2565 }
2566 },
2567 I::FundsWithdrawal(withdrawal) => {
2568 message.set_funds_withdrawal(withdrawal);
2569 InputKind::FundsWithdrawal
2570 }
2571 };
2572
2573 message.set_kind(kind);
2574 message
2575 }
2576}
2577
2578impl From<crate::transaction::FundsWithdrawalArg> for FundsWithdrawal {
2579 fn from(value: crate::transaction::FundsWithdrawalArg) -> Self {
2580 use funds_withdrawal::Source;
2581
2582 let mut message = Self::default();
2583
2584 message.amount = match value.reservation {
2585 crate::transaction::Reservation::EntireBalance => None,
2586 crate::transaction::Reservation::MaxAmountU64(amount) => Some(amount),
2587 };
2588 let crate::transaction::WithdrawalTypeArg::Balance(coin_type) = value.type_arg;
2589 message.coin_type = Some(coin_type.to_canonical_string(true));
2590 message.set_source(match value.withdraw_from {
2591 crate::transaction::WithdrawFrom::Sender => Source::Sender,
2592 crate::transaction::WithdrawFrom::Sponsor => Source::Sponsor,
2593 });
2594
2595 message
2596 }
2597}
2598
2599impl From<crate::transaction::Argument> for Argument {
2604 fn from(value: crate::transaction::Argument) -> Self {
2605 use crate::transaction::Argument as A;
2606 use argument::ArgumentKind;
2607
2608 let mut message = Self::default();
2609
2610 let kind = match value {
2611 A::GasCoin => ArgumentKind::Gas,
2612 A::Input(input) => {
2613 message.input = Some(input.into());
2614 ArgumentKind::Input
2615 }
2616 A::Result(result) => {
2617 message.result = Some(result.into());
2618 ArgumentKind::Result
2619 }
2620 A::NestedResult(result, subresult) => {
2621 message.result = Some(result.into());
2622 message.subresult = Some(subresult.into());
2623 ArgumentKind::Result
2624 }
2625 };
2626
2627 message.set_kind(kind);
2628 message
2629 }
2630}
2631
2632impl From<crate::transaction::Command> for Command {
2637 fn from(value: crate::transaction::Command) -> Self {
2638 use crate::transaction::Command as C;
2639 use command::Command;
2640
2641 let command = match value {
2642 C::MoveCall(move_call) => Command::MoveCall((*move_call).into()),
2643 C::TransferObjects(objects, address) => Command::TransferObjects({
2644 let mut message = TransferObjects::default();
2645 message.objects = objects.into_iter().map(Into::into).collect();
2646 message.address = Some(address.into());
2647 message
2648 }),
2649 C::SplitCoins(coin, amounts) => Command::SplitCoins({
2650 let mut message = SplitCoins::default();
2651 message.coin = Some(coin.into());
2652 message.amounts = amounts.into_iter().map(Into::into).collect();
2653 message
2654 }),
2655 C::MergeCoins(coin, coins_to_merge) => Command::MergeCoins({
2656 let mut message = MergeCoins::default();
2657 message.coin = Some(coin.into());
2658 message.coins_to_merge = coins_to_merge.into_iter().map(Into::into).collect();
2659 message
2660 }),
2661 C::Publish(modules, dependencies) => Command::Publish({
2662 let mut message = Publish::default();
2663 message.modules = modules.into_iter().map(Into::into).collect();
2664 message.dependencies = dependencies
2665 .iter()
2666 .map(|d| d.to_canonical_string(true))
2667 .collect();
2668 message
2669 }),
2670 C::MakeMoveVec(element_type, elements) => Command::MakeMoveVector({
2671 let mut message = MakeMoveVector::default();
2672 message.element_type = element_type.map(|t| t.to_canonical_string(true));
2673 message.elements = elements.into_iter().map(Into::into).collect();
2674 message
2675 }),
2676 C::Upgrade(modules, dependencies, package, ticket) => Command::Upgrade({
2677 let mut message = Upgrade::default();
2678 message.modules = modules.into_iter().map(Into::into).collect();
2679 message.dependencies = dependencies
2680 .iter()
2681 .map(|d| d.to_canonical_string(true))
2682 .collect();
2683 message.package = Some(package.to_canonical_string(true));
2684 message.ticket = Some(ticket.into());
2685 message
2686 }),
2687 };
2688
2689 let mut message = Self::default();
2690 message.command = Some(command);
2691 message
2692 }
2693}
2694
2695impl From<crate::transaction::ProgrammableMoveCall> for MoveCall {
2700 fn from(value: crate::transaction::ProgrammableMoveCall) -> Self {
2701 let mut message = Self::default();
2702 message.package = Some(value.package.to_canonical_string(true));
2703 message.module = Some(value.module.to_string());
2704 message.function = Some(value.function.to_string());
2705 message.type_arguments = value
2706 .type_arguments
2707 .iter()
2708 .map(|t| t.to_canonical_string(true))
2709 .collect();
2710 message.arguments = value.arguments.into_iter().map(Into::into).collect();
2711 message
2712 }
2713}
2714
2715impl From<crate::effects::TransactionEffects> for TransactionEffects {
2720 fn from(value: crate::effects::TransactionEffects) -> Self {
2721 Self::merge_from(&value, &FieldMaskTree::new_wildcard())
2722 }
2723}
2724
2725impl Merge<&crate::effects::TransactionEffects> for TransactionEffects {
2726 fn merge(&mut self, source: &crate::effects::TransactionEffects, mask: &FieldMaskTree) {
2727 if mask.contains(Self::BCS_FIELD.name) {
2728 let mut bcs = Bcs::serialize(&source).unwrap();
2729 bcs.name = Some("TransactionEffects".to_owned());
2730 self.bcs = Some(bcs);
2731 }
2732
2733 if mask.contains(Self::DIGEST_FIELD.name) {
2734 self.digest = Some(source.digest().to_string());
2735 }
2736
2737 match source {
2738 crate::effects::TransactionEffects::V1(v1) => self.merge(v1, mask),
2739 crate::effects::TransactionEffects::V2(v2) => self.merge(v2, mask),
2740 }
2741 }
2742}
2743
2744impl Merge<&crate::effects::TransactionEffectsV1> for TransactionEffects {
2749 fn merge(&mut self, value: &crate::effects::TransactionEffectsV1, mask: &FieldMaskTree) {
2750 use crate::effects::TransactionEffectsAPI;
2751
2752 if mask.contains(Self::VERSION_FIELD.name) {
2753 self.version = Some(1);
2754 }
2755
2756 if mask.contains(Self::STATUS_FIELD.name) {
2757 self.status = Some(value.status().clone().into());
2758 }
2759
2760 if mask.contains(Self::EPOCH_FIELD.name) {
2761 self.epoch = Some(value.executed_epoch());
2762 }
2763
2764 if mask.contains(Self::GAS_USED_FIELD.name) {
2765 self.gas_used = Some(value.gas_cost_summary().clone().into());
2766 }
2767
2768 if mask.contains(Self::TRANSACTION_DIGEST_FIELD.name) {
2769 self.transaction_digest = Some(value.transaction_digest().to_string());
2770 }
2771
2772 if mask.contains(Self::EVENTS_DIGEST_FIELD.name) {
2773 self.events_digest = value.events_digest().map(|d| d.to_string());
2774 }
2775
2776 if mask.contains(Self::DEPENDENCIES_FIELD.name) {
2777 self.dependencies = value
2778 .dependencies()
2779 .iter()
2780 .map(ToString::to_string)
2781 .collect();
2782 }
2783
2784 if mask.contains(Self::CHANGED_OBJECTS_FIELD.name)
2785 || mask.contains(Self::UNCHANGED_CONSENSUS_OBJECTS_FIELD.name)
2786 || mask.contains(Self::GAS_OBJECT_FIELD.name)
2787 {
2788 let mut changed_objects = Vec::new();
2789 let mut unchanged_consensus_objects = Vec::new();
2790
2791 for ((id, version, digest), owner) in value.created() {
2792 let mut change = ChangedObject::default();
2793 change.object_id = Some(id.to_canonical_string(true));
2794 change.input_state = Some(changed_object::InputObjectState::DoesNotExist.into());
2795 change.output_state = Some(changed_object::OutputObjectState::ObjectWrite.into());
2796 change.output_version = Some(version.value());
2797 change.output_digest = Some(digest.to_string());
2798 change.output_owner = Some(owner.clone().into());
2799 change.id_operation = Some(changed_object::IdOperation::Created.into());
2800
2801 changed_objects.push(change);
2802 }
2803
2804 for ((id, version, digest), owner) in value.mutated() {
2805 let mut change = ChangedObject::default();
2806 change.object_id = Some(id.to_canonical_string(true));
2807 change.input_state = Some(changed_object::InputObjectState::Exists.into());
2808 change.output_state = Some(changed_object::OutputObjectState::ObjectWrite.into());
2809 change.output_version = Some(version.value());
2810 change.output_digest = Some(digest.to_string());
2811 change.output_owner = Some(owner.clone().into());
2812 change.id_operation = Some(changed_object::IdOperation::None.into());
2813
2814 changed_objects.push(change);
2815 }
2816
2817 for ((id, version, digest), owner) in value.unwrapped() {
2818 let mut change = ChangedObject::default();
2819 change.object_id = Some(id.to_canonical_string(true));
2820 change.input_state = Some(changed_object::InputObjectState::DoesNotExist.into());
2821 change.output_state = Some(changed_object::OutputObjectState::ObjectWrite.into());
2822 change.output_version = Some(version.value());
2823 change.output_digest = Some(digest.to_string());
2824 change.output_owner = Some(owner.clone().into());
2825 change.id_operation = Some(changed_object::IdOperation::None.into());
2826
2827 changed_objects.push(change);
2828 }
2829
2830 for (id, version, digest) in value.deleted() {
2831 let mut change = ChangedObject::default();
2832 change.object_id = Some(id.to_canonical_string(true));
2833 change.input_state = Some(changed_object::InputObjectState::Exists.into());
2834 change.output_state = Some(changed_object::OutputObjectState::DoesNotExist.into());
2835 change.output_version = Some(version.value());
2836 change.output_digest = Some(digest.to_string());
2837 change.id_operation = Some(changed_object::IdOperation::Deleted.into());
2838
2839 changed_objects.push(change);
2840 }
2841
2842 for (id, version, digest) in value.unwrapped_then_deleted() {
2843 let mut change = ChangedObject::default();
2844 change.object_id = Some(id.to_canonical_string(true));
2845 change.input_state = Some(changed_object::InputObjectState::DoesNotExist.into());
2846 change.output_state = Some(changed_object::OutputObjectState::DoesNotExist.into());
2847 change.output_version = Some(version.value());
2848 change.output_digest = Some(digest.to_string());
2849 change.id_operation = Some(changed_object::IdOperation::Deleted.into());
2850
2851 changed_objects.push(change);
2852 }
2853
2854 for (id, version, digest) in value.wrapped() {
2855 let mut change = ChangedObject::default();
2856 change.object_id = Some(id.to_canonical_string(true));
2857 change.input_state = Some(changed_object::InputObjectState::Exists.into());
2858 change.output_state = Some(changed_object::OutputObjectState::DoesNotExist.into());
2859 change.output_version = Some(version.value());
2860 change.output_digest = Some(digest.to_string());
2861 change.id_operation = Some(changed_object::IdOperation::Deleted.into());
2862
2863 changed_objects.push(change);
2864 }
2865
2866 for (object_id, version) in value.modified_at_versions() {
2867 let object_id = object_id.to_canonical_string(true);
2868 let version = version.value();
2869 if let Some(changed_object) = changed_objects
2870 .iter_mut()
2871 .find(|object| object.object_id() == object_id)
2872 {
2873 changed_object.input_version = Some(version);
2874 }
2875 }
2876
2877 for (id, version, digest) in value.shared_objects() {
2878 let object_id = id.to_canonical_string(true);
2879 let version = version.value();
2880 let digest = digest.to_string();
2881
2882 if let Some(changed_object) = changed_objects
2883 .iter_mut()
2884 .find(|object| object.object_id() == object_id)
2885 {
2886 changed_object.input_version = Some(version);
2887 changed_object.input_digest = Some(digest);
2888 } else {
2889 let mut unchanged_consensus_object = UnchangedConsensusObject::default();
2890 unchanged_consensus_object.kind = Some(
2891 unchanged_consensus_object::UnchangedConsensusObjectKind::ReadOnlyRoot
2892 .into(),
2893 );
2894 unchanged_consensus_object.object_id = Some(object_id);
2895 unchanged_consensus_object.version = Some(version);
2896 unchanged_consensus_object.digest = Some(digest);
2897
2898 unchanged_consensus_objects.push(unchanged_consensus_object);
2899 }
2900 }
2901
2902 if mask.contains(Self::GAS_OBJECT_FIELD.name) {
2903 let gas_object_id = value.gas_object().0.0.to_canonical_string(true);
2904 self.gas_object = changed_objects
2905 .iter()
2906 .find(|object| object.object_id() == gas_object_id)
2907 .cloned();
2908 }
2909
2910 if mask.contains(Self::CHANGED_OBJECTS_FIELD.name) {
2911 self.changed_objects = changed_objects;
2912 }
2913
2914 if mask.contains(Self::UNCHANGED_CONSENSUS_OBJECTS_FIELD.name) {
2915 self.unchanged_consensus_objects = unchanged_consensus_objects;
2916 }
2917 }
2918 }
2919}
2920
2921impl Merge<&crate::effects::TransactionEffectsV2> for TransactionEffects {
2926 fn merge(
2927 &mut self,
2928 crate::effects::TransactionEffectsV2 {
2929 status,
2930 executed_epoch,
2931 gas_used,
2932 transaction_digest,
2933 gas_object_index,
2934 events_digest,
2935 dependencies,
2936 lamport_version,
2937 changed_objects,
2938 unchanged_consensus_objects,
2939 aux_data_digest,
2940 }: &crate::effects::TransactionEffectsV2,
2941 mask: &FieldMaskTree,
2942 ) {
2943 if mask.contains(Self::VERSION_FIELD.name) {
2944 self.version = Some(2);
2945 }
2946
2947 if mask.contains(Self::STATUS_FIELD.name) {
2948 self.status = Some(status.clone().into());
2949 }
2950
2951 if mask.contains(Self::EPOCH_FIELD.name) {
2952 self.epoch = Some(*executed_epoch);
2953 }
2954
2955 if mask.contains(Self::GAS_USED_FIELD.name) {
2956 self.gas_used = Some(gas_used.clone().into());
2957 }
2958
2959 if mask.contains(Self::TRANSACTION_DIGEST_FIELD.name) {
2960 self.transaction_digest = Some(transaction_digest.to_string());
2961 }
2962
2963 if mask.contains(Self::GAS_OBJECT_FIELD.name) {
2964 self.gas_object = gas_object_index
2965 .map(|index| {
2966 changed_objects
2967 .get(index as usize)
2968 .cloned()
2969 .map(|(id, change)| {
2970 let mut message = ChangedObject::from(change);
2971 message.object_id = Some(id.to_canonical_string(true));
2972 message
2973 })
2974 })
2975 .flatten();
2976 }
2977
2978 if mask.contains(Self::EVENTS_DIGEST_FIELD.name) {
2979 self.events_digest = events_digest.map(|d| d.to_string());
2980 }
2981
2982 if mask.contains(Self::DEPENDENCIES_FIELD.name) {
2983 self.dependencies = dependencies.iter().map(ToString::to_string).collect();
2984 }
2985
2986 if mask.contains(Self::LAMPORT_VERSION_FIELD.name) {
2987 self.lamport_version = Some(lamport_version.value());
2988 }
2989
2990 if mask.contains(Self::CHANGED_OBJECTS_FIELD.name) {
2991 self.changed_objects = changed_objects
2992 .clone()
2993 .into_iter()
2994 .map(|(id, change)| {
2995 let mut message = ChangedObject::from(change);
2996 message.object_id = Some(id.to_canonical_string(true));
2997 message
2998 })
2999 .collect();
3000 }
3001
3002 for object in self.changed_objects.iter_mut().chain(&mut self.gas_object) {
3003 if object.output_digest.is_some() && object.output_version.is_none() {
3004 object.output_version = Some(lamport_version.value());
3005 }
3006 }
3007
3008 if mask.contains(Self::UNCHANGED_CONSENSUS_OBJECTS_FIELD.name) {
3009 self.unchanged_consensus_objects = unchanged_consensus_objects
3010 .clone()
3011 .into_iter()
3012 .map(|(id, unchanged)| {
3013 let mut message = UnchangedConsensusObject::from(unchanged);
3014 message.object_id = Some(id.to_canonical_string(true));
3015 message
3016 })
3017 .collect();
3018 }
3019
3020 if mask.contains(Self::AUXILIARY_DATA_DIGEST_FIELD.name) {
3021 self.auxiliary_data_digest = aux_data_digest.map(|d| d.to_string());
3022 }
3023 }
3024}
3025
3026impl From<crate::effects::EffectsObjectChange> for ChangedObject {
3031 fn from(value: crate::effects::EffectsObjectChange) -> Self {
3032 use crate::effects::ObjectIn;
3033 use crate::effects::ObjectOut;
3034 use changed_object::InputObjectState;
3035 use changed_object::OutputObjectState;
3036
3037 let mut message = Self::default();
3038
3039 let input_state = match value.input_state {
3041 ObjectIn::NotExist => InputObjectState::DoesNotExist,
3042 ObjectIn::Exist(((version, digest), owner)) => {
3043 message.input_version = Some(version.value());
3044 message.input_digest = Some(digest.to_string());
3045 message.input_owner = Some(owner.into());
3046 InputObjectState::Exists
3047 }
3048 };
3049 message.set_input_state(input_state);
3050
3051 let output_state = match value.output_state {
3053 ObjectOut::NotExist => OutputObjectState::DoesNotExist,
3054 ObjectOut::ObjectWrite((digest, owner)) => {
3055 message.output_digest = Some(digest.to_string());
3056 message.output_owner = Some(owner.into());
3057 OutputObjectState::ObjectWrite
3058 }
3059 ObjectOut::PackageWrite((version, digest)) => {
3060 message.output_version = Some(version.value());
3061 message.output_digest = Some(digest.to_string());
3062 OutputObjectState::PackageWrite
3063 }
3064 ObjectOut::AccumulatorWriteV1(accumulator_write) => {
3065 message.set_accumulator_write(accumulator_write);
3066 OutputObjectState::AccumulatorWrite
3067 }
3068 };
3069 message.set_output_state(output_state);
3070
3071 message.set_id_operation(value.id_operation.into());
3072 message
3073 }
3074}
3075
3076impl From<crate::effects::AccumulatorWriteV1> for AccumulatorWrite {
3077 fn from(value: crate::effects::AccumulatorWriteV1) -> Self {
3078 use accumulator_write::AccumulatorOperation;
3079
3080 let mut message = Self::default();
3081
3082 message.set_address(value.address.address.to_string());
3083 message.set_accumulator_type(value.address.ty.to_canonical_string(true));
3084 message.set_operation(match value.operation {
3085 crate::effects::AccumulatorOperation::Merge => AccumulatorOperation::Merge,
3086 crate::effects::AccumulatorOperation::Split => AccumulatorOperation::Split,
3087 });
3088 match value.value {
3089 crate::effects::AccumulatorValue::Integer(value) => message.set_value(value),
3090 crate::effects::AccumulatorValue::IntegerTuple(_, _)
3092 | crate::effects::AccumulatorValue::EventDigest(_) => {}
3093 }
3094
3095 message
3096 }
3097}
3098
3099impl From<crate::effects::IDOperation> for changed_object::IdOperation {
3104 fn from(value: crate::effects::IDOperation) -> Self {
3105 use crate::effects::IDOperation as I;
3106
3107 match value {
3108 I::None => Self::None,
3109 I::Created => Self::Created,
3110 I::Deleted => Self::Deleted,
3111 }
3112 }
3113}
3114
3115impl From<crate::effects::UnchangedConsensusKind> for UnchangedConsensusObject {
3120 fn from(value: crate::effects::UnchangedConsensusKind) -> Self {
3121 use crate::effects::UnchangedConsensusKind as K;
3122 use unchanged_consensus_object::UnchangedConsensusObjectKind;
3123
3124 let mut message = Self::default();
3125
3126 let kind = match value {
3127 K::ReadOnlyRoot((version, digest)) => {
3128 message.version = Some(version.value());
3129 message.digest = Some(digest.to_string());
3130 UnchangedConsensusObjectKind::ReadOnlyRoot
3131 }
3132 K::MutateConsensusStreamEnded(version) => {
3133 message.version = Some(version.value());
3134 UnchangedConsensusObjectKind::MutateConsensusStreamEnded
3135 }
3136 K::ReadConsensusStreamEnded(version) => {
3137 message.version = Some(version.value());
3138 UnchangedConsensusObjectKind::ReadConsensusStreamEnded
3139 }
3140 K::Cancelled(version) => {
3141 message.version = Some(version.value());
3142 UnchangedConsensusObjectKind::Canceled
3143 }
3144 K::PerEpochConfig => UnchangedConsensusObjectKind::PerEpochConfig,
3145 };
3150
3151 message.set_kind(kind);
3152 message
3153 }
3154}
3155
3156impl From<simulate_transaction_request::TransactionChecks>
3161 for crate::transaction_executor::TransactionChecks
3162{
3163 fn from(value: simulate_transaction_request::TransactionChecks) -> Self {
3164 match value {
3165 simulate_transaction_request::TransactionChecks::Enabled => Self::Enabled,
3166 simulate_transaction_request::TransactionChecks::Disabled => Self::Disabled,
3167 _ => Self::Enabled,
3169 }
3170 }
3171}
3172
3173impl From<crate::coin_registry::MetadataCapState> for coin_metadata::MetadataCapState {
3178 fn from(value: crate::coin_registry::MetadataCapState) -> Self {
3179 match value {
3180 crate::coin_registry::MetadataCapState::Claimed(_) => {
3181 coin_metadata::MetadataCapState::Claimed
3182 }
3183 crate::coin_registry::MetadataCapState::Unclaimed => {
3184 coin_metadata::MetadataCapState::Unclaimed
3185 }
3186 crate::coin_registry::MetadataCapState::Deleted => {
3187 coin_metadata::MetadataCapState::Deleted
3188 }
3189 }
3190 }
3191}
3192
3193impl From<&crate::coin_registry::Currency> for CoinMetadata {
3194 fn from(value: &crate::coin_registry::Currency) -> Self {
3195 let mut metadata = CoinMetadata::default();
3196 metadata.id = Some(sui_sdk_types::Address::from(value.id.into_bytes()).to_string());
3197 metadata.decimals = Some(value.decimals.into());
3198 metadata.name = Some(value.name.clone());
3199 metadata.symbol = Some(value.symbol.clone());
3200 metadata.description = Some(value.description.clone());
3201 metadata.icon_url = Some(value.icon_url.clone());
3202
3203 match &value.metadata_cap_id {
3204 crate::coin_registry::MetadataCapState::Claimed(id) => {
3205 metadata.metadata_cap_state = Some(coin_metadata::MetadataCapState::Claimed as i32);
3206 metadata.metadata_cap_id = Some(sui_sdk_types::Address::from(*id).to_string());
3207 }
3208 crate::coin_registry::MetadataCapState::Unclaimed => {
3209 metadata.metadata_cap_state =
3210 Some(coin_metadata::MetadataCapState::Unclaimed as i32);
3211 }
3212 crate::coin_registry::MetadataCapState::Deleted => {
3213 metadata.metadata_cap_state = Some(coin_metadata::MetadataCapState::Deleted as i32);
3214 }
3215 }
3216
3217 metadata
3218 }
3219}
3220
3221impl From<crate::coin::CoinMetadata> for CoinMetadata {
3222 fn from(value: crate::coin::CoinMetadata) -> Self {
3223 let mut metadata = CoinMetadata::default();
3224 metadata.id = Some(sui_sdk_types::Address::from(value.id.id.bytes).to_string());
3225 metadata.decimals = Some(value.decimals.into());
3226 metadata.name = Some(value.name);
3227 metadata.symbol = Some(value.symbol);
3228 metadata.description = Some(value.description);
3229 metadata.icon_url = value.icon_url;
3230 metadata
3231 }
3232}
3233
3234impl From<crate::coin_registry::SupplyState> for coin_treasury::SupplyState {
3235 fn from(value: crate::coin_registry::SupplyState) -> Self {
3236 match value {
3237 crate::coin_registry::SupplyState::Fixed(_) => coin_treasury::SupplyState::Fixed,
3238 crate::coin_registry::SupplyState::BurnOnly(_) => coin_treasury::SupplyState::BurnOnly,
3239 crate::coin_registry::SupplyState::Unknown => coin_treasury::SupplyState::Unknown,
3240 }
3241 }
3242}
3243
3244impl From<crate::coin::TreasuryCap> for CoinTreasury {
3245 fn from(value: crate::coin::TreasuryCap) -> Self {
3246 let mut treasury = CoinTreasury::default();
3247 treasury.id = Some(sui_sdk_types::Address::from(value.id.id.bytes).to_string());
3248 treasury.total_supply = Some(value.total_supply.value);
3249 treasury
3250 }
3251}
3252
3253impl From<&crate::coin_registry::RegulatedState> for RegulatedCoinMetadata {
3254 fn from(value: &crate::coin_registry::RegulatedState) -> Self {
3255 let mut regulated = RegulatedCoinMetadata::default();
3256
3257 match value {
3258 crate::coin_registry::RegulatedState::Regulated {
3259 cap,
3260 allow_global_pause,
3261 variant,
3262 } => {
3263 regulated.deny_cap_object = Some(sui_sdk_types::Address::from(*cap).to_string());
3264 regulated.allow_global_pause = *allow_global_pause;
3265 regulated.variant = Some(*variant as u32);
3266 regulated.coin_regulated_state =
3267 Some(regulated_coin_metadata::CoinRegulatedState::Regulated as i32);
3268 }
3269 crate::coin_registry::RegulatedState::Unregulated => {
3270 regulated.coin_regulated_state =
3271 Some(regulated_coin_metadata::CoinRegulatedState::Unregulated as i32);
3272 }
3273 crate::coin_registry::RegulatedState::Unknown => {
3274 regulated.coin_regulated_state =
3275 Some(regulated_coin_metadata::CoinRegulatedState::Unknown as i32);
3276 }
3277 }
3278
3279 regulated
3280 }
3281}
3282
3283impl From<crate::coin_registry::RegulatedState> for RegulatedCoinMetadata {
3284 fn from(value: crate::coin_registry::RegulatedState) -> Self {
3285 (&value).into()
3286 }
3287}
3288
3289impl From<crate::coin::RegulatedCoinMetadata> for RegulatedCoinMetadata {
3290 fn from(value: crate::coin::RegulatedCoinMetadata) -> Self {
3291 let mut message = RegulatedCoinMetadata::default();
3292 message.id = Some(sui_sdk_types::Address::from(value.id.id.bytes).to_string());
3293 message.coin_metadata_object =
3294 Some(sui_sdk_types::Address::from(value.coin_metadata_object.bytes).to_string());
3295 message.deny_cap_object =
3296 Some(sui_sdk_types::Address::from(value.deny_cap_object.bytes).to_string());
3297 message.coin_regulated_state =
3298 Some(regulated_coin_metadata::CoinRegulatedState::Regulated as i32);
3299 message
3300 }
3301}
3302
3303impl TryFrom<&ObjectSet> for crate::full_checkpoint_content::ObjectSet {
3304 type Error = TryFromProtoError;
3305
3306 fn try_from(value: &ObjectSet) -> Result<Self, Self::Error> {
3307 let mut objects = Self::default();
3308
3309 for o in value.objects() {
3310 objects.insert(
3311 o.bcs()
3312 .deserialize()
3313 .map_err(|e| TryFromProtoError::invalid("object.bcs", e))?,
3314 );
3315 }
3316
3317 Ok(objects)
3318 }
3319}