Skip to content

Add helper for claimable balance IDs from transaction results#967

Open
chrisx9z wants to merge 2 commits into
stellar:masterfrom
chrisx9z:feat/claimable-balance-result-id
Open

Add helper for claimable balance IDs from transaction results#967
chrisx9z wants to merge 2 commits into
stellar:masterfrom
chrisx9z:feat/claimable-balance-result-id

Conversation

@chrisx9z

Copy link
Copy Markdown

Summary

  • add getClaimableBalanceIdFromResult for extracting createClaimableBalance IDs from successful transaction result XDR
  • support base64 result XDR strings, raw Buffers, and xdr.TransactionResult objects
  • handle regular transaction success and fee-bump inner success results
  • add unit coverage and a TypeScript declaration check

Fixes stellar/js-stellar-sdk#584.

Testing

  • git diff --check
  • node --check src/get_claimable_balance_id.js
  • node --check test/unit/get_claimable_balance_id_test.js

Full yarn test was not run locally because this environment does not have yarn/npm or installed node_modules available.

Copilot AI review requested due to automatic review settings May 26, 2026 16:35
Comment: Extract claimable balance IDs from successful transaction result XDRs, including fee-bump inner results.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.
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 helpers to obtain Claimable Balance IDs

2 participants