Skip to content

Commit

Permalink
Merge branch 'fix/fees-estimation' into 'master'
Browse files Browse the repository at this point in the history
Fix/fees estimation

See merge request network/nekoton!1
  • Loading branch information
MrWad3r committed Sep 14, 2023
2 parents d70dd09 + 116b2a9 commit e05964a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ impl TryFrom<ton_types::Cell> for Message {
fn try_from(raw: ton_types::Cell) -> Result<Self, Self::Error> {
let hash = raw.repr_hash();

let s = ton_block::Message::construct_from_cell(raw.clone())
let s = ton_block::Message::construct_from_cell(raw)
.map_err(|_| TransactionError::InvalidStructure)?;

#[cfg(not(feature = "extended_models"))]
Expand Down
23 changes: 16 additions & 7 deletions src/core/token_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,35 @@ impl TokenWallet {
// Simulate source transaction
let source_tx = tree.next().await?.ok_or(TokenWalletError::NoSourceTx)?;
check_exit_code(&source_tx, TokenWalletError::SourceTxFailed)?;
attached_amount += source_tx.total_fees.grams.as_u128() * FEE_MULTIPLIER;
attached_amount += source_tx.total_fees.grams.as_u128();

if source_tx.outmsg_cnt == 0 {
return Err(TokenWalletError::NoDestTx.into());
}
//

if let Some(message) = tree.peek() {
if message.state_init().is_some() && message.src_ref() == Some(self.address()) {
//simulate first deploy transaction (we don't need to count attached amount here because of)
let dest_tx = tree.next().await?.ok_or(TokenWalletError::NoDestTx)?;
check_exit_code(&dest_tx, TokenWalletError::DestinationTxFailed)?;
}
}

// Remove deployment messages
tree.retain_message_queue(|message| {
message.state_init().is_none() && message.src_ref() == Some(self.address())
message.state_init().is_none() && (message.src_ref() == Some(self.address()))
});
if tree.message_queue().len() != 1 {

if tree.message_queue().len() != 1 {
return Err(TokenWalletError::NoDestTx.into());
}

// Simulate destination transaction
let dest_tx = tree.next().await?.ok_or(TokenWalletError::NoDestTx)?;
check_exit_code(&dest_tx, TokenWalletError::DestinationTxFailed)?;
attached_amount += dest_tx.total_fees.grams.as_u128() * FEE_MULTIPLIER;
attached_amount += dest_tx.total_fees.grams.as_u128();

// Done
Ok(attached_amount as u64)
Ok((attached_amount * FEE_MULTIPLIER) as u64)
}

pub fn prepare_transfer(
Expand Down Expand Up @@ -822,4 +830,5 @@ mod tests {
let root_state = RootTokenContractState(&root_state);
root_state.guess_details(&SimpleClock).unwrap();
}

}
4 changes: 4 additions & 0 deletions src/core/transactions_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl TransactionsTreeStream {
}
}

pub fn peek(&self) -> Option<&Message> {
self.messages.get(0)
}

async fn step(&mut self, mut message: Message) -> TransactionTreeResult<Transaction> {
const A_LOT: u64 = 1_000_000_000_000_000; // 1'000'000 ever

Expand Down

0 comments on commit e05964a

Please sign in to comment.