Skip to content

Commit

Permalink
fix with available_credit
Browse files Browse the repository at this point in the history
  • Loading branch information
SeHor05 committed Jan 27, 2025
1 parent 41f1c4a commit d625d70
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
27 changes: 13 additions & 14 deletions tvm_debugger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use std::path::PathBuf;

use clap::ArgAction;
use clap::Parser;
use tvm_block::StateInit;
use tvm_types::{base64_decode, read_single_root_boc};
use tvm_block::Deserializable;
use tvm_block::Serializable;
use tvm_block::StateInit;
use tvm_types::base64_decode;
use tvm_types::read_single_root_boc;

use crate::execute::execute;
use crate::result::ExecutionResult;

Expand Down Expand Up @@ -93,7 +95,7 @@ struct Args {

fn main() -> anyhow::Result<()> {
let args: Args = Args::parse();
if let Some( new_code) = args.replace_code {
if let Some(new_code) = args.replace_code {
replace_code(args.input_file, new_code)?;
return Ok(());
}
Expand All @@ -104,17 +106,14 @@ fn main() -> anyhow::Result<()> {
}

fn replace_code(input_file: PathBuf, code: String) -> anyhow::Result<()> {
let mut contract_state_init =
StateInit::construct_from_file(&input_file).map_err(|e| {
anyhow::format_err!(
"Failed to load state init from input file {:?}: {e}",
input_file
)
})?;
let bytes = base64_decode(&code).map_err(|e| anyhow::format_err!("Failed to decode code as base64: {e}"))?;
let code_cell = read_single_root_boc(bytes).map_err(|e| anyhow::format_err!(
"Failed to construct code cell from base64 decoded code cell: {e}",
))?;
let mut contract_state_init = StateInit::construct_from_file(&input_file).map_err(|e| {
anyhow::format_err!("Failed to load state init from input file {:?}: {e}", input_file)
})?;
let bytes = base64_decode(&code)
.map_err(|e| anyhow::format_err!("Failed to decode code as base64: {e}"))?;
let code_cell = read_single_root_boc(bytes).map_err(|e| {
anyhow::format_err!("Failed to construct code cell from base64 decoded code cell: {e}",)
})?;
contract_state_init.set_code(code_cell);
contract_state_init
.write_to_file(&input_file)
Expand Down
2 changes: 1 addition & 1 deletion tvm_executor/src/ordinary_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl TransactionExecutor for OrdinaryTransactionExecutor {
is_masterchain,
is_special,
params.available_credit,
minted_shell
minted_shell,
) {
Ok(storage_ph) => {
storage_fee = storage_ph.storage_fees_collected.as_u128();
Expand Down
2 changes: 1 addition & 1 deletion tvm_executor/src/tick_tock_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl TransactionExecutor for TickTockTransactionExecutor {
is_masterchain,
is_special,
0,
&mut 0
&mut 0,
) {
Ok(storage_ph) => {
let mut storage_fee = storage_ph.storage_fees_collected.as_u128();
Expand Down
14 changes: 5 additions & 9 deletions tvm_executor/src/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub trait TransactionExecutor {
is_masterchain: bool,
is_special: bool,
available_credit: i128,
minted_shell: &mut u128
minted_shell: &mut u128,
) -> Result<TrStoragePhase> {
log::debug!(target: "executor", "storage_phase");
if tr.now() < acc.last_paid() {
Expand Down Expand Up @@ -313,8 +313,7 @@ pub trait TransactionExecutor {
acc_balance.grams.add(&diff)?;
*minted_shell += diff.as_u128();
diff = Grams::zero();
}
else {
} else {
acc_balance.grams.add(&Grams::from(available_credit as u64))?;
*minted_shell += available_credit as u128;
diff.sub(&Grams::from(available_credit as u64))?;
Expand All @@ -323,7 +322,7 @@ pub trait TransactionExecutor {
let ecc_balance = match acc_balance.other.get(&ECC_SHELL_KEY) {
Ok(Some(data)) => data,
Ok(None) => VarUInteger32::default(),
Err(_) => VarUInteger32::default()
Err(_) => VarUInteger32::default(),
};
if ecc_balance > VarUInteger32::from(diff.as_u128()) {
let mut sub_value = CurrencyCollection::new();
Expand Down Expand Up @@ -706,7 +705,7 @@ pub trait TransactionExecutor {
new_data: Option<Cell>,
my_addr: &MsgAddressInt,
is_special: bool,
mut available_credit: i128,
available_credit: i128,
minted_shell: &mut u128,
need_to_burn: u64,
message_src_dapp_id: Option<UInt256>,
Expand Down Expand Up @@ -911,16 +910,13 @@ pub trait TransactionExecutor {
}
OutAction::MintShellToken { mut value } => {
if available_credit != INFINITY_CREDIT {
if value as i128 > available_credit {
if value as i128 + minted_shell.clone() as i128 > available_credit {
value = available_credit.clone().try_into()?;
}
}
match acc_remaining_balance.grams.add(&(Grams::from(value))) {
Ok(true) => {
*minted_shell += value as u128;
if available_credit != INFINITY_CREDIT {
available_credit -= value as i128;
}
phase.spec_actions += 1;
0
}
Expand Down

0 comments on commit d625d70

Please sign in to comment.