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

Add the fromXdrBase64, fromXdrByteArray, toXdrBase64 and toXdrByteArray methods to the XDR classes. #503

Merged

Conversation

overcat
Copy link
Member

@overcat overcat commented Aug 9, 2023

Closes #501

The XDR class generation in this PR depends on stellar/xdrgen#164

Breaking changes

  • Remove Utils.claimableBalanceIdToXDR and Utils.xdrToClaimableBalanceId.

@overcat overcat changed the title Add the fromXdrBase64 and toXdrBase64 methods to the XDR classes. Add the fromXdrBase64, fromXdrByteArray, toXdrBase64 and toXdrByteArray methods to the XDR classes. Aug 9, 2023
@overcat overcat marked this pull request as ready for review August 9, 2023 07:42
@overcat
Copy link
Member Author

overcat commented Aug 9, 2023

This PR is ready for review and merge.

@sreuland
Copy link
Contributor

sreuland commented Aug 9, 2023

@overcat , Can you provide a brief overview or drill down on where to focus for real logic/functionality changes, key files to look at? there's 367 changed files in the pr and trying to find efficient way to understand what's been done vs. compile-time fixes.

[edit] - I can ignore the entire org.stellar.sdk.xdr package correct, those are all copied from an xdrgen run? then I can proceed on review, is narrows down what's real changes.

The one follow-up is can you add a comment on the readme.md in the xdrgen section that states what git ref of stellar/xdrgen and stellar/stellar-xdr/next was used?

try {
return ClaimableBalanceID.decode(balanceIdXdrDataInputStream);
return ClaimableBalanceID.fromXdrByteArray(balanceIdBytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems too specific to claimablebalance to be in a generic util, and since you've added the xdr helper methods, how about refactoring this and deleting these claimable balance methods from Util and clients can just inline the one remaining line in the method for same result?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in fb44420

LedgerEntry.LedgerEntryData ledgerEntryData =
ledgerEntryDataFromXdrBase64(entries.get(0).getXdr());
LedgerEntry.LedgerEntryData ledgerEntryData;
try {
Copy link
Contributor

@sreuland sreuland Aug 9, 2023

Choose a reason for hiding this comment

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

Suggested change
try {
try {
LedgerEntry.LedgerEntryData ledgerEntryData = LedgerEntry.LedgerEntryData.fromXdrBase64(entries.get(0).getXdr());
long sequence = ledgerEntryData.getAccount().getSeqNum().getSequenceNumber().getInt64();
return new Account(accountId, sequence);
} catch (IOException e) {
throw new IllegalArgumentException("Invalid ledgerEntryData: " + entries.get(0).getXdr(), e);
}

rather than declare ledgerEntryData outside of try/catch, just use it inside when it's valid.

Copy link
Member Author

Choose a reason for hiding this comment

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

I personally prefer to include as little code as possible within the try block. Assuming there is some other business logic before returning Account, should we also place it within the try block?

@@ -421,7 +427,11 @@ private Transaction assembleTransaction(
List<SorobanAuthorizationEntry> newEntries = new ArrayList<>(originalEntries);
if (simulateHostFunctionResult.getAuth() != null) {
for (String auth : simulateHostFunctionResult.getAuth()) {
newEntries.add(sorobanAuthorizationEntryFromXdrBase64(auth));
try {
newEntries.add(SorobanAuthorizationEntry.fromXdrBase64(auth));
Copy link
Contributor

Choose a reason for hiding this comment

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

@overcat , please refer to the js soroban client for a reference on how it merges simulation results to original transaction,

https://github.com/stellar/js-soroban-client/blob/main/src/transaction.ts#L21

the java sdk should be consistent to how that handles merging auths, the js sdk will not apply simulated auths if the original tx had auths.

Copy link
Member Author

@overcat overcat Aug 10, 2023

Choose a reason for hiding this comment

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

It seems that this is a recent change introduced in the JS SDK. Let's track it in the new issue.
[update] Fixed in #505

Copy link
Contributor

@sreuland sreuland left a comment

Choose a reason for hiding this comment

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

overall looks good, just need to get response on the simulation results with auth, left comment - https://github.com/stellar/java-stellar-sdk/pull/503/files#r1289105610

can merge after that is resolved, thanks!

@overcat
Copy link
Member Author

overcat commented Aug 10, 2023

The one follow-up is can you add a comment on the readme.md in the xdrgen section that states what git ref of stellar/xdrgen and stellar/stellar-xdr/next was used?

Let's track it in #502 and I'm pushing it forward.

@sreuland sreuland merged commit 0dc9b4b into lightsail-network:soroban Aug 10, 2023
@overcat overcat deleted the base64-methods branch August 11, 2023 08:38
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.

2 participants