iota_json_rpc_types/
balance_changes.rs

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