Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txnbuild: Add helper to calculate claimable balance IDs without submitting transactions. #3122

Merged
merged 10 commits into from
Oct 14, 2020

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Oct 9, 2020

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Balance IDs are a crucial piece of information when dealing with claimable balances. They are highly predictable by design, and so SDK users shouldn't need to submit the transaction to determine the ID.

This PR introduces a helper within the txnbuild package:

func (t *Transaction) ClaimableBalanceID(operationIndex int) string {}

It returns a claimable balance ID for the particular operation within the transaction, assuming it is of the type CREATE_CLAIMABLE_BALANCE.

It also introduces an integration test to confirm this behavior. Since it's appended to an existing test, this only adds a few extra seconds of running time. I believe this also only can be integration tested since we need Core to actually run the calculation as well, but I'd love to be wrong.

Why

Closes #3116.

Known limitations

Obviously, this only applies to the Go SDK.

(added @jonjove to review to sanity-check the balance ID calculation and @leighmcculloch purely for visibility on the txnbuild changelog)

@Shaptic Shaptic requested review from leighmcculloch, jonjove and a team October 9, 2020 22:57
@Shaptic Shaptic self-assigned this Oct 9, 2020
@cla-bot cla-bot bot added the cla: yes label Oct 9, 2020
Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

Yes! Thanks for doing this. Couple suggestions below.

txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
This is a cleaner design than returning a list of IDs, because it actually
enforces a correlation between the returned ID and a specific operation.
Otherwise, it's strange to have the returned array be different that the list
of operations in the transaction.
Copy link
Contributor

@howardtw howardtw left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! I left a couple of nitpicks. This PR looks good to me, but I'd defer the approval to @leighmcculloch to make sure it looks good to him too before you merge the PR.

txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
services/horizon/internal/test/integration/integration.go Outdated Show resolved Hide resolved
services/horizon/internal/test/integration/integration.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
Shaptic and others added 3 commits October 14, 2020 14:26
@Shaptic Shaptic merged commit e016d0f into stellar:master Oct 14, 2020
@Shaptic Shaptic deleted the balanceid-helper branch October 28, 2020 19:04
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.

Feature Request: Add a function get ID of a CalimableBalance on Transaction object
3 participants