Merge pull request #945 from eordano/fix/addressInstantiate
Add alternative to create an Address
This commit is contained in:
commit
8089b0c765
|
@ -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
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue