TxBuilder: copy version/locktime in fromTransaction

This commit is contained in:
Daniel Cousens 2015-01-23 16:35:09 +11:00
parent 510212a3bd
commit a529b3fa0b
3 changed files with 31 additions and 0 deletions

View file

@ -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)

View file

@ -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
}
]
}
]
},

View file

@ -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)