Repository navigation
Port JS snippets to stellar-sdk v17 XDR property access - #3083
Conversation
Replace the method-style XDR getters, enum factory calls and union constructors that v17 removed with property access, .type checks and xdr.expectUnionVariant. Also fix the restore snippets so the footprint holds the instance and its Wasm code key.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
ElliotFriend
left a comment
There was a problem hiding this comment.
Thanks for this. I ran the new accessors against @stellar/stellar-sdk 17.4.0, using XDR objects decoded with fromXdr, and they all work: expectUnionVariant and isUnionVariant, the LedgerKey.account and LedgerKey.trustline factories, the Wasm hash chains (including the TypeError for a Stellar Asset Contract), claimant.v0.destination.ed25519.toBytes(), tr.createClaimableBalanceResult.balanceId.toXdr("hex"), SorobanTransactionDataExt.v0(), and the rebuilt ContractEvent through humanizeEvents. The extractEvent excerpt also matches src/base/events.ts at v17.4.0.
One change before this merges:
- Drop the
docs/build/apps/guestbook/frontend.mdxhunk. That page mirrors the companion app (ElliotFriend/ye-olde-guestbook), which still pins@stellar/stellar-sdk ^16.4.1. The v17 property access won't work there. We'll update the page and the app together when the app moves to 17. Please leave the rest of the PR as it is, and don't remove the guestbook item from #3082 either; we'll track it there.
The page mirrors ElliotFriend/ye-olde-guestbook, which still pins @stellar/stellar-sdk ^16.4.1. The page and the app move to v17 together, tracked in #3082.
|
🤖 Automated message from the Stellar Triage Bot. Back on this because @ElliotFriend requested changes.
Ready to merge once your change request is cleared. |
🤖 Automated message from the Stellar Triage Bot.
Closes #3082
Working this because @ElliotFriend added bot:take. This PR ports the JS snippets that use v16 XDR getters to
@stellar/stellar-sdk17.x.What changes:
entry.val.trustLine,claimant.v0.destination). Int64 fields are alreadybigint, so.toBigInt()goes..switch()becomes a.typecheck. TypeScript snippets narrow withxdr.expectUnionVariant.xdr.ContractEventType.contract,xdr.ContractEventBody.v0(...))..toBytes()beforeStrKey.Beyond the checklist (the same v17 break, or a bug in a block this PR rewrites):
create-account.mdx,pooled-accounts-muxed-accounts-memos.mdxand moreclawbacks.mdxlines callbalance().toBigInt().events.mdx:fullEventLogusedContractEventType.contract()andnew ContractEventBody(0, ...). It now wraps the ID inxdr.ContractId, because v17humanizeEventscallscontractId.toBytes().create-restoration-footprint-js.mdx:new xdr.SorobanTransactionDataExt(0)throws on v17.restore-contract-js.mdx, bothstate-archival.mdxpages) never put the Wasm code key in the footprint. They now read the instance entry, get its Wasm hash and restore both keys. Therestore-contract-js.mdxintro saidgetFootprint()covers the Wasm code. It does not, so I reworded it and repointed its two js-soroban-client links (item 4 of Reflect stellar-base fold-in (SDK v16): stop pointing readers at js-stellar-base and js-soroban-client #2560).getLedgerEntries.mdx:LedgerKey.ledgerKeyAccountandledgerKeyTrustLinedo not exist (account,trustline). The TS tab now fetches the trustline, like the Python tab. The request JSON lacked a comma. All edits are below the generated block.stellar-transaction.mdx: the auth check readentry.switch()instead of the entry's credentials, and theasyncmap returned promises. It now usesPromise.all.xdr.mdx: theextractEventexcerpt now copies the v17.4.0 source, so the Structures section agrees with the new Unions section. The Python imports in that section were invalid.Verification: every property, arm name and factory comes from the 17.4.0 typings on unpkg and the v17 XDR migration guide. I could not run the snippets here (no Node), and
pnpm checkdid not run. Thechecksjob covers formatting.Notes:
ElliotFriend/ye-olde-guestbook,src/lib/server/getLedgerEntries.ts) still pins^16.4.1and uses the old getters. It needs the same change plus the SDK bump.wallet/sep7.mdx:26usestoXDR().toString("base64"), but through the wallet SDK's own stellar-sdk.state-archival.mdx.