diff --git a/src/transaction_builder.js b/src/transaction_builder.js index 5e0a35f..71a46ec 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -19,6 +19,10 @@ function TransactionBuilder() { TransactionBuilder.fromTransaction = function(transaction) { var txb = new TransactionBuilder() + // Copy other transaction fields + txb.tx.version = transaction.version + txb.tx.locktime = transaction.locktime + // Extract/add inputs transaction.ins.forEach(function(txIn) { txb.addInput(txIn.hash, txIn.index, txIn.sequence) diff --git a/test/fixtures/transaction_builder.json b/test/fixtures/transaction_builder.json index a44078b..ad09d7d 100644 --- a/test/fixtures/transaction_builder.json +++ b/test/fixtures/transaction_builder.json @@ -83,6 +83,29 @@ "value": 10000 } ] + }, + { + "description": "Transaction w/ non-default input sequence numbers, version and locktime", + "txid": "4503038f144af7b0c11fad6e09cf8deb4ef04645d203e1c90b86f25b7b243fe8", + "txhex": "0400000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff020000006b483045022100c5bcd521df085481e2dcc2c0f14173043f0fa2001dca582b45186a95d248d28002204c571eabcec1410bd53a7da29b9da6b4c858c3fdabbfdb110a030c507ff5bc0501210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798b9c220000110270000000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac09990400", + "version": 4, + "locktime": 301321, + "inputs": [ + { + "index": 2, + "prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "sequence": 2147001, + "privKeys": [ + "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn" + ] + } + ], + "outputs": [ + { + "script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG", + "value": 10000 + } + ] } ] }, diff --git a/test/transaction_builder.js b/test/transaction_builder.js index 63ad8be..8e2b528 100644 --- a/test/transaction_builder.js +++ b/test/transaction_builder.js @@ -196,6 +196,10 @@ describe('TransactionBuilder', function() { }) }) + // FIXME: add support for locktime/version in TransactionBuilder API + if (f.version !== undefined) txb.tx.version = f.version + if (f.locktime !== undefined) txb.tx.locktime = f.locktime + var tx = txb.build() assert.equal(tx.getId(), f.txid)