Skip to content

Commit

Permalink
cli/http: add bwallet-cli bump <txid> <rate> <sign> <passphrase>
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Aug 11, 2023
1 parent 161089f commit 86b081b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
15 changes: 15 additions & 0 deletions bin/bwallet-cli
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ class CLI {
this.log('Abandoned tx: ' + hash);
}

async bumpTX() {
const hash = this.config.str([0, 'hash']);
const rate = this.config.uint([1, 'rate']);
const sign = this.config.bool([2, 'sign']);
const passphrase = this.config.str([3, 'passphrase']);

const tx = await this.wallet.bumpTX(hash, rate, sign, passphrase);

this.log(tx);
}

async getDetails() {
const hash = this.config.str(0);
const details = await this.wallet.getTX(hash);
Expand Down Expand Up @@ -605,6 +616,9 @@ class CLI {
case 'rescan':
await this.rescan();
break;
case 'bump':
await this.bumpTX();
break;
default:
this.log('Unrecognized command.');
this.log('Commands:');
Expand All @@ -617,6 +631,7 @@ class CLI {
this.log(' $ balance: Get wallet balance.');
this.log(' $ block [height]: View wallet block.');
this.log(' $ blocks: List wallet blocks.');
this.log(' $ bump [hash]: Bump TX fee with replacement.');
this.log(' $ change: Derive new change address.');
this.log(' $ coins: View wallet coins.');
this.log(' $ dump [address]: Get wallet key WIF by address.');
Expand Down
28 changes: 28 additions & 0 deletions lib/client/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ class WalletClient extends Client {
return this.del(`/wallet/${id}/tx/${hash}`);
}

/**
* @param {Number} id
* @param {Hash} hash
* @param {Number?} rate
* @param {Bool?} sign
* @param {String?} passphrase
* @returns {Promise}
*/

bumpTX(id, hash, rate, sign, passphrase) {
return this.post(
`/wallet/${id}/bump/${hash}`,
{hash, rate, sign, passphrase});
}

/**
* Create a transaction, fill.
* @param {Number} id
Expand Down Expand Up @@ -832,6 +847,19 @@ class Wallet extends EventEmitter {
return this.client.abandon(this.id, hash);
}

/**
* Send an RBF replacement to bump fee
* @param {Hash} hash
* @param {Number?} rate
* @param {Bool?} sign
* @param {String?} passphrase
* @returns {Promise}
*/

bumpTX(hash, rate, sign, passphrase) {
return this.client.bumpTX(this.id, hash);
}

/**
* Create a transaction, fill.
* @param {Object} options
Expand Down
17 changes: 17 additions & 0 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,23 @@ class HTTP extends Server {
res.json(200, tx.getJSON(this.network));
});

// Create replacement fee-bump TX
this.post('/wallet/:id/bump/:hash', async (req, res) => {
const valid = Validator.fromRequest(req);
const hash = valid.brhash('hash');
enforce(hash, 'txid is required.');
let rate = valid.u64('rate');
if (!rate)
rate = this.network.minRelay;
const sign = valid.bool('sign', true);
const passphrase = valid.str('passphrase');

// Bump fee by reducing change output value.
const tx = await req.wallet.bumpTXFee(hash, rate, sign, passphrase);

res.json(200, tx.getJSON(this.network));
});

// Zap Wallet TXs
this.post('/wallet/:id/zap', async (req, res) => {
const valid = Validator.fromRequest(req);
Expand Down
4 changes: 2 additions & 2 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1301,12 +1301,12 @@ class Wallet extends EventEmitter {
* Complies with BIP-125 replace-by-fee
* @param {Hash} hash
* @param {Rate} rate
* @param {(String|Buffer)?} passphrase
* @param {Boolean?} sign - sign with wallet
* @param {(String|Buffer)?} passphrase
* @returns {Promise} - Returns {@link TX}.
*/

async bumpTXFee(hash, rate, passphrase, sign) {
async bumpTXFee(hash, rate, sign, passphrase) {
assert((rate >>> 0) === rate, 'Rate must be a number.');

const wtx = await this.getTX(hash);
Expand Down

0 comments on commit 86b081b

Please sign in to comment.