Skip to content

Commit

Permalink
fix firefox compatibility issue with buffertools#compare
Browse files Browse the repository at this point in the history
  • Loading branch information
matiu committed Mar 21, 2014
1 parent 227a952 commit 02296d9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Block.prototype.checkMerkleRoot = function checkMerkleRoot(txs) {
throw new VerificationError('No merkle root');
}

if (buffertools.compare(this.calcMerkleRoot(txs), this.merkle_root) !== 0) {
if (buffertools.compare(this.calcMerkleRoot(txs), new Buffer(this.merkle_root)) !== 0) {
throw new VerificationError('Merkle root incorrect');
}

Expand Down
4 changes: 3 additions & 1 deletion Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ TransactionIn.prototype.getScript = function getScript() {

TransactionIn.prototype.isCoinBase = function isCoinBase() {
if (!this.o) return false;
return buffertools.compare(this.o, COINBASE_OP) === 0;

//The new Buffer is for Firefox compatibility
return buffertools.compare(new Buffer(this.o), COINBASE_OP) === 0;
};

TransactionIn.prototype.serialize = function serialize() {
Expand Down
3 changes: 1 addition & 2 deletions test/test.Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Block', function() {

var b = getBlock();
b.getMerkleTree(b.txs).length.should.equal(45);
bitcore.buffertools.toHex(b.calcMerkleRoot(b.txs)).should.equal(bitcore.buffertools.toHex(b.merkle_root));
bitcore.buffertools.toHex(b.calcMerkleRoot(b.txs)).should.equal(bitcore.buffertools.toHex(new Buffer(b.merkle_root)));

b.checkMerkleRoot(b.txs);

Expand Down Expand Up @@ -177,7 +177,6 @@ describe('Block', function() {

});


it('#createCoinbaseTx should create a tx', function() {
var b = new Block();
var pubkey = new Buffer('02d20b3fba521dcf88dfaf0eee8c15a8ba692d7eb0cb957d5bcf9f4cc052fb9cc6');
Expand Down

0 comments on commit 02296d9

Please sign in to comment.