Repository: bitcoinjs/bitcoinjs-lib
Pull request #701 (2016-11-14 00:39:04)

Transaction: Witness serialization support default only for some func…
…tions

- [x] Add [originally failing] tests to ensure TXID is encoded without SegWit


dcousens: - [ ] Add tests for `hasWitnesses`
dcousens: @afk11 the only part of any of this: naming things,  and finding test fixtures
afk11: I'll dig up the wtxid tomorrow - the witness fixtures are on testnet!
dcousens: Rebased and now adds failing fixtures before adding a fix commit.

For example, https://github.com/bitcoinjs/bitcoinjs-lib/pull/701/commits/16abf3ed2b6d10ed8f70fd991a6ca9f39ac565b0 was failing , but fixed with https://github.com/bitcoinjs/bitcoinjs-lib/pull/701/commits/2683391df2cc64edbe752d934628b68edae11366, as `setWitness` was not accepting valid arguments.

https://github.com/bitcoinjs/bitcoinjs-lib/pull/701/commits/7a54826c3e27245d1bbe592296bd562e2c664055 was failing due to the default serialization being to always serialize witnesses if available.
Fixed by https://github.com/bitcoinjs/bitcoinjs-lib/pull/701/commits/44e386ec6b2f726f9659cadaba700ea905c23a23.



dcousens: @afk11 we can put `getWitnessHash` and `getWitnessId` in another PR.
They are not limiting this one in any way, and not really related either.
dcousens: `hasWitnesses` being added to the public API should be discussed in https://github.com/bitcoinjs/bitcoinjs-lib/issues/703 first.

This PR purely focuses on fixing the `getId` and import/export ambiguity issues.
dcousens: Good to merge!

Patch:
diff --git a/src/transaction.js b/src/transaction.js
index 582204cb..008e7dc4 100644
--- a/src/transaction.js
+++ b/src/transaction.js
@@ -125,7 +125,7 @@ Transaction.fromBuffer = function (buffer, __noStrict) {
     }
 
     // was this pointless?
-    if (!tx._hasWitnesses()) throw new Error('Transaction has superfluous witness data')
+    if (!tx.__hasWitnesses()) throw new Error('Transaction has superfluous witness data')
   }
 
   tx.locktime = readUInt32()
@@ -184,14 +184,18 @@ Transaction.prototype.addOutput = function (scriptPubKey, value) {
   }) - 1)
 }
 
-Transaction.prototype._hasWitnesses = function () {
+Transaction.prototype.__hasWitnesses = function () {
   return this.ins.some(function (x) {
     return x.witness.length !== 0
   })
 }
 
 Transaction.prototype.byteLength = function () {
-  var hasWitnesses = this._hasWitnesses()
+  return this.__byteLength(true)
+}
+
+Transaction.prototype.__byteLength = function (__allowWitness) {
+  var hasWitnesses = __allowWitness && this.__hasWitnesses()
 
   return (
     (hasWitnesses ? 10 : 8) +
@@ -294,9 +298,9 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT
   }
 
   // serialize and hash
-  var buffer = new Buffer(txTmp.byteLength() + 4)
+  var buffer = new Buffer(txTmp.__byteLength(false) + 4)
   buffer.writeInt32LE(hashType, buffer.length - 4)
-  txTmp.toBuffer(buffer, 0)
+  txTmp.__toBuffer(buffer, 0, false)
 
   return bcrypto.hash256(buffer)
 }
@@ -386,7 +390,7 @@ Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, value
 }
 
 Transaction.prototype.getHash = function () {
-  return bcrypto.hash256(this.toBuffer())
+  return bcrypto.hash256(this.__toBuffer(undefined, undefined, false))
 }
 
 Transaction.prototype.getId = function () {
@@ -395,7 +399,11 @@ Transaction.prototype.getId = function () {
 }
 
 Transaction.prototype.toBuffer = function (buffer, initialOffset) {
-  if (!buffer) buffer = new Buffer(this.byteLength())
+  return this.__toBuffer(buffer, initialOffset, true)
+}
+
+Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitness) {
+  if (!buffer) buffer = new Buffer(this.__byteLength(__allowWitness))
 
   var offset = initialOffset || 0
   function writeSlice (slice) { offset += slice.copy(buffer, offset) }
@@ -409,7 +417,7 @@ Transaction.prototype.toBuffer = function (buffer, initialOffset) {
 
   writeInt32(this.version)
 
-  var hasWitnesses = this._hasWitnesses()
+  var hasWitnesses = __allowWitness && this.__hasWitnesses()
 
   if (hasWitnesses) {
     writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)
@@ -460,7 +468,7 @@ Transaction.prototype.setInputScript = function (index, scriptSig) {
 }
 
 Transaction.prototype.setWitness = function (index, witness) {
-  typeforce(types.tuple(types.Number, types.Buffer), arguments)
+  typeforce(types.tuple(types.Number, [types.Buffer]), arguments)
 
   this.ins[index].witness = witness
 }


Test patch:
diff --git a/test/fixtures/transaction.json b/test/fixtures/transaction.json
index 7410cadf..8c3fd4a7 100644
--- a/test/fixtures/transaction.json
+++ b/test/fixtures/transaction.json
@@ -229,158 +229,18 @@
         ]
       },
       "coinbase": false
-    }
-  ],
-  "hashForSignature": [
-    {
-      "description": "Out of range inIndex",
-      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
-      "inIndex": 2,
-      "script": "OP_0",
-      "type": 0,
-      "hash": "0000000000000000000000000000000000000000000000000000000000000001"
     },
-    {
-      "description": "inIndex > nOutputs (SIGHASH_SINGLE)",
-      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
-      "inIndex": 2,
-      "script": "OP_0",
-      "type": 3,
-      "hash": "0000000000000000000000000000000000000000000000000000000000000001"
-    },
-    {
-      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
-      "inIndex": 0,
-      "script": "OP_0 OP_3",
-      "type": 0,
-      "hash": "3d56a632462b9fc9b89eeddcad7dbe476297f34aff7e5f9320e2a99fb5e97136"
-    },
-    {
-      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
-      "inIndex": 0,
-      "script": "OP_0 OP_CODESEPARATOR OP_3",
-      "type": 0,
-      "hash": "3d56a632462b9fc9b89eeddcad7dbe476297f34aff7e5f9320e2a99fb5e97136"
-    },
-    {
-      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
-      "inIndex": 0,
-      "script": "OP_0 OP_CODESEPARATOR OP_4",
-      "type": 0,
-      "hash": "fa075877cb54916236806a6562e4a8cdad48adf1268e73d72d1f9fdd867df463"
-    }
-  ],
-  "invalid": {
-    "addInput": [
-      {
-        "exception": "Expected property \"0\" of type Buffer\\(Length: 32\\), got Buffer\\(Length: 30\\)",
-        "hash": "0aed1366a73b6057ee7800d737bff1bdf8c448e98d86bc0998f2b009816d",
-        "index": 0
-      },
-      {
-        "exception": "Expected property \"0\" of type Buffer\\(Length: 32\\), got Buffer\\(Length: 34\\)",
-        "hash": "0aed1366a73b6057ee7800d737bff1bdf8c448e98d86bc0998f2b009816da9b0ffff",
-        "index": 0
-      }
-    ],
-    "fromBuffer": [
-      {
-        "exception": "Transaction has unexpected data",
-        "hex": "0100000002f1fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe000000006b483045022100e661badd8d2cf1af27eb3b82e61b5d3f5d5512084591796ae31487f5b82df948022006df3c2a2cac79f68e4b179f4bbb8185a0bb3c4a2486d4405c59b2ba07a74c2101210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798fffffffff2fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe0100000083483045022100be54a46a44fb7e6bf4ebf348061d0dace7ddcbb92d4147ce181cf4789c7061f0022068ccab2a89a47fc29bb5074bca99ae846ab446eecf3c3aaeb238a13838783c78012102c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee517a9147ccb85f0ab2d599bc17246c98babd5a20b1cdc7687ffffffff0250c30000000000001976a914c42e7ef92fdb603af844d064faad95db9bcdfd3d88acf04902000000000017a9147ccb85f0ab2d599bc17246c98babd5a20b1cdc768700000000ffffffff"
-      },
-      {
-        "exception": "Transaction has superfluous witness data",
-        "hex": "0100000000010113ae35a2063ba413c3a1bb9b3820c76291e40e83bd3f23c8ff83333f0c64d623000000004a00483045022100e332e8367d5fee22c205ce1bf4e01e39f1a8decb3ba20d1336770cf38b8ee72d022076b5f83b3ee15390133b7ebf526ec189eb73cc6ee0a726f70b939bc51fa18d8001ffffffff0180969800000000001976a914b1ae3ceac136e4bdb733663e7a1e2f0961198a1788ac0000000000"
-      }
-    ]
-  },
-  "hashForWitnessV0": [
-    {
-      "description": "Native P2WPKH with SIGHASH_ALL",
-      "txHex": "0100000002fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f0000000000eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac11000000",
-      "inIndex": 1,
-      "script": "OP_DUP OP_HASH160 1d0f172a0ecb48aee1be1f2687d2963ae33f71a1 OP_EQUALVERIFY OP_CHECKSIG",
-      "type": 1,
-      "hash": "c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670",
-      "value": 600000000
-    },
-    {
-      "description": "P2SH(P2WPKH) with SIGHASH_ALL",
-      "txHex": "0100000001db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a54770100000000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac0008af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac92040000",
-      "inIndex": 0,
-      "script": "OP_DUP OP_HASH160 79091972186c449eb1ded22b78e40d009bdf0089 OP_EQUALVERIFY OP_CHECKSIG",
-      "type": 1,
-      "hash": "64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6",
-      "value": 1000000000
-    },
-    {
-      "description": "P2SH(P2WSH) with SIGHASH_ALL",
-      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
-      "inIndex": 0,
-      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
-      "type": 1,
-      "hash": "185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c",
-      "value": 987654321
-    },
-    {
-      "description": "P2SH(P2WSH) with SIGHASH_NONE",
-      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
-      "inIndex": 0,
-      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
-      "type": 2,
-      "hash": "e9733bc60ea13c95c6527066bb975a2ff29a925e80aa14c213f686cbae5d2f36",
-      "value": 987654321
-    },
-    {
-      "description": "P2SH(P2WSH) with SIGHASH_SINGLE",
-      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
-      "inIndex": 0,
-      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
-      "type": 3,
-      "hash": "1e1f1c303dc025bd664acb72e583e933fae4cff9148bf78c157d1e8f78530aea",
-      "value": 987654321
-    },
-    {
-      "description": "P2SH(P2WSH) with SIGHASH_ALL | SIGHASH_ANYONECANPAY",
-      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
-      "inIndex": 0,
-      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
-      "type": 129,
-      "hash": "2a67f03e63a6a422125878b40b82da593be8d4efaafe88ee528af6e5a9955c6e",
-      "value": 987654321
-    },
-    {
-      "description": "P2SH(P2WSH) with SIGHASH_NONE | SIGHASH_ANYONECANPAY",
-      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
-      "inIndex": 0,
-      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
-      "type": 130,
-      "hash": "781ba15f3779d5542ce8ecb5c18716733a5ee42a6f51488ec96154934e2c890a",
-      "value": 987654321
-    },
-    {
-      "description": "P2SH(P2WSH) with SIGHASH_SINGLE | SIGHASH_ANYONECANPAY",
-      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
-      "inIndex": 0,
-      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
-      "type": 131,
-      "hash": "511e8e52ed574121fc1b654970395502128263f62662e076dc6baf05c2e6a99b",
-      "value": 987654321
-    }
-  ],
-  "witness": [
     {
       "description": "P2PK",
       "id": "8d4733995be9b3331a65eeb31bce24b213d4fabcbadf7f6634a8fea442c13e6a",
       "hash": "6a3ec142a4fea834667fdfbabcfad413b224ce1bb3ee651a33b3e95b9933478d",
       "hex": "010000000193aef40ae141694895e99e18e49d0181b086dd7c011c0241175c6eaf320099970000000049483045022100e57eba5380dcc8a7bdb5370b423dadd43070e1ca268f94bc97b2ded55ca45e9502206a43151c8af03a00f0ac86526d07981e303fc0daea8c6ed435abe8961533046d01ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": false,
-      "witnessHex": "",
+      "whex": "",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "97990032af6e5c1741021c017cdd86b081019de4189ee995486941e10af4ae93",
+            "hash": "93aef40ae141694895e99e18e49d0181b086dd7c011c0241175c6eaf32009997",
             "index": 0,
             "sigHash": "8d590cd3c3622f1cc22b17967abfeac8aa72e5b64f80d9ca7a61c59f07a47a8f",
             "script": "3045022100e57eba5380dcc8a7bdb5370b423dadd43070e1ca268f94bc97b2ded55ca45e9502206a43151c8af03a00f0ac86526d07981e303fc0daea8c6ed435abe8961533046d01",
@@ -401,20 +261,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2SH P2PK",
       "id": "d4ebb5e09c06dd375f265b51eb7f1a14d12deba71329500e2a00a905fdfdc27d",
       "hash": "7dc2fdfd05a9002a0e502913a7eb2dd1141a7feb515b265f37dd069ce0b5ebd4",
       "hex": "0100000001a30e865fa60f6c25a8b218bb5a6b9acc7cf3f1db2f2e3a7114b51af5d6ae811f000000006c473044022026d2b56b6cb0269bf4e80dd655b9e917019e2ccef57f4b858d03bb45a2da59d9022010519a7f327f03e7c9613e0694f929544af29d3682e7ec8f19147e7a86651ecd012321038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bacffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": false,
-      "witnessHex": "",
+      "whex": "",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "1f81aed6f51ab514713a2e2fdbf1f37ccc9a6b5abb18b2a8256c0fa65f860ea3",
+            "hash": "a30e865fa60f6c25a8b218bb5a6b9acc7cf3f1db2f2e3a7114b51af5d6ae811f",
             "index": 0,
             "sigHash": "e5a339f87c44b443de94b28c1c2a5fe5acedd9ffd2d25ca194cd1d89284b08ed",
             "script": "3044022026d2b56b6cb0269bf4e80dd655b9e917019e2ccef57f4b858d03bb45a2da59d9022010519a7f327f03e7c9613e0694f929544af29d3682e7ec8f19147e7a86651ecd01 21038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac",
@@ -435,33 +295,26 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2WSH P2PK",
       "id": "60f04167a0c94d6439102f7fde9ad77c08a8716419805e77ef66b286cc5c7f87",
       "hash": "877f5ccc86b266ef775e80196471a8087cd79ade7f2f1039644dc9a06741f060",
       "hex": "01000000014533a3bc1e039bd787656068e135aaee10aee95a64776bfc047ee6a7c1ebdd2f0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": true,
-      "witnessHex": "010000000001014533a3bc1e039bd787656068e135aaee10aee95a64776bfc047ee6a7c1ebdd2f0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac02473044022039725bb7291a14dd182dafdeaf3ea0d5c05c34f4617ccbaa46522ca913995c4e02203b170d072ed2e489e7424ad96d8fa888deb530be2d4c5d9aaddf111a7efdb2d3012321038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac00000000",
+      "whex": "010000000001014533a3bc1e039bd787656068e135aaee10aee95a64776bfc047ee6a7c1ebdd2f0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac02473044022039725bb7291a14dd182dafdeaf3ea0d5c05c34f4617ccbaa46522ca913995c4e02203b170d072ed2e489e7424ad96d8fa888deb530be2d4c5d9aaddf111a7efdb2d3012321038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac00000000",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "2fddebc1a7e67e04fc6b77645ae9ae10eeaa35e168606587d79b031ebca33345",
+            "hash": "4533a3bc1e039bd787656068e135aaee10aee95a64776bfc047ee6a7c1ebdd2f",
             "index": 0,
-            "sigHash": "52601433fe6032a7de9afd72703ab6042015128b04472f8f896609ad274ae0f3",
-            "script": "",
-            "scriptHex": "",
             "sequence": 4294967295,
             "witness": [
               "3044022039725bb7291a14dd182dafdeaf3ea0d5c05c34f4617ccbaa46522ca913995c4e02203b170d072ed2e489e7424ad96d8fa888deb530be2d4c5d9aaddf111a7efdb2d301",
               "21038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac"
-            ],
-            "value": 80000,
-            "scriptPubKey": "00200f9ea7bae7166c980169059e39443ed13324495b0d6678ce716262e879591210",
-            "redeemScript": "",
-            "witnessScript": "21038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac"
+            ]
           }
         ],
         "outs": [
@@ -472,20 +325,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2SH P2WSH P2PK",
       "id": "da24fd5a422f72e3bde593628c2b47ff9ca7454e1f3ba5fb916344c218d31052",
       "hash": "5210d318c2446391fba53b1f4e45a79cff472b8c6293e5bde3722f425afd24da",
       "hex": "0100000001e0779d448aaa203a96b3de14d0482e26dd75a4278ae5bb6d7cc18e6874f3866000000000232200200f9ea7bae7166c980169059e39443ed13324495b0d6678ce716262e879591210ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": true,
-      "witnessHex": "01000000000101e0779d448aaa203a96b3de14d0482e26dd75a4278ae5bb6d7cc18e6874f3866000000000232200200f9ea7bae7166c980169059e39443ed13324495b0d6678ce716262e879591210ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac024730440220014207a5f0601ed7b3c3f9d82309b32e8f76dd6776a55cb5f8684b9ff029e0850220693afd7b69471b51d9354cc1a956b68b8d48e32f6b0ad7a19bb5dd3e4499179a012321038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac00000000",
+      "whex": "01000000000101e0779d448aaa203a96b3de14d0482e26dd75a4278ae5bb6d7cc18e6874f3866000000000232200200f9ea7bae7166c980169059e39443ed13324495b0d6678ce716262e879591210ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac024730440220014207a5f0601ed7b3c3f9d82309b32e8f76dd6776a55cb5f8684b9ff029e0850220693afd7b69471b51d9354cc1a956b68b8d48e32f6b0ad7a19bb5dd3e4499179a012321038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac00000000",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "6086f374688ec17c6dbbe58a27a475dd262e48d014deb3963a20aa8a449d77e0",
+            "hash": "e0779d448aaa203a96b3de14d0482e26dd75a4278ae5bb6d7cc18e6874f38660",
             "index": 0,
             "sigHash": "b3caa13417b83a07e4684c5f1b5f4563936cd66791ca106b1770aeeaae682794",
             "script": "00200f9ea7bae7166c980169059e39443ed13324495b0d6678ce716262e879591210",
@@ -509,20 +362,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2PKH",
       "id": "c7a77aeadf529759c8db9b3f205d690cdaed3df0eaf441ead648086e85a6a280",
       "hash": "80a2a6856e0848d6ea41f4eaf03dedda0c695d203f9bdbc8599752dfea7aa7c7",
       "hex": "010000000176d7b05b96e69d9760bacf14e496ea01085eff32be8f4e08b299eb92057826e5000000006b4830450221009bd6ff2561437155913c289923175d3f114cca1c0e2bc5989315d5261502c2c902201b71ad90dce076a5eb872330ed729e7c2c4bc2d0513efff099dbefb3b62eab4f0121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": false,
-      "witnessHex": "",
+      "whex": "",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "e526780592eb99b2084e8fbe32ff5e0801ea96e414cfba60979de6965bb0d776",
+            "hash": "76d7b05b96e69d9760bacf14e496ea01085eff32be8f4e08b299eb92057826e5",
             "index": 0,
             "sigHash": "b01334b1f522b3d824960b2ce215031b392b084eca649a6bd1efdf4caa841e7b",
             "script": "30450221009bd6ff2561437155913c289923175d3f114cca1c0e2bc5989315d5261502c2c902201b71ad90dce076a5eb872330ed729e7c2c4bc2d0513efff099dbefb3b62eab4f01 038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b",
@@ -543,20 +396,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2SH P2PKH",
       "id": "0b8fa64f89b95666a23e424fe94e9114806726be9753e140dbd74c0d673c9593",
       "hash": "93953c670d4cd7db40e15397be26678014914ee94f423ea26656b9894fa68f0b",
       "hex": "01000000014b9ffc17c3cce03ee66980bf32d36aaa13462980c3af9d9d29ec6b97ab1c91650000000084473044022003d738d855d0c54a419ac62ebe1a1c0bf2dc6993c9585adb9a8666736658107002204d57ff62ee7efae6df73430bba62494faeba8c125a4abcf2488757a4f8877dd50121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b1976a914851a33a5ef0d4279bd5854949174e2c65b1d450088acffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": false,
-      "witnessHex": "",
+      "whex": "",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "65911cab976bec299d9dafc380294613aa6ad332bf8069e63ee0ccc317fc9f4b",
+            "hash": "4b9ffc17c3cce03ee66980bf32d36aaa13462980c3af9d9d29ec6b97ab1c9165",
             "index": 0,
             "sigHash": "40c2576db2ad631c5799d344dcb5efd05eef3c52aacb51585af327f8efb3bcde",
             "script": "3044022003d738d855d0c54a419ac62ebe1a1c0bf2dc6993c9585adb9a8666736658107002204d57ff62ee7efae6df73430bba62494faeba8c125a4abcf2488757a4f8877dd501 038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b 76a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac",
@@ -577,20 +430,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2WSH P2PKH",
       "id": "62c62316f80beb10d9b1ce9183eb66e7e18a18324ca5f5e6f839be03f64aba83",
       "hash": "83ba4af603be39f8e6f5a54c32188ae1e766eb8391ceb1d910eb0bf81623c662",
       "hex": "010000000123539877e39a273819006de1c433e09f9e9af201fc178dd0f2cf2eaa5ad53b480000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": true,
-      "witnessHex": "0100000000010123539877e39a273819006de1c433e09f9e9af201fc178dd0f2cf2eaa5ad53b480000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac03483045022100f02a82b0a94a5d5dc4d2127ac34be62cb066713d71d56bdf5ef7810ab57a157302205f24abdde1dab554a02edcf378e98828024e57272e5e474a5b04accdca080a030121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b1976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
+      "whex": "0100000000010123539877e39a273819006de1c433e09f9e9af201fc178dd0f2cf2eaa5ad53b480000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac03483045022100f02a82b0a94a5d5dc4d2127ac34be62cb066713d71d56bdf5ef7810ab57a157302205f24abdde1dab554a02edcf378e98828024e57272e5e474a5b04accdca080a030121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b1976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "483bd55aaa2ecff2d08d17fc01f29a9e9fe033c4e16d001938279ae377985323",
+            "hash": "23539877e39a273819006de1c433e09f9e9af201fc178dd0f2cf2eaa5ad53b48",
             "index": 0,
             "sigHash": "b0197f4cd027b33ebb2ef54e02a7008dc29ec807ec2de58843fffbdf07ceb2c3",
             "script": "",
@@ -615,20 +468,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2SH P2WSH P2PKH",
       "id": "2ef1431ec41a75791b75d16526f23534ae66d8d4abfb483d98d14bcb259311c0",
       "hash": "c0119325cb4bd1983d48fbabd4d866ae3435f22665d1751b79751ac41e43f12e",
       "hex": "0100000001363dfbfe2566db77e3b1195bedf1d0daeb9ce526cd7611ba81759b2654ce415c0000000023220020578db4b54a6961060b71385c17d3280379a557224c52b11b19a3a1c1eef606a0ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": true,
-      "witnessHex": "01000000000101363dfbfe2566db77e3b1195bedf1d0daeb9ce526cd7611ba81759b2654ce415c0000000023220020578db4b54a6961060b71385c17d3280379a557224c52b11b19a3a1c1eef606a0ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac03483045022100c8bd5ebb26ba6719158650c3e7c5e80be4c886ba025c44cc41f5149b3114705a02203ac6e1f38f6c081d506f28f1b5e38ebec9e0f0fa911d0e3f68d48d8b0e77b34b0121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b1976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
+      "whex": "01000000000101363dfbfe2566db77e3b1195bedf1d0daeb9ce526cd7611ba81759b2654ce415c0000000023220020578db4b54a6961060b71385c17d3280379a557224c52b11b19a3a1c1eef606a0ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac03483045022100c8bd5ebb26ba6719158650c3e7c5e80be4c886ba025c44cc41f5149b3114705a02203ac6e1f38f6c081d506f28f1b5e38ebec9e0f0fa911d0e3f68d48d8b0e77b34b0121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b1976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "5c41ce54269b7581ba1176cd26e59cebdad0f1ed5b19b1e377db6625fefb3d36",
+            "hash": "363dfbfe2566db77e3b1195bedf1d0daeb9ce526cd7611ba81759b2654ce415c",
             "index": 0,
             "sigHash": "9580096496f72ae9fed63e6701b2a9df3c8d212d8accd4b1966d3239c33a859f",
             "script": "0020578db4b54a6961060b71385c17d3280379a557224c52b11b19a3a1c1eef606a0",
@@ -653,20 +506,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "Multisig",
       "id": "7f5d96a866a815f5a1896fcd3b49cd00ac4c366a371fe8555f124e628e977a5e",
       "hash": "5e7a978e624e125f55e81f376a364cac00cd493bcd6f89a1f515a866a8965d7f",
       "hex": "010000000179310ec46e734b3490ee839c5ae4a09d28561ee9fff2d051f733d201f958d6d2000000004a00483045022100d269531f120f377ed2f94f42bef893ff2fe6544ac97fb477fa291bc6cfb7647e02200983f6a5bbd4ce6cf97f571995634805a7324cc5d8353ed954fa62477b0fcd0901ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": false,
-      "witnessHex": "",
+      "whex": "",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "d2d658f901d233f751d0f2ffe91e56289da0e45a9c83ee90344b736ec40e3179",
+            "hash": "79310ec46e734b3490ee839c5ae4a09d28561ee9fff2d051f733d201f958d6d2",
             "index": 0,
             "sigHash": "1c68226955e39aed91eb7f35fa106240951208138b584caeb05b44f367078b09",
             "script": "OP_0 3045022100d269531f120f377ed2f94f42bef893ff2fe6544ac97fb477fa291bc6cfb7647e02200983f6a5bbd4ce6cf97f571995634805a7324cc5d8353ed954fa62477b0fcd0901",
@@ -687,20 +540,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2SH Multisig",
       "id": "3aef827e4306bab01f118a8eccad74713bcd1695362caf9fed55202ed54ef88b",
       "hash": "8bf84ed52e2055ed9faf2c369516cd3b7174adcc8e8a111fb0ba06437e82ef3a",
       "hex": "010000000152882c661c49dd2f53bd9ced7e9f44b184888ad2fe7d86737f0efaa7aecdced1000000006f00473044022025f2e161f0a97888df948f4dcc7c04fe502510b8d8260ca9920f38d55e4d17720220271b6843224b3a34542a4df31781d048da56ee46b8c5fb99043e30abd527b2d801255121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b51aeffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": false,
-      "witnessHex": "",
+      "whex": "",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "d1cecdaea7fa0e7f73867dfed28a8884b1449f7eed9cbd532fdd491c662c8852",
+            "hash": "52882c661c49dd2f53bd9ced7e9f44b184888ad2fe7d86737f0efaa7aecdced1",
             "index": 0,
             "sigHash": "a1b982ea4d57c3255268a801885ea8ee8b785d52bf7dd024997a5111c9295f5a",
             "script": "OP_0 3044022025f2e161f0a97888df948f4dcc7c04fe502510b8d8260ca9920f38d55e4d17720220271b6843224b3a34542a4df31781d048da56ee46b8c5fb99043e30abd527b2d801 5121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b51ae",
@@ -721,20 +574,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2WSH Multisig",
       "id": "03e6b741d25cbd061b8d0999a521788ef90263dd8ba96d91c2136a4386afdf8e",
       "hash": "8edfaf86436a13c2916da98bdd6302f98e7821a599098d1b06bd5cd241b7e603",
       "hex": "0100000001c1eced6216de0889d4629ff64a8af8e8ec6d0b414de0c57b46c02cc303d321fe0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": true,
-      "witnessHex": "01000000000101c1eced6216de0889d4629ff64a8af8e8ec6d0b414de0c57b46c02cc303d321fe0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac0300483045022100d4c0cbdb45915b8a3162362fa5f74556de919aeda5337fc44a7fb000e833460d022017742c37d7a061e2ae3a086c7c585c9c85e5d31af468d3e00045c0f35b8f8eb601255121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b51ae00000000",
+      "whex": "01000000000101c1eced6216de0889d4629ff64a8af8e8ec6d0b414de0c57b46c02cc303d321fe0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac0300483045022100d4c0cbdb45915b8a3162362fa5f74556de919aeda5337fc44a7fb000e833460d022017742c37d7a061e2ae3a086c7c585c9c85e5d31af468d3e00045c0f35b8f8eb601255121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b51ae00000000",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "fe21d303c32cc0467bc5e04d410b6dece8f88a4af69f62d48908de1662edecc1",
+            "hash": "c1eced6216de0889d4629ff64a8af8e8ec6d0b414de0c57b46c02cc303d321fe",
             "index": 0,
             "sigHash": "c57f8489d77552631b10fc703de3d2a72e473590b8b8283f4a1134855c6e4368",
             "script": "",
@@ -759,20 +612,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2SH P2WSH Multisig",
       "id": "e77fd9ea35346e295e1e15de9724fff42b5c127da4c5447a4ffddd361f66b1c1",
       "hash": "c1b1661f36ddfd4f7a44c5a47d125c2bf4ff2497de151e5e296e3435ead97fe7",
       "hex": "01000000013a5a2ab0223d3b504b52af76d650329750666fbf1be13d4cb08d0d9fc550a47d00000000232200201b8c0c2878c5634c3ce738cdc568c592e99783dbd28ff4c6cb5b7b4675d9ee99ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": true,
-      "witnessHex": "010000000001013a5a2ab0223d3b504b52af76d650329750666fbf1be13d4cb08d0d9fc550a47d00000000232200201b8c0c2878c5634c3ce738cdc568c592e99783dbd28ff4c6cb5b7b4675d9ee99ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac0300483045022100c97a5e205ce0023d3d44f846abf1f0e21b6f2646bd2496bbe92e4333fe4401be02201247e047d669f713582713e35d2eba430abc3d75a924bb500362bf47d6234ed501255121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b51ae00000000",
+      "whex": "010000000001013a5a2ab0223d3b504b52af76d650329750666fbf1be13d4cb08d0d9fc550a47d00000000232200201b8c0c2878c5634c3ce738cdc568c592e99783dbd28ff4c6cb5b7b4675d9ee99ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac0300483045022100c97a5e205ce0023d3d44f846abf1f0e21b6f2646bd2496bbe92e4333fe4401be02201247e047d669f713582713e35d2eba430abc3d75a924bb500362bf47d6234ed501255121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b51ae00000000",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "7da450c59f0d8db04c3de11bbf6f6650973250d676af524b503b3d22b02a5a3a",
+            "hash": "3a5a2ab0223d3b504b52af76d650329750666fbf1be13d4cb08d0d9fc550a47d",
             "index": 0,
             "sigHash": "90ced36a2a53e986837407ec5b34fca11c68b477fa51806715186595372c0b37",
             "script": "00201b8c0c2878c5634c3ce738cdc568c592e99783dbd28ff4c6cb5b7b4675d9ee99",
@@ -797,20 +650,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2WKH",
       "id": "10bbdf7e9301bc21f1da8684f25fd66bc1314904c30da25a8ebf967c58c89269",
       "hash": "6992c8587c96bf8e5aa20dc3044931c16bd65ff28486daf121bc01937edfbb10",
       "hex": "010000000133defbe3e28860007ff3e21222774c220cb35d554fa3e3796d25bf8ee983e1080000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": true,
-      "witnessHex": "0100000000010133defbe3e28860007ff3e21222774c220cb35d554fa3e3796d25bf8ee983e1080000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac0248304502210097c3006f0b390982eb47f762b2853773c6cedf83668a22d710f4c13c4fd6b15502205e26ef16a81fc818a37f3a34fc6d0700e61100ea6c6773907c9c046042c440340121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b00000000",
+      "whex": "0100000000010133defbe3e28860007ff3e21222774c220cb35d554fa3e3796d25bf8ee983e1080000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac0248304502210097c3006f0b390982eb47f762b2853773c6cedf83668a22d710f4c13c4fd6b15502205e26ef16a81fc818a37f3a34fc6d0700e61100ea6c6773907c9c046042c440340121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b00000000",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "08e183e98ebf256d79e3a34f555db30c224c772212e2f37f006088e2e3fbde33",
+            "hash": "33defbe3e28860007ff3e21222774c220cb35d554fa3e3796d25bf8ee983e108",
             "index": 0,
             "sigHash": "8ef2f4892fdbb44a7859ac059cdacf20903566a1472fae38ba37443c44b66202",
             "script": "",
@@ -834,20 +687,20 @@
           }
         ],
         "locktime": 0
-      }
+      },
+      "coinbase": false
     },
     {
       "description": "P2SH P2WKH",
       "id": "a0dd6714722a577c5db08f740cd1525f5383f8771dd0ebecd9ae96eb6623408a",
       "hash": "8a402366eb96aed9ecebd01d77f883535f52d10c748fb05d7c572a721467dda0",
       "hex": "01000000015df9a0b9ade2d835881704e0f53b51a4b19ecfc794ea1f3555783dd7f68659ce0000000017160014851a33a5ef0d4279bd5854949174e2c65b1d4500ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac00000000",
-      "hasWitness": true,
-      "witnessHex": "010000000001015df9a0b9ade2d835881704e0f53b51a4b19ecfc794ea1f3555783dd7f68659ce0000000017160014851a33a5ef0d4279bd5854949174e2c65b1d4500ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac02483045022100cb3929c128fec5108071b662e5af58e39ac8708882753a421455ca80462956f6022030c0f4738dd1a13fc7a34393002d25c6e8a6399f29c7db4b98f53a9475d94ca20121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b00000000",
+      "whex": "010000000001015df9a0b9ade2d835881704e0f53b51a4b19ecfc794ea1f3555783dd7f68659ce0000000017160014851a33a5ef0d4279bd5854949174e2c65b1d4500ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac02483045022100cb3929c128fec5108071b662e5af58e39ac8708882753a421455ca80462956f6022030c0f4738dd1a13fc7a34393002d25c6e8a6399f29c7db4b98f53a9475d94ca20121038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b00000000",
       "raw": {
         "version": 1,
         "ins": [
           {
-            "hash": "ce5986f6d73d7855351fea94c7cf9eb1a4513bf5e004178835d8e2adb9a0f95d",
+            "hash": "5df9a0b9ade2d835881704e0f53b51a4b19ecfc794ea1f3555783dd7f68659ce",
             "index": 0,
             "sigHash": "b9d9a395dbd84365e93016a3ba1ffe2c373b85e245598597b2f8cd6eb0706252",
             "script": "0014851a33a5ef0d4279bd5854949174e2c65b1d4500",
@@ -871,7 +724,145 @@
           }
         ],
         "locktime": 0
+      },
+      "coinbase": false
+    }
+  ],
+  "hashForSignature": [
+    {
+      "description": "Out of range inIndex",
+      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
+      "inIndex": 2,
+      "script": "OP_0",
+      "type": 0,
+      "hash": "0000000000000000000000000000000000000000000000000000000000000001"
+    },
+    {
+      "description": "inIndex > nOutputs (SIGHASH_SINGLE)",
+      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
+      "inIndex": 2,
+      "script": "OP_0",
+      "type": 3,
+      "hash": "0000000000000000000000000000000000000000000000000000000000000001"
+    },
+    {
+      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
+      "inIndex": 0,
+      "script": "OP_0 OP_3",
+      "type": 0,
+      "hash": "3d56a632462b9fc9b89eeddcad7dbe476297f34aff7e5f9320e2a99fb5e97136"
+    },
+    {
+      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
+      "inIndex": 0,
+      "script": "OP_0 OP_CODESEPARATOR OP_3",
+      "type": 0,
+      "hash": "3d56a632462b9fc9b89eeddcad7dbe476297f34aff7e5f9320e2a99fb5e97136"
+    },
+    {
+      "txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
+      "inIndex": 0,
+      "script": "OP_0 OP_CODESEPARATOR OP_4",
+      "type": 0,
+      "hash": "fa075877cb54916236806a6562e4a8cdad48adf1268e73d72d1f9fdd867df463"
+    }
+  ],
+  "invalid": {
+    "addInput": [
+      {
+        "exception": "Expected property \"0\" of type Buffer\\(Length: 32\\), got Buffer\\(Length: 30\\)",
+        "hash": "0aed1366a73b6057ee7800d737bff1bdf8c448e98d86bc0998f2b009816d",
+        "index": 0
+      },
+      {
+        "exception": "Expected property \"0\" of type Buffer\\(Length: 32\\), got Buffer\\(Length: 34\\)",
+        "hash": "0aed1366a73b6057ee7800d737bff1bdf8c448e98d86bc0998f2b009816da9b0ffff",
+        "index": 0
+      }
+    ],
+    "fromBuffer": [
+      {
+        "exception": "Transaction has unexpected data",
+        "hex": "0100000002f1fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe000000006b483045022100e661badd8d2cf1af27eb3b82e61b5d3f5d5512084591796ae31487f5b82df948022006df3c2a2cac79f68e4b179f4bbb8185a0bb3c4a2486d4405c59b2ba07a74c2101210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798fffffffff2fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe0100000083483045022100be54a46a44fb7e6bf4ebf348061d0dace7ddcbb92d4147ce181cf4789c7061f0022068ccab2a89a47fc29bb5074bca99ae846ab446eecf3c3aaeb238a13838783c78012102c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee517a9147ccb85f0ab2d599bc17246c98babd5a20b1cdc7687ffffffff0250c30000000000001976a914c42e7ef92fdb603af844d064faad95db9bcdfd3d88acf04902000000000017a9147ccb85f0ab2d599bc17246c98babd5a20b1cdc768700000000ffffffff"
+      },
+      {
+        "exception": "Transaction has superfluous witness data",
+        "hex": "0100000000010113ae35a2063ba413c3a1bb9b3820c76291e40e83bd3f23c8ff83333f0c64d623000000004a00483045022100e332e8367d5fee22c205ce1bf4e01e39f1a8decb3ba20d1336770cf38b8ee72d022076b5f83b3ee15390133b7ebf526ec189eb73cc6ee0a726f70b939bc51fa18d8001ffffffff0180969800000000001976a914b1ae3ceac136e4bdb733663e7a1e2f0961198a1788ac0000000000"
       }
+    ]
+  },
+  "hashForWitnessV0": [
+    {
+      "description": "Native P2WPKH with SIGHASH_ALL",
+      "txHex": "0100000002fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f0000000000eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac11000000",
+      "inIndex": 1,
+      "script": "OP_DUP OP_HASH160 1d0f172a0ecb48aee1be1f2687d2963ae33f71a1 OP_EQUALVERIFY OP_CHECKSIG",
+      "type": 1,
+      "hash": "c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670",
+      "value": 600000000
+    },
+    {
+      "description": "P2SH(P2WPKH) with SIGHASH_ALL",
+      "txHex": "0100000001db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a54770100000000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac0008af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac92040000",
+      "inIndex": 0,
+      "script": "OP_DUP OP_HASH160 79091972186c449eb1ded22b78e40d009bdf0089 OP_EQUALVERIFY OP_CHECKSIG",
+      "type": 1,
+      "hash": "64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6",
+      "value": 1000000000
+    },
+    {
+      "description": "P2SH(P2WSH) with SIGHASH_ALL",
+      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
+      "inIndex": 0,
+      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
+      "type": 1,
+      "hash": "185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c",
+      "value": 987654321
+    },
+    {
+      "description": "P2SH(P2WSH) with SIGHASH_NONE",
+      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
+      "inIndex": 0,
+      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
+      "type": 2,
+      "hash": "e9733bc60ea13c95c6527066bb975a2ff29a925e80aa14c213f686cbae5d2f36",
+      "value": 987654321
+    },
+    {
+      "description": "P2SH(P2WSH) with SIGHASH_SINGLE",
+      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
+      "inIndex": 0,
+      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
+      "type": 3,
+      "hash": "1e1f1c303dc025bd664acb72e583e933fae4cff9148bf78c157d1e8f78530aea",
+      "value": 987654321
+    },
+    {
+      "description": "P2SH(P2WSH) with SIGHASH_ALL | SIGHASH_ANYONECANPAY",
+      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
+      "inIndex": 0,
+      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
+      "type": 129,
+      "hash": "2a67f03e63a6a422125878b40b82da593be8d4efaafe88ee528af6e5a9955c6e",
+      "value": 987654321
+    },
+    {
+      "description": "P2SH(P2WSH) with SIGHASH_NONE | SIGHASH_ANYONECANPAY",
+      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
+      "inIndex": 0,
+      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
+      "type": 130,
+      "hash": "781ba15f3779d5542ce8ecb5c18716733a5ee42a6f51488ec96154934e2c890a",
+      "value": 987654321
+    },
+    {
+      "description": "P2SH(P2WSH) with SIGHASH_SINGLE | SIGHASH_ANYONECANPAY",
+      "txHex": "010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000",
+      "inIndex": 0,
+      "script": "OP_6 0307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba3 03b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b 034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a 033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f4 03a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac16 02d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b OP_6 OP_CHECKMULTISIG",
+      "type": 131,
+      "hash": "511e8e52ed574121fc1b654970395502128263f62662e076dc6baf05c2e6a99b",
+      "value": 987654321
     }
   ]
 }
\ No newline at end of file
diff --git a/test/transaction.js b/test/transaction.js
index 30b3d748..40482452 100644
--- a/test/transaction.js
+++ b/test/transaction.js
@@ -2,18 +2,16 @@
 
 var assert = require('assert')
 var bscript = require('../src/script')
-
-var Transaction = require('../src/transaction')
-
 var fixtures = require('./fixtures/transaction')
+var Transaction = require('../src/transaction')
 
 describe('Transaction', function () {
-  function fromRaw (raw) {
+  function fromRaw (raw, noWitness) {
     var tx = new Transaction()
     tx.version = raw.version
     tx.locktime = raw.locktime
 
-    raw.ins.forEach(function (txIn) {
+    raw.ins.forEach(function (txIn, i) {
       var txHash = new Buffer(txIn.hash, 'hex')
       var scriptSig
 
@@ -24,6 +22,14 @@ describe('Transaction', function () {
       }
 
       tx.addInput(txHash, txIn.index, txIn.sequence, scriptSig)
+
+      if (!noWitness && txIn.witness) {
+        var witness = txIn.witness.map(function (x) {
+          return new Buffer(x, 'hex')
+        })
+
+        tx.setWitness(i, witness)
+      }
     })
 
     raw.outs.forEach(function (txOut) {
@@ -46,23 +52,22 @@ describe('Transaction', function () {
       var id = f.id || f.hash
       var txHex = f.hex || f.txHex
 
-      if (f.hasWitness) {
-        it('imports ' + f.description + ' (' + id + ') as witness', function () {
-          var actual = Transaction.fromHex(f.witnessHex)
-
-          assert.strictEqual(actual.toHex(), f.witnessHex, actual.toHex())
-        })
-      }
-
       it('imports ' + f.description + ' (' + id + ')', function () {
         var actual = Transaction.fromHex(txHex)
 
-        assert.strictEqual(actual.toHex(), txHex, actual.toHex())
+        assert.strictEqual(actual.toHex(), txHex)
       })
+
+      if (f.whex) {
+        it('imports ' + f.description + ' (' + id + ') as witness', function () {
+          var actual = Transaction.fromHex(f.whex)
+
+          assert.strictEqual(actual.toHex(), f.whex)
+        })
+      }
     }
 
     fixtures.valid.forEach(importExport)
-    fixtures.witness.forEach(importExport)
     fixtures.hashForSignature.forEach(importExport)
     fixtures.hashForWitnessV0.forEach(importExport)
 
@@ -73,14 +78,25 @@ describe('Transaction', function () {
         }, new RegExp(f.exception))
       })
     })
+
+    it('.version should be interpreted as an int32le', function () {
+      var txHex = 'ffffffff0000ffffffff'
+      var tx = Transaction.fromHex(txHex)
+      assert.equal(-1, tx.version)
+      assert.equal(0xffffffff, tx.locktime)
+    })
   })
 
   describe('toBuffer/toHex', function () {
     fixtures.valid.forEach(function (f) {
       it('exports ' + f.description + ' (' + f.id + ')', function () {
-        var actual = fromRaw(f.raw)
+        if (f.whex) {
+          var wactual = fromRaw(f.raw)
+          assert.strictEqual(wactual.toHex(), f.whex)
+        }
 
-        assert.strictEqual(actual.toHex(), f.hex, actual.toHex())
+        var actual = fromRaw(f.raw, true)
+        assert.strictEqual(actual.toHex(), f.hex)
       })
     })
 
@@ -103,15 +119,6 @@ describe('Transaction', function () {
     })
   })
 
-  describe('transactionVersion', function () {
-    it('should be interpreted as an int32le', function () {
-      var txHex = 'ffffffff0000ffffffff'
-      var tx = Transaction.fromHex(txHex)
-      assert.equal(-1, tx.version)
-      assert.equal(0xffffffff, tx.locktime)
-    })
-  })
-
   describe('addInput', function () {
     var prevTxHash
     beforeEach(function () {
@@ -172,34 +179,29 @@ describe('Transaction', function () {
     })
   })
 
-  describe('getId', function () {
-    fixtures.valid.forEach(function (f) {
+  describe('getHash/getId', function () {
+    function verify (f) {
       it('should return the id for ' + f.id, function () {
-        var tx = Transaction.fromHex(f.hex)
+        var tx = Transaction.fromHex(f.whex || f.hex)
 
+        assert.strictEqual(tx.getHash().toString('hex'), f.hash)
         assert.strictEqual(tx.getId(), f.id)
       })
-    })
-  })
-
-  describe('getHash', function () {
-    fixtures.valid.forEach(function (f) {
-      it('should return the hash for ' + f.id, function () {
-        var tx = Transaction.fromHex(f.hex)
+    }
 
-        assert.strictEqual(tx.getHash().toString('hex'), f.hash)
-      })
-    })
+    fixtures.valid.forEach(verify)
   })
 
   describe('isCoinbase', function () {
-    fixtures.valid.forEach(function (f) {
+    function verify (f) {
       it('should return ' + f.coinbase + ' for ' + f.id, function () {
         var tx = Transaction.fromHex(f.hex)
 
         assert.strictEqual(tx.isCoinbase(), f.coinbase)
       })
-    })
+    }
+
+    fixtures.valid.forEach(verify)
   })
 
   describe('hashForSignature', function () {