Added inspect prototype G5

This commit is contained in:
Braydon Fuller 2014-12-14 15:13:01 -05:00
parent 5477a2d857
commit b13c4fb0c9
7 changed files with 39 additions and 1 deletions

View File

@ -387,6 +387,14 @@ HDPrivateKey.prototype.toString = function() {
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.
*

View File

@ -350,6 +350,14 @@ HDPublicKey.prototype.toString = function () {
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.
*

View File

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

View File

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

View File

@ -83,6 +83,10 @@ describe('HDPrivate key interface', function() {
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() {
HDPrivateKey(HDPrivateKey(xprivkey))
.xprivkey.should.equal(xprivkey);

View File

@ -148,6 +148,11 @@ describe('HDPublicKey interface', function() {
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() {
it('derivation is the same whether deriving with number or string', function() {
var pubkey = new HDPublicKey(xpubkey);

View File

@ -16,6 +16,11 @@ describe('Transaction', function() {
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() {
var transaction = new Transaction(tx_1_hex);
transaction.id.should.equal(tx_1_id);