-
Notifications
You must be signed in to change notification settings - Fork 38.7k
update bitcoin-tx to output witness data #8817
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
Conversation
|
utACK 76992bf Side note: it seems we have no tests for bitcoin-tx JSON functionality, despite there being some other tests for it. Perhaps it can be added (see |
|
I've added JSON test cases in #8829 |
|
I assume this needs backport? |
|
utACK 76992bf |
|
I'll reference this here as well since it all seems (to me) to be setting some kind of precedent wrt blank transactions. Cleared. |
|
Concept ACK. I believe it would be simpler and not harder for me to review if you go with your "full solution that doesn't duplicate code" in the same PR, but that may just be me... |
|
utACK 76992bf |
|
ACK |
src/core_write.cpp
Outdated
| if (!tx.wit.IsNull()) { | ||
| if (!tx.wit.vtxinwit[i].IsNull()) { | ||
| UniValue txinwitness(UniValue::VARR); | ||
| for (unsigned int j = 0; j < tx.wit.vtxinwit[i].scriptWitness.stack.size(); j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to use BOOST_FOREACH here (for readability and to avoid copying the stack items).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're trying to move away from BOOST in favour of c++11. See https://github.com/bitcoin/bitcoin/projects/3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, for (const auto& item : tx.wit.vtxinwit[i].scriptWitness.stack) would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Much better. Thanks!
src/core_write.cpp
Outdated
| o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||
| in.pushKV("scriptSig", o); | ||
| if (!tx.wit.IsNull()) { | ||
| if (!tx.wit.vtxinwit[i].IsNull()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is redundant with the check above, and might be worth removing.
It would probably also be good to add an (i < tx.wit.vtxinwit.size()) check or assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added your (i < tx.wit.vtxinwit.size()) check and moved all checks into a single if statement.
src/core_write.cpp
Outdated
| o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); | ||
| o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||
| in.pushKV("scriptSig", o); | ||
| if (!tx.wit.IsNull()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity and efficiency would suggest moving this outside the for loop, since internally CTxWitness::IsNull loops over all the i's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to be too concerned about efficiency here. ScriptPubKeyToUniv() isn't heavily used, so looping through the CTxIn isn't going to cause any performance issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I was suggesting this more for clarity than efficiency, though. Right now I would be surprised looking at this code to learn that if that any /single/ vtxinwit is null, then no output will be produced for all other vtxinwit. Adding a well named bool variable outside the for loop might make it a little clearer. Anyway, thanks for considering this, and for making the other changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm wrong about this. CTxWitness::IsNull returns true if all vtxinwits are null, not if any are null, so having this check isn't actually misleading w.r.t the individual entries, just redundant.
eb930c9 to
9f85db7
Compare
|
I've applied @ryanofsky's changes and rebased. |
|
Fails with |
src/core_write.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Please keep it at BOOST or make it cpp11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because he needs index i below. I've wondered this before: does c++11 have a canonical way to do enumerated iteration (like enumerate() in python or for i, a := range ... { in golang)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. I don't think there's a direct equivalent for python's enumerate in c++11. The most common suggestions I can find on stackoverflow are zipping with an index or tracking the index outside the for loop. I think it's clearer just to iterate through the indexes in the for loop.
|
Failing test: |
|
Looks like all tests are now passing. |
3a32aa8 to
4408558
Compare
|
Commits squashed and commit comment updated. |
4408558 Update bitcoin-tx to output witness data. (jonnynewbs)
Github-Pull: bitcoin#8817 Rebased-From: 4408558
In 7c4bf77 , @jl2012 updated
getrawtransaction()to return the witness data for transaction inputs spending P2WPK and P2WSH.bitcoin-tx doesn't call into this function and instead calls
TxToUniv()incore_write.cpp, so bitcoin-tx calls don't return witness data.This PR adds code to
TxToUniv()to return witness data.The full fix is to have
getrawtransaction()call intoTxToUniv()so there isn't duplicate code. I'll open a separate PR for that change.