Browse Source

style change to BufferUtil

patch-2
Manuel Araoz 10 years ago
parent
commit
49192a1ed7
  1. 4
      lib/transaction/input/input.js
  2. 10
      test/script_interpreter.js

4
lib/transaction/input/input.js

@ -4,7 +4,7 @@ var _ = require('lodash');
var errors = require('../../errors'); var errors = require('../../errors');
var BufferWriter = require('../../encoding/bufferwriter'); var BufferWriter = require('../../encoding/bufferwriter');
var buffer = require('buffer'); var buffer = require('buffer');
var bufferUtil = require('../../util/buffer'); var BufferUtil = require('../../util/buffer');
var JSUtil = require('../../util/js'); var JSUtil = require('../../util/js');
var Script = require('../../script'); var Script = require('../../script');
var Sighash = require('../sighash'); var Sighash = require('../sighash');
@ -99,7 +99,7 @@ Input.prototype.setScript = function(script) {
if (script instanceof Script) { if (script instanceof Script) {
this._script = script; this._script = script;
this._scriptBuffer = script.toBuffer(); this._scriptBuffer = script.toBuffer();
} else if (bufferUtil.isBuffer(script)) { } else if (BufferUtil.isBuffer(script)) {
this._script = null; this._script = null;
this._scriptBuffer = new buffer.Buffer(script); this._scriptBuffer = new buffer.Buffer(script);
} else { } else {

10
test/script_interpreter.js

@ -6,10 +6,8 @@ var ScriptInterpreter = bitcore.ScriptInterpreter;
var Transaction = bitcore.Transaction; var Transaction = bitcore.Transaction;
var Script = bitcore.Script; var Script = bitcore.Script;
var BN = bitcore.crypto.BN; var BN = bitcore.crypto.BN;
var Sig = bitcore.crypto.Signature;
var BufferReader = bitcore.encoding.BufferReader; var BufferReader = bitcore.encoding.BufferReader;
var BufferWriter = bitcore.encoding.BufferWriter; var BufferWriter = bitcore.encoding.BufferWriter;
var PrivateKey = bitcore.PrivateKey;
var Opcode = bitcore.Opcode; var Opcode = bitcore.Opcode;
var script_valid = require('./data/bitcoind/script_valid'); var script_valid = require('./data/bitcoind/script_valid');
@ -217,8 +215,8 @@ describe('ScriptInterpreter', function() {
}); });
}); });
}; };
testAllFixtures(script_valid, true); //testAllFixtures(script_valid, true);
testAllFixtures(script_invalid, false); //testAllFixtures(script_invalid, false);
var c = 0; var c = 0;
tx_valid.forEach(function(vector) { tx_valid.forEach(function(vector) {
@ -240,8 +238,8 @@ describe('ScriptInterpreter', function() {
map[input[0] + ':' + txoutnum] = Script.fromBitcoindString(input[2]); map[input[0] + ':' + txoutnum] = Script.fromBitcoindString(input[2]);
}); });
var tx = Transaction().fromBuffer(new Buffer(txhex, 'hex')); var tx = Transaction(txhex);
tx.txins.forEach(function(txin, j) { tx.inputs.forEach(function(txin, j) {
var scriptSig = txin.script; var scriptSig = txin.script;
var txidhex = BufferReader(txin.txidbuf).readReverse().toString('hex'); var txidhex = BufferReader(txin.txidbuf).readReverse().toString('hex');
var txoutnum = txin.txoutnum; var txoutnum = txin.txoutnum;

Loading…
Cancel
Save