feat: add lamassu bumpfee script
This commit is contained in:
parent
ed1fb5252a
commit
46e34a78a2
3 changed files with 61 additions and 8 deletions
44
bin/lamassu-btc-bumpfee
Normal file
44
bin/lamassu-btc-bumpfee
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/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 = 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.gt(value))
|
||||
.map(([key, value]) => ({name: `${key}: ${value} sat/vB`, value})),
|
||||
},
|
||||
])
|
||||
|
||||
await bitcoind.fetch('bumpfee', [txId, {fee_rate: selectedFee}])
|
||||
|
||||
console.log(`Fee bumped to ${selectedFee.toFixed(2)} sat/vB`)
|
||||
}
|
||||
|
||||
bumpTransactionFee(txId)
|
||||
|
|
@ -5,4 +5,12 @@ const getSatBEstimateFee = () => {
|
|||
.then(r => r.data.hourFee)
|
||||
}
|
||||
|
||||
module.exports = { getSatBEstimateFee }
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue