Skip to content

Commit

Permalink
- bug fixing; handle error retrieving seqno; #7
Browse files Browse the repository at this point in the history
  • Loading branch information
neodix42 committed Sep 8, 2022
1 parent 575679e commit bfd2c6f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 74 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/windows-build.yml

This file was deleted.

3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
### Changes in this release
- fix missing validator-engine for MacOS arm64

- bug fixing; handle error retrieving seqno; https://github.com/neodiX42/MyLocalTon/issues/7
94 changes: 51 additions & 43 deletions src/main/java/org/ton/actions/MyLocalTon.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.ton.db.entities.WalletEntity;
import org.ton.db.entities.WalletPk;
import org.ton.enums.LiteClientEnum;
import org.ton.exceptions.WrongSeqnoException;
import org.ton.executors.fift.Fift;
import org.ton.executors.liteclient.LiteClient;
import org.ton.executors.liteclient.LiteClientParser;
Expand Down Expand Up @@ -411,7 +412,7 @@ public void createPreInstalledWallets(Node genesisNode) throws Exception {
wallet.setSeqno(stateAndSeqno.getRight());
updateAccountsTabGui(wallet);
} catch (Exception e) {
log.error("Error updating account state. Wallet {}, AccountState {}, seqno {}", wallet.getWallet().getFullWalletAddress(), stateAndSeqno.getLeft(), stateAndSeqno.getRight());
log.error("Error updating account state. Wallet {}, AccountState {}, seqno {}. {}", wallet.getWallet().getFullWalletAddress(), stateAndSeqno.getLeft(), stateAndSeqno.getRight(), e.getMessage());
}
}
}
Expand Down Expand Up @@ -676,7 +677,7 @@ private void detectNewAccount(ResultLastBlock lastBlock, boolean updateGuiNow, R
tx.getTxSeqno(), tx.getLt(), lastBlock.getShortBlockSeqno());
WalletEntity walletEntity = insertNewAccountEntity(lastBlock, txDetails);

if (updateGuiNow) {
if (updateGuiNow && !isNull(walletEntity)) {
updateAccountsTabGui(walletEntity);
}
}
Expand Down Expand Up @@ -1176,52 +1177,56 @@ public List<TxEntity> extractTxsAndMsgs(ResultLastBlock lastBlock, ResultListBlo

public WalletEntity insertNewAccountEntity(ResultLastBlock lastBlock, Transaction txDetails) {

//AccountState accountState = LiteClientParser.parseGetAccount(LiteClientExecutor.getInstance().executeGetAccount(settings.getGenesisNode(), lastBlock.getWc() + ":" + txDetails.getAccountAddr()));
Pair<AccountState, Long> stateAndSeqno = getAccountStateAndSeqno(settings.getGenesisNode(), lastBlock.getWc() + ":" + txDetails.getAccountAddr());
log.debug("insertAccountEntity, wallet {}:{}, balance {}, state {}", stateAndSeqno.getLeft().getWc(), stateAndSeqno.getLeft().getAddress(), stateAndSeqno.getLeft().getBalance(), stateAndSeqno.getLeft().getStatus());
try {
Pair<AccountState, Long> stateAndSeqno = getAccountStateAndSeqno(settings.getGenesisNode(), lastBlock.getWc() + ":" + txDetails.getAccountAddr());
log.debug("insertAccountEntity, wallet {}:{}, balance {}, state {}", stateAndSeqno.getLeft().getWc(), stateAndSeqno.getLeft().getAddress(), stateAndSeqno.getLeft().getBalance(), stateAndSeqno.getLeft().getStatus());

Pair<WalletVersion, Long> walletVersionAndId = Utils.detectWalledVersionAndId(stateAndSeqno.getLeft());
Pair<WalletVersion, Long> walletVersionAndId = Utils.detectWalledVersionAndId(stateAndSeqno.getLeft());

WalletEntity foundWallet = App.dbPool.findWallet(WalletPk.builder()
.wc(lastBlock.getWc())
.hexAddress(txDetails.getAccountAddr())
.build());
WalletEntity foundWallet = App.dbPool.findWallet(WalletPk.builder()
.wc(lastBlock.getWc())
.hexAddress(txDetails.getAccountAddr())
.build());

if (isNull(foundWallet)) {
if (isNull(foundWallet)) {

WalletAddress wa = new Fift().convertAddr(settings.getGenesisNode(), lastBlock.getWc() + ":" + txDetails.getAccountAddr());
WalletAddress wa = new Fift().convertAddr(settings.getGenesisNode(), lastBlock.getWc() + ":" + txDetails.getAccountAddr());

WalletAddress walletAddress = WalletAddress.builder()
.wc(lastBlock.getWc())
.hexWalletAddress(txDetails.getAccountAddr())
.subWalletId(walletVersionAndId.getRight())
.fullWalletAddress(lastBlock.getWc() + ":" + txDetails.getAccountAddr())
.bounceableAddressBase64url(wa.getBounceableAddressBase64url())
.nonBounceableAddressBase64Url(wa.getNonBounceableAddressBase64Url())
.bounceableAddressBase64(wa.getBounceableAddressBase64())
.nonBounceableAddressBase64(wa.getNonBounceableAddressBase64())
.build();

WalletEntity walletEntity = WalletEntity.builder()
.wc(walletAddress.getWc())
.hexAddress(walletAddress.getHexWalletAddress())
.subWalletId(walletAddress.getSubWalletId())
.walletVersion(walletVersionAndId.getLeft())
.wallet(walletAddress)
.accountState(stateAndSeqno.getLeft())
.createdAt(txDetails.getNow())
.build();

App.dbPool.insertWallet(walletEntity);

return walletEntity;
} else {
foundWallet.setAccountState(stateAndSeqno.getLeft());
foundWallet.setSeqno(stateAndSeqno.getRight());
log.debug("Wallet found! Update state {}", foundWallet.getFullAddress()); // update state
App.dbPool.updateWalletStateAndSeqno(foundWallet, stateAndSeqno.getLeft(), stateAndSeqno.getRight());
WalletAddress walletAddress = WalletAddress.builder()
.wc(lastBlock.getWc())
.hexWalletAddress(txDetails.getAccountAddr())
.subWalletId(walletVersionAndId.getRight())
.fullWalletAddress(lastBlock.getWc() + ":" + txDetails.getAccountAddr())
.bounceableAddressBase64url(wa.getBounceableAddressBase64url())
.nonBounceableAddressBase64Url(wa.getNonBounceableAddressBase64Url())
.bounceableAddressBase64(wa.getBounceableAddressBase64())
.nonBounceableAddressBase64(wa.getNonBounceableAddressBase64())
.build();

return foundWallet;
WalletEntity walletEntity = WalletEntity.builder()
.wc(walletAddress.getWc())
.hexAddress(walletAddress.getHexWalletAddress())
.subWalletId(walletAddress.getSubWalletId())
.walletVersion(walletVersionAndId.getLeft())
.wallet(walletAddress)
.accountState(stateAndSeqno.getLeft())
.createdAt(txDetails.getNow())
.build();

App.dbPool.insertWallet(walletEntity);

return walletEntity;
} else {
foundWallet.setAccountState(stateAndSeqno.getLeft());
foundWallet.setSeqno(stateAndSeqno.getRight());
log.debug("Wallet found! Update state {}", foundWallet.getFullAddress()); // update state
App.dbPool.updateWalletStateAndSeqno(foundWallet, stateAndSeqno.getLeft(), stateAndSeqno.getRight());

return foundWallet;
}
} catch (Exception e) {
log.error("Error executing insertNewAccountEntity: {}", e.getMessage());
return null;
}
}

Expand Down Expand Up @@ -1496,10 +1501,13 @@ public void runAccountsMonitor() {
}, 0L, 5L, TimeUnit.SECONDS);
}

Pair<AccountState, Long> getAccountStateAndSeqno(Node node, String address) {
Pair<AccountState, Long> getAccountStateAndSeqno(Node node, String address) throws WrongSeqnoException {
AccountState accountState = LiteClientParser.parseGetAccount(LiteClient.getInstance(LiteClientEnum.GLOBAL).executeGetAccount(node, address));
if (nonNull(accountState.getBalance())) {
long seqno = LiteClient.getInstance(LiteClientEnum.GLOBAL).executeGetSeqno(getInstance().getSettings().getGenesisNode(), address);
if (seqno == -1L) {
throw new WrongSeqnoException("Cannot retrieve seqno from contract " + address);
}
return Pair.of(accountState, seqno);
}
return Pair.of(null, -1L);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/ton/exceptions/WrongSeqnoException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.ton.exceptions;

public class WrongSeqnoException extends Exception {
public WrongSeqnoException(String errorMessage) {
super(errorMessage);
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/ton/ui/controllers/YesNoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ private void doCreateAccount() {
MyLocalTon.getInstance().getSettings().getWalletSettings().getInitialAmount(),
false);

if (nonNull(walletEntity)) {
if (nonNull(walletEntity) && walletEntity.getSeqno() != -1L) {
App.mainController.showSuccessMsg("Wallet " + walletEntity.getFullAddress() + " created", 3);
} else {
App.mainController.showErrorMsg("Error creating wallet " + walletEntity.getFullAddress() + ". See logs for details.", 4);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/ton/wallet/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public Boolean sendTonCoins(SendToncoinsParam sendToncoinsParam) throws Exceptio
sendToncoinsParam.getAmount(),
sendToncoinsParam.getDestAddr());

if (seqno == -1L) {
log.error("Error retrieving seqno from contract {}", sendToncoinsParam.getFromWallet().getFullWalletAddress());
return false;
}

String externalMsgLocation = new Fift().prepareSendTonCoinsFromNodeWallet(sendToncoinsParam, seqno);

if (isNull(externalMsgLocation)) {
Expand Down

0 comments on commit bfd2c6f

Please sign in to comment.