Consistent UTXO Handling for CWC Transactions - #4213
Open
MicahMaphet wants to merge 6 commits into
Open
Conversation
…tcore-node and bitcore-lib style transactions
kajoseph
reviewed
Aug 7, 2026
kajoseph
left a comment
Collaborator
There was a problem hiding this comment.
Hey @MicahMaphet , thanks for the PR and nice catch. I think a better way to approach this is to have a standardizeUtxo function that looks something like this:
standardizeUtxo(utxo) {
return {
txid: utxo.txid || utxo.mintTxid,
vout: utxo.vout || utxo.mintIndex,
...etc...
};
}then, we can just do
utxos = utxos.map(this.standardizeUtxo);
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description 🗒️
Previously
crypto-wallet-core'sCWC.Transactionshad inconsistent handling of utxos..createand.signrequiredbitcore-nodeutxos. Bybitcore-nodeutxos I mean howbitcore-nodestores utxos in its database. These have mintTxid, spentTxid, mintIndex, and value; whilebitcore-libstyle utxos have txid, outputIndex, and satoshis..getSighashrequiredbitcore-libutxos.Now
CWC.Transactionsaccepts both kinds of utxos.Motivation
I need these changes for
bitcore-hardwarein order to sign transactions. I need to construct a transaction with.createand pass those utxos into a [a given hardware wallet object].sign. To sign with hardware wallets, I need to give the the sighash via.getSighash. The current version ofcrypto-wallet-coredoes not allow this because.createand.getSighashtake different utxo types. This problem could be most easily solved be simply making.getSighashconvertbitcore-nodeutxos intobitcore-libutxos. However, we want consistent handling of utxos. This PR instead solves the core problem by making all transaction methods in thecryto-wallet-coreutxo chains accept bothbitcore-nodeandbitcore-libutxos.Changelog 🪵
functionality 🔨
EveryUtxoTypewhere the properties are unknown due to it being received outside the Transactions class. Can contain any type of utxo data:UnspentOutput,UnspentOutput.toObject, and utxos from thebitcore-nodedatabase. Hard to work with because all the properties need to be checked individually.UtxoTypefor internal usage. Nice to work with because the properties don't need to be checked. Uses property naming fromUnspentOutput.Transactions.create,Transactions.sign,Transactions.getSighash, andTransactions.getSigningAddressesacceptEveryUtxoTypeTransactions.createsilently ignores utxomintHeightsorting when supplied withbitcore-libutxosorganization 🎶
Number()is used instead ofparseInt()getRelatedUtxosacceptsUtxoTyperather thanbitcore-nodeutxo typesTesting Notes 🥼 🧪
crypto-wallet-coretests all work, but I can add more to test the new functionality.The following cases would previously break, but they now work.
.createand.getSighashpreviously use different utxo types but now accept either.bitcore-lib utxos
bitcore-node utxos
Checklist ✅ 🗒️