From 735e1960aba1a853cddb40bbc0cd348eca0bb8bd Mon Sep 17 00:00:00 2001 From: Mikhail Date: Mon, 6 Nov 2023 20:20:31 +0300 Subject: [PATCH 1/5] Bug: Sending DOGE from the chat --- src/lib/bitcoin/doge-api.js | 166 ++++++++++++++++++++++++++++++------ 1 file changed, 138 insertions(+), 28 deletions(-) diff --git a/src/lib/bitcoin/doge-api.js b/src/lib/bitcoin/doge-api.js index 882e7ac1d..1669543c3 100644 --- a/src/lib/bitcoin/doge-api.js +++ b/src/lib/bitcoin/doge-api.js @@ -3,6 +3,12 @@ import qs from 'qs' import BtcBaseApi from './btc-base-api' import { Cryptos } from '../constants' import BigNumber from '../bignumber' +import * as bitcoin from 'bitcoinjs-lib' +import { isPositiveNumber } from '../numericHelpers' +import { ECPairFactory } from 'ecpair' +import * as tinysecp from 'tiny-secp256k1' + +const ECPairAPI = ECPairFactory(tinysecp) const POST_CONFIG = { headers: { @@ -10,61 +16,165 @@ const POST_CONFIG = { } } -export const MULTIPLIER = 1e8 export const CHUNK_SIZE = 20 +// P2PKH output size (https://gist.github.com/junderw/b43af3253ea5865ed52cb51c200ac19c) +export const OUTPUTS_COMPENSATION = 34 * 4 +export const NB_BLOCKS = 5 // Number of last blocks export default class DogeApi extends BtcBaseApi { - constructor (passphrase) { + constructor(passphrase) { super(Cryptos.DOGE, passphrase) } /** * @override */ - getBalance () { - return this._get(`/api/addr/${this.address}/balance`) - .then(balance => Number(balance) / this.multiplier) + getBalance() { + return this._get(`/api/addr/${this.address}/balance`).then( + (balance) => Number(balance) / this.multiplier + ) + } + + async getFeePerByte() { + const lastBlocksFee = await this._get(`/api/utils/estimatefee?nbBlocks=${NB_BLOCKS}`) + return lastBlocksFee[NB_BLOCKS] / 1024 } /** @override */ - sendTransaction (txHex) { - return this._post('/api/tx/send', { rawtx: txHex }).then(res => res.txid) + async createTransaction(address = '', amount = 0, fee) { + const unspents = await this.getUnspents() + + // populate unspents with full transaction in HEX + for (const unspent of unspents) { + // insight API v0.2.18 + const { rawtx } = await this._get(`/api/rawtx/${unspent.txid}`) + unspent.txHex = rawtx + } + + const hex = await this._buildTransaction(address, amount, unspents, fee) + + let txid = bitcoin.crypto.sha256(Buffer.from(hex, 'hex')) + txid = bitcoin.crypto.sha256(Buffer.from(txid)) + txid = txid.toString('hex').match(/.{2}/g).reverse().join('') + + return { hex, txid } } /** @override */ - getTransaction (txid) { - return this._get(`/api/tx/${txid}`).then(tx => this._mapTransaction(tx)) + async _buildTransaction(address, amount, unspents, fee) { + amount = new BigNumber(amount).times(this.multiplier).toNumber() + amount = Math.floor(amount) + const heldFee = Math.floor(new BigNumber(fee).times(this.multiplier).toNumber()) + + const txb = new bitcoin.Psbt({ + network: this._network + }) + txb.setVersion(1) + txb.setMaximumFeeRate(heldFee) + + let target = amount + heldFee + let transferAmount = 0 + let inputs = 0 + let estimatedTxBytes = 0 + + unspents.forEach((tx) => { + const amt = Math.floor(tx.amount) + if (transferAmount < target) { + const buffer = Buffer.from(tx.txHex, 'hex') + txb.addInput({ + hash: tx.txid, + index: tx.vout, + nonWitnessUtxo: buffer + }) + transferAmount += amt + estimatedTxBytes += buffer.length + inputs++ + } + }) + + txb.addOutput({ + address, + value: amount + }) + + // Estimated fee based on https://github.com/dogecoin/dogecoin/blob/master/doc/fee-recommendation.md + const currentFeeRate = await this.getFeePerByte() + let estimatedFee = Math.floor( + new BigNumber(currentFeeRate * (estimatedTxBytes + OUTPUTS_COMPENSATION)) + .times(this.multiplier) + .toNumber() + ) + + if (estimatedFee >= heldFee) { + estimatedFee = heldFee + } + + // This is a necessary step + // If we'll not add a change to output, it will burn in hell + const change = transferAmount - amount - estimatedFee + if (isPositiveNumber(change)) { + txb.addOutput({ + address: this._address, + value: change + }) + } + + for (let i = 0; i < inputs; ++i) { + txb.signInput(i, this._keyPair) + txb.validateSignaturesOfInput(i, this.validator) + } + + txb.finalizeAllInputs() + const tx = txb.extractTransaction() + + return tx.toHex() + } + + /** @override */ + sendTransaction(txHex) { + return this._post('/api/tx/send', { rawtx: txHex }).then((res) => res.txid) + } + + /** @override */ + getTransaction(txid) { + return this._get(`/api/tx/${txid}`).then((tx) => this._mapTransaction(tx)) } /** @override */ - getTransactions ({ from = 0 }) { + getTransactions({ from = 0 }) { const to = from + CHUNK_SIZE - return this._get(`/api/addrs/${this.address}/txs`, { from, to }) - .then(resp => ({ - ...resp, - hasMore: to < resp.totalItems, - items: resp.items.map(tx => this._mapTransaction(tx)) - })) + return this._get(`/api/addrs/${this.address}/txs`, { from, to }).then((resp) => ({ + ...resp, + hasMore: to < resp.totalItems, + items: resp.items.map((tx) => this._mapTransaction(tx)) + })) } /** @override */ - getUnspents () { - return this._get(`/api/addr/${this.address}/utxo?noCache=1`) - .then(unspents => { - return unspents.map(tx => ({ - ...tx, - amount: new BigNumber(tx.amount).times(this.multiplier).toNumber() - })) - }) + getUnspents() { + return this._get(`/api/addr/${this.address}/utxo?noCache=1`).then((unspents) => { + return unspents.map((tx) => ({ + ...tx, + amount: new BigNumber(tx.amount).times(this.multiplier).toNumber() + })) + }) } /** Executes a GET request to the DOGE API */ - _get (url, params) { - return this._getClient().get(url, { params }).then(response => response.data) + _get(url, params) { + return this._getClient() + .get(url, { params }) + .then((response) => response.data) } /** Executes a POST request to the DOGE API */ - _post (url, data) { - return this._getClient().post(url, qs.stringify(data), POST_CONFIG).then(response => response.data) + _post(url, data) { + return this._getClient() + .post(url, qs.stringify(data), POST_CONFIG) + .then((response) => response.data) + } + + validator(pubkey, msghash, signature) { + return ECPairAPI.fromPublicKey(pubkey).verify(msghash, signature) } } From 936d9041111a09b181fe153bdbf2a55e8a9bf0bb Mon Sep 17 00:00:00 2001 From: Mikhail Date: Mon, 6 Nov 2023 22:56:33 +0300 Subject: [PATCH 2/5] Bug: Sending DASH from the chat --- src/lib/bitcoin/bitcoin-api.js | 53 +++++++++++++++------------ src/lib/bitcoin/btc-base-api.js | 11 +++--- src/lib/bitcoin/dash-api.js | 64 ++++++++++++++++++--------------- src/lib/bitcoin/doge-api.js | 6 ++++ 4 files changed, 80 insertions(+), 54 deletions(-) diff --git a/src/lib/bitcoin/bitcoin-api.js b/src/lib/bitcoin/bitcoin-api.js index f2cfe03ad..fbe34cc6a 100644 --- a/src/lib/bitcoin/bitcoin-api.js +++ b/src/lib/bitcoin/bitcoin-api.js @@ -2,65 +2,72 @@ import BtcBaseApi from './btc-base-api' import { Cryptos } from '../constants' export default class BitcoinApi extends BtcBaseApi { - constructor (passphrase) { + constructor(passphrase) { super(Cryptos.BTC, passphrase) } /** * @override */ - getBalance () { + getBalance() { return this._get(`/address/${this.address}`).then( - data => (data.chain_stats.funded_txo_sum - data.chain_stats.spent_txo_sum) / this.multiplier + (data) => (data.chain_stats.funded_txo_sum - data.chain_stats.spent_txo_sum) / this.multiplier ) } /** @override */ - getFee () { + getFee() { return 0 } /** Returns last block height */ - getHeight () { - return this._get('/blocks/tip/height').then(data => Number(data) || 0) + getHeight() { + return this._get('/blocks/tip/height').then((data) => Number(data) || 0) } /** @override */ - sendTransaction (txHex) { - return this._getClient().post('/tx', txHex).then(response => response.data) + sendTransaction(txHex) { + return this._getClient() + .post('/tx', txHex) + .then((response) => response.data) } /** @override */ - getTransaction (txid) { - return this._get(`/tx/${txid}`).then(x => this._mapTransaction(x)) + getTransaction(txid) { + return this._get(`/tx/${txid}`).then((x) => this._mapTransaction(x)) } /** @override */ - getTransactions ({ toTx = '' }) { + getTransactions({ toTx = '' }) { let url = `/address/${this.address}/txs` if (toTx) { url += `/chain/${toTx}` } - return this._get(url).then(transactions => transactions.map(x => this._mapTransaction(x))) + return this._get(url).then((transactions) => transactions.map((x) => this._mapTransaction(x))) } /** @override */ - getUnspents () { - return this._get(`/address/${this.address}/utxo`).then(outputs => - outputs.map(x => ({ txid: x.txid, amount: x.value, vout: x.vout })) + getTransactionHex(txid) { + return this._get(`/tx/${txid}/hex`) + } + + /** @override */ + getUnspents() { + return this._get(`/address/${this.address}/utxo`).then((outputs) => + outputs.map((x) => ({ txid: x.txid, amount: x.value, vout: x.vout })) ) } - getFeeRate () { - return this._get('/fee-estimates').then(estimates => estimates['2']) + getFeeRate() { + return this._get('/fee-estimates').then((estimates) => estimates['2']) } /** @override */ - _mapTransaction (tx) { + _mapTransaction(tx) { const mapped = super._mapTransaction({ ...tx, - vin: tx.vin.map(x => ({ ...x, addr: x.prevout.scriptpubkey_address })), - vout: tx.vout.map(x => ({ + vin: tx.vin.map((x) => ({ ...x, addr: x.prevout.scriptpubkey_address })), + vout: tx.vout.map((x) => ({ ...x, scriptPubKey: { addresses: [x.scriptpubkey_address] } })), @@ -77,7 +84,9 @@ export default class BitcoinApi extends BtcBaseApi { } /** Executes a GET request to the API */ - _get (url, params) { - return this._getClient().get(url, { params }).then(response => response.data) + _get(url, params) { + return this._getClient() + .get(url, { params }) + .then((response) => response.data) } } diff --git a/src/lib/bitcoin/btc-base-api.js b/src/lib/bitcoin/btc-base-api.js index 200a629ed..4567c63dc 100644 --- a/src/lib/bitcoin/btc-base-api.js +++ b/src/lib/bitcoin/btc-base-api.js @@ -2,7 +2,7 @@ import * as bitcoin from 'bitcoinjs-lib' import axios from 'axios' import networks from './networks' -import { getRandomNodeUrl } from "@/config/utils"; +import { getRandomNodeUrl } from '@/config/utils' import BigNumber from '../bignumber' import { isPositiveNumber } from '@/lib/numericHelpers' import { CryptosInfo } from '../constants' @@ -88,8 +88,7 @@ export default class BtcBaseApi { // populate unspents with full transaction in HEX for (const unspent of unspents) { - const txHex = await this._get(`/tx/${unspent.txid}/hex`) - unspent.txHex = txHex + unspent.txHex = await this.getTransactionHex(unspent.txid) } const hex = this._buildTransaction(address, amount, unspents, fee) @@ -120,6 +119,10 @@ export default class BtcBaseApi { return Promise.resolve(null) } + getTransactionHex(txid) { + return Promise.resolve(null) + } + /** * Retrieves transactions for the specified address * @abstract @@ -198,7 +201,7 @@ export default class BtcBaseApi { } /** Picks a client for a random API endpoint */ - _getClient () { + _getClient() { const url = getRandomNodeUrl(this._crypto.toLowerCase()) if (!this._clients[url]) { this._clients[url] = createClient(url) diff --git a/src/lib/bitcoin/dash-api.js b/src/lib/bitcoin/dash-api.js index 630a5c489..c4bc6d14c 100644 --- a/src/lib/bitcoin/dash-api.js +++ b/src/lib/bitcoin/dash-api.js @@ -2,7 +2,7 @@ import BtcBaseApi from './btc-base-api' import { Cryptos } from '../constants' class DashApiError extends Error { - constructor (method, error) { + constructor(method, error) { super('Dash API returned an error') this.code = 'DASH_API' @@ -16,55 +16,61 @@ class DashApiError extends Error { } export default class DashApi extends BtcBaseApi { - constructor (passphrase) { + constructor(passphrase) { super(Cryptos.DASH, passphrase) } /** * @override */ - getBalance () { - return this._invoke('getaddressbalance', [this.address]) - .then(result => Number(result.balance) / this.multiplier) + getBalance() { + return this._invoke('getaddressbalance', [this.address]).then( + (result) => Number(result.balance) / this.multiplier + ) } /** @override */ - sendTransaction (txHex) { + sendTransaction(txHex) { return this._invoke('sendrawtransaction', [txHex]) } /** @override */ - getTransaction (txid) { - return this._invoke('getrawtransaction', [txid, true]) - .then(result => this._mapTransaction(result)) + getTransaction(txid) { + return this._invoke('getrawtransaction', [txid, true]).then((result) => + this._mapTransaction(result) + ) } /** @override */ - getTransactions (options) { + async getTransactionHex(txid) { + return await this._invoke('getrawtransaction', [txid, false]) + } + + /** @override */ + getTransactions(options) { return this._invoke('getaddresstxids', [this._address]) - .then(txids => { + .then((txids) => { const excludes = options.excludes || [] return txids - .filter(x => !excludes.includes(x)) - .map(x => ({ + .filter((x) => !excludes.includes(x)) + .map((x) => ({ method: 'getrawtransaction', params: [x, true] })) }) - .then(calls => this._invokeMany(calls)) - .then(results => results - .filter(x => !x.error && x.result) - .map(x => this._mapTransaction(x.result)) + .then((calls) => this._invokeMany(calls)) + .then((results) => + results.filter((x) => !x.error && x.result).map((x) => this._mapTransaction(x.result)) ) - .then(items => ({ hasMore: false, items })) + .then((items) => ({ hasMore: false, items })) } /** @override */ - getUnspents () { - return this._invoke('getaddressutxos', [this.address]).then(result => { + getUnspents() { + return this._invoke('getaddressutxos', [this.address]).then((result) => { if (!Array.isArray(result)) return [] - return result.map(x => ({ + return result.map((x) => ({ txid: x.txid, amount: x.satoshis, vout: x.outputIndex @@ -73,10 +79,10 @@ export default class DashApi extends BtcBaseApi { } /** @override */ - _mapTransaction (tx) { + _mapTransaction(tx) { return super._mapTransaction({ ...tx, - vin: tx.vin.map(x => ({ ...x, addr: x.address })) + vin: tx.vin.map((x) => ({ ...x, addr: x.address })) }) } @@ -86,16 +92,18 @@ export default class DashApi extends BtcBaseApi { * @param {object | Array} params method params * @returns {Promise} method result */ - _invoke (method, params) { - return this._getClient().post('/', { method, params }) + _invoke(method, params) { + return this._getClient() + .post('/', { method, params }) .then(({ data }) => { if (data.error) throw new DashApiError(method, data.error) return data.result }) } - _invokeMany (calls) { - return this._getClient().post('/', calls) - .then(response => response.data) + _invokeMany(calls) { + return this._getClient() + .post('/', calls) + .then((response) => response.data) } } diff --git a/src/lib/bitcoin/doge-api.js b/src/lib/bitcoin/doge-api.js index 1669543c3..1e710dfac 100644 --- a/src/lib/bitcoin/doge-api.js +++ b/src/lib/bitcoin/doge-api.js @@ -140,6 +140,12 @@ export default class DogeApi extends BtcBaseApi { return this._get(`/api/tx/${txid}`).then((tx) => this._mapTransaction(tx)) } + /** @override */ + getTransactionHex(txid) { + const { rawtx } = this._get(`/api/rawtx/${txid}`) + return rawtx + } + /** @override */ getTransactions({ from = 0 }) { const to = from + CHUNK_SIZE From 98b6b7814cf3a4c37d317d9f56a7fc48e7d3eae7 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 8 Nov 2023 16:53:41 +0300 Subject: [PATCH 3/5] Fixes --- src/lib/bitcoin/bitcoin-api.js | 4 +- src/lib/bitcoin/bitcoin-utils.js | 7 ++- src/lib/bitcoin/btc-base-api.js | 2 +- src/lib/bitcoin/doge-api.js | 99 +++++++++++++------------------- src/views/SendFunds.vue | 2 +- 5 files changed, 50 insertions(+), 64 deletions(-) diff --git a/src/lib/bitcoin/bitcoin-api.js b/src/lib/bitcoin/bitcoin-api.js index fbe34cc6a..bfa2c298c 100644 --- a/src/lib/bitcoin/bitcoin-api.js +++ b/src/lib/bitcoin/bitcoin-api.js @@ -47,8 +47,8 @@ export default class BitcoinApi extends BtcBaseApi { } /** @override */ - getTransactionHex(txid) { - return this._get(`/tx/${txid}/hex`) + async getTransactionHex(txid) { + return await this._get(`/tx/${txid}/hex`) } /** @override */ diff --git a/src/lib/bitcoin/bitcoin-utils.js b/src/lib/bitcoin/bitcoin-utils.js index 2bd329703..e3ece2c8a 100644 --- a/src/lib/bitcoin/bitcoin-utils.js +++ b/src/lib/bitcoin/bitcoin-utils.js @@ -1,11 +1,12 @@ import * as bitcoin from 'bitcoinjs-lib' +import BigNumber from '@/lib/bignumber' /** * Checks if the supplied string is a valid BTC address * @param {string} address address to check * @returns {boolean} */ -export function isValidAddress (address) { +export function isValidAddress(address) { try { bitcoin.address.toOutputScript(address) } catch (e) { @@ -14,3 +15,7 @@ export function isValidAddress (address) { return true } + +export function convertToSmallestUnit(amount, multiplier) { + return Math.floor(new BigNumber(amount).times(multiplier).toNumber()) +} diff --git a/src/lib/bitcoin/btc-base-api.js b/src/lib/bitcoin/btc-base-api.js index 4567c63dc..765bd8ca5 100644 --- a/src/lib/bitcoin/btc-base-api.js +++ b/src/lib/bitcoin/btc-base-api.js @@ -119,7 +119,7 @@ export default class BtcBaseApi { return Promise.resolve(null) } - getTransactionHex(txid) { + async getTransactionHex(txid) { return Promise.resolve(null) } diff --git a/src/lib/bitcoin/doge-api.js b/src/lib/bitcoin/doge-api.js index 1e710dfac..f7f14fd24 100644 --- a/src/lib/bitcoin/doge-api.js +++ b/src/lib/bitcoin/doge-api.js @@ -7,6 +7,7 @@ import * as bitcoin from 'bitcoinjs-lib' import { isPositiveNumber } from '../numericHelpers' import { ECPairFactory } from 'ecpair' import * as tinysecp from 'tiny-secp256k1' +import { convertToSmallestUnit } from './bitcoin-utils' const ECPairAPI = ECPairFactory(tinysecp) @@ -40,92 +41,72 @@ export default class DogeApi extends BtcBaseApi { return lastBlocksFee[NB_BLOCKS] / 1024 } - /** @override */ - async createTransaction(address = '', amount = 0, fee) { - const unspents = await this.getUnspents() - - // populate unspents with full transaction in HEX - for (const unspent of unspents) { - // insight API v0.2.18 - const { rawtx } = await this._get(`/api/rawtx/${unspent.txid}`) - unspent.txHex = rawtx - } - - const hex = await this._buildTransaction(address, amount, unspents, fee) - - let txid = bitcoin.crypto.sha256(Buffer.from(hex, 'hex')) - txid = bitcoin.crypto.sha256(Buffer.from(txid)) - txid = txid.toString('hex').match(/.{2}/g).reverse().join('') - - return { hex, txid } - } - /** @override */ async _buildTransaction(address, amount, unspents, fee) { - amount = new BigNumber(amount).times(this.multiplier).toNumber() - amount = Math.floor(amount) - const heldFee = Math.floor(new BigNumber(fee).times(this.multiplier).toNumber()) + const localAmount = convertToSmallestUnit(amount, this.multiplier) + const heldFee = convertToSmallestUnit(fee, this.multiplier) - const txb = new bitcoin.Psbt({ + const psbt = new bitcoin.Psbt({ network: this._network }) - txb.setVersion(1) - txb.setMaximumFeeRate(heldFee) + psbt.setVersion(1) + psbt.setMaximumFeeRate(heldFee) - let target = amount + heldFee + const target = localAmount + heldFee let transferAmount = 0 - let inputs = 0 + let inputsCount = 0 let estimatedTxBytes = 0 - unspents.forEach((tx) => { - const amt = Math.floor(tx.amount) - if (transferAmount < target) { - const buffer = Buffer.from(tx.txHex, 'hex') - txb.addInput({ - hash: tx.txid, - index: tx.vout, - nonWitnessUtxo: buffer - }) - transferAmount += amt - estimatedTxBytes += buffer.length - inputs++ + for (const tx of unspents) { + if (transferAmount >= target) { + break } - }) + const buffer = Buffer.from(tx.txHex, 'hex') + psbt.addInput({ + hash: tx.txid, + index: tx.vout, + nonWitnessUtxo: buffer + }) + transferAmount += tx.amount + estimatedTxBytes += buffer.length + inputsCount++ + } + + transferAmount = Math.floor(transferAmount) - txb.addOutput({ + psbt.addOutput({ address, - value: amount + value: localAmount }) // Estimated fee based on https://github.com/dogecoin/dogecoin/blob/master/doc/fee-recommendation.md const currentFeeRate = await this.getFeePerByte() let estimatedFee = Math.floor( - new BigNumber(currentFeeRate * (estimatedTxBytes + OUTPUTS_COMPENSATION)) + new BigNumber(currentFeeRate) + .times(estimatedTxBytes + OUTPUTS_COMPENSATION) .times(this.multiplier) .toNumber() ) - if (estimatedFee >= heldFee) { - estimatedFee = heldFee - } + estimatedFee = Math.min(estimatedFee, heldFee) // This is a necessary step - // If we'll not add a change to output, it will burn in hell - const change = transferAmount - amount - estimatedFee - if (isPositiveNumber(change)) { - txb.addOutput({ + // If we'll not add a difference to output, it will burn in hell + const difference = transferAmount - localAmount - estimatedFee + if (isPositiveNumber(difference)) { + psbt.addOutput({ address: this._address, - value: change + value: difference }) } - for (let i = 0; i < inputs; ++i) { - txb.signInput(i, this._keyPair) - txb.validateSignaturesOfInput(i, this.validator) + for (let i = 0; i < inputsCount; ++i) { + psbt.signInput(i, this._keyPair) + psbt.validateSignaturesOfInput(i, this.validator) } - txb.finalizeAllInputs() - const tx = txb.extractTransaction() + psbt.finalizeAllInputs() + const tx = psbt.extractTransaction() return tx.toHex() } @@ -141,8 +122,8 @@ export default class DogeApi extends BtcBaseApi { } /** @override */ - getTransactionHex(txid) { - const { rawtx } = this._get(`/api/rawtx/${txid}`) + async getTransactionHex(txid) { + const { rawtx } = await this._get(`/api/rawtx/${txid}`) return rawtx } diff --git a/src/views/SendFunds.vue b/src/views/SendFunds.vue index 6dd11b249..0d1d38d35 100644 --- a/src/views/SendFunds.vue +++ b/src/views/SendFunds.vue @@ -92,7 +92,7 @@ export default { this.$store.dispatch('snackbar/show', { message, color: '#ED5270', - timeout: 0 + timeout: 5000 }) } } From b61815982b4b1c0ed3a1e8f6c3c14232090012a1 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 8 Nov 2023 17:07:41 +0300 Subject: [PATCH 4/5] Rename validator as a private method --- src/lib/bitcoin/doge-api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/bitcoin/doge-api.js b/src/lib/bitcoin/doge-api.js index f7f14fd24..60f36c8da 100644 --- a/src/lib/bitcoin/doge-api.js +++ b/src/lib/bitcoin/doge-api.js @@ -102,7 +102,7 @@ export default class DogeApi extends BtcBaseApi { for (let i = 0; i < inputsCount; ++i) { psbt.signInput(i, this._keyPair) - psbt.validateSignaturesOfInput(i, this.validator) + psbt.validateSignaturesOfInput(i, this._validator) } psbt.finalizeAllInputs() @@ -161,7 +161,7 @@ export default class DogeApi extends BtcBaseApi { .then((response) => response.data) } - validator(pubkey, msghash, signature) { + _validator(pubkey, msghash, signature) { return ECPairAPI.fromPublicKey(pubkey).verify(msghash, signature) } } From 78ab496846c2d56ac029cc7edfb5cca059f8f16e Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 8 Nov 2023 18:59:36 +0300 Subject: [PATCH 5/5] async/await only in DOGE lib --- src/lib/bitcoin/bitcoin-api.js | 4 ++-- src/lib/bitcoin/btc-base-api.js | 2 +- src/lib/bitcoin/dash-api.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/bitcoin/bitcoin-api.js b/src/lib/bitcoin/bitcoin-api.js index bfa2c298c..fbe34cc6a 100644 --- a/src/lib/bitcoin/bitcoin-api.js +++ b/src/lib/bitcoin/bitcoin-api.js @@ -47,8 +47,8 @@ export default class BitcoinApi extends BtcBaseApi { } /** @override */ - async getTransactionHex(txid) { - return await this._get(`/tx/${txid}/hex`) + getTransactionHex(txid) { + return this._get(`/tx/${txid}/hex`) } /** @override */ diff --git a/src/lib/bitcoin/btc-base-api.js b/src/lib/bitcoin/btc-base-api.js index 765bd8ca5..4567c63dc 100644 --- a/src/lib/bitcoin/btc-base-api.js +++ b/src/lib/bitcoin/btc-base-api.js @@ -119,7 +119,7 @@ export default class BtcBaseApi { return Promise.resolve(null) } - async getTransactionHex(txid) { + getTransactionHex(txid) { return Promise.resolve(null) } diff --git a/src/lib/bitcoin/dash-api.js b/src/lib/bitcoin/dash-api.js index c4bc6d14c..9cf6f585b 100644 --- a/src/lib/bitcoin/dash-api.js +++ b/src/lib/bitcoin/dash-api.js @@ -42,8 +42,8 @@ export default class DashApi extends BtcBaseApi { } /** @override */ - async getTransactionHex(txid) { - return await this._invoke('getrawtransaction', [txid, false]) + getTransactionHex(txid) { + return this._invoke('getrawtransaction', [txid, false]) } /** @override */