Add helper for claimable balance IDs from transaction results#967
Open
chrisx9z wants to merge 2 commits into
Open
Add helper for claimable balance IDs from transaction results#967chrisx9z wants to merge 2 commits into
chrisx9z wants to merge 2 commits into
Conversation
Comment: Extract claimable balance IDs from successful transaction result XDRs, including fee-bump inner results.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds a new helper for extracting a claimable balance ID from a transaction result XDR, exposing it from the public API and publishing corresponding TypeScript typings.
Changes:
- Added
getClaimableBalanceIdFromResult()implementation and export - Added TypeScript declaration + tsd type assertion
- Added unit tests for string/object inputs, fee-bump inner success, and invalid op index
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/get_claimable_balance_id.js | Implements parsing/extraction logic for claimable balance IDs from result XDR |
| src/index.js | Exposes the new helper from the package entrypoint |
| test/unit/get_claimable_balance_id_test.js | Adds unit tests covering common success paths and invalid op index |
| types/index.d.ts | Adds TypeScript signature for the exported helper |
| types/test.ts | Adds a type-level assertion for the helper’s return type |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+5
| function buildClaimableBalanceResult() { | ||
| const balanceId = StellarBase.xdr.ClaimableBalanceId.claimableBalanceIdTypeV0( | ||
| Buffer.from( | ||
| '536af35c666a28d26775008321655e9eda2039154270484e3f81d72c66d5c26f', | ||
| 'hex' |
Comment on lines
+47
to
+55
| * @param {string|Buffer|xdr.TransactionResult} transactionResult - The transaction | ||
| * result XDR as base64, raw Buffer, or XDR object. | ||
| * @param {number} opIndex - The operation index containing createClaimableBalance. | ||
| * | ||
| * @return {string} the claimable balance ID as a hex string. | ||
| */ | ||
| export function getClaimableBalanceIdFromResult( | ||
| transactionResult, | ||
| opIndex = 0 |
Comment on lines
+57
to
+67
| if (!Number.isInteger(opIndex) || opIndex < 0) { | ||
| throw new RangeError('invalid operation index'); | ||
| } | ||
|
|
||
| const operationResults = getOperationResults( | ||
| parseTransactionResult(transactionResult) | ||
| ); | ||
|
|
||
| if (opIndex >= operationResults.length) { | ||
| throw new RangeError('invalid operation index'); | ||
| } |
Comment on lines
+21
to
+40
| function getOperationResults(transactionResult) { | ||
| const result = transactionResult.result(); | ||
| const resultCode = result.switch().name; | ||
|
|
||
| if (resultCode === 'txSuccess') { | ||
| return result.results(); | ||
| } | ||
|
|
||
| if (resultCode === 'txFeeBumpInnerSuccess') { | ||
| return result | ||
| .innerResultPair() | ||
| .result() | ||
| .result() | ||
| .results(); | ||
| } | ||
|
|
||
| throw new Error( | ||
| `transaction result does not contain successful operation results: ${resultCode}` | ||
| ); | ||
| } |
Comment: Clarifies optional operation index behavior and covers non-success transaction results.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getClaimableBalanceIdFromResultfor extracting createClaimableBalance IDs from successful transaction result XDRxdr.TransactionResultobjectsFixes stellar/js-stellar-sdk#584.
Testing
git diff --checknode --check src/get_claimable_balance_id.jsnode --check test/unit/get_claimable_balance_id_test.jsFull
yarn testwas not run locally because this environment does not have yarn/npm or installed node_modules available.