sui_jsonrpc/msgs/
balance_changes.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::fmt::Display;
5
6use serde::{Deserialize, Serialize};
7use serde_with::{DisplayFromStr, serde_as};
8use sui_sdk_types::TypeTag;
9
10use crate::msgs::Owner;
11
12#[serde_as]
13#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
14#[serde(rename_all = "camelCase")]
15pub struct BalanceChange {
16    /// Owner of the balance change
17    pub owner: Owner,
18    // #[serde_as(as = "SuiTypeTag")]
19    #[serde_as(as = "DisplayFromStr")]
20    pub coin_type: TypeTag,
21    /// The amount indicate the balance value changes,
22    /// negative amount means spending coin value and positive means receiving coin value.
23    #[serde_as(as = "DisplayFromStr")]
24    pub amount: i128,
25}
26
27impl Display for BalanceChange {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        write!(
30            f,
31            " ┌──\n │ Owner: {:?} \n │ CoinType: {} \n │ Amount: {}\n └──",
32            self.owner, self.coin_type, self.amount
33        )
34    }
35}