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

Handle new RPC simulation response variations #132

Merged
merged 17 commits into from
Sep 13, 2023
Merged

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Aug 23, 2023

This aligns with stellar/stellar-cli#865 and stellar/stellar-cli#878. The new behavior is documented here. In summary:

The id and latestLedger fields always exist. Then, there are branching variations:

  • in error cases:
    • error always exists
  • in success cases:
    • transactionData, minResourceFee, and cost always exist
    • results only exists IF the simulation was for an invocation op
    • restorePreamble only exists IF the simulation required expired entries
      • this means a restoration is required for the invocation to exist, and this object contains both the fee andfootprint necessary for that
  • events may exist but we will make it always exist (maybe empty)

Our transformations are as follows:

  • the interface is broken down into types based on success / failure
  • every XDR object is decoded when possible
  • events always exists (but may be empty)
  • results?[] is coalesced into a single result?

@Shaptic Shaptic changed the base branch from main to testnet August 23, 2023 00:32
@Shaptic Shaptic added this to the Soroban Testnet Release milestone Aug 23, 2023
src/soroban_rpc.ts Outdated Show resolved Hide resolved
@Shaptic Shaptic marked this pull request as ready for review September 1, 2023 22:33
@socket-security
Copy link

socket-security bot commented Sep 1, 2023

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: @types/[email protected], @types/[email protected]

@Shaptic
Copy link
Contributor Author

Shaptic commented Sep 1, 2023

Note that this is targeting the testnet branch which contains the updated XDR changes.

src/soroban_rpc.ts Outdated Show resolved Hide resolved
const coalesced = parseRawSimulation(simulation);
if (!coalesced.result) {
throw new Error(`simulation incorrect: ${JSON.stringify(coalesced)}`);
let success = parseRawSimulation(simulation);
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit, your call, it's not success yet, maybe simulationResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but it should be! heh. slightly more annoying to read later lines if it's something like parsed, and reassigning after the if (!isSuccess...) check is also slightly more annoying 🙃

src/transaction.ts Outdated Show resolved Hide resolved
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.

looks good, left minor suggestions for consideration.

@Shaptic Shaptic merged commit 9df2920 into testnet Sep 13, 2023
4 checks passed
@Shaptic Shaptic deleted the rpc-restoration-reply branch September 13, 2023 17:16
Shaptic added a commit that referenced this pull request Sep 13, 2023
* Upgrade the codebase to work with testnet XDR (#135)
* Using [email protected]
* Prepare `v1.0.0-beta.0` for release (#143)
* Handle new RPC simulation response variations (#132)
* Add Core build reference to changelog for clarity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants