Skip to content

Commit

Permalink
fix: use u128 for balance and message values
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Jan 27, 2025
1 parent 4f6cb16 commit 03cd7d7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/core/contract_subscription/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -737,7 +737,7 @@ pub struct Message {
pub dst: Option<MsgAddressInt>,

/// Message value in nano TON
pub value: u64,
pub value: u128,

/// Whether this message will be bounced on unsuccessful execution.
pub bounce: bool,
Expand Down Expand Up @@ -771,7 +771,7 @@ impl<'de> Deserialize<'de> for Message {
#[serde(default, with = "serde_optional_address")]
dst: Option<MsgAddressInt>,
#[serde(with = "serde_string")]
value: u64,
value: u128,
bounce: bool,
bounced: bool,
body: Option<String>,
Expand Down Expand Up @@ -892,7 +892,7 @@ impl TryFrom<ton_types::Cell> 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,
Expand Down
2 changes: 1 addition & 1 deletion src/transport/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 03cd7d7

Please sign in to comment.