Compare commits
4 Commits
master
...
refactorTr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e095d487d | ||
|
|
5a60a03066 | ||
|
|
d85c4c9b9b | ||
|
|
936df0d49f |
10
src/block.js
10
src/block.js
@ -55,7 +55,7 @@ Block.fromBuffer = function (buffer) {
|
|||||||
|
|
||||||
function readTransaction () {
|
function readTransaction () {
|
||||||
var tx = Transaction.fromBuffer(buffer.slice(offset), true)
|
var tx = Transaction.fromBuffer(buffer.slice(offset), true)
|
||||||
offset += tx.byteLength()
|
offset += tx.byteLength
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ Block.prototype.byteLength = function (headersOnly) {
|
|||||||
if (headersOnly || !this.transactions) return 80
|
if (headersOnly || !this.transactions) return 80
|
||||||
|
|
||||||
return 80 + varuint.encodingLength(this.transactions.length) + this.transactions.reduce(function (a, x) {
|
return 80 + varuint.encodingLength(this.transactions.length) + this.transactions.reduce(function (a, x) {
|
||||||
return a + x.byteLength()
|
return a + x.byteLength
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ Block.prototype.toBuffer = function (headersOnly) {
|
|||||||
offset += varuint.encode.bytes
|
offset += varuint.encode.bytes
|
||||||
|
|
||||||
this.transactions.forEach(function (tx) {
|
this.transactions.forEach(function (tx) {
|
||||||
var txSize = tx.byteLength() // TODO: extract from toBuffer?
|
var txSize = tx.byteLength // TODO: extract from toBuffer?
|
||||||
tx.toBuffer(buffer, offset)
|
tx.toBuffer(buffer, offset)
|
||||||
offset += txSize
|
offset += txSize
|
||||||
})
|
})
|
||||||
@ -150,11 +150,11 @@ Block.calculateTarget = function (bits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Block.calculateMerkleRoot = function (transactions) {
|
Block.calculateMerkleRoot = function (transactions) {
|
||||||
typeforce([{ getHash: types.Function }], transactions)
|
typeforce([{ hash: types.Buffer }], transactions)
|
||||||
if (transactions.length === 0) throw TypeError('Cannot compute merkle root for zero transactions')
|
if (transactions.length === 0) throw TypeError('Cannot compute merkle root for zero transactions')
|
||||||
|
|
||||||
var hashes = transactions.map(function (transaction) {
|
var hashes = transactions.map(function (transaction) {
|
||||||
return transaction.getHash()
|
return transaction.hash
|
||||||
})
|
})
|
||||||
|
|
||||||
return fastMerkleRoot(hashes, bcrypto.hash256)
|
return fastMerkleRoot(hashes, bcrypto.hash256)
|
||||||
|
|||||||
@ -1,159 +1,140 @@
|
|||||||
var Buffer = require('safe-buffer').Buffer
|
const Buffer = require('safe-buffer').Buffer
|
||||||
var bcrypto = require('./crypto')
|
const bcrypto = require('./crypto')
|
||||||
var bscript = require('./script')
|
const bscript = require('./script')
|
||||||
var bufferutils = require('./bufferutils')
|
const bufferutils = require('./bufferutils')
|
||||||
var opcodes = require('bitcoin-ops')
|
const opcodes = require('bitcoin-ops')
|
||||||
var typeforce = require('typeforce')
|
const typeforce = require('typeforce')
|
||||||
var types = require('./types')
|
const types = require('./types')
|
||||||
var varuint = require('varuint-bitcoin')
|
const varuint = require('varuint-bitcoin')
|
||||||
|
|
||||||
function varSliceSize (someScript) {
|
const EMPTY_SCRIPT = Buffer.allocUnsafe(0)
|
||||||
var length = someScript.length
|
const EMPTY_WITNESS = []
|
||||||
|
const ZERO = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
||||||
return varuint.encodingLength(length) + length
|
const ONE = Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex')
|
||||||
}
|
const VALUE_UINT64_MAX = Buffer.from('ffffffffffffffff', 'hex')
|
||||||
|
const BLANK_OUTPUT = {
|
||||||
function vectorSize (someVector) {
|
|
||||||
var length = someVector.length
|
|
||||||
|
|
||||||
return varuint.encodingLength(length) + someVector.reduce(function (sum, witness) {
|
|
||||||
return sum + varSliceSize(witness)
|
|
||||||
}, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Transaction () {
|
|
||||||
this.version = 1
|
|
||||||
this.locktime = 0
|
|
||||||
this.ins = []
|
|
||||||
this.outs = []
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.DEFAULT_SEQUENCE = 0xffffffff
|
|
||||||
Transaction.SIGHASH_ALL = 0x01
|
|
||||||
Transaction.SIGHASH_NONE = 0x02
|
|
||||||
Transaction.SIGHASH_SINGLE = 0x03
|
|
||||||
Transaction.SIGHASH_ANYONECANPAY = 0x80
|
|
||||||
Transaction.ADVANCED_TRANSACTION_MARKER = 0x00
|
|
||||||
Transaction.ADVANCED_TRANSACTION_FLAG = 0x01
|
|
||||||
|
|
||||||
var EMPTY_SCRIPT = Buffer.allocUnsafe(0)
|
|
||||||
var EMPTY_WITNESS = []
|
|
||||||
var ZERO = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
|
||||||
var ONE = Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex')
|
|
||||||
var VALUE_UINT64_MAX = Buffer.from('ffffffffffffffff', 'hex')
|
|
||||||
var BLANK_OUTPUT = {
|
|
||||||
script: EMPTY_SCRIPT,
|
script: EMPTY_SCRIPT,
|
||||||
valueBuffer: VALUE_UINT64_MAX
|
valueBuffer: VALUE_UINT64_MAX
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.fromBuffer = function (buffer, __noStrict) {
|
const varSliceSize = (someScript) => {
|
||||||
var offset = 0
|
const length = someScript.length
|
||||||
function readSlice (n) {
|
|
||||||
offset += n
|
return varuint.encodingLength(length) + length
|
||||||
return buffer.slice(offset - n, offset)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function readUInt32 () {
|
const vectorSize = (someVector) => {
|
||||||
var i = buffer.readUInt32LE(offset)
|
const length = someVector.length
|
||||||
offset += 4
|
|
||||||
return i
|
return varuint.encodingLength(length) + someVector.reduce((sum, witness) =>
|
||||||
|
sum + varSliceSize(witness)
|
||||||
|
, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
function readInt32 () {
|
class Transaction {
|
||||||
var i = buffer.readInt32LE(offset)
|
constructor () {
|
||||||
offset += 4
|
this.version = 1
|
||||||
return i
|
this.locktime = 0
|
||||||
|
this.ins = []
|
||||||
|
this.outs = []
|
||||||
|
|
||||||
|
this._isCoinbase = null
|
||||||
|
this._hasWitnesses = null
|
||||||
|
this._weight = null
|
||||||
|
this._virtualSize = null
|
||||||
|
this._byteLength = null
|
||||||
|
this._hash = null
|
||||||
|
this._id = null
|
||||||
|
this._buffer = null
|
||||||
|
this._hex = null
|
||||||
}
|
}
|
||||||
|
|
||||||
function readUInt64 () {
|
static get DEFAULT_SEQUENCE () { return 0xffffffff }
|
||||||
var i = bufferutils.readUInt64LE(buffer, offset)
|
static get SIGHASH_ALL () { return 0x01 }
|
||||||
offset += 8
|
static get SIGHASH_NONE () { return 0x02 }
|
||||||
return i
|
static get SIGHASH_SINGLE () { return 0x03 }
|
||||||
|
static get SIGHASH_ANYONECANPAY () { return 0x80 }
|
||||||
|
static get ADVANCED_TRANSACTION_MARKER () { return 0x00 }
|
||||||
|
static get ADVANCED_TRANSACTION_FLAG () { return 0x01 }
|
||||||
|
|
||||||
|
get isCoinbase () {
|
||||||
|
if (this._isCoinbase !== null) {
|
||||||
|
return this._isCoinbase
|
||||||
|
}
|
||||||
|
this._isCoinbase = this.ins.length === 1 && Transaction.isCoinbaseHash(this.ins[0].hash)
|
||||||
|
return this._isCoinbase
|
||||||
}
|
}
|
||||||
|
|
||||||
function readVarInt () {
|
get hasWitnesses () {
|
||||||
var vi = varuint.decode(buffer, offset)
|
if (this._hasWitnesses !== null) {
|
||||||
offset += varuint.decode.bytes
|
return this._hasWitnesses
|
||||||
return vi
|
}
|
||||||
|
this._hasWitnesses = this.ins.some((x) =>
|
||||||
|
x.witness.length !== 0
|
||||||
|
)
|
||||||
|
return this._hasWitnesses
|
||||||
}
|
}
|
||||||
|
|
||||||
function readVarSlice () {
|
get weight () {
|
||||||
return readSlice(readVarInt())
|
if (this._weight !== null) {
|
||||||
|
return this._weight
|
||||||
|
}
|
||||||
|
const base = this.__byteLength(false)
|
||||||
|
const total = this.__byteLength(true)
|
||||||
|
this._weight = base * 3 + total
|
||||||
|
return this._weight
|
||||||
}
|
}
|
||||||
|
|
||||||
function readVector () {
|
get virtualSize () {
|
||||||
var count = readVarInt()
|
if (this._virtualSize !== null) {
|
||||||
var vector = []
|
return this._virtualSize
|
||||||
for (var i = 0; i < count; i++) vector.push(readVarSlice())
|
}
|
||||||
return vector
|
this._virtualSize = Math.ceil(this.weight / 4)
|
||||||
|
return this._virtualSize
|
||||||
}
|
}
|
||||||
|
|
||||||
var tx = new Transaction()
|
get byteLength () {
|
||||||
tx.version = readInt32()
|
if (this._byteLength !== null) {
|
||||||
|
return this._byteLength
|
||||||
var marker = buffer.readUInt8(offset)
|
}
|
||||||
var flag = buffer.readUInt8(offset + 1)
|
this._byteLength = this.__byteLength(true)
|
||||||
|
return this._byteLength
|
||||||
var hasWitnesses = false
|
|
||||||
if (marker === Transaction.ADVANCED_TRANSACTION_MARKER &&
|
|
||||||
flag === Transaction.ADVANCED_TRANSACTION_FLAG) {
|
|
||||||
offset += 2
|
|
||||||
hasWitnesses = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var vinLen = readVarInt()
|
get hash () {
|
||||||
for (var i = 0; i < vinLen; ++i) {
|
if (this._hash !== null) {
|
||||||
tx.ins.push({
|
return this._hash
|
||||||
hash: readSlice(32),
|
}
|
||||||
index: readUInt32(),
|
this._hash = bcrypto.hash256(this.__toBuffer(undefined, undefined, false))
|
||||||
script: readVarSlice(),
|
return this._hash
|
||||||
sequence: readUInt32(),
|
|
||||||
witness: EMPTY_WITNESS
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var voutLen = readVarInt()
|
get id () {
|
||||||
for (i = 0; i < voutLen; ++i) {
|
if (this._id !== null) {
|
||||||
tx.outs.push({
|
return this._id
|
||||||
value: readUInt64(),
|
}
|
||||||
script: readVarSlice()
|
// transaction hash's are displayed in reverse order
|
||||||
})
|
this._id = this.hash.reverse().toString('hex')
|
||||||
|
return this._id
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasWitnesses) {
|
get buffer () {
|
||||||
for (i = 0; i < vinLen; ++i) {
|
if (this._buffer !== null) {
|
||||||
tx.ins[i].witness = readVector()
|
return this._buffer
|
||||||
|
}
|
||||||
|
this._buffer = this.__toBuffer(undefined, undefined, true)
|
||||||
|
return this._buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// was this pointless?
|
get hex () {
|
||||||
if (!tx.hasWitnesses()) throw new Error('Transaction has superfluous witness data')
|
if (this._hex !== null) {
|
||||||
|
return this._hex
|
||||||
|
}
|
||||||
|
this._hex = this.buffer.toString('hex')
|
||||||
|
return this._hex
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.locktime = readUInt32()
|
addInput (hash, index, sequence, scriptSig) {
|
||||||
|
|
||||||
if (__noStrict) return tx
|
|
||||||
if (offset !== buffer.length) throw new Error('Transaction has unexpected data')
|
|
||||||
|
|
||||||
return tx
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.fromHex = function (hex) {
|
|
||||||
return Transaction.fromBuffer(Buffer.from(hex, 'hex'))
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.isCoinbaseHash = function (buffer) {
|
|
||||||
typeforce(types.Hash256bit, buffer)
|
|
||||||
for (var i = 0; i < 32; ++i) {
|
|
||||||
if (buffer[i] !== 0) return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.isCoinbase = function () {
|
|
||||||
return this.ins.length === 1 && Transaction.isCoinbaseHash(this.ins[0].hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.addInput = function (hash, index, sequence, scriptSig) {
|
|
||||||
typeforce(types.tuple(
|
typeforce(types.tuple(
|
||||||
types.Hash256bit,
|
types.Hash256bit,
|
||||||
types.UInt32,
|
types.UInt32,
|
||||||
@ -165,6 +146,8 @@ Transaction.prototype.addInput = function (hash, index, sequence, scriptSig) {
|
|||||||
sequence = Transaction.DEFAULT_SEQUENCE
|
sequence = Transaction.DEFAULT_SEQUENCE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.clearCache()
|
||||||
|
|
||||||
// Add the input and return the input's index
|
// Add the input and return the input's index
|
||||||
return (this.ins.push({
|
return (this.ins.push({
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@ -175,9 +158,11 @@ Transaction.prototype.addInput = function (hash, index, sequence, scriptSig) {
|
|||||||
}) - 1)
|
}) - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.addOutput = function (scriptPubKey, value) {
|
addOutput (scriptPubKey, value) {
|
||||||
typeforce(types.tuple(types.Buffer, types.Satoshi), arguments)
|
typeforce(types.tuple(types.Buffer, types.Satoshi), arguments)
|
||||||
|
|
||||||
|
this.clearCache()
|
||||||
|
|
||||||
// Add the output and return the output's index
|
// Add the output and return the output's index
|
||||||
return (this.outs.push({
|
return (this.outs.push({
|
||||||
script: scriptPubKey,
|
script: scriptPubKey,
|
||||||
@ -185,60 +170,40 @@ Transaction.prototype.addOutput = function (scriptPubKey, value) {
|
|||||||
}) - 1)
|
}) - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.hasWitnesses = function () {
|
__byteLength (__allowWitness) {
|
||||||
return this.ins.some(function (x) {
|
const hasWitnesses = __allowWitness && this.hasWitnesses
|
||||||
return x.witness.length !== 0
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.weight = function () {
|
|
||||||
var base = this.__byteLength(false)
|
|
||||||
var total = this.__byteLength(true)
|
|
||||||
return base * 3 + total
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.virtualSize = function () {
|
|
||||||
return Math.ceil(this.weight() / 4)
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.byteLength = function () {
|
|
||||||
return this.__byteLength(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.__byteLength = function (__allowWitness) {
|
|
||||||
var hasWitnesses = __allowWitness && this.hasWitnesses()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(hasWitnesses ? 10 : 8) +
|
(hasWitnesses ? 10 : 8) +
|
||||||
varuint.encodingLength(this.ins.length) +
|
varuint.encodingLength(this.ins.length) +
|
||||||
varuint.encodingLength(this.outs.length) +
|
varuint.encodingLength(this.outs.length) +
|
||||||
this.ins.reduce(function (sum, input) { return sum + 40 + varSliceSize(input.script) }, 0) +
|
this.ins.reduce((sum, input) => sum + 40 + varSliceSize(input.script), 0) +
|
||||||
this.outs.reduce(function (sum, output) { return sum + 8 + varSliceSize(output.script) }, 0) +
|
this.outs.reduce((sum, output) => sum + 8 + varSliceSize(output.script), 0) +
|
||||||
(hasWitnesses ? this.ins.reduce(function (sum, input) { return sum + vectorSize(input.witness) }, 0) : 0)
|
(hasWitnesses ? this.ins.reduce((sum, input) => sum + vectorSize(input.witness), 0) : 0)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.clone = function () {
|
clone () {
|
||||||
var newTx = new Transaction()
|
const newTx = new Transaction()
|
||||||
newTx.version = this.version
|
newTx.version = this.version
|
||||||
newTx.locktime = this.locktime
|
newTx.locktime = this.locktime
|
||||||
|
|
||||||
newTx.ins = this.ins.map(function (txIn) {
|
newTx.ins = this.ins.map((txIn) =>
|
||||||
return {
|
({
|
||||||
hash: txIn.hash,
|
hash: txIn.hash,
|
||||||
index: txIn.index,
|
index: txIn.index,
|
||||||
script: txIn.script,
|
script: txIn.script,
|
||||||
sequence: txIn.sequence,
|
sequence: txIn.sequence,
|
||||||
witness: txIn.witness
|
witness: txIn.witness
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
|
||||||
newTx.outs = this.outs.map(function (txOut) {
|
newTx.outs = this.outs.map((txOut) =>
|
||||||
return {
|
({
|
||||||
script: txOut.script,
|
script: txOut.script,
|
||||||
value: txOut.value
|
value: txOut.value
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
|
||||||
return newTx
|
return newTx
|
||||||
}
|
}
|
||||||
@ -251,25 +216,25 @@ Transaction.prototype.clone = function () {
|
|||||||
* hashType, and then hashes the result.
|
* hashType, and then hashes the result.
|
||||||
* This hash can then be used to sign the provided transaction input.
|
* This hash can then be used to sign the provided transaction input.
|
||||||
*/
|
*/
|
||||||
Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashType) {
|
hashForSignature (inIndex, prevOutScript, hashType) {
|
||||||
typeforce(types.tuple(types.UInt32, types.Buffer, /* types.UInt8 */ types.Number), arguments)
|
typeforce(types.tuple(types.UInt32, types.Buffer, /* types.UInt8 */ types.Number), arguments)
|
||||||
|
|
||||||
// https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L29
|
// https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L29
|
||||||
if (inIndex >= this.ins.length) return ONE
|
if (inIndex >= this.ins.length) return ONE
|
||||||
|
|
||||||
// ignore OP_CODESEPARATOR
|
// ignore OP_CODESEPARATOR
|
||||||
var ourScript = bscript.compile(bscript.decompile(prevOutScript).filter(function (x) {
|
const ourScript = bscript.compile(bscript.decompile(prevOutScript).filter((x) =>
|
||||||
return x !== opcodes.OP_CODESEPARATOR
|
x !== opcodes.OP_CODESEPARATOR
|
||||||
}))
|
))
|
||||||
|
|
||||||
var txTmp = this.clone()
|
const txTmp = this.clone()
|
||||||
|
|
||||||
// SIGHASH_NONE: ignore all outputs? (wildcard payee)
|
// SIGHASH_NONE: ignore all outputs? (wildcard payee)
|
||||||
if ((hashType & 0x1f) === Transaction.SIGHASH_NONE) {
|
if ((hashType & 0x1f) === Transaction.SIGHASH_NONE) {
|
||||||
txTmp.outs = []
|
txTmp.outs = []
|
||||||
|
|
||||||
// ignore sequence numbers (except at inIndex)
|
// ignore sequence numbers (except at inIndex)
|
||||||
txTmp.ins.forEach(function (input, i) {
|
txTmp.ins.forEach((input, i) => {
|
||||||
if (i === inIndex) return
|
if (i === inIndex) return
|
||||||
|
|
||||||
input.sequence = 0
|
input.sequence = 0
|
||||||
@ -284,12 +249,12 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT
|
|||||||
txTmp.outs.length = inIndex + 1
|
txTmp.outs.length = inIndex + 1
|
||||||
|
|
||||||
// "blank" outputs before
|
// "blank" outputs before
|
||||||
for (var i = 0; i < inIndex; i++) {
|
for (let i = 0; i < inIndex; i++) {
|
||||||
txTmp.outs[i] = BLANK_OUTPUT
|
txTmp.outs[i] = BLANK_OUTPUT
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore sequence numbers (except at inIndex)
|
// ignore sequence numbers (except at inIndex)
|
||||||
txTmp.ins.forEach(function (input, y) {
|
txTmp.ins.forEach((input, y) => {
|
||||||
if (y === inIndex) return
|
if (y === inIndex) return
|
||||||
|
|
||||||
input.sequence = 0
|
input.sequence = 0
|
||||||
@ -304,40 +269,40 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT
|
|||||||
// SIGHASH_ALL: only ignore input scripts
|
// SIGHASH_ALL: only ignore input scripts
|
||||||
} else {
|
} else {
|
||||||
// "blank" others input scripts
|
// "blank" others input scripts
|
||||||
txTmp.ins.forEach(function (input) { input.script = EMPTY_SCRIPT })
|
txTmp.ins.forEach((input) => { input.script = EMPTY_SCRIPT })
|
||||||
txTmp.ins[inIndex].script = ourScript
|
txTmp.ins[inIndex].script = ourScript
|
||||||
}
|
}
|
||||||
|
|
||||||
// serialize and hash
|
// serialize and hash
|
||||||
var buffer = Buffer.allocUnsafe(txTmp.__byteLength(false) + 4)
|
const buffer = Buffer.allocUnsafe(txTmp.__byteLength(false) + 4)
|
||||||
buffer.writeInt32LE(hashType, buffer.length - 4)
|
buffer.writeInt32LE(hashType, buffer.length - 4)
|
||||||
txTmp.__toBuffer(buffer, 0, false)
|
txTmp.__toBuffer(buffer, 0, false)
|
||||||
|
|
||||||
return bcrypto.hash256(buffer)
|
return bcrypto.hash256(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, value, hashType) {
|
hashForWitnessV0 (inIndex, prevOutScript, value, hashType) {
|
||||||
typeforce(types.tuple(types.UInt32, types.Buffer, types.Satoshi, types.UInt32), arguments)
|
typeforce(types.tuple(types.UInt32, types.Buffer, types.Satoshi, types.UInt32), arguments)
|
||||||
|
|
||||||
var tbuffer, toffset
|
let tbuffer, toffset
|
||||||
function writeSlice (slice) { toffset += slice.copy(tbuffer, toffset) }
|
const writeSlice = (slice) => { toffset += slice.copy(tbuffer, toffset) }
|
||||||
function writeUInt32 (i) { toffset = tbuffer.writeUInt32LE(i, toffset) }
|
const writeUInt32 = (i) => { toffset = tbuffer.writeUInt32LE(i, toffset) }
|
||||||
function writeUInt64 (i) { toffset = bufferutils.writeUInt64LE(tbuffer, i, toffset) }
|
const writeUInt64 = (i) => { toffset = bufferutils.writeUInt64LE(tbuffer, i, toffset) }
|
||||||
function writeVarInt (i) {
|
const writeVarInt = (i) => {
|
||||||
varuint.encode(i, tbuffer, toffset)
|
varuint.encode(i, tbuffer, toffset)
|
||||||
toffset += varuint.encode.bytes
|
toffset += varuint.encode.bytes
|
||||||
}
|
}
|
||||||
function writeVarSlice (slice) { writeVarInt(slice.length); writeSlice(slice) }
|
const writeVarSlice = (slice) => { writeVarInt(slice.length); writeSlice(slice) }
|
||||||
|
|
||||||
var hashOutputs = ZERO
|
let hashOutputs = ZERO
|
||||||
var hashPrevouts = ZERO
|
let hashPrevouts = ZERO
|
||||||
var hashSequence = ZERO
|
let hashSequence = ZERO
|
||||||
|
|
||||||
if (!(hashType & Transaction.SIGHASH_ANYONECANPAY)) {
|
if (!(hashType & Transaction.SIGHASH_ANYONECANPAY)) {
|
||||||
tbuffer = Buffer.allocUnsafe(36 * this.ins.length)
|
tbuffer = Buffer.allocUnsafe(36 * this.ins.length)
|
||||||
toffset = 0
|
toffset = 0
|
||||||
|
|
||||||
this.ins.forEach(function (txIn) {
|
this.ins.forEach((txIn) => {
|
||||||
writeSlice(txIn.hash)
|
writeSlice(txIn.hash)
|
||||||
writeUInt32(txIn.index)
|
writeUInt32(txIn.index)
|
||||||
})
|
})
|
||||||
@ -351,7 +316,7 @@ Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, value
|
|||||||
tbuffer = Buffer.allocUnsafe(4 * this.ins.length)
|
tbuffer = Buffer.allocUnsafe(4 * this.ins.length)
|
||||||
toffset = 0
|
toffset = 0
|
||||||
|
|
||||||
this.ins.forEach(function (txIn) {
|
this.ins.forEach((txIn) => {
|
||||||
writeUInt32(txIn.sequence)
|
writeUInt32(txIn.sequence)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -360,21 +325,21 @@ Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, value
|
|||||||
|
|
||||||
if ((hashType & 0x1f) !== Transaction.SIGHASH_SINGLE &&
|
if ((hashType & 0x1f) !== Transaction.SIGHASH_SINGLE &&
|
||||||
(hashType & 0x1f) !== Transaction.SIGHASH_NONE) {
|
(hashType & 0x1f) !== Transaction.SIGHASH_NONE) {
|
||||||
var txOutsSize = this.outs.reduce(function (sum, output) {
|
const txOutsSize = this.outs.reduce((sum, output) =>
|
||||||
return sum + 8 + varSliceSize(output.script)
|
sum + 8 + varSliceSize(output.script)
|
||||||
}, 0)
|
, 0)
|
||||||
|
|
||||||
tbuffer = Buffer.allocUnsafe(txOutsSize)
|
tbuffer = Buffer.allocUnsafe(txOutsSize)
|
||||||
toffset = 0
|
toffset = 0
|
||||||
|
|
||||||
this.outs.forEach(function (out) {
|
this.outs.forEach((out) => {
|
||||||
writeUInt64(out.value)
|
writeUInt64(out.value)
|
||||||
writeVarSlice(out.script)
|
writeVarSlice(out.script)
|
||||||
})
|
})
|
||||||
|
|
||||||
hashOutputs = bcrypto.hash256(tbuffer)
|
hashOutputs = bcrypto.hash256(tbuffer)
|
||||||
} else if ((hashType & 0x1f) === Transaction.SIGHASH_SINGLE && inIndex < this.outs.length) {
|
} else if ((hashType & 0x1f) === Transaction.SIGHASH_SINGLE && inIndex < this.outs.length) {
|
||||||
var output = this.outs[inIndex]
|
const output = this.outs[inIndex]
|
||||||
|
|
||||||
tbuffer = Buffer.allocUnsafe(8 + varSliceSize(output.script))
|
tbuffer = Buffer.allocUnsafe(8 + varSliceSize(output.script))
|
||||||
toffset = 0
|
toffset = 0
|
||||||
@ -387,7 +352,7 @@ Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, value
|
|||||||
tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript))
|
tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript))
|
||||||
toffset = 0
|
toffset = 0
|
||||||
|
|
||||||
var input = this.ins[inIndex]
|
const input = this.ins[inIndex]
|
||||||
writeUInt32(this.version)
|
writeUInt32(this.version)
|
||||||
writeSlice(hashPrevouts)
|
writeSlice(hashPrevouts)
|
||||||
writeSlice(hashSequence)
|
writeSlice(hashSequence)
|
||||||
@ -402,38 +367,29 @@ Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, value
|
|||||||
return bcrypto.hash256(tbuffer)
|
return bcrypto.hash256(tbuffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.getHash = function () {
|
toBuffer (buffer, initialOffset) {
|
||||||
return bcrypto.hash256(this.__toBuffer(undefined, undefined, false))
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.getId = function () {
|
|
||||||
// transaction hash's are displayed in reverse order
|
|
||||||
return this.getHash().reverse().toString('hex')
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.toBuffer = function (buffer, initialOffset) {
|
|
||||||
return this.__toBuffer(buffer, initialOffset, true)
|
return this.__toBuffer(buffer, initialOffset, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitness) {
|
__toBuffer (buffer, initialOffset, __allowWitness) {
|
||||||
if (!buffer) buffer = Buffer.allocUnsafe(this.__byteLength(__allowWitness))
|
if (!buffer) buffer = Buffer.allocUnsafe(this.__byteLength(__allowWitness))
|
||||||
|
|
||||||
var offset = initialOffset || 0
|
let offset = initialOffset || 0
|
||||||
function writeSlice (slice) { offset += slice.copy(buffer, offset) }
|
const writeSlice = (slice) => { offset += slice.copy(buffer, offset) }
|
||||||
function writeUInt8 (i) { offset = buffer.writeUInt8(i, offset) }
|
const writeUInt8 = (i) => { offset = buffer.writeUInt8(i, offset) }
|
||||||
function writeUInt32 (i) { offset = buffer.writeUInt32LE(i, offset) }
|
const writeUInt32 = (i) => { offset = buffer.writeUInt32LE(i, offset) }
|
||||||
function writeInt32 (i) { offset = buffer.writeInt32LE(i, offset) }
|
const writeInt32 = (i) => { offset = buffer.writeInt32LE(i, offset) }
|
||||||
function writeUInt64 (i) { offset = bufferutils.writeUInt64LE(buffer, i, offset) }
|
const writeUInt64 = (i) => { offset = bufferutils.writeUInt64LE(buffer, i, offset) }
|
||||||
function writeVarInt (i) {
|
const writeVarInt = (i) => {
|
||||||
varuint.encode(i, buffer, offset)
|
varuint.encode(i, buffer, offset)
|
||||||
offset += varuint.encode.bytes
|
offset += varuint.encode.bytes
|
||||||
}
|
}
|
||||||
function writeVarSlice (slice) { writeVarInt(slice.length); writeSlice(slice) }
|
const writeVarSlice = (slice) => { writeVarInt(slice.length); writeSlice(slice) }
|
||||||
function writeVector (vector) { writeVarInt(vector.length); vector.forEach(writeVarSlice) }
|
const writeVector = (vector) => { writeVarInt(vector.length); vector.forEach(writeVarSlice) }
|
||||||
|
|
||||||
writeInt32(this.version)
|
writeInt32(this.version)
|
||||||
|
|
||||||
var hasWitnesses = __allowWitness && this.hasWitnesses()
|
const hasWitnesses = __allowWitness && this.hasWitnesses
|
||||||
|
|
||||||
if (hasWitnesses) {
|
if (hasWitnesses) {
|
||||||
writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)
|
writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)
|
||||||
@ -442,7 +398,7 @@ Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitne
|
|||||||
|
|
||||||
writeVarInt(this.ins.length)
|
writeVarInt(this.ins.length)
|
||||||
|
|
||||||
this.ins.forEach(function (txIn) {
|
this.ins.forEach((txIn) => {
|
||||||
writeSlice(txIn.hash)
|
writeSlice(txIn.hash)
|
||||||
writeUInt32(txIn.index)
|
writeUInt32(txIn.index)
|
||||||
writeVarSlice(txIn.script)
|
writeVarSlice(txIn.script)
|
||||||
@ -450,7 +406,7 @@ Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitne
|
|||||||
})
|
})
|
||||||
|
|
||||||
writeVarInt(this.outs.length)
|
writeVarInt(this.outs.length)
|
||||||
this.outs.forEach(function (txOut) {
|
this.outs.forEach((txOut) => {
|
||||||
if (!txOut.valueBuffer) {
|
if (!txOut.valueBuffer) {
|
||||||
writeUInt64(txOut.value)
|
writeUInt64(txOut.value)
|
||||||
} else {
|
} else {
|
||||||
@ -461,7 +417,7 @@ Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitne
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (hasWitnesses) {
|
if (hasWitnesses) {
|
||||||
this.ins.forEach(function (input) {
|
this.ins.forEach((input) => {
|
||||||
writeVector(input.witness)
|
writeVector(input.witness)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -473,20 +429,136 @@ Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitne
|
|||||||
return buffer
|
return buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.toHex = function () {
|
setInputScript (index, scriptSig) {
|
||||||
return this.toBuffer().toString('hex')
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.prototype.setInputScript = function (index, scriptSig) {
|
|
||||||
typeforce(types.tuple(types.Number, types.Buffer), arguments)
|
typeforce(types.tuple(types.Number, types.Buffer), arguments)
|
||||||
|
|
||||||
|
this.clearCache()
|
||||||
|
|
||||||
this.ins[index].script = scriptSig
|
this.ins[index].script = scriptSig
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.setWitness = function (index, witness) {
|
setWitness (index, witness) {
|
||||||
typeforce(types.tuple(types.Number, [types.Buffer]), arguments)
|
typeforce(types.tuple(types.Number, [types.Buffer]), arguments)
|
||||||
|
|
||||||
|
this.clearCache()
|
||||||
|
|
||||||
this.ins[index].witness = witness
|
this.ins[index].witness = witness
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearCache () {
|
||||||
|
this._isCoinbase = null
|
||||||
|
this._hasWitnesses = null
|
||||||
|
this._weight = null
|
||||||
|
this._virtualSize = null
|
||||||
|
this._byteLength = null
|
||||||
|
this._hash = null
|
||||||
|
this._id = null
|
||||||
|
this._buffer = null
|
||||||
|
this._hex = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Transaction.fromBuffer = (buffer, __noStrict) => {
|
||||||
|
let offset = 0
|
||||||
|
const readSlice = (n) => {
|
||||||
|
offset += n
|
||||||
|
return buffer.slice(offset - n, offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
const readUInt32 = () => {
|
||||||
|
const i = buffer.readUInt32LE(offset)
|
||||||
|
offset += 4
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
const readInt32 = () => {
|
||||||
|
const i = buffer.readInt32LE(offset)
|
||||||
|
offset += 4
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
const readUInt64 = () => {
|
||||||
|
const i = bufferutils.readUInt64LE(buffer, offset)
|
||||||
|
offset += 8
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
const readVarInt = () => {
|
||||||
|
const vi = varuint.decode(buffer, offset)
|
||||||
|
offset += varuint.decode.bytes
|
||||||
|
return vi
|
||||||
|
}
|
||||||
|
|
||||||
|
const readVarSlice = () => {
|
||||||
|
return readSlice(readVarInt())
|
||||||
|
}
|
||||||
|
|
||||||
|
const readVector = () => {
|
||||||
|
const count = readVarInt()
|
||||||
|
const vector = []
|
||||||
|
for (let i = 0; i < count; i++) vector.push(readVarSlice())
|
||||||
|
return vector
|
||||||
|
}
|
||||||
|
|
||||||
|
const tx = new Transaction()
|
||||||
|
tx.version = readInt32()
|
||||||
|
|
||||||
|
const marker = buffer.readUInt8(offset)
|
||||||
|
const flag = buffer.readUInt8(offset + 1)
|
||||||
|
|
||||||
|
let hasWitnesses = false
|
||||||
|
if (marker === Transaction.ADVANCED_TRANSACTION_MARKER &&
|
||||||
|
flag === Transaction.ADVANCED_TRANSACTION_FLAG) {
|
||||||
|
offset += 2
|
||||||
|
hasWitnesses = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const vinLen = readVarInt()
|
||||||
|
for (let i = 0; i < vinLen; ++i) {
|
||||||
|
tx.ins.push({
|
||||||
|
hash: readSlice(32),
|
||||||
|
index: readUInt32(),
|
||||||
|
script: readVarSlice(),
|
||||||
|
sequence: readUInt32(),
|
||||||
|
witness: EMPTY_WITNESS
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const voutLen = readVarInt()
|
||||||
|
for (let i = 0; i < voutLen; ++i) {
|
||||||
|
tx.outs.push({
|
||||||
|
value: readUInt64(),
|
||||||
|
script: readVarSlice()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasWitnesses) {
|
||||||
|
for (let i = 0; i < vinLen; ++i) {
|
||||||
|
tx.ins[i].witness = readVector()
|
||||||
|
}
|
||||||
|
|
||||||
|
// was this pointless?
|
||||||
|
if (!tx.hasWitnesses) throw new Error('Transaction has superfluous witness data')
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.locktime = readUInt32()
|
||||||
|
|
||||||
|
if (__noStrict) return tx
|
||||||
|
if (offset !== buffer.length) throw new Error('Transaction has unexpected data')
|
||||||
|
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
Transaction.fromHex = (hex) => {
|
||||||
|
return Transaction.fromBuffer(Buffer.from(hex, 'hex'))
|
||||||
|
}
|
||||||
|
|
||||||
|
Transaction.isCoinbaseHash = (buffer) => {
|
||||||
|
typeforce(types.Hash256bit, buffer)
|
||||||
|
for (let i = 0; i < 32; ++i) {
|
||||||
|
if (buffer[i] !== 0) return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Transaction
|
module.exports = Transaction
|
||||||
|
|||||||
@ -547,7 +547,7 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
|
|||||||
prevOutScript = txOut.script
|
prevOutScript = txOut.script
|
||||||
value = txOut.value
|
value = txOut.value
|
||||||
|
|
||||||
txHash = txHash.getHash()
|
txHash = txHash.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.__addInputUnsafe(txHash, vout, {
|
return this.__addInputUnsafe(txHash, vout, {
|
||||||
@ -648,7 +648,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
|
|||||||
|
|
||||||
if (!allowIncomplete) {
|
if (!allowIncomplete) {
|
||||||
// do not rely on this, its merely a last resort
|
// do not rely on this, its merely a last resort
|
||||||
if (this.__overMaximumFees(tx.virtualSize())) {
|
if (this.__overMaximumFees(tx.virtualSize)) {
|
||||||
throw new Error('Transaction has absurd fees')
|
throw new Error('Transaction has absurd fees')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -184,7 +184,7 @@ describe('Bitcoin-core', function () {
|
|||||||
|
|
||||||
it('should hash ' + txHex.slice(0, 40) + '... (' + hashTypeName + ')', function () {
|
it('should hash ' + txHex.slice(0, 40) + '... (' + hashTypeName + ')', function () {
|
||||||
var transaction = bitcoin.Transaction.fromHex(txHex)
|
var transaction = bitcoin.Transaction.fromHex(txHex)
|
||||||
assert.strictEqual(transaction.toHex(), txHex)
|
assert.strictEqual(transaction.hex, txHex)
|
||||||
|
|
||||||
var script = Buffer.from(scriptHex, 'hex')
|
var script = Buffer.from(scriptHex, 'hex')
|
||||||
var scriptChunks = bitcoin.script.decompile(script)
|
var scriptChunks = bitcoin.script.decompile(script)
|
||||||
|
|||||||
@ -61,11 +61,11 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||||||
], redeemScript)
|
], redeemScript)
|
||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.hex, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
regtestUtils.verify({
|
regtestUtils.verify({
|
||||||
txId: tx.getId(),
|
txId: tx.id,
|
||||||
address: regtestUtils.RANDOM_ADDRESS,
|
address: regtestUtils.RANDOM_ADDRESS,
|
||||||
vout: 0,
|
vout: 0,
|
||||||
value: 7e4
|
value: 7e4
|
||||||
@ -106,7 +106,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
// TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently
|
// TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently
|
||||||
// regtestUtils.broadcast(tx.toHex(), function (err) {
|
// regtestUtils.broadcast(tx.hex, function (err) {
|
||||||
// // fails before the expiry
|
// // fails before the expiry
|
||||||
// assert.throws(function () {
|
// assert.throws(function () {
|
||||||
// if (err) throw err
|
// if (err) throw err
|
||||||
@ -116,11 +116,11 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||||||
regtestUtils.mine(51, function (err) {
|
regtestUtils.mine(51, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.hex, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
regtestUtils.verify({
|
regtestUtils.verify({
|
||||||
txId: tx.getId(),
|
txId: tx.id,
|
||||||
address: regtestUtils.RANDOM_ADDRESS,
|
address: regtestUtils.RANDOM_ADDRESS,
|
||||||
vout: 0,
|
vout: 0,
|
||||||
value: 7e4
|
value: 7e4
|
||||||
@ -161,11 +161,11 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||||||
], redeemScript)
|
], redeemScript)
|
||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.hex, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
regtestUtils.verify({
|
regtestUtils.verify({
|
||||||
txId: tx.getId(),
|
txId: tx.id,
|
||||||
address: regtestUtils.RANDOM_ADDRESS,
|
address: regtestUtils.RANDOM_ADDRESS,
|
||||||
vout: 0,
|
vout: 0,
|
||||||
value: 8e4
|
value: 8e4
|
||||||
@ -203,7 +203,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||||||
], redeemScript)
|
], redeemScript)
|
||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.hex, function (err) {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
}, /Error: 64: non-final/)
|
}, /Error: 64: non-final/)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||||||
txb.sign(0, alice)
|
txb.sign(0, alice)
|
||||||
|
|
||||||
// prepare for broadcast to the Bitcoin network, see "can broadcast a Transaction" below
|
// prepare for broadcast to the Bitcoin network, see "can broadcast a Transaction" below
|
||||||
assert.strictEqual(txb.build().toHex(), '01000000019d344070eac3fe6e394a16d06d7704a7d5c0a10eb2a2c16bc98842b7cc20d561000000006b48304502210088828c0bdfcdca68d8ae0caeb6ec62cd3fd5f9b2191848edae33feb533df35d302202e0beadd35e17e7f83a733f5277028a9b453d525553e3f5d2d7a7aa8010a81d60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01e02e0000000000001976a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac00000000')
|
assert.strictEqual(txb.build().hex, '01000000019d344070eac3fe6e394a16d06d7704a7d5c0a10eb2a2c16bc98842b7cc20d561000000006b48304502210088828c0bdfcdca68d8ae0caeb6ec62cd3fd5f9b2191848edae33feb533df35d302202e0beadd35e17e7f83a733f5277028a9b453d525553e3f5d2d7a7aa8010a81d60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01e02e0000000000001976a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac00000000')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can create a 2-to-2 Transaction', function () {
|
it('can create a 2-to-2 Transaction', function () {
|
||||||
@ -41,7 +41,7 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||||||
txb.sign(0, alice) // Alice signs her input, which was the first input (0th)
|
txb.sign(0, alice) // Alice signs her input, which was the first input (0th)
|
||||||
|
|
||||||
// prepare for broadcast to the Bitcoin network, see "can broadcast a Transaction" below
|
// prepare for broadcast to the Bitcoin network, see "can broadcast a Transaction" below
|
||||||
assert.strictEqual(txb.build().toHex(), '01000000024c94e48a870b85f41228d33cf25213dfcc8dd796e7211ed6b1f9a014809dbbb5060000006a473044022041450c258ce7cac7da97316bf2ea1ce66d88967c4df94f3e91f4c2a30f5d08cb02203674d516e6bb2b0afd084c3551614bd9cec3c2945231245e891b145f2d6951f0012103e05ce435e462ec503143305feb6c00e06a3ad52fbf939e85c65f3a765bb7baacffffffff3077d9de049574c3af9bc9c09a7c9db80f2d94caaf63988c9166249b955e867d000000006b483045022100aeb5f1332c79c446d3f906e4499b2e678500580a3f90329edf1ba502eec9402e022072c8b863f8c8d6c26f4c691ac9a6610aa4200edc697306648ee844cfbc089d7a012103df7940ee7cddd2f97763f67e1fb13488da3fbdd7f9c68ec5ef0864074745a289ffffffff0220bf0200000000001976a9147dd65592d0ab2fe0d0257d571abf032cd9db93dc88ac10980200000000001976a914c42e7ef92fdb603af844d064faad95db9bcdfd3d88ac00000000')
|
assert.strictEqual(txb.build().hex, '01000000024c94e48a870b85f41228d33cf25213dfcc8dd796e7211ed6b1f9a014809dbbb5060000006a473044022041450c258ce7cac7da97316bf2ea1ce66d88967c4df94f3e91f4c2a30f5d08cb02203674d516e6bb2b0afd084c3551614bd9cec3c2945231245e891b145f2d6951f0012103e05ce435e462ec503143305feb6c00e06a3ad52fbf939e85c65f3a765bb7baacffffffff3077d9de049574c3af9bc9c09a7c9db80f2d94caaf63988c9166249b955e867d000000006b483045022100aeb5f1332c79c446d3f906e4499b2e678500580a3f90329edf1ba502eec9402e022072c8b863f8c8d6c26f4c691ac9a6610aa4200edc697306648ee844cfbc089d7a012103df7940ee7cddd2f97763f67e1fb13488da3fbdd7f9c68ec5ef0864074745a289ffffffff0220bf0200000000001976a9147dd65592d0ab2fe0d0257d571abf032cd9db93dc88ac10980200000000001976a914c42e7ef92fdb603af844d064faad95db9bcdfd3d88ac00000000')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can create (and broadcast via 3PBP) a typical Transaction', function (done) {
|
it('can create (and broadcast via 3PBP) a typical Transaction', function (done) {
|
||||||
@ -70,7 +70,7 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||||||
txb.sign(1, alice2)
|
txb.sign(1, alice2)
|
||||||
|
|
||||||
// build and broadcast our RegTest network
|
// build and broadcast our RegTest network
|
||||||
regtestUtils.broadcast(txb.build().toHex(), done)
|
regtestUtils.broadcast(txb.build().hex, done)
|
||||||
// to build and broadcast to the actual Bitcoin network, see https://github.com/bitcoinjs/bitcoinjs-lib/issues/839
|
// to build and broadcast to the actual Bitcoin network, see https://github.com/bitcoinjs/bitcoinjs-lib/issues/839
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -94,7 +94,7 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||||||
txb.sign(0, keyPair)
|
txb.sign(0, keyPair)
|
||||||
|
|
||||||
// build and broadcast to the RegTest network
|
// build and broadcast to the RegTest network
|
||||||
regtestUtils.broadcast(txb.build().toHex(), done)
|
regtestUtils.broadcast(txb.build().hex, done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -125,11 +125,11 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||||||
var tx = txb.build()
|
var tx = txb.build()
|
||||||
|
|
||||||
// build and broadcast to the Bitcoin RegTest network
|
// build and broadcast to the Bitcoin RegTest network
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.hex, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
regtestUtils.verify({
|
regtestUtils.verify({
|
||||||
txId: tx.getId(),
|
txId: tx.id,
|
||||||
address: regtestUtils.RANDOM_ADDRESS,
|
address: regtestUtils.RANDOM_ADDRESS,
|
||||||
vout: 0,
|
vout: 0,
|
||||||
value: 1e4
|
value: 1e4
|
||||||
@ -161,11 +161,11 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||||||
var tx = txb.build()
|
var tx = txb.build()
|
||||||
|
|
||||||
// build and broadcast to the Bitcoin RegTest network
|
// build and broadcast to the Bitcoin RegTest network
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.hex, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
regtestUtils.verify({
|
regtestUtils.verify({
|
||||||
txId: tx.getId(),
|
txId: tx.id,
|
||||||
address: regtestUtils.RANDOM_ADDRESS,
|
address: regtestUtils.RANDOM_ADDRESS,
|
||||||
vout: 0,
|
vout: 0,
|
||||||
value: 2e4
|
value: 2e4
|
||||||
@ -203,11 +203,11 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||||||
var tx = txb.build()
|
var tx = txb.build()
|
||||||
|
|
||||||
// build and broadcast to the Bitcoin RegTest network
|
// build and broadcast to the Bitcoin RegTest network
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.hex, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
regtestUtils.verify({
|
regtestUtils.verify({
|
||||||
txId: tx.getId(),
|
txId: tx.id,
|
||||||
address: regtestUtils.RANDOM_ADDRESS,
|
address: regtestUtils.RANDOM_ADDRESS,
|
||||||
vout: 0,
|
vout: 0,
|
||||||
value: 3e4
|
value: 3e4
|
||||||
|
|||||||
@ -55,14 +55,14 @@ describe('Transaction', function () {
|
|||||||
it('imports ' + f.description + ' (' + id + ')', function () {
|
it('imports ' + f.description + ' (' + id + ')', function () {
|
||||||
var actual = Transaction.fromHex(txHex)
|
var actual = Transaction.fromHex(txHex)
|
||||||
|
|
||||||
assert.strictEqual(actual.toHex(), txHex)
|
assert.strictEqual(actual.hex, txHex)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (f.whex) {
|
if (f.whex) {
|
||||||
it('imports ' + f.description + ' (' + id + ') as witness', function () {
|
it('imports ' + f.description + ' (' + id + ') as witness', function () {
|
||||||
var actual = Transaction.fromHex(f.whex)
|
var actual = Transaction.fromHex(f.whex)
|
||||||
|
|
||||||
assert.strictEqual(actual.toHex(), f.whex)
|
assert.strictEqual(actual.hex, f.whex)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,13 +91,13 @@ describe('Transaction', function () {
|
|||||||
fixtures.valid.forEach(function (f) {
|
fixtures.valid.forEach(function (f) {
|
||||||
it('exports ' + f.description + ' (' + f.id + ')', function () {
|
it('exports ' + f.description + ' (' + f.id + ')', function () {
|
||||||
var actual = fromRaw(f.raw, true)
|
var actual = fromRaw(f.raw, true)
|
||||||
assert.strictEqual(actual.toHex(), f.hex)
|
assert.strictEqual(actual.hex, f.hex)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (f.whex) {
|
if (f.whex) {
|
||||||
it('exports ' + f.description + ' (' + f.id + ') as witness', function () {
|
it('exports ' + f.description + ' (' + f.id + ') as witness', function () {
|
||||||
var wactual = fromRaw(f.raw)
|
var wactual = fromRaw(f.raw)
|
||||||
assert.strictEqual(wactual.toHex(), f.whex)
|
assert.strictEqual(wactual.hex, f.whex)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -105,7 +105,7 @@ describe('Transaction', function () {
|
|||||||
it('accepts target Buffer and offset parameters', function () {
|
it('accepts target Buffer and offset parameters', function () {
|
||||||
var f = fixtures.valid[0]
|
var f = fixtures.valid[0]
|
||||||
var actual = fromRaw(f.raw)
|
var actual = fromRaw(f.raw)
|
||||||
var byteLength = actual.byteLength()
|
var byteLength = actual.byteLength
|
||||||
|
|
||||||
var target = Buffer.alloc(byteLength * 2)
|
var target = Buffer.alloc(byteLength * 2)
|
||||||
var a = actual.toBuffer(target, 0)
|
var a = actual.toBuffer(target, 0)
|
||||||
@ -124,7 +124,7 @@ describe('Transaction', function () {
|
|||||||
describe('hasWitnesses', function () {
|
describe('hasWitnesses', function () {
|
||||||
fixtures.valid.forEach(function (f) {
|
fixtures.valid.forEach(function (f) {
|
||||||
it('detects if the transaction has witnesses: ' + (f.whex ? 'true' : 'false'), function () {
|
it('detects if the transaction has witnesses: ' + (f.whex ? 'true' : 'false'), function () {
|
||||||
assert.strictEqual(Transaction.fromHex(f.whex ? f.whex : f.hex).hasWitnesses(), !!f.whex)
|
assert.strictEqual(Transaction.fromHex(f.whex ? f.whex : f.hex).hasWitnesses, !!f.whex)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -134,7 +134,7 @@ describe('Transaction', function () {
|
|||||||
fixtures.valid.forEach(function (f) {
|
fixtures.valid.forEach(function (f) {
|
||||||
var transaction = Transaction.fromHex(f.whex ? f.whex : f.hex)
|
var transaction = Transaction.fromHex(f.whex ? f.whex : f.hex)
|
||||||
|
|
||||||
assert.strictEqual(transaction.virtualSize(), f.virtualSize)
|
assert.strictEqual(transaction.virtualSize, f.virtualSize)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ describe('Transaction', function () {
|
|||||||
fixtures.valid.forEach(function (f) {
|
fixtures.valid.forEach(function (f) {
|
||||||
var transaction = Transaction.fromHex(f.whex ? f.whex : f.hex)
|
var transaction = Transaction.fromHex(f.whex ? f.whex : f.hex)
|
||||||
|
|
||||||
assert.strictEqual(transaction.weight(), f.weight)
|
assert.strictEqual(transaction.weight, f.weight)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -212,8 +212,8 @@ describe('Transaction', function () {
|
|||||||
it('should return the id for ' + f.id + '(' + f.description + ')', function () {
|
it('should return the id for ' + f.id + '(' + f.description + ')', function () {
|
||||||
var tx = Transaction.fromHex(f.whex || f.hex)
|
var tx = Transaction.fromHex(f.whex || f.hex)
|
||||||
|
|
||||||
assert.strictEqual(tx.getHash().toString('hex'), f.hash)
|
assert.strictEqual(tx.hash.toString('hex'), f.hash)
|
||||||
assert.strictEqual(tx.getId(), f.id)
|
assert.strictEqual(tx.id, f.id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ describe('Transaction', function () {
|
|||||||
it('should return ' + f.coinbase + ' for ' + f.id + '(' + f.description + ')', function () {
|
it('should return ' + f.coinbase + ' for ' + f.id + '(' + f.description + ')', function () {
|
||||||
var tx = Transaction.fromHex(f.hex)
|
var tx = Transaction.fromHex(f.hex)
|
||||||
|
|
||||||
assert.strictEqual(tx.isCoinbase(), f.coinbase)
|
assert.strictEqual(tx.isCoinbase, f.coinbase)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -72,7 +72,7 @@ function construct (f, dontSign) {
|
|||||||
|
|
||||||
if (sign.stage) {
|
if (sign.stage) {
|
||||||
var tx = txb.buildIncomplete()
|
var tx = txb.buildIncomplete()
|
||||||
assert.strictEqual(tx.toHex(), stages.shift())
|
assert.strictEqual(tx.hex, stages.shift())
|
||||||
txb = TransactionBuilder.fromTransaction(tx, network)
|
txb = TransactionBuilder.fromTransaction(tx, network)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -101,7 +101,7 @@ describe('TransactionBuilder', function () {
|
|||||||
var txb = TransactionBuilder.fromTransaction(tx, network)
|
var txb = TransactionBuilder.fromTransaction(tx, network)
|
||||||
var txAfter = f.incomplete ? txb.buildIncomplete() : txb.build()
|
var txAfter = f.incomplete ? txb.buildIncomplete() : txb.build()
|
||||||
|
|
||||||
assert.strictEqual(txAfter.toHex(), f.txHex)
|
assert.strictEqual(txAfter.hex, f.txHex)
|
||||||
assert.strictEqual(txb.network, network)
|
assert.strictEqual(txb.network, network)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -192,7 +192,7 @@ describe('TransactionBuilder', function () {
|
|||||||
assert.strictEqual(vin, 0)
|
assert.strictEqual(vin, 0)
|
||||||
|
|
||||||
var txIn = txb.__tx.ins[0]
|
var txIn = txb.__tx.ins[0]
|
||||||
assert.deepEqual(txIn.hash, prevTx.getHash())
|
assert.deepEqual(txIn.hash, prevTx.hash)
|
||||||
assert.strictEqual(txIn.index, 1)
|
assert.strictEqual(txIn.index, 1)
|
||||||
assert.strictEqual(txIn.sequence, 54)
|
assert.strictEqual(txIn.sequence, 54)
|
||||||
assert.strictEqual(txb.__inputs[0].prevOutScript, scripts[1])
|
assert.strictEqual(txb.__inputs[0].prevOutScript, scripts[1])
|
||||||
@ -306,7 +306,7 @@ describe('TransactionBuilder', function () {
|
|||||||
txb.addInput('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 1)
|
txb.addInput('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 1)
|
||||||
txb.addOutput('1111111111111111111114oLvT2', 100000)
|
txb.addOutput('1111111111111111111114oLvT2', 100000)
|
||||||
txb.sign(0, keyPair)
|
txb.sign(0, keyPair)
|
||||||
assert.equal(txb.build().toHex(), '0100000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff010000002c0930060201000201000121030303030303030303030303030303030303030303030303030303030303030303ffffffff01a0860100000000001976a914000000000000000000000000000000000000000088ac00000000')
|
assert.equal(txb.build().hex, '0100000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff010000002c0930060201000201000121030303030303030303030303030303030303030303030303030303030303030303ffffffff01a0860100000000001976a914000000000000000000000000000000000000000088ac00000000')
|
||||||
})
|
})
|
||||||
|
|
||||||
fixtures.invalid.sign.forEach(function (f) {
|
fixtures.invalid.sign.forEach(function (f) {
|
||||||
@ -346,7 +346,7 @@ describe('TransactionBuilder', function () {
|
|||||||
var txb = construct(f)
|
var txb = construct(f)
|
||||||
var tx = f.incomplete ? txb.buildIncomplete() : txb.build()
|
var tx = f.incomplete ? txb.buildIncomplete() : txb.build()
|
||||||
|
|
||||||
assert.strictEqual(tx.toHex(), f.txHex)
|
assert.strictEqual(tx.hex, f.txHex)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ describe('TransactionBuilder', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tx = txb.build()
|
tx = txb.build()
|
||||||
assert.strictEqual(tx.toHex(), f.txHex)
|
assert.strictEqual(tx.hex, f.txHex)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -529,8 +529,8 @@ describe('TransactionBuilder', function () {
|
|||||||
// 2-of-2 signed only once
|
// 2-of-2 signed only once
|
||||||
var tx = txb.buildIncomplete()
|
var tx = txb.buildIncomplete()
|
||||||
// Only input is segwit, so txid should be accurate with the final tx
|
// Only input is segwit, so txid should be accurate with the final tx
|
||||||
assert.equal(tx.getId(), 'f15d0a65b21b4471405b21a099f8b18e1ae4d46d55efbd0f4766cf11ad6cb821')
|
assert.equal(tx.id, 'f15d0a65b21b4471405b21a099f8b18e1ae4d46d55efbd0f4766cf11ad6cb821')
|
||||||
var txHex = tx.toHex()
|
var txHex = tx.hex
|
||||||
var newTxb = TransactionBuilder.fromTransaction(Transaction.fromHex(txHex))
|
var newTxb = TransactionBuilder.fromTransaction(Transaction.fromHex(txHex))
|
||||||
// input should have the key 'witness' set to true
|
// input should have the key 'witness' set to true
|
||||||
assert.equal(newTxb.__inputs[0].witness, true)
|
assert.equal(newTxb.__inputs[0].witness, true)
|
||||||
@ -552,7 +552,7 @@ describe('TransactionBuilder', function () {
|
|||||||
txb.sign(0, keyPair2, redeemScript)
|
txb.sign(0, keyPair2, redeemScript)
|
||||||
|
|
||||||
var tx2 = txb.build()
|
var tx2 = txb.build()
|
||||||
assert.equal(tx2.getId(), 'eab59618a564e361adef6d918bd792903c3d41bcf1220137364fb847880467f9')
|
assert.equal(tx2.id, 'eab59618a564e361adef6d918bd792903c3d41bcf1220137364fb847880467f9')
|
||||||
assert.equal(bscript.toASM(tx2.ins[0].script), 'OP_0 3045022100daf0f4f3339d9fbab42b098045c1e4958ee3b308f4ae17be80b63808558d0adb02202f07e3d1f79dc8da285ae0d7f68083d769c11f5621ebd9691d6b48c0d4283d7d01 3045022100a346c61738304eac5e7702188764d19cdf68f4466196729db096d6c87ce18cdd022018c0e8ad03054b0e7e235cda6bedecf35881d7aa7d94ff425a8ace7220f38af001 52410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a4104f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e67253ae')
|
assert.equal(bscript.toASM(tx2.ins[0].script), 'OP_0 3045022100daf0f4f3339d9fbab42b098045c1e4958ee3b308f4ae17be80b63808558d0adb02202f07e3d1f79dc8da285ae0d7f68083d769c11f5621ebd9691d6b48c0d4283d7d01 3045022100a346c61738304eac5e7702188764d19cdf68f4466196729db096d6c87ce18cdd022018c0e8ad03054b0e7e235cda6bedecf35881d7aa7d94ff425a8ace7220f38af001 52410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a4104f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e67253ae')
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -561,20 +561,20 @@ describe('TransactionBuilder', function () {
|
|||||||
txb.setVersion(1)
|
txb.setVersion(1)
|
||||||
txb.addInput('aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31', 0)
|
txb.addInput('aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31', 0)
|
||||||
|
|
||||||
var incomplete = txb.buildIncomplete().toHex()
|
var incomplete = txb.buildIncomplete().hex
|
||||||
var keyPair = ECPair.fromWIF('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy')
|
var keyPair = ECPair.fromWIF('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy')
|
||||||
|
|
||||||
// sign, as expected
|
// sign, as expected
|
||||||
txb.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)
|
txb.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)
|
||||||
txb.sign(0, keyPair)
|
txb.sign(0, keyPair)
|
||||||
var txId = txb.build().getId()
|
var txId = txb.build().id
|
||||||
assert.equal(txId, '54f097315acbaedb92a95455da3368eb45981cdae5ffbc387a9afc872c0f29b3')
|
assert.equal(txId, '54f097315acbaedb92a95455da3368eb45981cdae5ffbc387a9afc872c0f29b3')
|
||||||
|
|
||||||
// and, repeat
|
// and, repeat
|
||||||
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(incomplete))
|
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(incomplete))
|
||||||
txb.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)
|
txb.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)
|
||||||
txb.sign(0, keyPair)
|
txb.sign(0, keyPair)
|
||||||
var txId2 = txb.build().getId()
|
var txId2 = txb.build().id
|
||||||
assert.equal(txId, txId2)
|
assert.equal(txId, txId2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user