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) {
|
watchAddress(address) {
|
||||||
if (typeof address === 'string')
|
if (typeof address === 'string')
|
||||||
address = Address.fromString(address);
|
address = Address.fromString(address, this.network);
|
||||||
|
|
||||||
const hash = Address.getHash(address);
|
const hash = Address.getHash(address);
|
||||||
this.watch(hash);
|
this.watch(hash);
|
||||||
|
|||||||
@ -384,6 +384,7 @@ class Address {
|
|||||||
|
|
||||||
const addr = bech32.decode(data);
|
const addr = bech32.decode(data);
|
||||||
|
|
||||||
|
// make sure HRP is correct.
|
||||||
Network.fromBech32(addr.hrp, network);
|
Network.fromBech32(addr.hrp, network);
|
||||||
|
|
||||||
return this.fromHash(addr.hash, type, addr.version);
|
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.
|
* Get the hash of a base58 address or address-related object.
|
||||||
* @param {String|Address|Hash} data
|
* @param {String|Address|Hash} data
|
||||||
* @param {String?} enc
|
* @param {String?} enc - Can be `"hex"` or `null`.
|
||||||
* @param {Network?} network
|
|
||||||
* @returns {Hash}
|
* @returns {Hash}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static getHash(data, network) {
|
static getHash(data, enc) {
|
||||||
if (!data)
|
if (!data)
|
||||||
throw new Error('Object is not an address.');
|
throw new Error('Object is not an address.');
|
||||||
|
|
||||||
@ -814,6 +814,9 @@ class Address {
|
|||||||
throw new Error('Object is not an address.');
|
throw new Error('Object is not an address.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enc === 'hex')
|
||||||
|
return hash.toString('hex');
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -377,7 +377,7 @@ class HTTP extends Server {
|
|||||||
const passphrase = valid.str('passphrase');
|
const passphrase = valid.str('passphrase');
|
||||||
const pub = valid.buf('publicKey');
|
const pub = valid.buf('publicKey');
|
||||||
const priv = valid.str('privateKey');
|
const priv = valid.str('privateKey');
|
||||||
const b58 = valid.str('address');
|
const address = valid.str('address');
|
||||||
|
|
||||||
if (pub) {
|
if (pub) {
|
||||||
const key = KeyRing.fromPublic(pub);
|
const key = KeyRing.fromPublic(pub);
|
||||||
@ -393,8 +393,8 @@ class HTTP extends Server {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b58) {
|
if (address) {
|
||||||
const addr = Address.fromString(b58, this.network);
|
const addr = Address.fromString(address, this.network);
|
||||||
await req.wallet.importAddress(acct, addr);
|
await req.wallet.importAddress(acct, addr);
|
||||||
res.json(200, { success: true });
|
res.json(200, { success: true });
|
||||||
return;
|
return;
|
||||||
@ -627,12 +627,12 @@ class HTTP extends Server {
|
|||||||
// Get private key
|
// Get private key
|
||||||
this.get('/wallet/:id/wif/:address', async (req, res) => {
|
this.get('/wallet/:id/wif/:address', async (req, res) => {
|
||||||
const valid = Validator.fromRequest(req);
|
const valid = Validator.fromRequest(req);
|
||||||
const b58 = valid.str('address');
|
const address = valid.str('address');
|
||||||
const passphrase = valid.str('passphrase');
|
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);
|
const key = await req.wallet.getPrivateKey(addr, passphrase);
|
||||||
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user