Skip to content

Conversation

@barnjamin
Copy link
Contributor

Untested, will work on that next but please take a look and make sure it's reasonable.

Seems like too many args for the method
Had to set the logic.StateSchema bytes/ints to public since that is what is used in Transaction class (tho we also have it in models?)

@barnjamin barnjamin requested review from ahangsu and winder December 10, 2021 19:14
Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a helpful utility. I haven't used the DryRun feature, so I'll let @ahangsu respond to the correctness of how that is being constructed.

For my part, just some small cleanup requests.

@barnjamin
Copy link
Contributor Author

While testing this with tealdbg && msgpack encoded DryrunRequest, I found that tealdbg is expecting the programs to be a byte array but I'm not sure I can force the output of Encoder.encodeToMsgpack(drr) to be the raw bytes.

Guessing here without digging too deep into the encoder/decoder stuff but I think this decorator is used to flag the property we use when decoding and when its called, it automatically b64 encodes the underlying bytes:
https://github.com/algorand/java-algorand-sdk/blob/develop/src/main/java/com/algorand/algosdk/v2/client/model/ApplicationParams.java#L27

...
      "params": {
        "approval-program": "BSAIBAAKAWQCBgMmAwNyYWIBcANnb3YxGCMSQACyMRmBBRJAAKQxGSISQACXMRkhBRJAAIsxGSUSQACAMRkjEkAAAQA2GgCAB2RlcG9zaXQSQABiNhoAgAh3aXRoZHJhdxJAAEs2GgCABHN3YXASQAA4NhoAgAphZG1pbl9pbml0EkAAHzYaAIAMYWRtaW5fdXBkYXRlEkAAAQA2HAGIAfVCAC2IAgFCACeIAUBCACGIAOFCABuIADtCABUjQgARJUIADYgBuEIAB4gBskIAASVDMgokcAA1AzUEMgokcAA1BTUGNAM0BRBEKDQENAYKZyhkiTIEIQcSNjAAJBI2MAEhBBIQEDMAECEGEhA3ADAAMwEREhA3ADABMwIREhAzARAiEhAzARQyChIQMwERJBIQMwIQIhIQMwIUMgoSEDMCESEEEhAzAAAzAQASEDMBADMCABIQRCMoZTUBNQI0AUAABoj/bEIAAjQCNQAzAhI0AAszARISRLEishApZLIRMwESNAAKMwISCLISNhwAsgezJYkyBCEFEjYwACQSNjABIQQSEBAzABAhBhIQMwEQIhIQMwEUMgoSEDMBESlkEhBEsSKyECSyETMBEihkCrISMQCyFLOxIrIQIQSyETMBEihkCrISMQCyFLMliTYwADYwAQ1AAAaIAEZCAAOIAAGJMgQhBRI2MAAkEjYwASEEEhAQMwAQIQYSEDMBECISEDMBESQSEDMBEiMNEESxIrIQIQSyETMBEihkCrISsyWJMgQhBRI2MAAkEjYwASEEEhAQMwAQIQYSEDMBECISEDMBESEEEhAzARIjDRBEsSKyECSyETMBEihkC7ISsyWJIyplNQc1CDEANAdAAAUyCUIAAjQIEok1CYj/5EAABCNCAAUqNAlnJYmI/9RAAAQjQgADiAABibEhB7IQgA1EZW1vUG9vbFRva2VusiaAA2RwdLIlgYCU69wDsiIjsiMyCrIpMgqyKrMpMTxnJYk=",
...

@ahangsu
Copy link
Contributor

ahangsu commented Dec 16, 2021

@barnjamin I think your observation is correct, namely it automatically encodes the raw bytes in b64 format.
Minor question: do we want to enforce the program bytes to be exactly in raw byte format?

@barnjamin
Copy link
Contributor Author

do we want to enforce the program bytes to be exactly in raw byte format?

In order for it to be read by tealdbg when passing a msgp formated dryrun request, it must be the raw bytes. The decoder logic of tealdbg tries to interpret the b64 string as the bytes of an assembled program.

We need to either add something to this SDK to allow it or tweak the decoder in tealdbg to figure out it should try to b64 decode the bytes.

Or maybe there is another option?

Copy link
Contributor

@ahangsu ahangsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@winder winder self-requested a review February 14, 2022 19:42
@barnjamin barnjamin requested a review from ahangsu March 16, 2022 13:44
public void approvalProgram(String base64Encoded) {
this.approvalProgram = Encoder.decodeFromBase64(base64Encoded);
}
@JsonProperty("approval-program")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the model code seems to be generated from https://github.com/algorand/generator/blob/master/src/main/java/com/algorand/sdkutils/listeners/JavaGenerator.java#L970-L986, I haven't checked whether we want to remove this annotation, but apparently there are two options:

  • open a PR for generator in favor of this PR
  • if the annotation does not hurt the behavior, then revert it back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open one for generator, removing this annotation allows us to pass the bytes for the approval/clear program as bytes when we msgpack encode them rather than getting the b64 encoded version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping me once this is opened, and hopefully nothing's broken 😅

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary import

assets.addAll(tx.foreignAssets);
}

if (tx.accounts.size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw in implementation of createDryrun for other SDK that you add sender to accts, wondering do we also want to do this in Java, or sender is included in tx.accounts so we can omit this.


for (String acct : accts) {
Response<Account> ar = client.AccountInformation(new Address(acct)).execute();
if(ar.isSuccessful()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing to make sure: for other SDK implementation, there's a decodeProgram involved here, this is not needed in Java case, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I can edit the generator to allow raw bytes when we msgpack encode, this should work without decoding since the java decoder handles it for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants