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

🧮 Calculating claimable balance ID #836

Closed
JFWooten4 opened this issue Jul 29, 2024 · 6 comments
Closed

🧮 Calculating claimable balance ID #836

JFWooten4 opened this issue Jul 29, 2024 · 6 comments

Comments

@JFWooten4
Copy link
Contributor

| balance_id | The unique identifier of the claimable balance. The id is comprised of 8 character type code + SHA-256 hash of the history operation id that created the balance. The balance id can be joined back to the \`claimable_balances\` table to gather more details about the balance | string | | | | | | history_operations | |

Claimable balance IDs use a "history operation id that created the balance" to get the final CB_ID. You are supposed to be able to do this outside of the network:

1. The submitter of the entry (Account A in this case) can retrieve the Balance ID before submitting the transaction;

However, the documentation isn't clear on how to precisely find your CB_ID, which adds operational complexity.

@Shaptic
Copy link
Contributor

Shaptic commented Jul 31, 2024

There are examples in three languages? Ctrl-f "method 1"

@JFWooten4
Copy link
Contributor Author

JFWooten4 commented Aug 1, 2024

@Shaptic I am not entirely sure what you mean, as each instance of method 1 in stellar-docs/docs/learn/encyclopedia/transactions-specialized/claimable-balances.mdx has no implementation in their respective SDKs. If this is incorrect, then please do correct me for #723, but I can't find the exact docs in any language for precomputing balance IDs.1 I also searched the entire doc repo, but please do let me know if I'm missing the reference you're referring to.

Footnotes

  1. Except for the go implementation, but the docs there are extremely abstracted.

@Shaptic
Copy link
Contributor

Shaptic commented Aug 1, 2024

@JFWooten4 err yeah, you're right (I had the Go tab open by default). There are still the other methods of course, but it'd be good to document computation of the claimable balance 👍 and add a JS helper for it if that's a feature request.

@Shaptic
Copy link
Contributor

Shaptic commented Aug 1, 2024

Oh lol there already is one in JS: https://stellar.github.io/js-stellar-sdk/Transaction.html#getClaimableBalanceId, it's just not updated in the docs.

@Shaptic
Copy link
Contributor

Shaptic commented Aug 1, 2024

The claimable balance ID is the sha256 hash of the claimable balance operation body encoded as a claimable balance ID. Namely,

hex(claimableBalanceIdTypeV0(sha256(
  the operation/transaction source account's public key,
  the transaction's source account sequence number
  the operation index within the transaction
)))

@JFWooten4
Copy link
Contributor Author

just not updated in the docs.

Thank you for the help, George. I drafted an update in P1516 and will get the docs updated tomorrow. Mocking up the code examples now, all per your insights!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants