Skip to content

Commit

Permalink
address: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Nov 15, 2018
1 parent e305d90 commit 579a98a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/net/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -3152,7 +3152,7 @@ class Pool extends EventEmitter {

watchAddress(address) {
if (typeof address === 'string')
address = Address.fromString(address);
address = Address.fromString(address, this.network);

const hash = Address.getHash(address);
this.watch(hash);
Expand Down
9 changes: 6 additions & 3 deletions lib/primitives/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class Address {

const addr = bech32.decode(data);

// make sure HRP is correct.
Network.fromBech32(addr.hrp, network);

return this.fromHash(addr.hash, type, addr.version);
Expand Down Expand Up @@ -793,12 +794,11 @@ class Address {
/**
* Get the hash of a base58 address or address-related object.
* @param {String|Address|Hash} data
* @param {String?} enc
* @param {Network?} network
* @param {String?} enc - Can be `"hex"` or `null`.
* @returns {Hash}
*/

static getHash(data, network) {
static getHash(data, enc) {
if (!data)
throw new Error('Object is not an address.');

Expand All @@ -814,6 +814,9 @@ class Address {
throw new Error('Object is not an address.');
}

if (enc === 'hex')
return hash.toString('hex');

return hash;
}

Expand Down
12 changes: 6 additions & 6 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class HTTP extends Server {
const passphrase = valid.str('passphrase');
const pub = valid.buf('publicKey');
const priv = valid.str('privateKey');
const b58 = valid.str('address');
const address = valid.str('address');

if (pub) {
const key = KeyRing.fromPublic(pub);
Expand All @@ -393,8 +393,8 @@ class HTTP extends Server {
return;
}

if (b58) {
const addr = Address.fromString(b58, this.network);
if (address) {
const addr = Address.fromString(address, this.network);
await req.wallet.importAddress(acct, addr);
res.json(200, { success: true });
return;
Expand Down Expand Up @@ -627,12 +627,12 @@ class HTTP extends Server {
// Get private key
this.get('/wallet/:id/wif/:address', async (req, res) => {
const valid = Validator.fromRequest(req);
const b58 = valid.str('address');
const address = valid.str('address');
const passphrase = valid.str('passphrase');

enforce(b58, 'Address is required.');
enforce(address, 'Address is required.');

const addr = Address.fromString(b58, this.network);
const addr = Address.fromString(address, this.network);
const key = await req.wallet.getPrivateKey(addr, passphrase);

if (!key) {
Expand Down

0 comments on commit 579a98a

Please sign in to comment.