Package txsort provides the transaction sorting according to BIP 69.
BIP 69 defines a standard lexicographical sort order of transaction inputs andoutputs. This is useful to standardize transactions for faster multi-partyagreement as well as preventing information leaks in a single-party use case.The BIP goes into more detail, but for a quick and simplistic overview, the order for inputs is defined as first sorting on the previous output hash and then on the index as a tie breaker. The order for outputs is defined as first sorting on the amount and then on the raw public key script bytes as a tie breaker. A comprehensive suite of tests is provided to ensure proper functionality.
Installation and Updating
$ go get -u github.com/p9c/pod/btcutil/txsort
License
Package txsort is licensed under the copyfree ISC License.
BIP 69 defines a standard lexicographical sort order of transaction inputs and outputs. This is useful to standardize
transactions for faster multi-party agreement as well as preventing information leaks in a single-party use case. The
BIP goes into more detail, but for a quick and simplistic overview, the order for inputs is defined as first sorting on
the previous output hash and then on the index as a tie breaker. The order for outputs is defined as first sorting on
the amount and then on the raw public key script bytes as a tie breaker.
InPlaceSort modifies the passed transaction inputs and outputs to be sorted based on BIP 69.
WARNING: This function must NOT be called with published transactions since it will mutate the transaction if it's
not already sorted. This can cause issues if you mutate a tx in a block, for example, which would invalidate the
block. It could also cause cached hashes, such as in a util.Tx to become invalidated. The function should only be
used if the caller is creating the transaction or is otherwise 100% positive mutating will not cause adverse affects
due to other dependencies.
Sort returns a new transaction with the inputs and outputs sorted based on BIP 69. The passed transaction is not
modified and the new transaction might have a different hash if any sorting was done.