Transaction: remove .outpoint object
This commit is contained in:
parent
569e0d4ff1
commit
c0e5393595
5 changed files with 31 additions and 32 deletions
|
@ -1,5 +1,3 @@
|
|||
// FIXME: To all ye that enter here, be weary of Buffers, Arrays and Hex interchanging between the outpoints
|
||||
|
||||
var assert = require('assert')
|
||||
var bufferutils = require('./bufferutils')
|
||||
var crypto = require('./crypto')
|
||||
|
@ -53,10 +51,8 @@ Transaction.prototype.addInput = function(tx, index) {
|
|||
assert.equal(typeof index, 'number', 'Expected number index, got ' + index)
|
||||
|
||||
return (this.ins.push({
|
||||
outpoint: {
|
||||
hash: hash,
|
||||
index: index
|
||||
},
|
||||
hash: hash,
|
||||
index: index,
|
||||
script: Script.EMPTY,
|
||||
sequence: DEFAULT_SEQUENCE
|
||||
}) - 1)
|
||||
|
@ -129,8 +125,8 @@ Transaction.prototype.toBuffer = function () {
|
|||
writeVarInt(this.ins.length)
|
||||
|
||||
this.ins.forEach(function(txin) {
|
||||
writeSlice(txin.outpoint.hash)
|
||||
writeUInt32(txin.outpoint.index)
|
||||
writeSlice(txin.hash)
|
||||
writeUInt32(txin.index)
|
||||
writeVarInt(txin.script.buffer.length)
|
||||
writeSlice(txin.script.buffer)
|
||||
writeUInt32(txin.sequence)
|
||||
|
@ -211,7 +207,8 @@ Transaction.prototype.clone = function () {
|
|||
|
||||
newTx.ins = this.ins.map(function(txin) {
|
||||
return {
|
||||
outpoint: txin.outpoint,
|
||||
hash: txin.hash,
|
||||
index: txin.index,
|
||||
script: txin.script,
|
||||
sequence: txin.sequence
|
||||
}
|
||||
|
@ -261,10 +258,8 @@ Transaction.fromBuffer = function(buffer) {
|
|||
var sequence = readUInt32()
|
||||
|
||||
tx.ins.push({
|
||||
outpoint: {
|
||||
hash: hash,
|
||||
index: vout
|
||||
},
|
||||
hash: hash,
|
||||
index: vout,
|
||||
script: Script.fromBuffer(script),
|
||||
sequence: sequence
|
||||
})
|
||||
|
|
|
@ -170,14 +170,12 @@ function Wallet(seed, network) {
|
|||
})
|
||||
|
||||
tx.ins.forEach(function(txIn) {
|
||||
var op = txIn.outpoint
|
||||
|
||||
// copy and convert to big-endian hex
|
||||
var txinHash = new Buffer(op.hash)
|
||||
Array.prototype.reverse.call(txinHash)
|
||||
txinHash = txinHash.toString('hex')
|
||||
var txinId = new Buffer(txIn.hash)
|
||||
Array.prototype.reverse.call(txinId)
|
||||
txinId = txinId.toString('hex')
|
||||
|
||||
var output = txinHash + ':' + op.index
|
||||
var output = txinId + ':' + txIn.index
|
||||
|
||||
if(me.outputs[output]) delete me.outputs[output]
|
||||
})
|
||||
|
|
|
@ -147,7 +147,7 @@ describe('Bitcoin-core', function() {
|
|||
var prevOutIndex = input[1]
|
||||
// var prevOutScriptPubKey = input[2] // TODO: we don't have a ASM parser
|
||||
|
||||
var actualHash = txin.outpoint.hash
|
||||
var actualHash = txin.hash
|
||||
|
||||
// Test data is big-endian
|
||||
Array.prototype.reverse.call(actualHash)
|
||||
|
@ -155,7 +155,7 @@ describe('Bitcoin-core', function() {
|
|||
assert.equal(actualHash.toString('hex'), prevOutHash)
|
||||
|
||||
// we read UInt32, not Int32
|
||||
assert.equal(txin.outpoint.index & 0xffffffff, prevOutIndex)
|
||||
assert.equal(txin.index & 0xffffffff, prevOutIndex)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -51,8 +51,8 @@ describe('Transaction', function() {
|
|||
var input = tx.ins[0]
|
||||
assert.equal(input.sequence, 4294967295)
|
||||
|
||||
assert.equal(input.outpoint.index, 0)
|
||||
assert.equal(input.outpoint.hash.toString('hex'), "344630cbff61fbc362f7e1ff2f11a344c29326e4ee96e787dc0d4e5cc02fd069")
|
||||
assert.equal(input.index, 0)
|
||||
assert.equal(input.hash.toString('hex'), "344630cbff61fbc362f7e1ff2f11a344c29326e4ee96e787dc0d4e5cc02fd069")
|
||||
|
||||
assert.equal(input.script.toHex(), "493046022100ef89701f460e8660c80808a162bbf2d676f40a331a243592c36d6bd1f81d6bdf022100d29c072f1b18e59caba6e1f0b8cadeb373fd33a25feded746832ec179880c23901")
|
||||
})
|
||||
|
@ -118,8 +118,8 @@ describe('Transaction', function() {
|
|||
var input = tx.ins[0]
|
||||
assert.equal(input.sequence, 4294967295)
|
||||
|
||||
assert.equal(input.outpoint.index, 0)
|
||||
assert.equal(input.outpoint.hash.toString('hex'), "576bc3c3285dbdccd8c3cbd8c03e10d7f77a5c839c744f34c3eb00511059b80c")
|
||||
assert.equal(input.index, 0)
|
||||
assert.equal(input.hash.toString('hex'), "576bc3c3285dbdccd8c3cbd8c03e10d7f77a5c839c744f34c3eb00511059b80c")
|
||||
|
||||
assert.equal(input.script, Script.EMPTY)
|
||||
}
|
||||
|
|
|
@ -328,11 +328,11 @@ describe('Wallet', function() {
|
|||
|
||||
it("deletes corresponding 'output'", function(){
|
||||
var txIn = spendTx.ins[0]
|
||||
var txInId = new Buffer(txIn.outpoint.hash)
|
||||
var txInId = new Buffer(txIn.hash)
|
||||
Array.prototype.reverse.call(txInId)
|
||||
txInId = txInId.toString('hex')
|
||||
|
||||
var expected = txInId + ':' + txIn.outpoint.index
|
||||
var expected = txInId + ':' + txIn.index
|
||||
assert(expected in wallet.outputs)
|
||||
|
||||
wallet.processConfirmedTx(spendTx)
|
||||
|
@ -400,7 +400,8 @@ describe('Wallet', function() {
|
|||
var tx = wallet.createTx(to, value)
|
||||
|
||||
assert.equal(tx.ins.length, 1)
|
||||
assert.deepEqual(tx.ins[0].outpoint, { hash: fakeTxHash(3), index: 0 })
|
||||
assert.deepEqual(tx.ins[0].hash, fakeTxHash(3))
|
||||
assert.equal(tx.ins[0].index, 0)
|
||||
})
|
||||
|
||||
it('allows fee to be specified', function(){
|
||||
|
@ -408,8 +409,11 @@ describe('Wallet', function() {
|
|||
var tx = wallet.createTx(to, value, fee)
|
||||
|
||||
assert.equal(tx.ins.length, 2)
|
||||
assert.deepEqual(tx.ins[0].outpoint, { hash: fakeTxHash(3), index: 0 })
|
||||
assert.deepEqual(tx.ins[1].outpoint, { hash: fakeTxHash(2), index: 1 })
|
||||
|
||||
assert.deepEqual(tx.ins[0].hash, fakeTxHash(3))
|
||||
assert.equal(tx.ins[0].index, 0)
|
||||
assert.deepEqual(tx.ins[1].hash, fakeTxHash(2))
|
||||
assert.equal(tx.ins[1].index, 1)
|
||||
})
|
||||
|
||||
it('allows fee to be set to zero', function(){
|
||||
|
@ -418,7 +422,8 @@ describe('Wallet', function() {
|
|||
var tx = wallet.createTx(to, value, fee)
|
||||
|
||||
assert.equal(tx.ins.length, 1)
|
||||
assert.deepEqual(tx.ins[0].outpoint, { hash: fakeTxHash(3), index: 0 })
|
||||
assert.deepEqual(tx.ins[0].hash, fakeTxHash(3))
|
||||
assert.equal(tx.ins[0].index, 0)
|
||||
})
|
||||
|
||||
it('ignores pending outputs', function(){
|
||||
|
@ -436,7 +441,8 @@ describe('Wallet', function() {
|
|||
var tx = wallet.createTx(to, value)
|
||||
|
||||
assert.equal(tx.ins.length, 1)
|
||||
assert.deepEqual(tx.ins[0].outpoint, { hash: fakeTxHash(3), index: 0 })
|
||||
assert.deepEqual(tx.ins[0].hash, fakeTxHash(3))
|
||||
assert.equal(tx.ins[0].index, 0)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue