From 03cd7d75257e21657fe76f9e598314afd0a21c1b Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Tue, 28 Jan 2025 00:09:51 +0100 Subject: [PATCH] fix: use u128 for balance and message values --- src/core/contract_subscription/mod.rs | 18 ++++++++++-------- src/core/utils.rs | 2 +- src/models.rs | 8 ++++---- src/transport/models.rs | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/core/contract_subscription/mod.rs b/src/core/contract_subscription/mod.rs index 59bf0c638..6a9aa14f2 100644 --- a/src/core/contract_subscription/mod.rs +++ b/src/core/contract_subscription/mod.rs @@ -1,16 +1,16 @@ use std::sync::Arc; +use super::models::{ + ContractState, PendingTransaction, ReliableBehavior, TransactionsBatchInfo, + TransactionsBatchType, +}; +use super::{utils, PollingMethod}; use anyhow::Result; use futures_util::StreamExt; use nekoton_abi::{Executor, LastTransactionId}; use nekoton_utils::*; use serde::{Deserialize, Serialize}; use ton_block::{AccountStuff, MsgAddressInt}; -use super::models::{ - ContractState, PendingTransaction, ReliableBehavior, TransactionsBatchInfo, - TransactionsBatchType, -}; -use super::{utils, PollingMethod}; use crate::core::utils::{MessageContext, PendingTransactionsExt}; use crate::transport::models::{RawContractState, RawTransaction}; @@ -251,13 +251,15 @@ impl ContractSubscription { let mut account = match self.transport.get_contract_state(&self.address).await? { RawContractState::Exists(state) => ton_block::Account::Account(state.account), RawContractState::NotExists { .. } if options.override_balance.is_some() => { - let stuff = AccountStuff { addr: self.address.clone(), ..Default::default() }; + let stuff = AccountStuff { + addr: self.address.clone(), + ..Default::default() + }; ton_block::Account::Account(stuff) } - RawContractState::NotExists { .. } => ton_block::Account::AccountNone + RawContractState::NotExists { .. } => ton_block::Account::AccountNone, }; - if let Some(balance) = options.override_balance { account.set_balance(balance.into()); } diff --git a/src/core/utils.rs b/src/core/utils.rs index c9b4bc9b6..3e3408884 100644 --- a/src/core/utils.rs +++ b/src/core/utils.rs @@ -140,7 +140,7 @@ pub fn parse_block( let new_contract_state = ContractState { last_lt, - balance: balance as u64, + balance: balance.try_into().unwrap_or_default(), gen_timings: GenTimings::Known { gen_lt: info.end_lt(), gen_utime: info.gen_utime().as_u32(), diff --git a/src/models.rs b/src/models.rs index 5de00239d..95a8fb07a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -509,7 +509,7 @@ pub struct ContractState { /// Full account balance in nano TON #[serde(with = "serde_string")] - pub balance: u64, + pub balance: u128, /// At what point was this state obtained pub gen_timings: GenTimings, /// Last transaction id @@ -737,7 +737,7 @@ pub struct Message { pub dst: Option, /// Message value in nano TON - pub value: u64, + pub value: u128, /// Whether this message will be bounced on unsuccessful execution. pub bounce: bool, @@ -771,7 +771,7 @@ impl<'de> Deserialize<'de> for Message { #[serde(default, with = "serde_optional_address")] dst: Option, #[serde(with = "serde_string")] - value: u64, + value: u128, bounce: bool, bounced: bool, body: Option, @@ -892,7 +892,7 @@ impl TryFrom for Message { ton_block::MsgAddressIntOrNone::None => None, }, dst: Some(header.dst.clone()), - value: header.value.grams.as_u128() as u64, + value: header.value.grams.as_u128(), body, bounce: header.bounce, bounced: header.bounced, diff --git a/src/transport/models.rs b/src/transport/models.rs index 0a0036d3b..1535c33e9 100644 --- a/src/transport/models.rs +++ b/src/transport/models.rs @@ -104,7 +104,7 @@ impl ExistingContract { pub fn brief(&self) -> ContractState { ContractState { last_lt: self.account.storage.last_trans_lt, - balance: self.account.storage.balance.grams.as_u128() as u64, + balance: self.account.storage.balance.grams.as_u128(), gen_timings: self.timings, last_transaction_id: Some(self.last_transaction_id), is_deployed: matches!(