Merge pull request #945 from eordano/fix/addressInstantiate

Add alternative to create an Address
This commit is contained in:
Braydon Fuller 2015-01-10 12:54:24 -05:00
commit 8089b0c765
2 changed files with 17 additions and 5 deletions

View File

@ -143,12 +143,13 @@ Address._transformHash = function(hash){
* @return {Address}
*/
Address._transformObject = function(data) {
$.checkArgument(data.hash, 'Must provide a `hash` property');
$.checkArgument(data.hash || data.hashBuffer, 'Must provide a `hash` or `hashBuffer` property');
$.checkArgument(data.type, 'Must provide a `type` property');
data.hashBuffer = new Buffer(data.hash, 'hex');
data.network = Networks.get(data.network) || Networks.defaultNetwork;
return data;
return {
hashBuffer: data.hash ? new Buffer(data.hash, 'hex') : data.hashBuffer,
network: Networks.get(data.network) || Networks.defaultNetwork,
type: data.type
};
};
/**

View File

@ -210,7 +210,18 @@ describe('Address', function() {
should.not.exist(error);
}
});
});
describe('instantiation', function() {
it('can be instantiated from another address', function() {
var address = Address.fromBuffer(buf);
var address2 = new Address({
hashBuffer: address.hashBuffer,
network: address.network,
type: address.type
});
address.toString().should.equal(address2.toString());
});
});
describe('encodings', function() {