Merge pull request #743 from braydonf/feature/inspect-g5

Added inspect prototype G5
This commit is contained in:
Esteban Ordano 2014-12-15 09:58:47 -03:00
commit c06a3f1fe9
7 changed files with 39 additions and 1 deletions

View File

@ -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.
* *

View File

@ -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.
* *

View File

@ -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
/** /**

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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);