Skip to content

Commit e2f8aa3

Browse files
committed
wallet: check account ownership of name before making revoke TX
1 parent c8ae6b9 commit e2f8aa3

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

lib/wallet/wallet.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,12 +3036,17 @@ class Wallet extends EventEmitter {
30363036
* @returns {MTX}
30373037
*/
30383038

3039-
async makeRevoke(name) {
3039+
async makeRevoke(name, acct) {
30403040
assert(typeof name === 'string');
30413041

30423042
if (!rules.verifyName(name))
30433043
throw new Error('Invalid name.');
30443044

3045+
if (acct != null) {
3046+
assert((acct >>> 0) === acct || typeof acct === 'string');
3047+
acct = await this.getAccountIndex(acct);
3048+
}
3049+
30453050
const rawName = Buffer.from(name, 'ascii');
30463051
const nameHash = rules.hashName(rawName);
30473052
const ns = await this.getNameState(nameHash);
@@ -3057,6 +3062,9 @@ class Wallet extends EventEmitter {
30573062
if (!coin)
30583063
throw new Error(`Wallet does not own: "${name}".`);
30593064

3065+
if (acct != null && !await this.txdb.hasCoinByAccount(acct, hash, index))
3066+
throw new Error(`Account does not own: "${name}".`);
3067+
30603068
// Is local?
30613069
if (coin.height < ns.height)
30623070
throw new Error(`Wallet does not own: "${name}".`);
@@ -3100,7 +3108,8 @@ class Wallet extends EventEmitter {
31003108
*/
31013109

31023110
async _createRevoke(name, options) {
3103-
const mtx = await this.makeRevoke(name);
3111+
const acct = options ? options.account : null;
3112+
const mtx = await this.makeRevoke(name, acct);
31043113
await this.fill(mtx, options);
31053114
return this.finalize(mtx, options);
31063115
}
@@ -3131,7 +3140,7 @@ class Wallet extends EventEmitter {
31313140

31323141
async _sendRevoke(name, options) {
31333142
const passphrase = options ? options.passphrase : null;
3134-
const mtx = await this._createRevoke(name);
3143+
const mtx = await this._createRevoke(name, options);
31353144
return this.sendMTX(mtx, passphrase);
31363145
}
31373146

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)