Merge pull request #632 from nodar-chkuaselidze/fix/addresses
address minor fixes
This commit is contained in:
commit
bd7a0949b6
@ -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);
|
||||
|
||||
@ -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);
|
||||
@ -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.');
|
||||
|
||||
@ -814,6 +814,9 @@ class Address {
|
||||
throw new Error('Object is not an address.');
|
||||
}
|
||||
|
||||
if (enc === 'hex')
|
||||
return hash.toString('hex');
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
@ -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;
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user