Repository navigation
txnbuild: reset CreateClaimableBalance and RevokeSponsorship in FromXDR - #6023
marwen-abid wants to merge 2 commits into
Conversation
CreateClaimableBalance.FromXDR appended the decoded claimants to cb.Destinations and did not reset it. When a caller decoded into a populated value, the old claimants stayed, and a rebuild let them claim the balance. RevokeSponsorship.FromXDR set only the field for the decoded sponsorship type and kept the field of the earlier type. BuildXDR reads only the field that SponsorshipType selects, so the XDR was correct, but the struct showed a stale target. Both methods now reset the receiver after the type check, as SetOptions.FromXDR does since #6021. RevokeSponsorship.FromXDR now checks the operation type before it sets SourceAccount, so a wrong operation type leaves the receiver unchanged.
There was a problem hiding this comment.
🟢 Approval recommended
The changes are fully reviewed, tested, and have no unresolved blocking issues.
0 open findings
What changed in this PR
Updates FromXDR decoding to safely reset reused receivers and avoid stale fields for claimable-balance and sponsorship operations.
Changes:
- Reset decoded operation state.
- Validate operation types before mutating receivers.
- Add regression tests and changelog documentation.
| File | Description |
|---|---|
txnbuild/revoke_sponsorship.go |
Validates type before mutation and clears stale fields. |
txnbuild/revoke_sponsorship_test.go |
Tests reuse and wrong-type behavior. |
txnbuild/create_claimable_balance.go |
Resets decoded claimable-balance fields. |
txnbuild/create_claimable_balance_test.go |
Tests receiver reuse and rebuild behavior. |
txnbuild/CHANGELOG.md |
Documents the fixes. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
d2da1ee to
ae18d56
Compare
ae18d56 to
ddce05f
Compare
ddce05f to
131cb5e
Compare
|
Thanks, this looks good. Decoding into a local and assigning only on success also leaves the receiver unchanged on every error, which is nice. Could you handle |
What
CreateClaimableBalance.FromXDRandRevokeSponsorship.FromXDRnow reset the receiver after the type check, before they read the operation. This is the same change that #6021 made toSetOptions.FromXDR.RevokeSponsorship.FromXDRnow checks the operation type before it setsSourceAccount.Why
Follow-up to the review of #6021.
CreateClaimableBalance.FromXDRappended the decoded claimants tocb.Destinationsand did not reset it. Example: decode an operation with claimant A into a value that already has claimant B. The result has claimants B and A. If the caller builds it again, B can claim the balance, but B is not in the decoded operation.RevokeSponsorship.FromXDRset only the field for the decoded sponsorship type, so a reused value kept the field of the earlier type.BuildXDRreads only the field thatSponsorshipTypeselects, so the XDR was correct. But the struct showed a stale target, and a comparison with a freshly decoded value failed.Before,
RevokeSponsorship.FromXDRsetSourceAccountbefore the type check, so a wrong operation type changed the receiver and then returned an error. Now the receiver does not change when the type is wrong.Compatibility
The public API does not change. A caller that decodes into a new value gets the same result as before. A caller that decoded into a populated value and expected the claimants to merge now gets only the decoded claimants.