Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getNextNonce should return BigInteger.ONE if account doesn't exist #66

Closed
marc0olo opened this issue Jul 14, 2021 · 10 comments
Closed

getNextNonce should return BigInteger.ONE if account doesn't exist #66

marc0olo opened this issue Jul 14, 2021 · 10 comments
Assignees
Labels
bug Something isn't working
Projects

Comments

@marc0olo
Copy link
Member

I tried to perform dry-run calls and those always failed because getNextNonce() doesn't handle Account not found properly

image

we should return BigInteger.ONE if the account does not exist yet which should allow us to perform the dry-run call

@marc0olo marc0olo added the bug Something isn't working label Jul 14, 2021
@marc0olo
Copy link
Member Author

would be good to have this fixed quickly because I want to add a new example to the showcase repo which requires this as it runs against mainnet (TokenMigration contract)

@marc0olo
Copy link
Member Author

@mitch-lbw I think we can close this. just tried the workaround and I am getting an error for the dry-run call:

  • Internal error: insufficient_funds

so it probably doesn't matter. maybe it's possible to provide an option to the dry-run endpoint to ignore insufficient funds

@marc0olo
Copy link
Member Author

seems like it is possible to provide an amount for dry-run calls, see discussion here aeternity/aeternity#3677

@marc0olo
Copy link
Member Author

marc0olo commented Jul 14, 2021

so the bug here is still valid as we need to cover Account not found anyway.

@mitch-lbw we need to think about how and where we want to provide this. it probably makes sense to additionally introduce a new config-param for the AeternityServiceConfiguration in the SDK where a user can optionally define an amount to be used for the account that performs a dry-run call.

@marc0olo
Copy link
Member Author

marc0olo commented Jul 14, 2021

amount should also be quite easy to add:

  private DryRunTransactionResult dryRunCall(ContractCallTransactionModel contractCallModel,
      String functionName) {
    DryRunTransactionResults dryRunResults = aeternityService.transactions.blockingDryRunTransactions(DryRunRequest.builder().build().transactionInputItem(contractCallModel).account(DryRunAccountModel.builder().amount(new BigInteger("100000000000000000000000000000000000").publicKey(this.config.getKeyPair().getAddress()).build()));
    if(dryRunResults.getResults() != null && dryRunResults.getResults().size()>0) {
      return dryRunResults.getResults().get(0);
    }
    Object dryRunErrorMessage = dryRunResults.getResults().get(0).getContractCallObject().getReturnValue();
    try{dryRunErrorMessage=this.aeternityService.compiler.blockingDecodeCallResult(aesSourcecode,functionName,dryRunResults.getResults().get(0).getContractCallObject().getReturnType(),dryRunResults.getResults().get(0).getContractCallObject().getReturnValue(),aesIncludes).getResult();} catch(Exception e){}throw new RuntimeException(String.format("\n"
            + "Dry run call of function %s failed: %s\n"
            + "Causing Exception: %s%nException Details: %s\n"
            + "Exception Hint   : %s",functionName,dryRunErrorMessage,dryRunResults.getAeAPIErrorMessage(),dryRunResults.getRootErrorMessage(),"Please validate your input data"));
  }

in the snippet above (generated by the plugin) I added .amount(new BigInteger("100000000000000000000000000000000000") to the builder of the DryRunAccountModel

note

  • so just simply adding an amount to the DryRunAccount probably does work if the amount is enough to cover the potential fees, e.g. BigInteger.TEN (which I tested first) obviously wasn't enough

@marc0olo
Copy link
Member Author

the javascript sdk e.g. always uses the zero address with a pre-defined amount for every dry-run call.

see:

doing it that way would allow us to skip the requirement of having a configured keypair and we could use this for every static call. the next nonce would always be 2 for that account

@mitch-lbw mitch-lbw added this to To do in v2.0.0 Aug 28, 2021
@mitch-lbw mitch-lbw moved this from To do to In progress in v2.0.0 Aug 28, 2021
@mitch-lbw
Copy link
Member

Will be fixed with kryptokrauts/aepp-sdk-java#173

@marc0olo
Copy link
Member Author

marc0olo commented Nov 8, 2021

@mitch-lbw can/should we close this then?

@mitch-lbw
Copy link
Member

Yes we can close this issue

@mitch-lbw
Copy link
Member

fixed with kryptokrauts/aepp-sdk-java#173

@mitch-lbw mitch-lbw moved this from In progress to Done in v2.0.0 Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
v2.0.0
  
Done
Development

No branches or pull requests

2 participants