Browse Source

Transaction: remove TxIn/TxOut

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
d8fdd50950
  1. 42
      src/transaction.js

42
src/transaction.js

@ -52,13 +52,14 @@ Transaction.prototype.addInput = function(tx, index) {
assert.equal(typeof index, 'number', 'Expected number index, got ' + index) assert.equal(typeof index, 'number', 'Expected number index, got ' + index)
return (this.ins.push(new TransactionIn({ return (this.ins.push({
outpoint: { outpoint: {
hash: hash, hash: hash,
index: index index: index
}, },
script: Script.EMPTY script: Script.EMPTY,
})) - 1) sequence: DEFAULT_SEQUENCE
}) - 1)
} }
/** /**
@ -83,10 +84,10 @@ Transaction.prototype.addOutput = function(scriptPubKey, value) {
scriptPubKey = address.toOutputScript() scriptPubKey = address.toOutputScript()
} }
return (this.outs.push(new TransactionOut({ return (this.outs.push({
script: scriptPubKey, script: scriptPubKey,
value: value, value: value,
})) - 1) }) - 1)
} }
Transaction.prototype.toBuffer = function () { Transaction.prototype.toBuffer = function () {
@ -209,11 +210,18 @@ Transaction.prototype.clone = function () {
newTx.locktime = this.locktime newTx.locktime = this.locktime
newTx.ins = this.ins.map(function(txin) { newTx.ins = this.ins.map(function(txin) {
return new TransactionIn(txin) return {
outpoint: txin.outpoint,
script: txin.script,
sequence: txin.sequence
}
}) })
newTx.outs = this.outs.map(function(txout) { newTx.outs = this.outs.map(function(txout) {
return new TransactionOut(txout) return {
script: txout.script,
value: txout.value
}
}) })
return newTx return newTx
@ -252,14 +260,14 @@ Transaction.fromBuffer = function(buffer) {
var script = readSlice(scriptLen) var script = readSlice(scriptLen)
var sequence = readUInt32() var sequence = readUInt32()
tx.ins.push(new TransactionIn({ tx.ins.push({
outpoint: { outpoint: {
hash: hash, hash: hash,
index: vout index: vout
}, },
script: Script.fromBuffer(script), script: Script.fromBuffer(script),
sequence: sequence sequence: sequence
})) })
} }
var voutLen = readVarInt() var voutLen = readVarInt()
@ -268,10 +276,10 @@ Transaction.fromBuffer = function(buffer) {
var scriptLen = readVarInt() var scriptLen = readVarInt()
var script = readSlice(scriptLen) var script = readSlice(scriptLen)
tx.outs.push(new TransactionOut({ tx.outs.push({
value: value, value: value,
script: Script.fromBuffer(script) script: Script.fromBuffer(script)
})) })
} }
tx.locktime = readUInt32() tx.locktime = readUInt32()
@ -325,16 +333,4 @@ Transaction.prototype.validateInput = function(index, prevOutScript, pubKey, DER
return pubKey.verify(hash, signature) return pubKey.verify(hash, signature)
} }
function TransactionIn(data) {
assert(data.outpoint && data.script, 'Invalid TxIn parameters')
this.outpoint = data.outpoint
this.script = data.script
this.sequence = data.sequence == undefined ? DEFAULT_SEQUENCE : data.sequence
}
function TransactionOut(data) {
this.script = data.script
this.value = data.value
}
module.exports = Transaction module.exports = Transaction

Loading…
Cancel
Save