Skip to content

Commit

Permalink
wallet: send OPENs to unspendable nullData address
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Aug 14, 2020
1 parent 0301f47 commit 4075ae8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,6 @@ class Wallet extends EventEmitter {
async _importName(name) {
const nameHash = rules.hashName(name);

if (await this.txdb.hasNameState(nameHash))
throw new Error('Name already exists.');

const b = this.db.batch();
await this.wdb.addNameMap(b, nameHash, this.wid);
await b.write();
Expand Down Expand Up @@ -1561,7 +1558,17 @@ class Wallet extends EventEmitter {
if (start !== 0 && start !== height)
throw new Error('Name is already opening.');

const addr = await this.receiveAddress(acct);
// Send 0-value output to provably unspendable address:
// hs1lqqqqhuxwgy (mainnet) is the smallest valid nulldata address
// and represents witness version 31 folowed by data of 0x0000.
// Unspendable outputs do not bloat the UTXO set or the wallet's coin set.
const addr = Address.fromNulldata(Buffer.alloc(2));

// Since this address is not in our wallet, we must "manually" add the name
// to the wallet database's name map. Normally the wallet would do this in
// txdb.js connectNames() when a TX is inserted into the DB, and the wallet
// recognizes the output address.
await this.importName(name);

const output = new Output();
output.address = addr;
Expand Down

0 comments on commit 4075ae8

Please sign in to comment.