Skip to content

Commit 7ee8b97

Browse files
committed
AdnlLiteClient - add tests to all contracts to test adnl liteclient usage; VmCellSlice serialization fix.
1 parent 94aacfc commit 7ee8b97

File tree

59 files changed

+4575
-889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4575
-889
lines changed

adnl/src/main/java/org/ton/java/adnl/AdnlLiteClient.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,14 @@ public Account getAccount(Address address) throws Exception {
929929
return getAccountState(getMasterchainInfo().getLast(), address).getAccount();
930930
}
931931

932+
public String getAccountStatus(Address address) throws Exception {
933+
Account account = getAccountState(getMasterchainInfo().getLast(), address).getAccount();
934+
if (account == null) {
935+
return "UNINIT";
936+
}
937+
return account.getAccountStorage().getAccountStatus();
938+
}
939+
932940
public AccountState getAccountState(BlockIdExt id, Address accountAddress) throws Exception {
933941
return executeWithRetry(
934942
() -> {
@@ -1118,7 +1126,7 @@ public RunMethodResult runMethod(
11181126
Address accountAddress, String methodName, VmStackValue... params) {
11191127
try {
11201128
List<VmStackValue> vmStackValuesReversed = Arrays.asList(params);
1121-
Collections.reverse(vmStackValuesReversed);
1129+
// Collections.reverse(vmStackValuesReversed);
11221130
VmStack vmStackParams =
11231131
VmStack.builder()
11241132
.depth(vmStackValuesReversed.size())
@@ -1889,7 +1897,7 @@ public void waitForBalanceChange(Address address, int timeoutSeconds) {
18891897
do {
18901898
if (++i * 2 >= timeoutSeconds) {
18911899
throw new Error(
1892-
"Balance of " + address.toRaw() + "was not changed within specified timeout.");
1900+
"Balance of " + address.toRaw() + " was not changed within specified timeout.");
18931901
}
18941902
Utils.sleep(2);
18951903
} while (initialBalance.equals(getBalance(address)));
@@ -1934,12 +1942,13 @@ public void sendRawMessageWithConfirmation(Message externalMessage, Address acco
19341942

19351943
TransactionList rawTransactions;
19361944
for (int i = 0; i < 12; i++) {
1937-
rawTransactions = getTransactions(account, 0, null, 10);
1945+
rawTransactions = getTransactions(account, 0, null, 2);
19381946
for (Transaction tx : rawTransactions.getTransactionsParsed()) {
19391947
if (nonNull(tx.getInOut().getIn())
19401948
&& Arrays.equals(
19411949
tx.getInOut().getIn().getNormalizedHash(), externalMessage.getNormalizedHash())) {
19421950
log.info("Message has been delivered.");
1951+
return;
19431952
}
19441953
}
19451954
Utils.sleep(5);

adnl/src/main/java/org/ton/java/adnl/AdnlTcpTransport.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ private void processIncomingPacket(byte[] packetData) {
293293

294294
if (!Arrays.equals(receivedChecksum, calculatedChecksum)) {
295295
log.info("Invalid packet checksum");
296-
log.info("Received checksum: {}", CryptoUtils.hex(receivedChecksum));
297-
log.info("Calculated checksum: {}", CryptoUtils.hex(calculatedChecksum));
296+
log.info(
297+
"Received checksum: {}, Calculated checksum: {}",
298+
CryptoUtils.hex(receivedChecksum),
299+
CryptoUtils.hex(calculatedChecksum));
298300
return;
299301
}
300302

smartcontract/src/main/java/org/ton/ton4j/smartcontract/LibraryDeployer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.ton.ton4j.smartcontract;
22

33
import static java.util.Objects.isNull;
4+
import static java.util.Objects.nonNull;
45

56
import lombok.Builder;
67
import lombok.Data;
@@ -90,6 +91,9 @@ public Message prepareDeployMsg() {
9091
}
9192

9293
public ExtMessageInfo deploy() {
94+
if (nonNull(adnlLiteClient)) {
95+
return send(prepareDeployMsg());
96+
}
9397
return tonlib.sendRawMessage(prepareDeployMsg().toCell().toBase64());
9498
}
9599
}
Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.ton.ton4j.smartcontract.dns;
22

3+
import static java.util.Objects.nonNull;
4+
35
import lombok.Builder;
6+
import org.ton.java.adnl.AdnlLiteClient;
47
import org.ton.ton4j.address.Address;
58
import org.ton.ton4j.cell.Cell;
69
import org.ton.ton4j.tonlib.Tonlib;
@@ -9,45 +12,53 @@
912
@Builder
1013
public class Dns {
1114

12-
public static final String DNS_CATEGORY_NEXT_RESOLVER = "dns_next_resolver"; // Smart Contract address
13-
public static final String DNS_CATEGORY_WALLET = "wallet"; // Smart Contract address
14-
public static final String DNS_CATEGORY_SITE = "site"; // ADNL address
15+
public static final String DNS_CATEGORY_NEXT_RESOLVER =
16+
"dns_next_resolver"; // Smart Contract address
17+
public static final String DNS_CATEGORY_WALLET = "wallet"; // Smart Contract address
18+
public static final String DNS_CATEGORY_SITE = "site"; // ADNL address
1519

16-
private Tonlib tonlib;
20+
private Tonlib tonlib;
21+
private AdnlLiteClient adnlLiteClient;
1722

18-
public Address getRootDnsAddress() {
19-
Cell cell = tonlib.getConfigParam(tonlib.getLast().getLast(), 4);
20-
byte[] byteArray = cell.getBits().toByteArray();
21-
if (byteArray.length != 256 / 8) {
22-
throw new Error("Invalid ConfigParam 4 length " + byteArray.length);
23-
}
24-
String hex = Utils.bytesToHex(byteArray);
25-
return Address.of("-1:" + hex);
23+
public Address getRootDnsAddress() {
24+
if (nonNull(adnlLiteClient)) {
25+
return Address.of("-1:" + adnlLiteClient.getConfigParam4().getDnsRootAddr());
2626
}
2727

28-
public Object resolve(String domain, String category, boolean oneStep) {
29-
Address rootDnsAddress = getRootDnsAddress();
30-
31-
return DnsUtils.dnsResolve(tonlib, rootDnsAddress, domain, category, oneStep);
28+
Cell cell = tonlib.getConfigParam(tonlib.getLast().getLast(), 4);
29+
byte[] byteArray = cell.getBits().toByteArray();
30+
if (byteArray.length != 256 / 8) {
31+
throw new Error("Invalid ConfigParam 4 length " + byteArray.length);
3232
}
33+
String hex = Utils.bytesToHex(byteArray);
34+
return Address.of("-1:" + hex);
35+
}
3336

34-
public Object resolve(String domain, String category) {
35-
return resolve(domain, category, false);
37+
public Object resolve(String domain, String category, boolean oneStep) {
38+
Address rootDnsAddress = getRootDnsAddress();
39+
if (nonNull(adnlLiteClient)) {
40+
return DnsUtils.dnsResolve(adnlLiteClient, rootDnsAddress, domain, category, oneStep);
3641
}
42+
return DnsUtils.dnsResolve(tonlib, rootDnsAddress, domain, category, oneStep);
43+
}
3744

38-
/**
39-
* @param domain String e.g "sub.alice.ton"
40-
* @return Address | null
41-
*/
42-
public Object getWalletAddress(String domain) {
43-
return this.resolve(domain, DNS_CATEGORY_WALLET);
44-
}
45+
public Object resolve(String domain, String category) {
46+
return resolve(domain, category, false);
47+
}
4548

46-
/**
47-
* @param domain String e.g "sub.alice.ton"
48-
* @return AdnlAddress | null
49-
*/
50-
public Object getSiteAddress(String domain) {
51-
return this.resolve(domain, DNS_CATEGORY_SITE);
52-
}
49+
/**
50+
* @param domain String e.g "sub.alice.ton"
51+
* @return Address | null
52+
*/
53+
public Object getWalletAddress(String domain) {
54+
return resolve(domain, DNS_CATEGORY_WALLET);
55+
}
56+
57+
/**
58+
* @param domain String e.g "sub.alice.ton"
59+
* @return AdnlAddress | null
60+
*/
61+
public Object getSiteAddress(String domain) {
62+
return resolve(domain, DNS_CATEGORY_SITE);
63+
}
5364
}

0 commit comments

Comments
 (0)