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

TxId Byte Order #56

Open
breavyn opened this issue Jul 20, 2022 · 0 comments
Open

TxId Byte Order #56

breavyn opened this issue Jul 20, 2022 · 0 comments

Comments

@breavyn
Copy link

breavyn commented Jul 20, 2022

A txid is calculated as sha256d(tx). When a txid is presented as a string for a human or a text based api, it is first reversed, then hex encoded. This reversing step can be a source of bugs and confusion. Unfortunately, this convention also sees use with block ids, merkle roots, merkle tree nodes, etc.

This lib is currently using reverse order everywhere. As the lib is for low level manipulation of bitcoin primitives, I believe txid should always be in normal order. A txid string in reverse order, should be considered a different construct.

This could be achieved by having separate methods on every object using this bitcoin id convention, or with functions for explicit conversion.

tx.get_id()
tx.get_id_string()

txin.set_prev_tx_id(id)
txin.set_prev_tx_id_string(id)

// or

tx.get_id()
bitidtos(tx.get_id())

txin.set_prev_tx_id(id)
txin.set_prev_tx_id(stobitid(id))

Another thing to consider is the get_id_hex methods. For new users of the lib, it is not clear from the method name what this actually returns. It may be best to remove them entirely.

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

No branches or pull requests

1 participant