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 f3c22a3 commit e4303b4
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 29 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::external::GqlConnection;
Expand Down Expand Up @@ -255,13 +255,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/jetton_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl JettonWallet {
custom_payload: Option<ton_types::Cell>,
callback_value: BigUint,
callback_payload: Option<ton_types::Cell>,
attached_amount: u64,
attached_amount: u128,
) -> Result<InternalMessage> {
let mut builder = BuilderData::new();

Expand Down
2 changes: 1 addition & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct InternalMessage {
#[serde(with = "serde_address")]
pub destination: ton_block::MsgAddressInt,
#[serde(with = "serde_string")]
pub amount: u64,
pub amount: u128,
pub bounce: bool,
#[serde(with = "serde_boc")]
pub body: ton_types::SliceData,
Expand Down
6 changes: 3 additions & 3 deletions src/core/nft_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Nft {
send_gas_to: MsgAddressInt,
callbacks: BTreeMap<MsgAddressInt, NftCallbackPayload>,
) -> Result<InternalMessage> {
const ATTACHED_AMOUNT: u64 = 1_000_000_000; // 1 TON
const ATTACHED_AMOUNT: u128 = 1_000_000_000; // 1 TON
let (function, input) = MessageBuilder::new(nft_contract::transfer())
.arg(to)
.arg(send_gas_to)
Expand All @@ -246,7 +246,7 @@ impl Nft {
send_gas_to: MsgAddressInt,
callbacks: BTreeMap<MsgAddressInt, NftCallbackPayload>,
) -> Result<InternalMessage> {
const ATTACHED_AMOUNT: u64 = 1_000_000_000; // 1 TON
const ATTACHED_AMOUNT: u128 = 1_000_000_000; // 1 TON
let (function, input) = MessageBuilder::new(nft_contract::change_manager())
.arg(new_manager)
.arg(send_gas_to)
Expand All @@ -272,7 +272,7 @@ impl Nft {
send_gas_to: MsgAddressInt,
callbacks: BTreeMap<MsgAddressInt, NftCallbackPayload>,
) -> Result<InternalMessage> {
const ATTACHED_AMOUNT: u64 = 1_000_000_000; // 1 TON
const ATTACHED_AMOUNT: u128 = 1_000_000_000; // 1 TON
let (function, input) = MessageBuilder::new(nft_contract::change_owner())
.arg(new_owner)
.arg(send_gas_to)
Expand Down
8 changes: 4 additions & 4 deletions src/core/token_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl TokenWallet {
&self,
config: &BlockchainConfig,
address: &MsgAddressInt,
) -> Result<u64> {
) -> Result<u128> {
let gas_config = config.get_gas_config(address.is_masterchain());

let prices = config.raw_config().storage_prices()?;
Expand Down Expand Up @@ -256,7 +256,7 @@ impl TokenWallet {

let fees = 30000u64.saturating_mul(gas_config.gas_price.shr(16)) + fee_base;

Ok(fees)
Ok(fees as u128)
}

pub async fn prepare_transfer(
Expand All @@ -265,9 +265,9 @@ impl TokenWallet {
tokens: BigUint,
notify_receiver: bool,
payload: ton_types::Cell,
mut attached_amount: u64,
mut attached_amount: u128,
) -> Result<InternalMessage> {
fn stub_balance(address: &MsgAddressInt) -> u64 {
fn stub_balance(address: &MsgAddressInt) -> u128 {
if address.is_masterchain() {
1000
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/core/ton_wallet/ever_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ pub fn prepare_transfer(
ihr_disabled: true,
bounce: gift.bounce,
dst: gift.destination,
value: gift.amount.into(),
value: ton_block::CurrencyCollection::from_grams(ton_block::Grams::new(
gift.amount,
)?),
..Default::default()
});

Expand Down
4 changes: 3 additions & 1 deletion src/core/ton_wallet/highload_wallet_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ impl InitData {
ihr_disabled: true,
bounce: gift.bounce,
dst: gift.destination,
value: gift.amount.into(),
value: ton_block::CurrencyCollection::from_grams(ton_block::Grams::new(
gift.amount,
)?),
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/ton_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ pub struct Gift {
pub flags: u8,
pub bounce: bool,
pub destination: MsgAddressInt,
pub amount: u64,
pub amount: u128,
pub body: Option<SliceData>,
pub state_init: Option<ton_block::StateInit>,
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/ton_wallet/wallet_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ impl InitData {
ihr_disabled: true,
bounce: gift.bounce,
dst: gift.destination,
value: gift.amount.into(),
value: ton_block::CurrencyCollection::from_grams(ton_block::Grams::new(
gift.amount,
)?),
..Default::default()
});

Expand Down
4 changes: 3 additions & 1 deletion src/core/ton_wallet/wallet_v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ impl InitData {
ihr_disabled: true,
bounce: gift.bounce,
dst: gift.destination,
value: gift.amount.into(),
value: ton_block::CurrencyCollection::from_grams(ton_block::Grams::new(
gift.amount,
)?),
..Default::default()
});

Expand Down
4 changes: 3 additions & 1 deletion src/core/ton_wallet/wallet_v5r1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ impl InitData {
ihr_disabled: true,
bounce: gift.bounce,
dst: gift.destination,
value: gift.amount.into(),
value: ton_block::CurrencyCollection::from_grams(ton_block::Grams::new(
gift.amount,
)?),
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,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 e4303b4

Please sign in to comment.