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 StateChanges in SimulateTransaction API response #963

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

psheth9
Copy link

@psheth9 psheth9 commented May 10, 2024

Fixes #936

This Diff has following changes:

  • Add stateDiff in SimulateTransaction API response where stateDiff interface is below
  • Add parsing of XDR types to build SimulateTxnResponse from Raw encoded XDR
  • Add unit tests

  interface LedgerEntryDiff{
    type: number;
    key: xdr.LedgerKey;
    before?: xdr.LedgerEntry;
    after?: xdr.LedgerEntry;
  }

Copy link

github-actions bot commented May 10, 2024

Size Change: +9.92 kB (+0.08%)

Total Size: 12 MB

Filename Size Change
dist/stellar-sdk.js 6.69 MB +6.52 kB (+0.1%)
dist/stellar-sdk.min.js 5.28 MB +3.4 kB (+0.06%)

compressed-size-action

@psheth9 psheth9 marked this pull request as ready for review May 13, 2024 16:33
@psheth9 psheth9 requested a review from Shaptic May 13, 2024 16:33
src/soroban/parsers.ts Outdated Show resolved Hide resolved
@Shaptic Shaptic mentioned this pull request May 14, 2024
4 tasks
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

Don't forget a CHANGELOG.md entry!

src/soroban/api.ts Outdated Show resolved Hide resolved
src/soroban/api.ts Outdated Show resolved Hide resolved
src/soroban/api.ts Outdated Show resolved Hide resolved
Comment on lines 149 to 150
before: !!entryChange.before ? xdr.LedgerEntry.fromXDR(entryChange.before, 'base64') : undefined,
after: !!entryChange.after ? xdr.LedgerEntry.fromXDR(entryChange.after, 'base64') : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

if you want before and after to be omitted when they aren't present you'll need to use the spread operator (check in this file for examples, I think it's something like

key: xdr.LedgerKey.fromXDR(entryChange.key, 'base64'),
...(entryChange.before && { before: xdr.LedgerEntry.fromXDR(entryChange.before, 'base64') },

and you want this for stateChanges too. Alternatively you can use delete (much easier to read lol).

Copy link
Author

Choose a reason for hiding this comment

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

I think now there is no need to omit as these are required fields. so spread operator wont be needed here

Copy link
Contributor

Choose a reason for hiding this comment

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

What I mean is that maybe we want to omit them at the SDK level since the API choice of making them null is odd (imo).

@@ -6,6 +6,10 @@ A breaking change will get clearly marked in this log.

## Unreleased

Added:

- Add stateChanges in SimulateTransaction API response ([#963](https://github.com/stellar/js-stellar-sdk/pull/963))
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have a bit more detail, e.g. at least the schema change and mention rpc.Server.simulateTransaction

@@ -175,8 +168,21 @@ export namespace Api {
value: string;
}

export interface RequestAirdropResponse {
transaction_id: string;
export interface RawLedgerEntryChange {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can get away with not exporting this one?

},
{
type: 3,
key: "example-key-3",
Copy link
Contributor

Choose a reason for hiding this comment

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

wait shouldn't this fail to decode to a LedgerKey?

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.

Add support for new stateChanges in simulateTransaction
3 participants