Skip to content

Commit 2db37fb

Browse files
committed
wallet: check account ownership of name before making revoke TX
1 parent 8204e66 commit 2db37fb

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

lib/wallet/wallet.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,15 +3039,21 @@ class Wallet extends EventEmitter {
30393039
/**
30403040
* Make a revoke MTX.
30413041
* @param {String} name
3042+
* @param {String|Number} acct
30423043
* @returns {MTX}
30433044
*/
30443045

3045-
async makeRevoke(name) {
3046+
async makeRevoke(name, acct) {
30463047
assert(typeof name === 'string');
30473048

30483049
if (!rules.verifyName(name))
30493050
throw new Error('Invalid name.');
30503051

3052+
if (acct != null) {
3053+
assert((acct >>> 0) === acct || typeof acct === 'string');
3054+
acct = await this.getAccountIndex(acct);
3055+
}
3056+
30513057
const rawName = Buffer.from(name, 'ascii');
30523058
const nameHash = rules.hashName(rawName);
30533059
const ns = await this.getNameState(nameHash);
@@ -3063,6 +3069,9 @@ class Wallet extends EventEmitter {
30633069
if (!coin)
30643070
throw new Error(`Wallet does not own: "${name}".`);
30653071

3072+
if (acct != null && !await this.txdb.hasCoinByAccount(acct, hash, index))
3073+
throw new Error(`Account does not own: "${name}".`);
3074+
30663075
// Is local?
30673076
if (coin.height < ns.height)
30683077
throw new Error(`Wallet does not own: "${name}".`);
@@ -3106,7 +3115,8 @@ class Wallet extends EventEmitter {
31063115
*/
31073116

31083117
async _createRevoke(name, options) {
3109-
const mtx = await this.makeRevoke(name);
3118+
const acct = options ? options.account : null;
3119+
const mtx = await this.makeRevoke(name, acct);
31103120
await this.fill(mtx, options);
31113121
return this.finalize(mtx, options);
31123122
}
@@ -3137,7 +3147,7 @@ class Wallet extends EventEmitter {
31373147

31383148
async _sendRevoke(name, options) {
31393149
const passphrase = options ? options.passphrase : null;
3140-
const mtx = await this._createRevoke(name);
3150+
const mtx = await this._createRevoke(name, options);
31413151
return this.sendMTX(mtx, passphrase);
31423152
}
31433153

test/wallet-accounts-auction-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,37 @@ describe('Multiple accounts participating in same auction', function() {
366366
assert.strictEqual(node.mempool.map.size, 0);
367367
});
368368
});
369+
370+
describe('REVOKE', function() {
371+
it('should reject REVOKE from wrong account', async () => {
372+
await assert.rejects(async () => {
373+
await wallet.sendRevoke(name, {account: 'bob'});
374+
}, {
375+
name: 'Error',
376+
message: `Account does not own: "${name}".`
377+
});
378+
});
379+
380+
it('should send REVOKE from correct account', async () => {
381+
const tx = await wallet.sendRevoke(name, {account: 0});
382+
assert(tx);
383+
384+
await wallet.abandon(tx.hash());
385+
386+
assert.strictEqual(node.mempool.map.size, 1);
387+
await node.mempool.reset();
388+
assert.strictEqual(node.mempool.map.size, 0);
389+
});
390+
391+
it('should send REVOKE from correct account automatically', async () => {
392+
const tx = await wallet.sendRevoke(name);
393+
assert(tx);
394+
395+
await wallet.abandon(tx.hash());
396+
397+
assert.strictEqual(node.mempool.map.size, 1);
398+
await node.mempool.reset();
399+
assert.strictEqual(node.mempool.map.size, 0);
400+
});
401+
});
369402
});

0 commit comments

Comments
 (0)