From d8d043754644cf2a9182673f6f7e22d01c9094fb Mon Sep 17 00:00:00 2001 From: neodiX Date: Tue, 12 Nov 2024 11:06:26 +0400 Subject: [PATCH] added initial balance to all transactions summary --- .../main/java/org/ton/java/Blockchain.java | 10 +++- .../java/org/ton/java/BlockchainTest.java | 4 +- .../java/org/ton/java/tlb/types/Block.java | 2 +- .../org/ton/java/tlb/types/Transaction.java | 58 ++++++++++++------- .../ton/java/tlb/types/TransactionFees.java | 1 + 5 files changed, 50 insertions(+), 25 deletions(-) diff --git a/blockchain/src/main/java/org/ton/java/Blockchain.java b/blockchain/src/main/java/org/ton/java/Blockchain.java index 851e8e93..7c76305e 100644 --- a/blockchain/src/main/java/org/ton/java/Blockchain.java +++ b/blockchain/src/main/java/org/ton/java/Blockchain.java @@ -346,6 +346,9 @@ public SendExternalResult sendExternal(Message message) { } return SendExternalResult.builder().tonlibResult(tonlibResult).build(); } else { // emulator + + String initialBalance = Utils.formatNanoValue(customEmulatorShardAccount.getBalance()); + log.info( "Sending external message to bounceable address {} on {}...", stateInit.getAddress().toBounceable(), @@ -367,7 +370,12 @@ public SendExternalResult sendExternal(Message message) { .printEmulatorInfo(false) .build(); - emulateTransactionResult.getTransaction().printTransactionFees(true, true); + emulateTransactionResult + .getTransaction() + .printTransactionFees(true, true, initialBalance); + log.info( + "final balance {}", + Utils.formatNanoValue(emulateTransactionResult.getNewShardAccount().getBalance())); emulateTransactionResult.getTransaction().printAllMessages(true); } else { log.error( diff --git a/blockchain/src/test/java/org/ton/java/BlockchainTest.java b/blockchain/src/test/java/org/ton/java/BlockchainTest.java index 812a3c62..9086eab5 100644 --- a/blockchain/src/test/java/org/ton/java/BlockchainTest.java +++ b/blockchain/src/test/java/org/ton/java/BlockchainTest.java @@ -70,7 +70,7 @@ public void testDeployCustomContractContractOnEmulator() { Blockchain blockchain = Blockchain.builder() .network(Network.EMULATOR) - .customContractAsResource("simple.fc") + .customContractAsResource("simple.tolk") .customContractDataCell( CellBuilder.beginCell() .storeUint(0, 32) // seqno @@ -359,7 +359,6 @@ public void testSendMessagesChainCustomContractOnEmulatorTolk() { .endCell(); Message extMsg = MsgUtils.createExternalMessage(dummyAddress, null, bodyCell); - blockchain.sendExternal(extMsg); currentSeqno = blockchain.runGetSeqNo(); @@ -371,7 +370,6 @@ public void testSendMessagesChainCustomContractOnEmulatorTolk() { .endCell(); extMsg = MsgUtils.createExternalMessage(dummyAddress, null, bodyCell); - blockchain.sendExternal(extMsg); currentSeqno = blockchain.runGetSeqNo(); System.out.printf("current seqno %s\n", currentSeqno); diff --git a/cell/src/main/java/org/ton/java/tlb/types/Block.java b/cell/src/main/java/org/ton/java/tlb/types/Block.java index 933695ec..ea05516e 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/Block.java +++ b/cell/src/main/java/org/ton/java/tlb/types/Block.java @@ -110,7 +110,7 @@ public void printAllTransactions() { log.info("No transactions"); return; } - Transaction.printTxHeader(); + Transaction.printTxHeader(""); for (Transaction tx : txs) { tx.printTransactionFees(); } diff --git a/cell/src/main/java/org/ton/java/tlb/types/Transaction.java b/cell/src/main/java/org/ton/java/tlb/types/Transaction.java index 9b1708f7..2f4af6ca 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/Transaction.java +++ b/cell/src/main/java/org/ton/java/tlb/types/Transaction.java @@ -370,29 +370,27 @@ public void printTransactionFees() { printTransactionFees(false, false); } + public void printTransactionFees(boolean withHeader, boolean withFooter, String balance) { + TransactionFees txFees = getTransactionFees(); + + if (withHeader) { + printTxHeader(" (initial balance " + balance + ")"); + } + printTxData(txFees); + + if (withFooter) { + printTxFooter(); + } + } + public void printTransactionFees(boolean withHeader, boolean withFooter) { TransactionFees txFees = getTransactionFees(); if (withHeader) { - printTxHeader(); + printTxHeader(""); } - String str = - String.format( - "| %-9s| %-13s| %-15s| %-15s| %-13s| %-13s| %-14s| %-11s| %-8s| %-14s| %-9s| %-11s| %-13s |", - txFees.getOp(), - txFees.getType(), - Utils.formatNanoValueZero(txFees.getValueIn()), - Utils.formatNanoValueZero(txFees.getValueOut()), - Utils.formatNanoValueZero(txFees.getTotalFees()), - Utils.formatNanoValueZero(txFees.getInForwardFee()), - Utils.formatNanoValueZero(txFees.getOutForwardFee()), - txFees.getTotalActions(), - txFees.getOutMsgs(), - Utils.formatNanoValueZero(txFees.getComputeFee()), - txFees.getExitCode(), - txFees.getActionCode(), - txFees.getAccount()); - log.info(str); + printTxData(txFees); + if (withFooter) { printTxFooter(); } @@ -571,9 +569,9 @@ public void printAllMessages(boolean withHeader) { MessageFees.printMessageFeesFooter(); } - public static void printTxHeader() { + public static void printTxHeader(String balance) { log.info(""); - log.info("Transactions"); + log.info("Transactions" + balance); log.info( "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"); log.info( @@ -587,6 +585,26 @@ public static void printTxFooter() { "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"); } + public static void printTxData(TransactionFees txFees) { + String str = + String.format( + "| %-9s| %-13s| %-15s| %-15s| %-13s| %-13s| %-14s| %-11s| %-8s| %-14s| %-9s| %-11s| %-13s |", + txFees.getOp(), + txFees.getType(), + Utils.formatNanoValueZero(txFees.getValueIn()), + Utils.formatNanoValueZero(txFees.getValueOut()), + Utils.formatNanoValueZero(txFees.getTotalFees()), + Utils.formatNanoValueZero(txFees.getInForwardFee()), + Utils.formatNanoValueZero(txFees.getOutForwardFee()), + txFees.getTotalActions(), + txFees.getOutMsgs(), + Utils.formatNanoValueZero(txFees.getComputeFee()), + txFees.getExitCode(), + txFees.getActionCode(), + txFees.getAccount()); + log.info(str); + } + private String formatMsgType(String fullMsgType) { if (fullMsgType.equals("InternalMessageInfo")) { return "internal-in"; diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionFees.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionFees.java index 403a80b8..5d05ea9e 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionFees.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionFees.java @@ -22,4 +22,5 @@ public class TransactionFees { long now; BigInteger lt; String account; + BigInteger balance; }