Browse Source

Added inspect prototype G5

patch-2
Braydon Fuller 10 years ago
parent
commit
b13c4fb0c9
  1. 8
      lib/hdprivatekey.js
  2. 8
      lib/hdpublickey.js
  3. 4
      lib/script.js
  4. 6
      lib/transaction/transaction.js
  5. 4
      test/hdprivatekey.js
  6. 5
      test/hdpublickey.js
  7. 5
      test/transaction.js

8
lib/hdprivatekey.js

@ -387,6 +387,14 @@ HDPrivateKey.prototype.toString = function() {
return this.xprivkey; return this.xprivkey;
}; };
/**
* Returns the console representation of this extended private key.
* @return string
*/
HDPrivateKey.prototype.inspect = function() {
return '<HDPrivateKey: ' + this.xprivkey + '>';
};
/** /**
* Returns a plain object with a representation of this private key. * Returns a plain object with a representation of this private key.
* *

8
lib/hdpublickey.js

@ -350,6 +350,14 @@ HDPublicKey.prototype.toString = function () {
return this.xpubkey; return this.xpubkey;
}; };
/**
* Returns the console representation of this extended public key.
* @return string
*/
HDPublicKey.prototype.inspect = function() {
return '<HDPublicKey: ' + this.xpubkey + '>';
};
/** /**
* Returns a plain javascript object with information to reconstruct a key. * Returns a plain javascript object with information to reconstruct a key.
* *

4
lib/script.js

@ -196,6 +196,10 @@ Script.prototype.toString = function() {
return str.substr(1); return str.substr(1);
}; };
Script.prototype.inspect = function() {
return '<Script: ' + this.toString() + '>';
};
// script classification methods // script classification methods
/** /**

6
lib/transaction/transaction.js

@ -75,10 +75,14 @@ Transaction.prototype._getHash = function() {
return Hash.sha256sha256(this.toBuffer()); return Hash.sha256sha256(this.toBuffer());
}; };
Transaction.prototype.serialize = function() { Transaction.prototype.serialize = Transaction.prototype.toString = function() {
return this.toBuffer().toString('hex'); return this.toBuffer().toString('hex');
}; };
Transaction.prototype.inspect = function () {
return '<Transaction: ' + this.toString() + '>';
};
Transaction.prototype.toBuffer = function() { Transaction.prototype.toBuffer = function() {
var writer = new BufferWriter(); var writer = new BufferWriter();
return this.toBufferWriter(writer).toBuffer(); return this.toBufferWriter(writer).toBuffer();

4
test/hdprivatekey.js

@ -83,6 +83,10 @@ describe('HDPrivate key interface', function() {
HDPrivateKey(xprivkey).toString().should.equal(xprivkey); HDPrivateKey(xprivkey).toString().should.equal(xprivkey);
}); });
it('inspect() displays correctly', function() {
HDPrivateKey(xprivkey).inspect().should.equal('<HDPrivateKey: ' + xprivkey + '>');
});
it('allows the use of a copy constructor', function() { it('allows the use of a copy constructor', function() {
HDPrivateKey(HDPrivateKey(xprivkey)) HDPrivateKey(HDPrivateKey(xprivkey))
.xprivkey.should.equal(xprivkey); .xprivkey.should.equal(xprivkey);

5
test/hdpublickey.js

@ -148,6 +148,11 @@ describe('HDPublicKey interface', function() {
pubKey.toString().should.equal(pubKey.xpubkey); pubKey.toString().should.equal(pubKey.xpubkey);
}); });
it('inspect() displays correctly', function() {
var pubKey = new HDPublicKey(xpubkey);
pubKey.inspect().should.equal('<HDPublicKey: ' + pubKey.xpubkey + '>');
});
describe('derivation', function() { describe('derivation', function() {
it('derivation is the same whether deriving with number or string', function() { it('derivation is the same whether deriving with number or string', function() {
var pubkey = new HDPublicKey(xpubkey); var pubkey = new HDPublicKey(xpubkey);

5
test/transaction.js

@ -16,6 +16,11 @@ describe('Transaction', function() {
transaction.serialize().should.equal(tx_1_hex); transaction.serialize().should.equal(tx_1_hex);
}); });
it('should display correctly in console', function() {
var transaction = new Transaction(tx_1_hex);
transaction.inspect().should.equal('<Transaction: ' + tx_1_hex + '>');
});
it('standard hash of transaction should be decoded correctly', function() { it('standard hash of transaction should be decoded correctly', function() {
var transaction = new Transaction(tx_1_hex); var transaction = new Transaction(tx_1_hex);
transaction.id.should.equal(tx_1_id); transaction.id.should.equal(tx_1_id);

Loading…
Cancel
Save