From 47b0177efe290426c987384d0980f2df229eb144 Mon Sep 17 00:00:00 2001 From: overtorment Date: Wed, 15 Mar 2023 21:30:00 +0000 Subject: [PATCH] REF: fix ts lint errors --- class/wallets/abstract-hd-electrum-wallet.ts | 35 +++++++++++--------- class/wallets/hd-legacy-p2pkh-wallet.js | 2 +- class/wallets/hd-segwit-p2sh-wallet.js | 14 +------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/class/wallets/abstract-hd-electrum-wallet.ts b/class/wallets/abstract-hd-electrum-wallet.ts index 4f7d7fe30..393b9c58e 100644 --- a/class/wallets/abstract-hd-electrum-wallet.ts +++ b/class/wallets/abstract-hd-electrum-wallet.ts @@ -148,7 +148,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { return child.toWIF(); } - _getNodeAddressByIndex(node: number, index: number) { + _getNodeAddressByIndex(node: number, index: number): string { index = index * 1; // cast to int if (node === 0) { if (this.external_addresses_cache[index]) return this.external_addresses_cache[index]; // cache hit @@ -170,22 +170,20 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { this._node1 = hdNode.derive(node); } - let address; + let address: string; if (node === 0) { // @ts-ignore address = this._hdNodeToAddress(this._node0.derive(index)); - } - - if (node === 1) { + } else { + // tbh the only possible else is node === 1 // @ts-ignore address = this._hdNodeToAddress(this._node1.derive(index)); } if (node === 0) { return (this.external_addresses_cache[index] = address); - } - - if (node === 1) { + } else { + // tbh the only possible else option is node === 1 return (this.internal_addresses_cache[index] = address); } } @@ -216,7 +214,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { throw new Error('Internal error: this._node0 or this._node1 is undefined'); } - _getExternalAddressByIndex(index: number) { + _getExternalAddressByIndex(index: number): string { return this._getNodeAddressByIndex(0, index); } @@ -1295,22 +1293,29 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { /** * Creates Segwit Bech32 Bitcoin address - * - * @param hdNode - * @returns {String} */ - static _nodeToBech32SegwitAddress(hdNode: BIP32Interface) { + _nodeToBech32SegwitAddress(hdNode: BIP32Interface): string { return bitcoin.payments.p2wpkh({ pubkey: hdNode.publicKey, }).address; } - static _nodeToLegacyAddress(hdNode: BIP32Interface) { + _nodeToLegacyAddress(hdNode: BIP32Interface): string { return bitcoin.payments.p2pkh({ pubkey: hdNode.publicKey, }).address; } + /** + * Creates Segwit P2SH Bitcoin address + */ + _nodeToP2shSegwitAddress(hdNode: BIP32Interface): string { + const { address } = bitcoin.payments.p2sh({ + redeem: bitcoin.payments.p2wpkh({ pubkey: hdNode.publicKey }), + }); + return address; + } + static _getTransactionsFromHistories(histories: Record) { const txs = []; for (const history of Object.values(histories)) { @@ -1496,7 +1501,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { } _hdNodeToAddress(hdNode: BIP32Interface): string { - return this.constructor._nodeToBech32SegwitAddress(hdNode); + return this._nodeToBech32SegwitAddress(hdNode); } _getBIP47Address(paymentCode: string, index: number): string { diff --git a/class/wallets/hd-legacy-p2pkh-wallet.js b/class/wallets/hd-legacy-p2pkh-wallet.js index 16f2a5917..a85486ca0 100644 --- a/class/wallets/hd-legacy-p2pkh-wallet.js +++ b/class/wallets/hd-legacy-p2pkh-wallet.js @@ -53,7 +53,7 @@ export class HDLegacyP2PKHWallet extends AbstractHDElectrumWallet { } _hdNodeToAddress(hdNode) { - return this.constructor._nodeToLegacyAddress(hdNode); + return this._nodeToLegacyAddress(hdNode); } async fetchUtxo() { diff --git a/class/wallets/hd-segwit-p2sh-wallet.js b/class/wallets/hd-segwit-p2sh-wallet.js index 8cc7c45d3..41da38c64 100644 --- a/class/wallets/hd-segwit-p2sh-wallet.js +++ b/class/wallets/hd-segwit-p2sh-wallet.js @@ -41,7 +41,7 @@ export class HDSegwitP2SHWallet extends AbstractHDElectrumWallet { } _hdNodeToAddress(hdNode) { - return this.constructor._nodeToP2shSegwitAddress(hdNode); + return this._nodeToP2shSegwitAddress(hdNode); } /** @@ -98,18 +98,6 @@ export class HDSegwitP2SHWallet extends AbstractHDElectrumWallet { return psbt; } - /** - * Creates Segwit P2SH Bitcoin address - * @param hdNode - * @returns {String} - */ - static _nodeToP2shSegwitAddress(hdNode) { - const { address } = bitcoin.payments.p2sh({ - redeem: bitcoin.payments.p2wpkh({ pubkey: hdNode.publicKey }), - }); - return address; - } - isSegwit() { return true; }