Browse Source

TxBuilder: extract isCoinbaseHash function

hk-custom-address
Daniel Cousens 10 years ago
parent
commit
46db11e04a
  1. 32
      src/transaction_builder.js

32
src/transaction_builder.js

@ -7,20 +7,13 @@ var ECSignature = require('./ecsignature')
var Script = require('./script') var Script = require('./script')
var Transaction = require('./transaction') var Transaction = require('./transaction')
function TransactionBuilder() { function isCoinbase(txHash) {
this.prevOutMap = {} return Array.prototype.every.call(txHash, function(x) {
this.prevOutScripts = {} return x === 0
this.prevOutTypes = {} })
this.signatures = []
this.tx = new Transaction()
} }
function extractSignature(txIn) { function extractSignature(txIn) {
assert(!Array.prototype.every.call(txIn.hash, function(x) {
return x === 0
}), 'coinbase inputs not supported')
var redeemScript var redeemScript
var scriptSig = txIn.script var scriptSig = txIn.script
var scriptType = scripts.classifyInput(scriptSig, true) var scriptType = scripts.classifyInput(scriptSig, true)
@ -81,7 +74,15 @@ function extractSignature(txIn) {
} }
} }
// Static constructors function TransactionBuilder() {
this.prevOutMap = {}
this.prevOutScripts = {}
this.prevOutTypes = {}
this.signatures = []
this.tx = new Transaction()
}
TransactionBuilder.fromTransaction = function(transaction) { TransactionBuilder.fromTransaction = function(transaction) {
var txb = new TransactionBuilder() var txb = new TransactionBuilder()
@ -101,10 +102,8 @@ TransactionBuilder.fromTransaction = function(transaction) {
// Extract/add signatures // Extract/add signatures
txb.signatures = transaction.ins.map(function(txIn) { txb.signatures = transaction.ins.map(function(txIn) {
// Coinbase inputs not supported // TODO: remove me after testcase added
assert(!Array.prototype.every.call(txIn.hash, function(x) { assert(!isCoinbase(txIn.hash), 'coinbase inputs not supported')
return x === 0
}), 'coinbase inputs not supported')
// Ignore empty scripts // Ignore empty scripts
if (txIn.script.buffer.length === 0) return if (txIn.script.buffer.length === 0) return
@ -115,7 +114,6 @@ TransactionBuilder.fromTransaction = function(transaction) {
return txb return txb
} }
// Operations
TransactionBuilder.prototype.addInput = function(prevTx, index, sequence, prevOutScript) { TransactionBuilder.prototype.addInput = function(prevTx, index, sequence, prevOutScript) {
var prevOutHash var prevOutHash

Loading…
Cancel
Save