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::{base_types::TypeTag, object::Owner};
8use schemars::JsonSchema;
9use serde::{Deserialize, Serialize};
10use serde_with::{DisplayFromStr, serde_as};
11
12use crate::{iota_owner::OwnerSchema, iota_primitives::TypeTag as TypeTagSchema};
13
14#[serde_as]
15#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
16#[serde(rename_all = "camelCase")]
17pub struct BalanceChange {
18    /// Owner of the balance change
19    #[schemars(with = "OwnerSchema")]
20    #[serde_as(as = "OwnerSchema")]
21    pub owner: Owner,
22    #[schemars(with = "TypeTagSchema")]
23    #[serde_as(as = "TypeTagSchema")]
24    pub coin_type: TypeTag,
25    /// The amount indicate the balance value changes,
26    /// negative amount means spending coin value and positive means receiving
27    /// coin value.
28    #[schemars(with = "String")]
29    #[serde_as(as = "DisplayFromStr")]
30    pub amount: i128,
31}
32
33impl Display for BalanceChange {
34    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
35        write!(
36            f,
37            " ┌──\n │ Owner: {} \n │ CoinType: {} \n │ Amount: {}\n └──",
38            self.owner, self.coin_type, self.amount
39        )
40    }
41}