Skip to content

txnbuild: reject empty Destinations in CreateClaimableBalance.Validate - #6008

Open
yigitcangokmen wants to merge 1 commit into
stellar:mainfrom
yigitcangokmen:fix/validate-empty-destinations
Open

yigitcangokmen wants to merge 1 commit into
stellar:mainfrom
yigitcangokmen:fix/validate-empty-destinations

Conversation

@yigitcangokmen

Copy link
Copy Markdown

Fixes #6007.

The bug

CreateClaimableBalance.Validate() returns nil when Destinations is nil or an empty []Claimant{}. The for range loop over the slice is a no-op in both cases, so the method falls through to the amount/asset checks and reports no error.

stellar-core rejects such operations with CREATE_CLAIMABLE_BALANCE_MALFORMED -- its doCheckValid guard explicitly checks claimants.empty(). The SDK should catch this at build time rather than letting an invalid operation reach the network.

js-stellar-base already validates this ('must provide at least one claimant').

The fix

Add a len(cb.Destinations) == 0 guard at the top of Validate(), covering both nil and empty-slice cases. len(nil) returns 0 in Go, so a single check handles both.

Test plan

  • New test TestCreateClaimableBalanceValidateNoDestinations covers nil and empty-slice Destinations
  • Existing TestCreateClaimableBalanceRoundTrip and TestClaimableBalanceID still pass

Validate() silently accepted nil or empty Destinations because `for range`
over a nil/empty slice is a no-op. stellar-core rejects such operations
with CREATE_CLAIMABLE_BALANCE_MALFORMED, so the SDK should catch this
at build time rather than letting it reach the network.

Add a len check at the top of Validate() and tests for both nil and
empty-slice cases.
Copilot AI balanced review requested due to automatic review settings September 17, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused validation change correctly handles both cases and includes appropriate regression coverage.

Pull request overview

Adds build-time validation for claimable balances without claimants.

Changes:

  • Rejects nil or empty Destinations.
  • Tests both invalid cases.
  • Documents the fix.
File summaries
File Description
txnbuild/create_claimable_balance.go Adds validation guard.
txnbuild/create_claimable_balance_test.go Covers nil and empty destinations.
txnbuild/CHANGELOG.md Records the bug fix.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

txnbuild: CreateClaimableBalance.Validate() accepts empty Destinations

2 participants