Skip to content

Commit e2b8c39

Browse files
committed
Merge #8817: update bitcoin-tx to output witness data
4408558 Update bitcoin-tx to output witness data. (jonnynewbs)
2 parents e2a17e4 + 4408558 commit e2b8c39

12 files changed

+21
-1
lines changed

src/core_write.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
151151
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
152152
{
153153
entry.pushKV("txid", tx.GetHash().GetHex());
154+
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
154155
entry.pushKV("version", tx.nVersion);
155156
entry.pushKV("locktime", (int64_t)tx.nLockTime);
156157

157158
UniValue vin(UniValue::VARR);
158-
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
159+
for (unsigned int i = 0; i < tx.vin.size(); i++) {
160+
const CTxIn& txin = tx.vin[i];
159161
UniValue in(UniValue::VOBJ);
160162
if (tx.IsCoinBase())
161163
in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
@@ -166,6 +168,13 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
166168
o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true));
167169
o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
168170
in.pushKV("scriptSig", o);
171+
if (!tx.wit.IsNull() && i < tx.wit.vtxinwit.size() && !tx.wit.vtxinwit[i].IsNull()) {
172+
UniValue txinwitness(UniValue::VARR);
173+
for (const auto& item : tx.wit.vtxinwit[i].scriptWitness.stack) {
174+
txinwitness.push_back(HexStr(item.begin(), item.end()));
175+
}
176+
in.pushKV("txinwitness", txinwitness);
177+
}
169178
}
170179
in.pushKV("sequence", (int64_t)txin.nSequence);
171180
vin.push_back(in);

src/test/data/blanktx.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",
3+
"hash": "d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",
34
"version": 1,
45
"locktime": 0,
56
"vin": [

src/test/data/tt-delin1-out.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "81b2035be1da1abe745c6141174a73d151009ec17b3d5ebffa2e177408c50dfd",
3+
"hash": "81b2035be1da1abe745c6141174a73d151009ec17b3d5ebffa2e177408c50dfd",
34
"version": 1,
45
"locktime": 0,
56
"vin": [

src/test/data/tt-delout1-out.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "c46ccd75b5050e942b2e86a3648f843f525fe6fc000bf0534ba5973063354493",
3+
"hash": "c46ccd75b5050e942b2e86a3648f843f525fe6fc000bf0534ba5973063354493",
34
"version": 1,
45
"locktime": 0,
56
"vin": [

src/test/data/tt-locktime317000-out.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "aded538f642c17e15f4d3306b8be7e1a4d1ae0c4616d641ab51ea09ba65e5cb5",
3+
"hash": "aded538f642c17e15f4d3306b8be7e1a4d1ae0c4616d641ab51ea09ba65e5cb5",
34
"version": 1,
45
"locktime": 317000,
56
"vin": [

src/test/data/txcreate1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "f70f0d6c71416ed538e37549f430ab3665fee2437a42f10238c1bd490e782231",
3+
"hash": "f70f0d6c71416ed538e37549f430ab3665fee2437a42f10238c1bd490e782231",
34
"version": 1,
45
"locktime": 0,
56
"vin": [

src/test/data/txcreate2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "cf90229625e9eb10f6be8156bf6aa5ec2eca19a42b1e05c11f3029b560a32e13",
3+
"hash": "cf90229625e9eb10f6be8156bf6aa5ec2eca19a42b1e05c11f3029b560a32e13",
34
"version": 1,
45
"locktime": 0,
56
"vin": [

src/test/data/txcreatedata1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "07894b4d12fe7853dd911402db1620920d261b9627c447f931417d330c25f06e",
3+
"hash": "07894b4d12fe7853dd911402db1620920d261b9627c447f931417d330c25f06e",
34
"version": 1,
45
"locktime": 0,
56
"vin": [

src/test/data/txcreatedata2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "4ed17118f5e932ba8c75c461787d171bc02a016d8557cb5bcf34cd416c27bb8b",
3+
"hash": "4ed17118f5e932ba8c75c461787d171bc02a016d8557cb5bcf34cd416c27bb8b",
34
"version": 1,
45
"locktime": 0,
56
"vin": [

src/test/data/txcreatedata_seq0.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"txid": "71603ccb1cd76d73d76eb6cfd5f0b9df6d65d90d76860ee52cb461c4be7032e8",
3+
"hash": "71603ccb1cd76d73d76eb6cfd5f0b9df6d65d90d76860ee52cb461c4be7032e8",
34
"version": 1,
45
"locktime": 0,
56
"vin": [

0 commit comments

Comments
 (0)