Merge pull request #1774 from RafaelTaranto/feat/replace-btc-fee-script
LAM-1098 replace btc fee script
This commit is contained in:
commit
58e625f798
4 changed files with 65 additions and 8 deletions
47
bin/lamassu-btc-bumpfee
Normal file
47
bin/lamassu-btc-bumpfee
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const inquirer = require('inquirer')
|
||||
|
||||
const bitcoind = require('../lib/plugins/wallet/bitcoind/bitcoind')
|
||||
const BN = require('../lib/bn')
|
||||
const mempool = require('../lib/blockexplorers/mempool.space')
|
||||
|
||||
const txId = process.argv[2]
|
||||
if (!txId) {
|
||||
console.error('Please provide a BTC transaction hash as input.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const bumpTransactionFee = async (txId) => {
|
||||
const txData = await bitcoind.fetch('gettransaction', [txId, true, true])
|
||||
|
||||
const fee = new BN(txData.fee).abs().shiftedBy(8).decimalPlaces(0)
|
||||
const size = txData.decoded.vsize
|
||||
const satPerVb = fee.div(size)
|
||||
|
||||
console.log(`Current fee: ${satPerVb.toFixed(2).toString()} sat/vB`)
|
||||
|
||||
const recommendedFees = await mempool.getSatBEstimateFees()
|
||||
|
||||
console.log('Recommended fees (sat/vB):', recommendedFees)
|
||||
|
||||
const { selectedFee } = await inquirer.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'selectedFee',
|
||||
message: 'Select a fee higher than the current one:',
|
||||
choices: Object.entries(recommendedFees)
|
||||
.filter(([_, value]) => satPerVb.lt(value))
|
||||
.map(([key, value]) => ({name: `${key}: ${value} sat/vB`, value})),
|
||||
},
|
||||
])
|
||||
|
||||
const { txid } = await bitcoind.fetch('bumpfee', [txId, {fee_rate: selectedFee}])
|
||||
|
||||
console.log(`
|
||||
Fee bumped to ${selectedFee.toFixed(2)} sat/vB
|
||||
Transaction ID: ${txid}
|
||||
`)
|
||||
}
|
||||
|
||||
bumpTransactionFee(txId)
|
||||
|
|
@ -1,8 +1,16 @@
|
|||
const axios = require("axios");
|
||||
|
||||
const getSatBEstimateFee = () => {
|
||||
return axios.get('https://mempool.space/api/v1/fees/recommended')
|
||||
.then(r => r.data.hourFee)
|
||||
}
|
||||
|
||||
module.exports = { getSatBEstimateFee }
|
||||
const axios = require("axios");
|
||||
|
||||
const getSatBEstimateFee = () => {
|
||||
return axios.get('https://mempool.space/api/v1/fees/recommended')
|
||||
.then(r => r.data.hourFee)
|
||||
}
|
||||
|
||||
const getSatBEstimateFees = () => {
|
||||
return axios.get('https://mempool.space/api/v1/fees/recommended')
|
||||
.then(r => r.data)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSatBEstimateFees,
|
||||
getSatBEstimateFee
|
||||
}
|
||||
|
|
@ -219,5 +219,6 @@ module.exports = {
|
|||
sendCoinsBatch,
|
||||
checkBlockchainStatus,
|
||||
getTxHashesByAddress,
|
||||
fetch,
|
||||
SUPPORTS_BATCHING
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@
|
|||
"lamassu-ofac-update": "./bin/lamassu-ofac-update",
|
||||
"lamassu-send-coins": "./bin/lamassu-send-coins",
|
||||
"lamassu-update-to-mnemonic": "./bin/lamassu-update-to-mnemonic",
|
||||
"lamassu-btc-bumpfee": "./bin/lamassu-btc-bumpfee",
|
||||
"lamassu-update-wallet-nodes": "./bin/lamassu-update-wallet-nodes",
|
||||
"lamassu-configure-frontcamera": "./bin/lamassu-configure-frontcamera",
|
||||
"lamassu-ofac-update-sources": "./bin/lamassu-ofac-update-sources",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue