Skip to content

Commit

Permalink
TxBuilder: add setLockTime
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Jan 27, 2016
1 parent 96fb92f commit fd5cd55
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var bscript = require('./script')
var bufferEquals = require('buffer-equals')
var networks = require('./networks')
var ops = require('./opcodes')
var typeforce = require('typeforce')
var types = require('./types')

var ECPair = require('./ecpair')
var ECSignature = require('./ecsignature')
Expand Down Expand Up @@ -135,6 +137,21 @@ function TransactionBuilder (network) {
this.tx = new Transaction()
}

TransactionBuilder.prototype.setLockTime = function (locktime) {
typeforce(types.Uint32, locktime)

// if any signatures exist, throw
if (this.inputs.some(function (input) {
if (!input.signatures) return false

return input.signatures.some(function (s) { return s })
})) {
throw new Error('No, this would invalidate signatures')
}

this.tx.locktime = locktime
}

TransactionBuilder.fromTransaction = function (transaction, network) {
var txb = new TransactionBuilder(network)

Expand Down
22 changes: 22 additions & 0 deletions test/fixtures/transaction_builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,28 @@
"value": 10000
}
]
},
{
"description": "Transaction w/ nLockTime, pubKeyHash -> pubKeyHash",
"txHex": "0100000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000006b483045022100a3b254e1c10b5d039f36c05f323995d6e5a367d98dd78a13d5bbc3991b35720e022022fccea3897d594de0689601fbd486588d5bfa6915be2386db0397ee9a6e80b601210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ffffffff0110270000000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588acffff0000",
"locktime": 65535,
"inputs": [
{
"txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"vout": 0,
"signs": [
{
"keyPair": "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn"
}
]
}
],
"outputs": [
{
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
"value": 10000
}
]
}
],
"fromTransaction": [
Expand Down
2 changes: 2 additions & 0 deletions test/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function construct (f, sign) {
var network = NETWORKS[f.network]
var txb = new TransactionBuilder(network)

txb.setLockTime(f.lockTime)

f.inputs.forEach(function (input) {
var prevTxScript

Expand Down

0 comments on commit fd5cd55

Please sign in to comment.