Skip to content

Commit

Permalink
rework run-method result parser
Browse files Browse the repository at this point in the history
  • Loading branch information
neodix42 committed Nov 23, 2022
1 parent ff2f52e commit 4c1d86b
Show file tree
Hide file tree
Showing 31 changed files with 570 additions and 897 deletions.
6 changes: 3 additions & 3 deletions smartcontract/custom-smc-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ Check if contract was deployed successfully
Tonlib tonlib = Tonlib.builder().build();

RunResult result = tonlib.runMethod(address,"seqno");
TvmStackEntryNumber seqno = (TvmStackEntryNumber) result.getStackEntry();
TvmStackEntryNumber seqno = (TvmStackEntryNumber) result.getStack();
log.info("seqno: {}", seqno.getNumber());

result=tonlib.runMethod(address, "get_x_data");
TvmStackEntryNumber x_data=(TvmStackEntryNumber)result.getStackEntry();
TvmStackEntryNumber x_data=(TvmStackEntryNumber)result.getStack();
log.info("x_data: {}", seqno.getNumber());

result=tonlib.runMethod(address,"get_extra_field");
TvmStackEntryNumber extra_field = (TvmStackEntryNumber)result.getStackEntry();
TvmStackEntryNumber extra_field = (TvmStackEntryNumber)result.getStack();
log.info("extra_field: {}", seqno.getNumber());

// result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public CollectionData getCollectionData(Tonlib tonlib) {
throw new Error("method get_collection_data, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber nextItemIndexResult = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber nextItemIndexResult = (TvmStackEntryNumber) result.getStack().get(0);
long nextItemIndex = nextItemIndexResult.getNumber().longValue();

TvmStackEntryCell collectionContentResult = (TvmStackEntryCell) result.getStackEntry().get(1); // cell or slice
TvmStackEntryCell collectionContentResult = (TvmStackEntryCell) result.getStack().get(1); // cell or slice
Cell collectionContent = Cell.fromBoc(Utils.base64ToBytes(collectionContentResult.getCell().getBytes()));
String collectionContentUri = NftUtils.parseOffchainUriCell(collectionContent);

Expand Down Expand Up @@ -132,7 +132,7 @@ public Address getNftItemAddressByIndex(Tonlib tonlib, BigInteger index) {
throw new Error("method get_nft_address_by_index, returned an exit code " + result.getExit_code());
}

TvmStackEntryCell addr = (TvmStackEntryCell) result.getStackEntry().get(0);
TvmStackEntryCell addr = (TvmStackEntryCell) result.getStack().get(0);
return NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(addr.getCell().getBytes())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ public ItemData getData(Tonlib tonlib) {
throw new Error("method get_nft_data, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber isInitializedNumber = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber isInitializedNumber = (TvmStackEntryNumber) result.getStack().get(0);
boolean isInitialized = isInitializedNumber.getNumber().longValue() == -1;

BigInteger index = ((TvmStackEntryNumber) result.getStackEntry().get(1)).getNumber();
BigInteger index = ((TvmStackEntryNumber) result.getStack().get(1)).getNumber();

TvmStackEntryCell collectionAddr = (TvmStackEntryCell) result.getStackEntry().get(2);
TvmStackEntryCell collectionAddr = (TvmStackEntryCell) result.getStack().get(2);
Address collectionAddress = NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(collectionAddr.getCell().getBytes())));

TvmStackEntryCell ownerAddr = (TvmStackEntryCell) result.getStackEntry().get(3);
TvmStackEntryCell ownerAddr = (TvmStackEntryCell) result.getStack().get(3);
Address ownerAddress = isInitialized ? NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(ownerAddr.getCell().getBytes()))) : null;

TvmStackEntryCell contentC = (TvmStackEntryCell) result.getStackEntry().get(4);
TvmStackEntryCell contentC = (TvmStackEntryCell) result.getStack().get(4);
Cell contentCell = CellBuilder.fromBoc(Utils.base64ToBytes(contentC.getCell().getBytes()));

return ItemData.builder()
Expand Down Expand Up @@ -152,7 +152,7 @@ public String getDomain(Tonlib tonlib) {
throw new Error("method get_domain, returned an exit code " + result.getExit_code());
}

TvmStackEntryCell domainCell = (TvmStackEntryCell) result.getStackEntry().get(0);
TvmStackEntryCell domainCell = (TvmStackEntryCell) result.getStack().get(0);
return new String(CellBuilder.fromBoc(Utils.base64ToBytes(domainCell.getCell().getBytes())).bits.toByteArray());
}

Expand All @@ -164,7 +164,7 @@ public Address getEditor(Tonlib tonlib) {
throw new Error("method get_editor, returned an exit code " + result.getExit_code());
}

TvmStackEntryCell editorCell = (TvmStackEntryCell) result.getStackEntry().get(0);
TvmStackEntryCell editorCell = (TvmStackEntryCell) result.getStack().get(0);
return NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(editorCell.getCell().getBytes())));
}

Expand All @@ -179,13 +179,13 @@ public AuctionInfo getAuctionInfo(Tonlib tonlib) {
throw new Error("method get_auction_info, returned an exit code " + result.getExit_code());
}

TvmStackEntryCell maxBidAddressCell = (TvmStackEntryCell) result.getStackEntry().get(0);
TvmStackEntryCell maxBidAddressCell = (TvmStackEntryCell) result.getStack().get(0);
Address maxBidAddress = NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(maxBidAddressCell.getCell().getBytes())));

TvmStackEntryNumber maxBidAmountNumber = (TvmStackEntryNumber) result.getStackEntry().get(1);
TvmStackEntryNumber maxBidAmountNumber = (TvmStackEntryNumber) result.getStack().get(1);
BigInteger maxBidAmount = maxBidAmountNumber.getNumber();

TvmStackEntryNumber auctionEndTimeNumber = (TvmStackEntryNumber) result.getStackEntry().get(2);
TvmStackEntryNumber auctionEndTimeNumber = (TvmStackEntryNumber) result.getStack().get(2);
long auctionEndTime = auctionEndTimeNumber.getNumber().longValue();

return AuctionInfo.builder()
Expand All @@ -203,7 +203,7 @@ public long getLastFillUpTime(Tonlib tonlib) {
throw new Error("method get_last_fill_up_time, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber time = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber time = (TvmStackEntryNumber) result.getStack().get(0);
return time.getNumber().longValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ private static Object dnsResolveImpl(Tonlib tonlib, Address dnsAddress, byte[] r
stack.offer("[num, " + categoryInteger + "]");

RunResult result = tonlib.runMethod(dnsAddress, "dnsresolve", stack);
if (result.getStackEntry().size() != 2) {
if (result.getStack().size() != 2) {
throw new Error("Invalid dnsresolve response");
}

Cell cell = null;

int resultLen = ((TvmStackEntryNumber) result.getStackEntry().get(0)).getNumber().intValue();
Object r = result.getStackEntry().get(1);
int resultLen = ((TvmStackEntryNumber) result.getStack().get(0)).getNumber().intValue();
Object r = result.getStack().get(1);
if (r instanceof TvmStackEntryCell) {
TvmStackEntryCell cellResult = (TvmStackEntryCell) result.getStackEntry().get(1);
TvmStackEntryCell cellResult = (TvmStackEntryCell) result.getStack().get(1);
cell = CellBuilder.fromBoc(Utils.base64ToBytes(cellResult.getCell().getBytes()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public long getWalletId(Tonlib tonlib) {

Address myAddress = getAddress();
RunResult result = tonlib.runMethod(myAddress, "wallet_id");
TvmStackEntryNumber subWalletId = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber subWalletId = (TvmStackEntryNumber) result.getStack().get(0);

return subWalletId.getNumber().longValue();
}
Expand All @@ -149,7 +149,7 @@ public String getPublicKey(Tonlib tonlib) {

Address myAddress = getAddress();
RunResult result = tonlib.runMethod(myAddress, "get_public_key");
TvmStackEntryNumber pubkey = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber pubkey = (TvmStackEntryNumber) result.getStack().get(0);

return pubkey.getNumber().toString(16);
}
Expand All @@ -165,7 +165,7 @@ public boolean check_destination(Tonlib tonlib, String destination) {
stack.offer("[slice, " + c.endCell().toHex(true) + "]");

RunResult result = tonlib.runMethod(myAddress, "check_destination", stack);
TvmStackEntryNumber found = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber found = (TvmStackEntryNumber) result.getStack().get(0);

return (found.getNumber().intValue() == -1);
}
Expand Down Expand Up @@ -201,9 +201,9 @@ public BigInteger getNominalLockedBalance(Tonlib tonlib) {
public List<BigInteger> getBalances(Tonlib tonlib) {
Address myAddress = getAddress();
RunResult result = tonlib.runMethod(myAddress, "get_balances");
TvmStackEntryNumber balance = (TvmStackEntryNumber) result.getStackEntry().get(0); // ton balance
TvmStackEntryNumber restrictedValue = (TvmStackEntryNumber) result.getStackEntry().get(1); // total_restricted_value
TvmStackEntryNumber lockedValue = (TvmStackEntryNumber) result.getStackEntry().get(2); // total_locked_value
TvmStackEntryNumber balance = (TvmStackEntryNumber) result.getStack().get(0); // ton balance
TvmStackEntryNumber restrictedValue = (TvmStackEntryNumber) result.getStack().get(1); // total_restricted_value
TvmStackEntryNumber lockedValue = (TvmStackEntryNumber) result.getStack().get(2); // total_locked_value

return List.of(
balance.getNumber(),
Expand All @@ -216,7 +216,7 @@ public long getSeqno(Tonlib tonlib) {

Address myAddress = getAddress();
RunResult result = tonlib.runMethod(myAddress, "seqno");
TvmStackEntryNumber seqno = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber seqno = (TvmStackEntryNumber) result.getStack().get(0);

return seqno.getNumber().longValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public BigInteger getChannelState(Tonlib tonlib) {
throw new Error("method get_channel_state, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber addr = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber addr = (TvmStackEntryNumber) result.getStack().get(0);
return addr.getNumber();
}

Expand All @@ -264,35 +264,35 @@ public ChannelData getData(Tonlib tonlib) {
throw new Error("method get_channel_data, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber stateNumber = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber stateNumber = (TvmStackEntryNumber) result.getStack().get(0);

TvmStackEntryTuple balanceTuple = (TvmStackEntryTuple) result.getStackEntry().get(1);
TvmStackEntryTuple balanceTuple = (TvmStackEntryTuple) result.getStack().get(1);
TvmStackEntryNumber balanceA = (TvmStackEntryNumber) balanceTuple.getTuple().getElements().get(0);
TvmStackEntryNumber balanceB = (TvmStackEntryNumber) balanceTuple.getTuple().getElements().get(1);

TvmStackEntryTuple keyTuple = (TvmStackEntryTuple) result.getStackEntry().get(2);
TvmStackEntryTuple keyTuple = (TvmStackEntryTuple) result.getStack().get(2);
TvmStackEntryNumber publicKeyA = (TvmStackEntryNumber) keyTuple.getTuple().getElements().get(0);
TvmStackEntryNumber publicKeyB = (TvmStackEntryNumber) keyTuple.getTuple().getElements().get(1);

TvmStackEntryNumber channelIdNumber = (TvmStackEntryNumber) result.getStackEntry().get(3);
TvmStackEntryNumber channelIdNumber = (TvmStackEntryNumber) result.getStack().get(3);

TvmStackEntryTuple closureConfigTuple = (TvmStackEntryTuple) result.getStackEntry().get(4);
TvmStackEntryTuple closureConfigTuple = (TvmStackEntryTuple) result.getStack().get(4);
TvmStackEntryNumber quarantineDuration = (TvmStackEntryNumber) closureConfigTuple.getTuple().getElements().get(0);
TvmStackEntryNumber misbehaviourFine = (TvmStackEntryNumber) closureConfigTuple.getTuple().getElements().get(1);
TvmStackEntryNumber conditionalCloseDuration = (TvmStackEntryNumber) closureConfigTuple.getTuple().getElements().get(2);

TvmStackEntryTuple commitedSeqnoTuple = (TvmStackEntryTuple) result.getStackEntry().get(5);
TvmStackEntryTuple commitedSeqnoTuple = (TvmStackEntryTuple) result.getStack().get(5);
TvmStackEntryNumber seqnoA = (TvmStackEntryNumber) commitedSeqnoTuple.getTuple().getElements().get(0);
TvmStackEntryNumber seqnoB = (TvmStackEntryNumber) commitedSeqnoTuple.getTuple().getElements().get(1);

Cell quarantine = null;
TvmStackEntryList quarantineList = (TvmStackEntryList) result.getStackEntry().get(6);
TvmStackEntryList quarantineList = (TvmStackEntryList) result.getStack().get(6);
for (Object o : quarantineList.getList().getElements()) {
TvmStackEntryCell t = (TvmStackEntryCell) o;
quarantine = CellBuilder.fromBoc(Utils.base64ToBytes(t.getCell().getBytes()));
}

TvmStackEntryTuple trippleTuple = (TvmStackEntryTuple) result.getStackEntry().get(7);
TvmStackEntryTuple trippleTuple = (TvmStackEntryTuple) result.getStack().get(7);
TvmStackEntryNumber excessFee = (TvmStackEntryNumber) trippleTuple.getTuple().getElements().get(0);

TvmStackEntryCell addressACell = (TvmStackEntryCell) trippleTuple.getTuple().getElements().get(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ public JettonMinterData getJettonData(Tonlib tonlib) {
throw new Error("method get_nft_data, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber totalSupplyNumber = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber totalSupplyNumber = (TvmStackEntryNumber) result.getStack().get(0);
BigInteger totalSupply = totalSupplyNumber.getNumber();

System.out.println("minter totalSupply: " + Utils.formatNanoValue(totalSupply));

boolean isMutable = ((TvmStackEntryNumber) result.getStackEntry().get(1)).getNumber().longValue() == -1;
boolean isMutable = ((TvmStackEntryNumber) result.getStack().get(1)).getNumber().longValue() == -1;

TvmStackEntryCell adminAddr = (TvmStackEntryCell) result.getStackEntry().get(2);
TvmStackEntryCell adminAddr = (TvmStackEntryCell) result.getStack().get(2);
Address adminAddress = NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(adminAddr.getCell().getBytes())));

TvmStackEntryCell jettonContent = (TvmStackEntryCell) result.getStackEntry().get(3);
TvmStackEntryCell jettonContent = (TvmStackEntryCell) result.getStack().get(3);
Cell jettonContentCell = CellBuilder.fromBoc(Utils.base64ToBytes(jettonContent.getCell().getBytes()));
String jettonContentUri = null;
try {
Expand All @@ -178,7 +178,7 @@ public JettonMinterData getJettonData(Tonlib tonlib) {
//todo
}

TvmStackEntryCell contentC = (TvmStackEntryCell) result.getStackEntry().get(4);
TvmStackEntryCell contentC = (TvmStackEntryCell) result.getStack().get(4);
Cell jettonWalletCode = CellBuilder.fromBoc(Utils.base64ToBytes(contentC.getCell().getBytes()));

return JettonMinterData.builder()
Expand All @@ -199,7 +199,7 @@ public BigInteger getTotalSupply(Tonlib tonlib) {
throw new Error("method get_jetton_data, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber totalSupplyNumber = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber totalSupplyNumber = (TvmStackEntryNumber) result.getStack().get(0);
return totalSupplyNumber.getNumber();
}

Expand All @@ -223,7 +223,7 @@ public Address getJettonWalletAddress(Tonlib tonlib, Address ownerAddress) {
throw new Error("method get_wallet_address, returned an exit code " + result.getExit_code());
}

TvmStackEntryCell addr = (TvmStackEntryCell) result.getStackEntry().get(0);
TvmStackEntryCell addr = (TvmStackEntryCell) result.getStack().get(0);
return NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(addr.getCell().getBytes())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ public JettonWalletData getData(Tonlib tonlib) {
throw new Error("method get_wallet_data, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber balanceNumber = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber balanceNumber = (TvmStackEntryNumber) result.getStack().get(0);
BigInteger balance = balanceNumber.getNumber();

TvmStackEntryCell ownerAddr = (TvmStackEntryCell) result.getStackEntry().get(1);
TvmStackEntryCell ownerAddr = (TvmStackEntryCell) result.getStack().get(1);
Address ownerAddress = NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(ownerAddr.getCell().getBytes())));

TvmStackEntryCell jettonMinterAddr = (TvmStackEntryCell) result.getStackEntry().get(2);
TvmStackEntryCell jettonMinterAddr = (TvmStackEntryCell) result.getStack().get(2);
Address jettonMinterAddress = NftUtils.parseAddress(CellBuilder.fromBoc(Utils.base64ToBytes(jettonMinterAddr.getCell().getBytes())));

TvmStackEntryCell jettonWallet = (TvmStackEntryCell) result.getStackEntry().get(3);
TvmStackEntryCell jettonWallet = (TvmStackEntryCell) result.getStack().get(3);
Cell jettonWalletCode = CellBuilder.fromBoc(Utils.base64ToBytes(jettonWallet.getCell().getBytes()));
return JettonWalletData.builder()
.balance(balance)
Expand All @@ -131,7 +131,7 @@ public BigInteger getBalance(Tonlib tonlib) {
throw new Error("method get_wallet_data, returned an exit code " + result.getExit_code());
}

TvmStackEntryNumber balanceNumber = (TvmStackEntryNumber) result.getStackEntry().get(0);
TvmStackEntryNumber balanceNumber = (TvmStackEntryNumber) result.getStack().get(0);
return balanceNumber.getNumber();
}
}
Loading

0 comments on commit 4c1d86b

Please sign in to comment.