From 49345748bbcf3c87c048c5e50e218005384a24bf Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 19 Feb 2015 12:04:37 +1100 Subject: [PATCH] Transaction: add isCoinbaseHash static method --- src/transaction.js | 6 ++++++ src/transaction_builder.js | 8 +------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 6202fbe..7d45e09 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -85,6 +85,12 @@ Transaction.fromHex = function(hex) { return Transaction.fromBuffer(new Buffer(hex, 'hex')) } +Transaction.isCoinbaseHash = function(buffer) { + return Array.prototype.every.call(buffer, function(x) { + return x === 0 + }) +} + /** * Create a new txIn. * diff --git a/src/transaction_builder.js b/src/transaction_builder.js index 40a5546..a45b06b 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -7,12 +7,6 @@ var ECSignature = require('./ecsignature') var Script = require('./script') var Transaction = require('./transaction') -function isCoinbase(txHash) { - return Array.prototype.every.call(txHash, function(x) { - return x === 0 - }) -} - function extractInput(txIn) { var redeemScript var scriptSig = txIn.script @@ -116,7 +110,7 @@ TransactionBuilder.fromTransaction = function(transaction) { // Extract/add signatures txb.inputs = transaction.ins.map(function(txIn) { // TODO: remove me after testcase added - assert(!isCoinbase(txIn.hash), 'coinbase inputs not supported') + assert(!Transaction.isCoinbaseHash(txIn.hash), 'coinbase inputs not supported') // Ignore empty scripts if (txIn.script.buffer.length === 0) return