txnbuild: reject empty Destinations in CreateClaimableBalance.Validate - #6008
Open
yigitcangokmen wants to merge 1 commit into
Open
yigitcangokmen wants to merge 1 commit into
yigitcangokmen wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
🟢 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.
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.
Fixes #6007.
The bug
CreateClaimableBalance.Validate()returnsnilwhenDestinationsisnilor an empty[]Claimant{}. Thefor rangeloop 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-- itsdoCheckValidguard explicitly checksclaimants.empty(). The SDK should catch this at build time rather than letting an invalid operation reach the network.js-stellar-basealready validates this ('must provide at least one claimant').The fix
Add a
len(cb.Destinations) == 0guard at the top ofValidate(), covering both nil and empty-slice cases.len(nil)returns 0 in Go, so a single check handles both.Test plan
TestCreateClaimableBalanceValidateNoDestinationscovers nil and empty-sliceDestinationsTestCreateClaimableBalanceRoundTripandTestClaimableBalanceIDstill pass