sui_rpc/proto/sui/rpc/v2beta2/
balance_change.rs1use super::*;
2use crate::merge::Merge;
3use crate::proto::TryFromProtoError;
4
5impl From<sui_sdk_types::BalanceChange> for BalanceChange {
6 fn from(value: sui_sdk_types::BalanceChange) -> Self {
7 Self {
8 address: Some(value.address.to_string()),
9 coin_type: Some(value.coin_type.to_string()),
10 amount: Some(value.amount.to_string()),
11 }
12 }
13}
14
15impl Merge<&sui_sdk_types::BalanceChange> for BalanceChange {
16 fn merge(&mut self, source: &sui_sdk_types::BalanceChange, mask: &crate::field::FieldMaskTree) {
17 if mask.contains(Self::ADDRESS_FIELD) {
18 self.address = Some(source.address.to_string());
19 }
20 if mask.contains(Self::COIN_TYPE_FIELD) {
21 self.coin_type = Some(source.coin_type.to_string());
22 }
23 if mask.contains(Self::AMOUNT_FIELD) {
24 self.amount = Some(source.amount.to_string());
25 }
26 }
27}
28
29impl TryFrom<&BalanceChange> for sui_sdk_types::BalanceChange {
30 type Error = TryFromProtoError;
31
32 fn try_from(value: &BalanceChange) -> Result<Self, Self::Error> {
33 Ok(Self {
34 address: value
35 .address()
36 .parse()
37 .map_err(|e| TryFromProtoError::invalid(BalanceChange::ADDRESS_FIELD, e))?,
38 coin_type: value
39 .coin_type()
40 .parse()
41 .map_err(|e| TryFromProtoError::invalid(BalanceChange::COIN_TYPE_FIELD, e))?,
42 amount: value
43 .amount()
44 .parse()
45 .map_err(|e| TryFromProtoError::invalid(BalanceChange::AMOUNT_FIELD, e))?,
46 })
47 }
48}