diff --git a/README.md b/README.md
index 044ed97c..816a6f0e 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,9 @@ You can use each submodule individually. Click the module below to get more deta
* [Liteclient](liteclient/README.md) - wrapper for using with external precompiled lite-client binary.
* [Fift](fift/README.md) - wrapper for using with external precompiled fift binary.
* [Func](func/README.md) - wrapper for using with external precompiled func binary.
+* [Tolk](tolk/README.md) - wrapper for using with external precompiled tolk binary.
* [TonConnect](tonconnect/README.md) - implementation of Ton Connect standard.
+* [Blockchain](blockchain/README.md) - To Do.
* [Utils](utils/README.md) - create private and public keys, convert data, etc.
### Features
diff --git a/blockchain/README.md b/blockchain/README.md
new file mode 100644
index 00000000..4fe6a34f
--- /dev/null
+++ b/blockchain/README.md
@@ -0,0 +1,39 @@
+# Blockchain module
+
+Description
+
+## Maven [![Maven Central][maven-central-svg]][maven-central]
+
+```xml
+
+
+ io.github.neodix42
+ blockchain
+ 0.7.1
+
+```
+
+## Jitpack
+
+```xml
+
+
+ io.github.neodix42.ton4j
+ blockchain
+ 0.7.1
+
+```
+
+## Usage
+
+```java
+// todo
+```
+
+[maven-central-svg]: https://img.shields.io/maven-central/v/io.github.neodix42/blockchain
+
+[maven-central]: https://mvnrepository.com/artifact/io.github.neodix42/blockchain
+
+[ton-svg]: https://img.shields.io/badge/Based%20on-TON-blue
+
+[ton]: https://ton.org
\ No newline at end of file
diff --git a/blockchain/src/main/java/org/ton/java/Blockchain.java b/blockchain/src/main/java/org/ton/java/Blockchain.java
index a154230d..851e8e93 100644
--- a/blockchain/src/main/java/org/ton/java/Blockchain.java
+++ b/blockchain/src/main/java/org/ton/java/Blockchain.java
@@ -212,15 +212,15 @@ private void initializeSmartContractCompiler() {
private void printBlockchainInfo() {
if (super.network == Network.EMULATOR) {
- System.out.printf(
+ log.info(
"Blockchain configuration:\n"
- + "Target network: %s\n"
- + "Emulator location: %s, configType: %s, txVerbosity: %s, tvmVerbosity: %s\n"
- + "Emulator ShardAccount: balance %s, address: %s, lastPaid: %s, lastTransLt: %s\n"
- + "Func location: %s\n"
- + "Tolk location: %s\n"
- + "Fift location: %s, FIFTPATH=%s\n"
- + "Contract: %s\n\n",
+ + "Target network: {}\n"
+ + "Emulator location: {}, configType: {}, txVerbosity: {}, tvmVerbosity: {}\n"
+ + "Emulator ShardAccount: balance {}, address: {}, lastPaid: {}, lastTransLt: {}\n"
+ + "Func location: {}\n"
+ + "Tolk location: {}"
+ + "Fift location: {}, FIFTPATH={}\n"
+ + "Contract: {}\n",
super.network,
Utils.detectAbsolutePath("emulator", true),
txEmulator.getConfigType(),
@@ -240,16 +240,16 @@ private void printBlockchainInfo() {
? "integrated resource " + super.customContractAsResource
: super.customContractPath);
} else {
- System.out.printf(
+ log.info(
"Blockchain configuration:\n"
- + "Target network: %s\n"
+ + "Target network: {}\n"
+ "Emulator not used\n"
- + "Tonlib location: %s\n"
- + "Tonlib global config: %s\n"
- + "Func location: %s\n"
- + "Tolk location: %s\n"
- + "Fift location: %s, FIFTPATH=%s\n"
- + "Contract: %s\n\n",
+ + "Tonlib location: {}\n"
+ + "Tonlib global config: {}\n"
+ + "Func location: {}\n"
+ + "Tolk location: {}\n"
+ + "Fift location: {}, FIFTPATH={}\n"
+ + "Contract: {}\n",
super.network,
super.tonlib.pathToTonlibSharedLib,
super.tonlib.pathToGlobalConfig,
@@ -323,32 +323,58 @@ private void initializeTonlib() {
}
public SendExternalResult sendExternal(Message message) {
- System.out.printf("sending external message on %s\n", network);
- ExtMessageInfo tonlibResult = null;
try {
if (network != Network.EMULATOR) {
- tonlibResult = tonlib.sendRawMessage(message.toCell().toBase64());
+ String bounceableAddress =
+ (network == Network.TESTNET)
+ ? contract.getAddress().toBounceableTestnet()
+ : contract.getAddress().toBounceable();
+ log.info(
+ "Sending external message to bounceable address {} on {}...",
+ bounceableAddress,
+ network);
+ ExtMessageInfo tonlibResult = tonlib.sendRawMessage(message.toCell().toBase64());
if (tonlibResult.getError().getCode() != 0) {
throw new Error(
"Cannot send external message on "
+ network
- + ". Error code "
+ + ". Error code: "
+ tonlibResult.getError().getCode());
} else {
- System.out.printf("successfully sent external message on %s\n", network);
+ log.info("Successfully sent external message on {}", network);
}
return SendExternalResult.builder().tonlibResult(tonlibResult).build();
} else { // emulator
+ log.info(
+ "Sending external message to bounceable address {} on {}...",
+ stateInit.getAddress().toBounceable(),
+ network);
EmulateTransactionResult emulateTransactionResult =
txEmulator.emulateTransaction(
customEmulatorShardAccount.toCell().toBase64(), message.toCell().toBase64());
- if (emulateTransactionResult.isSuccess()) {
+ if (emulateTransactionResult.isSuccess()
+ && emulateTransactionResult.getVm_exit_code() == 0) {
customEmulatorShardAccount = emulateTransactionResult.getNewShardAccount();
+ log.info("Successfully emulated external message on {}", network);
+
+ // reinit TVM emulator with a new stateInit
+ tvmEmulator =
+ TvmEmulator.builder()
+ .codeBoc(emulateTransactionResult.getNewStateInit().getCode().toBase64())
+ .dataBoc(emulateTransactionResult.getNewStateInit().getData().toBase64())
+ .verbosityLevel(tvmEmulatorVerbosityLevel)
+ .printEmulatorInfo(false)
+ .build();
+
emulateTransactionResult.getTransaction().printTransactionFees(true, true);
emulateTransactionResult.getTransaction().printAllMessages(true);
} else {
- log.error("Cannot emulate transaction. Error " + emulateTransactionResult.getError());
+ log.error(
+ "Cannot emulate transaction. Error: "
+ + emulateTransactionResult.getError()
+ + ", VM exit code: "
+ + emulateTransactionResult.getVm_exit_code());
}
return SendExternalResult.builder().emulatorResult(emulateTransactionResult).build();
}
@@ -360,15 +386,15 @@ public SendExternalResult sendExternal(Message message) {
}
public boolean deploy(int waitForDeploymentSeconds) {
- System.out.printf("deploying on %s\n", network);
try {
-
if (nonNull(contract)) {
deployRegularContract(contract, waitForDeploymentSeconds);
} else { // deploy on emulator custom contract
deployCustomContract(stateInit, waitForDeploymentSeconds);
}
- System.out.printf("deployed on %s\n", network);
+ if (network == Network.EMULATOR) {
+ log.info("Deployed on {}", network);
+ }
return true;
} catch (Exception e) {
log.error("Cannot deploy the contract on " + network + ". Error " + e.getMessage());
@@ -378,15 +404,21 @@ public boolean deploy(int waitForDeploymentSeconds) {
}
public GetterResult runGetMethod(String methodName) {
- System.out.printf("running GetMethod %s on %s\n", methodName, network);
+
if (network == Network.EMULATOR) {
+ log.info(
+ "Running GetMethod {} against {} on {}...",
+ methodName,
+ stateInit.getAddress().toBounceable(),
+ network);
+
GetterResult result =
GetterResult.builder().emulatorResult(tvmEmulator.runGetMethod(methodName)).build();
if (result.getEmulatorResult().getVm_exit_code() != 0) {
throw new Error(
"Cannot execute run method ("
+ methodName
- + "), Error:\n"
+ + "), Error:"
+ result.getEmulatorResult().getVm_log());
}
return result;
@@ -397,13 +429,22 @@ public GetterResult runGetMethod(String methodName) {
} else {
address = stateInit.getAddress();
}
+ String bounceableAddress =
+ (network == Network.TESTNET) ? address.toBounceableTestnet() : address.toBounceable();
+
+ log.info("Running GetMethod {} against {} on {}...", methodName, bounceableAddress, network);
+
return GetterResult.builder().tonlibResult(tonlib.runMethod(address, methodName)).build();
}
}
public BigInteger runGetSeqNo() {
- System.out.printf("running %s on %s\n", "seqno", network);
if (network == Network.EMULATOR) {
+ log.info(
+ "Running GetMethod {} against {} on {}...",
+ "seqno",
+ stateInit.getAddress().toBounceable(),
+ network);
return tvmEmulator.runGetSeqNo();
} else {
@@ -413,21 +454,17 @@ public BigInteger runGetSeqNo() {
} else {
address = stateInit.getAddress();
}
+ String bounceableAddress =
+ (network == Network.TESTNET) ? address.toBounceableTestnet() : address.toBounceable();
+
+ log.info("Running GetMethod {} against {} on {}...", "seqno", bounceableAddress, network);
RunResult result = tonlib.runMethod(address, "seqno");
if (result.getExit_code() != 0) {
- if (network == Network.TESTNET) {
- throw new Error(
- "Cannot get seqno from contract "
- + address.toBounceableTestnet()
- + ", exitCode "
- + result.getExit_code());
- } else {
- throw new Error(
- "Cannot get seqno from contract "
- + address.toBounceable()
- + ", exitCode "
- + result.getExit_code());
- }
+ throw new Error(
+ "Cannot get seqno from contract "
+ + bounceableAddress
+ + ", exitCode "
+ + result.getExit_code());
}
TvmStackEntryNumber seqno = (TvmStackEntryNumber) result.getStack().get(0);
@@ -436,8 +473,13 @@ public BigInteger runGetSeqNo() {
}
public String runGetPublicKey() {
- System.out.printf("running %s on %s\n", "get_public_key", network);
+
if (network == Network.EMULATOR) {
+ log.info(
+ "Running GetMethod {} against {} on {}...",
+ "get_public_key",
+ stateInit.getAddress().toBounceable(),
+ network);
return tvmEmulator.runGetPublicKey();
} else {
Address address;
@@ -446,21 +488,18 @@ public String runGetPublicKey() {
} else {
address = stateInit.getAddress();
}
+ String bounceableAddress =
+ (network == Network.TESTNET) ? address.toBounceableTestnet() : address.toBounceable();
+
+ log.info(
+ "Running GetMethod {} against {} on {}...", "get_public_key", bounceableAddress, network);
RunResult result = tonlib.runMethod(address, "get_public_key");
if (result.getExit_code() != 0) {
- if (network == Network.TESTNET) {
- throw new Error(
- "Cannot get_public_key from contract "
- + address.toBounceableTestnet()
- + ", exitCode "
- + result.getExit_code());
- } else {
- throw new Error(
- "Cannot get_public_key from contract "
- + address.toBounceable()
- + ", exitCode "
- + result.getExit_code());
- }
+ throw new Error(
+ "Cannot get_public_key from contract "
+ + bounceableAddress
+ + ", exitCode "
+ + result.getExit_code());
}
TvmStackEntryNumber publicKeyNumber = (TvmStackEntryNumber) result.getStack().get(0);
return publicKeyNumber.getNumber().toString(16);
@@ -468,8 +507,13 @@ public String runGetPublicKey() {
}
public BigInteger runGetSubWalletId() {
- System.out.printf("running %s on %s\n", "get_subwallet_id", network);
+
if (network == Network.EMULATOR) {
+ log.info(
+ "Running GetMethod {} against {} on {}...",
+ "get_subwallet_id",
+ stateInit.getAddress().toBounceable(),
+ network);
return tvmEmulator.runGetSubWalletId();
} else {
Address address;
@@ -478,21 +522,21 @@ public BigInteger runGetSubWalletId() {
} else {
address = stateInit.getAddress();
}
+ String bounceableAddress =
+ (network == Network.TESTNET) ? address.toBounceableTestnet() : address.toBounceable();
+
+ log.info(
+ "Running GetMethod {} against {} on {}...",
+ "get_subwallet_id",
+ bounceableAddress,
+ network);
RunResult result = tonlib.runMethod(address, "get_subwallet_id");
if (result.getExit_code() != 0) {
- if (network == Network.TESTNET) {
- throw new Error(
- "Cannot get_subwallet_id from contract "
- + address.toBounceableTestnet()
- + ", exitCode "
- + result.getExit_code());
- } else {
- throw new Error(
- "Cannot get_subwallet_id from contract "
- + address.toBounceable()
- + ", exitCode "
- + result.getExit_code());
- }
+ throw new Error(
+ "Cannot get_subwallet_id from contract "
+ + bounceableAddress
+ + ", exitCode "
+ + result.getExit_code());
}
TvmStackEntryNumber subWalletId = (TvmStackEntryNumber) result.getStack().get(0);
@@ -512,14 +556,14 @@ private BigInteger topUpFromMyLocalTonFaucet(Address address) {
Utils.hexToSignedBytes(
"44e67357b8e3333b617eb62f759890c95a6bb3cc95557ba60b80b8619f8b7c9d")))
.build();
- System.out.printf(
- "faucetMyLocalTonWallet address %s\n", faucetMyLocalTonWallet.getAddress().toRaw());
+ log.info("faucetMyLocalTonWallet address {}", faucetMyLocalTonWallet.getAddress().toRaw());
- System.out.printf("myLocalTon faucet balance %s\n", faucetMyLocalTonWallet.getBalance());
+ log.info("myLocalTon faucet balance {}", faucetMyLocalTonWallet.getBalance());
nonBounceableAddress = address.toNonBounceable();
- System.out.printf(
- "topping up %s with %s toncoin from MyLocalTon Faucet\n",
- nonBounceableAddress, Utils.formatNanoValue(initialDeployTopUpAmount));
+ log.info(
+ "Topping up ({}) with {} toncoin from MyLocalTon Faucet",
+ nonBounceableAddress,
+ Utils.formatNanoValue(initialDeployTopUpAmount));
WalletV3Config walletV3Config =
WalletV3Config.builder()
@@ -534,7 +578,11 @@ private BigInteger topUpFromMyLocalTonFaucet(Address address) {
result = faucetMyLocalTonWallet.send(walletV3Config);
if (result.getError().getCode() != 0) {
- throw new Error("Cannot send external message. Error: " + result.getError().getMessage());
+ throw new Error(
+ "Cannot send external message to "
+ + nonBounceableAddress
+ + ". Error: "
+ + result.getError().getMessage());
}
tonlib.waitForBalanceChange(address, 20);
@@ -544,63 +592,89 @@ private BigInteger topUpFromMyLocalTonFaucet(Address address) {
private void deployRegularContract(Contract contract, int waitForDeploymentSeconds)
throws InterruptedException {
Address address = contract.getAddress();
- System.out.printf("contract address %s\n", address.toRaw());
+ log.info("Deploying {} ({}) on {}...", contract.getName(), address.toRaw(), network);
// contract.getTonlib();
if (network != Network.EMULATOR) {
ExtMessageInfo result;
if (waitForDeploymentSeconds != 0) {
- String nonBounceableAddress = address.toNonBounceableTestnet();
- if (network == Network.MAINNET) {
- System.out.printf(
- "waiting %ss for toncoins to be deposited to address %s\n",
- waitForDeploymentSeconds, nonBounceableAddress);
+ if (network == Network.MAINNET) {
+ String nonBounceableAddress = address.toNonBounceable();
+ log.info(
+ "Waiting {}s for toncoins to be deposited to address {} ({})",
+ waitForDeploymentSeconds,
+ nonBounceableAddress,
+ address.toRaw());
tonlib.waitForBalanceChange(address, waitForDeploymentSeconds);
- System.out.println("sending external message with deploy instructions...");
+ log.info(
+ "Sending external message to non-bounceable address {} with deploy instructions...",
+ nonBounceableAddress);
Message msg = contract.prepareDeployMsg();
result = tonlib.sendRawMessage(msg.toCell().toBase64());
assert result.getError().getCode() != 0;
tonlib.waitForDeployment(address, waitForDeploymentSeconds);
- System.out.printf(
- "%s deployed at address %s\n", contract.getName(), nonBounceableAddress);
+ log.info(
+ "{} deployed at non-bounceable address {} ({})",
+ contract.getName(),
+ nonBounceableAddress,
+ address.toBounceable());
} else if (network == Network.TESTNET) {
-
- System.out.printf(
- "topping up %s with %s toncoin from TestnetFaucet\n",
- nonBounceableAddress, Utils.formatNanoValue(initialDeployTopUpAmount));
+ String nonBounceableAddress = address.toNonBounceableTestnet();
+ log.info(
+ "Topping up {} with {} toncoin from TestnetFaucet",
+ nonBounceableAddress,
+ Utils.formatNanoValue(initialDeployTopUpAmount));
BigInteger newBalance =
TestnetFaucet.topUpContract(tonlib, contract.getAddress(), initialDeployTopUpAmount);
- System.out.printf(
- "topped up successfully, new balance %s\n", Utils.formatNanoValue(newBalance));
- System.out.println("sending external message with deploy instructions...");
+ log.info(
+ "Topped up ({}) successfully, new balance {}",
+ nonBounceableAddress,
+ Utils.formatNanoValue(newBalance));
+ log.info(
+ "Sending external message to non-bounceable address {} with deploy instructions...",
+ nonBounceableAddress);
Message msg = contract.prepareDeployMsg();
result = tonlib.sendRawMessage(msg.toCell().toBase64());
if (result.getError().getCode() != 0) {
throw new Error(
- "Cannot send external message. Error: " + result.getError().getMessage());
+ "Cannot send external message to non-bounceable address "
+ + nonBounceableAddress
+ + ". Error: "
+ + result.getError().getMessage());
}
tonlib.waitForDeployment(address, waitForDeploymentSeconds);
- System.out.printf(
- "%s deployed at address %s\n", contract.getName(), nonBounceableAddress);
+ log.info(
+ "{} deployed at bounceable address {} ({})",
+ contract.getName(),
+ address.toBounceableTestnet(),
+ address.toRaw());
} else { // myLocalTon
-
+ String nonBounceableAddress = address.toNonBounceable();
// top up first
BigInteger newBalance = topUpFromMyLocalTonFaucet(address);
- System.out.printf(
- "topped up successfully, new balance %s\n", Utils.formatNanoValue(newBalance));
+ log.info(
+ "Topped up ({}) successfully, new balance {}",
+ nonBounceableAddress,
+ Utils.formatNanoValue(newBalance));
// deploy smc
Message msg = contract.prepareDeployMsg();
result = tonlib.sendRawMessage(msg.toCell().toBase64());
if (result.getError().getCode() != 0) {
throw new Error(
- "Cannot send external message. Error: " + result.getError().getMessage());
+ "Cannot send external message to non-bounceable address "
+ + nonBounceableAddress
+ + ". Error: "
+ + result.getError().getMessage());
}
tonlib.waitForDeployment(address, waitForDeploymentSeconds);
- System.out.printf(
- "%s deployed at address %s\n", contract.getName(), nonBounceableAddress);
+ log.info(
+ "{} deployed at bounceable address {} ({})",
+ contract.getName(),
+ address.toBounceable(),
+ address.toRaw());
}
}
}
@@ -612,19 +686,23 @@ private void deployCustomContract(StateInit stateInit, int waitForDeploymentSeco
String contractName =
isNull(customContractAsResource) ? customContractPath : customContractAsResource;
Address address = stateInit.getAddress();
- System.out.printf("contract address %s\n", address.toRaw());
+ log.info("Deploying {} on {}...", address.toRaw(), network);
if (network != Network.EMULATOR) {
ExtMessageInfo result;
if (waitForDeploymentSeconds != 0) {
- String nonBounceableAddress = address.toNonBounceableTestnet();
+
if (network == Network.MAINNET) {
+ String nonBounceableAddress = address.toNonBounceable();
- System.out.printf(
- "waiting %ss for toncoins to be deposited to address %s\n",
- waitForDeploymentSeconds, nonBounceableAddress);
+ log.info(
+ "Waiting {}s for toncoins to be deposited to non-bounceable address {}",
+ waitForDeploymentSeconds,
+ nonBounceableAddress);
tonlib.waitForBalanceChange(address, waitForDeploymentSeconds);
- System.out.println("sending external message with deploy instructions...");
+ log.info(
+ "Sending external message to non-bounceable address {} with deploy instructions...",
+ nonBounceableAddress);
Message msg =
MsgUtils.createExternalMessage(
address,
@@ -633,17 +711,26 @@ private void deployCustomContract(StateInit stateInit, int waitForDeploymentSeco
result = tonlib.sendRawMessage(msg.toCell().toBase64());
assert result.getError().getCode() != 0;
tonlib.waitForDeployment(address, waitForDeploymentSeconds);
- System.out.printf("%s deployed at address %s", contractName, nonBounceableAddress);
+ log.info(
+ "{} deployed at bounceable address {} ({})",
+ contractName,
+ address.toBounceable(),
+ address.toRaw());
} else if (network == Network.TESTNET) {
-
- System.out.printf(
- "topping up %s with %s toncoin from TestnetFaucet\n",
- nonBounceableAddress, Utils.formatNanoValue(initialDeployTopUpAmount));
+ String nonBounceableAddress = address.toNonBounceableTestnet();
+ log.info(
+ "Topping up non-bounceable {} with {} toncoin from TestnetFaucet",
+ nonBounceableAddress,
+ Utils.formatNanoValue(initialDeployTopUpAmount));
BigInteger newBalance =
TestnetFaucet.topUpContract(tonlib, address, initialDeployTopUpAmount);
- System.out.printf(
- "topped up successfully, new balance %s", Utils.formatNanoValue(newBalance));
- System.out.println("sending external message with deploy instructions...");
+ log.info(
+ "Topped up ({}) successfully, new balance {}",
+ nonBounceableAddress,
+ Utils.formatNanoValue(newBalance));
+ log.info(
+ "Sending external message to non-bounceable address {} with deploy instructions...",
+ nonBounceableAddress);
Message msg =
MsgUtils.createExternalMessage(
address,
@@ -652,17 +739,26 @@ private void deployCustomContract(StateInit stateInit, int waitForDeploymentSeco
result = tonlib.sendRawMessage(msg.toCell().toBase64());
if (result.getError().getCode() != 0) {
throw new Error(
- "Cannot send external message. Error: " + result.getError().getMessage());
+ "Cannot send external message to non-bounceable address "
+ + nonBounceableAddress
+ + ". Error: "
+ + result.getError().getMessage());
}
tonlib.waitForDeployment(address, waitForDeploymentSeconds);
- System.out.printf("%s deployed at address %s\n", contractName, nonBounceableAddress);
+ log.info(
+ "{} deployed at bounceable address {} ({})",
+ contractName,
+ address.toBounceableTestnet(),
+ address.toRaw());
} else { // myLocalTon
-
+ String nonBounceableAddress = address.toNonBounceable();
// top up first
BigInteger newBalance = topUpFromMyLocalTonFaucet(address);
- System.out.printf(
- "topped up successfully, new balance %s\n", Utils.formatNanoValue(newBalance));
+ log.info(
+ "Topped up ({}) successfully, new balance {}",
+ nonBounceableAddress,
+ Utils.formatNanoValue(newBalance));
// deploy smc
Message msg =
MsgUtils.createExternalMessage(
@@ -672,11 +768,18 @@ private void deployCustomContract(StateInit stateInit, int waitForDeploymentSeco
result = tonlib.sendRawMessage(msg.toCell().toBase64());
if (result.getError().getCode() != 0) {
throw new Error(
- "Cannot send external message. Error: " + result.getError().getMessage());
+ "Cannot send external message to non-bounceable address "
+ + nonBounceableAddress
+ + ". Error: "
+ + result.getError().getMessage());
}
tonlib.waitForDeployment(address, waitForDeploymentSeconds);
- System.out.printf("%s deployed at address %s\n", contractName, nonBounceableAddress);
+ log.info(
+ "{} deployed at bounceable address {} ({})",
+ contractName,
+ address.toBounceable(),
+ address.toRaw());
}
}
}
diff --git a/blockchain/src/main/resources/logback.xml b/blockchain/src/main/resources/logback.xml
new file mode 100644
index 00000000..2c36c50b
--- /dev/null
+++ b/blockchain/src/main/resources/logback.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+ %msg%n
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/blockchain/src/test/java/org/ton/java/BlockchainTest.java b/blockchain/src/test/java/org/ton/java/BlockchainTest.java
index dc91aada..812a3c62 100644
--- a/blockchain/src/test/java/org/ton/java/BlockchainTest.java
+++ b/blockchain/src/test/java/org/ton/java/BlockchainTest.java
@@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import com.iwebpp.crypto.TweetNaclFast;
+import java.math.BigInteger;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -251,8 +252,6 @@ public void testSendMessageV3R2ContractOnEmulator() {
Blockchain blockchain = Blockchain.builder().network(Network.EMULATOR).contract(wallet).build();
assertThat(blockchain.deploy(30)).isTrue();
- blockchain.runGetMethod("seqno");
-
WalletV3Config configA =
WalletV3Config.builder()
.walletId(42)
@@ -293,7 +292,17 @@ public void testSendMessageCustomContractOnTestnetTolk() {
assertThat(blockchain.deploy(30)).isTrue();
GetterResult result = blockchain.runGetMethod("unique");
System.out.printf("result %s\n", result);
- System.out.printf("returned seqno %s\n", blockchain.runGetSeqNo());
+ System.out.printf("current seqno %s\n", blockchain.runGetSeqNo());
+
+ Cell bodyCell =
+ CellBuilder.beginCell()
+ .storeUint(0, 32) // seqno
+ .endCell();
+
+ Message extMsg = MsgUtils.createExternalMessage(dummyAddress, null, bodyCell);
+
+ blockchain.sendExternal(extMsg);
+ System.out.printf("current seqno %s\n", blockchain.runGetSeqNo());
}
@Test
@@ -312,7 +321,7 @@ public void testSendMessageCustomContractOnEmulatorTolk() {
.build();
assertThat(blockchain.deploy(30)).isTrue();
blockchain.runGetMethod("unique");
- System.out.printf("returned seqno %s\n", blockchain.runGetSeqNo());
+ System.out.printf("current seqno %s\n", blockchain.runGetSeqNo());
Cell bodyCell =
CellBuilder.beginCell()
@@ -321,8 +330,50 @@ public void testSendMessageCustomContractOnEmulatorTolk() {
Message extMsg = MsgUtils.createExternalMessage(dummyAddress, null, bodyCell);
- SendExternalResult result = blockchain.sendExternal(extMsg);
- // log.info("result {}", result);
+ blockchain.sendExternal(extMsg);
+ System.out.printf("current seqno %s\n", blockchain.runGetSeqNo());
+ }
+
+ @Test
+ public void testSendMessagesChainCustomContractOnEmulatorTolk() {
+ Blockchain blockchain =
+ Blockchain.builder()
+ .network(Network.EMULATOR)
+ .customContractAsResource("simple.tolk")
+ .customContractDataCell(
+ CellBuilder.beginCell()
+ .storeUint(0, 32)
+ .storeInt(Utils.getRandomInt(), 32)
+ .endCell())
+ // .tvmEmulatorVerbosityLevel(TvmVerbosityLevel.WITH_ALL_STACK_VALUES)
+ // .txEmulatorVerbosityLevel(TxVerbosityLevel.WITH_ALL_STACK_VALUES)
+ .build();
+ assertThat(blockchain.deploy(30)).isTrue();
+ blockchain.runGetMethod("unique");
+ BigInteger currentSeqno = blockchain.runGetSeqNo();
+ System.out.printf("current seqno %s\n", currentSeqno);
+
+ Cell bodyCell =
+ CellBuilder.beginCell()
+ .storeUint(0, 32) // seqno
+ .endCell();
+
+ Message extMsg = MsgUtils.createExternalMessage(dummyAddress, null, bodyCell);
+
+ blockchain.sendExternal(extMsg);
+
+ currentSeqno = blockchain.runGetSeqNo();
+ System.out.printf("current seqno %s\n", currentSeqno);
+
+ bodyCell =
+ CellBuilder.beginCell()
+ .storeUint(1, 32) // seqno
+ .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/pom.xml b/cell/pom.xml
index b9f485bf..7ea08942 100644
--- a/cell/pom.xml
+++ b/cell/pom.xml
@@ -90,7 +90,6 @@
ch.qos.logback
logback-classic
- test
org.assertj
diff --git a/cell/src/main/java/org/ton/java/cell/Cell.java b/cell/src/main/java/org/ton/java/cell/Cell.java
index e5fe9f1b..ad70d596 100644
--- a/cell/src/main/java/org/ton/java/cell/Cell.java
+++ b/cell/src/main/java/org/ton/java/cell/Cell.java
@@ -10,11 +10,13 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.java.bitstring.BitString;
import org.ton.java.utils.Utils;
/** Implements Cell class, where BitString having elements of Boolean type. */
+@Slf4j
public class Cell {
BitString bits;
@@ -210,7 +212,6 @@ public void calculateHashes() {
off = hashIndex - hashIndexOffset - 1;
byte[] partHash = new byte[32];
System.arraycopy(hashes, off * 32, partHash, 0, (off + 1) * 32);
- // System.out.println("partHash "+Utils.bytesToHex(partHash));
hash = Utils.concatBytes(hash, partHash);
}
@@ -597,7 +598,7 @@ public void toFile(String filename, boolean withCrc) {
try {
Files.write(Paths.get(filename), boc);
} catch (Exception e) {
- System.err.println("Cannot write to file. " + e.getMessage());
+ log.error("Cannot write to file. Error: {} ", e.getMessage());
}
}
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 761ff0b4..933695ec 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
@@ -4,6 +4,7 @@
import java.util.List;
import lombok.Builder;
import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
import org.ton.java.cell.Cell;
import org.ton.java.cell.CellBuilder;
import org.ton.java.cell.CellSlice;
@@ -22,6 +23,7 @@
*/
@Builder
@Data
+@Slf4j
public class Block {
long magic;
int globalId;
@@ -105,7 +107,7 @@ public List getAllTransactions() {
public void printAllTransactions() {
List txs = getAllTransactions();
if (txs.isEmpty()) {
- System.out.println("No transactions");
+ log.info("No transactions");
return;
}
Transaction.printTxHeader();
@@ -128,7 +130,7 @@ public List getAllMessageFees() {
public void printAllMessages() {
List msgFees = getAllMessageFees();
if (msgFees.isEmpty()) {
- System.out.println("No messages");
+ log.info("No messages");
return;
}
MessageFees.printMessageFeesHeader();
diff --git a/cell/src/main/java/org/ton/java/tlb/types/MessageFees.java b/cell/src/main/java/org/ton/java/tlb/types/MessageFees.java
index 76b970de..d9293ff3 100644
--- a/cell/src/main/java/org/ton/java/tlb/types/MessageFees.java
+++ b/cell/src/main/java/org/ton/java/tlb/types/MessageFees.java
@@ -5,11 +5,13 @@
import java.math.BigInteger;
import lombok.Builder;
import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.ton.java.utils.Utils;
@Builder
@Data
+@Slf4j
public class MessageFees {
String direction;
String type;
@@ -46,22 +48,23 @@ public void printMessageFees() {
isNull(msgFee.getCreatedLt()) ? "N/A" : msgFee.getCreatedLt().toString(),
getSrc(),
getDst());
- System.out.println(str);
+ log.info(str);
}
public static void printMessageFeesHeader() {
String header =
"| in/out | type | op | value | fwdFee | ihrFee | importFee | timestamp | lt | src | dst |";
- System.out.println("\nMessages");
- System.out.println(
+ log.info("");
+ log.info("Messages");
+ log.info(
"---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
- System.out.println(header);
- System.out.println(
+ log.info(header);
+ log.info(
"---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
}
public static void printMessageFeesFooter() {
- System.out.println(
+ log.info(
"---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
}
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 8ad8f8dc..9b1708f7 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
@@ -8,6 +8,7 @@
import java.util.List;
import lombok.Builder;
import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.ton.java.cell.Cell;
import org.ton.java.cell.CellBuilder;
@@ -39,6 +40,7 @@
*/
@Builder
@Data
+@Slf4j
public class Transaction {
int magic;
BigInteger accountAddr;
@@ -132,7 +134,7 @@ public static Transaction deserialize(CellSlice cs) {
// if (nonNull(tx.getInOut().getOut())) { // todo cleanup
// for (Map.Entry