Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include domain name in more error messages #7

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ class Wallet extends EventEmitter {
assert((acct >>> 0) === acct || typeof acct === 'string');

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -1555,10 +1555,10 @@ class Wallet extends EventEmitter {

// TODO: Handle expired behavior.
if (rules.isReserved(nameHash, height, network))
throw new Error('Name is reserved.');
throw new Error(`Name is reserved: "${name}".`);

if (!rules.hasRollout(nameHash, height, network))
throw new Error('Name not yet available.');
throw new Error(`Name not yet available: "${name}".`);

let ns = await this.getNameState(nameHash);

Expand All @@ -1571,10 +1571,10 @@ class Wallet extends EventEmitter {
const start = ns.height;

if (state !== states.OPENING)
throw new Error('Name is not available.');
throw new Error(`Name is not available: "${name}".`);

if (start !== 0 && start !== height)
throw new Error('Name is already opening.');
throw new Error(`Name is already opening: "${name}".`);

const addr = await this.receiveAddress(acct);

Expand Down Expand Up @@ -1676,18 +1676,18 @@ class Wallet extends EventEmitter {
assert((acct >>> 0) === acct || typeof acct === 'string');

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
const height = this.wdb.height + 1;
const network = this.network;

if (rules.isReserved(nameHash, height, network))
throw new Error('Name is reserved.');
throw new Error(`Name is reserved: "${name}".`);

if (!rules.hasRollout(nameHash, height, network))
throw new Error('Name not yet available.');
throw new Error(`Name not yet available: "${name}".`);

let ns = await this.getNameState(nameHash);

Expand All @@ -1700,13 +1700,13 @@ class Wallet extends EventEmitter {
const start = ns.height;

if (state === states.OPENING)
throw new Error('Name has not reached the bidding phase yet.');
throw new Error(`Name has not reached the bidding phase yet: "${name}".`);

if (state !== states.BIDDING)
throw new Error('Name is not available.');
throw new Error(`Name is not available: "${name}".`);

if (value > lockup)
throw new Error('Bid exceeds lockup value.');
throw new Error(`Bid exceeds lockup value: "${name}".`);

const addr = await this.receiveAddress(acct);
const blind = await this.generateBlind(nameHash, addr, value);
Expand Down Expand Up @@ -1803,7 +1803,7 @@ class Wallet extends EventEmitter {
assert(typeof name === 'string');

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -1819,10 +1819,10 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);

if (state < states.REVEAL)
throw new Error('Cannot reveal yet.');
throw new Error(`Cannot reveal yet: "${name}".`);

if (state > states.REVEAL)
throw new Error('Reveal period has passed.');
throw new Error(`Reveal period has passed: "${name}".`);

const bids = await this.getBids(nameHash);

Expand All @@ -1846,7 +1846,7 @@ class Wallet extends EventEmitter {
const bv = await this.getBlind(blind);

if (!bv)
throw new Error('Blind value not found.');
throw new Error(`Blind value not found: "${name}".`);

const {value, nonce} = bv;

Expand All @@ -1863,7 +1863,7 @@ class Wallet extends EventEmitter {
}

if (mtx.outputs.length === 0)
throw new Error('No bids to reveal.');
throw new Error(`No bids to reveal: "${name}".`);

return mtx;
}
Expand Down Expand Up @@ -2056,7 +2056,7 @@ class Wallet extends EventEmitter {
assert(typeof name === 'string');

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -2073,7 +2073,7 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);

if (state < states.CLOSED)
throw new Error('Auction is not yet closed.');
throw new Error(`Auction is not yet closed: "${name}".`);

const reveals = await this.txdb.getReveals(nameHash);

Expand Down Expand Up @@ -2110,7 +2110,7 @@ class Wallet extends EventEmitter {
}

if (mtx.outputs.length === 0)
throw new Error(`No reveals to redeem (${name}).`);
throw new Error(`No reveals to redeem: "${name}".`);

return mtx;
}
Expand Down Expand Up @@ -2305,7 +2305,7 @@ class Wallet extends EventEmitter {
assert(!resource || (resource instanceof Resource));

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -2320,27 +2320,27 @@ class Wallet extends EventEmitter {
const coin = await this.getCoin(hash, index);

if (!coin)
throw new Error('Wallet did not win the auction.');
throw new Error(`Wallet did not win the auction: "${name}".`);

if (ns.isExpired(height, network))
throw new Error(`Name has expired: "${name}"!`);

// Is local?
if (coin.height < ns.height)
throw new Error('Wallet did not win the auction.');
throw new Error(`Wallet did not win the auction: "${name}".`);

if (!coin.covenant.isReveal() && !coin.covenant.isClaim())
throw new Error('Name must be in REVEAL or CLAIM state.');
throw new Error(`Name must be in REVEAL or CLAIM state: "${name}".`);

if (coin.covenant.isClaim()) {
if (height < coin.height + network.coinbaseMaturity)
throw new Error('Claim is not yet mature.');
throw new Error(`Claim is not yet mature: "${name}".`);
}

const state = ns.state(height, network);

if (state !== states.CLOSED)
throw new Error('Auction is not yet closed.');
throw new Error(`Auction is not yet closed: "${name}".`);

const output = new Output();
output.address = coin.address;
Expand All @@ -2354,7 +2354,7 @@ class Wallet extends EventEmitter {
const raw = resource.encode();

if (raw.length > rules.MAX_RESOURCE_SIZE)
throw new Error('Resource exceeds maximum size.');
throw new Error(`Resource exceeds maximum size: "${name}".`);

output.covenant.push(raw);
} else {
Expand Down Expand Up @@ -2382,7 +2382,7 @@ class Wallet extends EventEmitter {
assert(resource instanceof Resource);

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand Down Expand Up @@ -2412,19 +2412,19 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);

if (state !== states.CLOSED)
throw new Error('Auction is not yet closed.');
throw new Error(`Auction is not yet closed: "${name}".`);

if (!coin.covenant.isRegister()
&& !coin.covenant.isUpdate()
&& !coin.covenant.isRenew()
&& !coin.covenant.isFinalize()) {
throw new Error('Name must be registered.');
throw new Error(`Name must be registered: "${name}".`);
}

const raw = resource.encode();

if (raw.length > rules.MAX_RESOURCE_SIZE)
throw new Error('Resource exceeds maximum size.');
throw new Error(`Resource exceeds maximum size: "${name}".`);

const output = new Output();
output.address = coin.address;
Expand Down Expand Up @@ -2517,7 +2517,7 @@ class Wallet extends EventEmitter {
assert(typeof name === 'string');

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -2544,17 +2544,17 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);

if (state !== states.CLOSED)
throw new Error('Auction is not yet closed.');
throw new Error(`Auction is not yet closed: "${name}".`);

if (!coin.covenant.isRegister()
&& !coin.covenant.isUpdate()
&& !coin.covenant.isRenew()
&& !coin.covenant.isFinalize()) {
throw new Error('Name must be registered.');
throw new Error(`Name must be registered: "${name}".`);
}

if (height < ns.renewal + network.names.treeInterval)
throw new Error('Must wait to renew.');
throw new Error(`Must wait to renew: "${name}".`);

const output = new Output();
output.address = coin.address;
Expand Down Expand Up @@ -2643,7 +2643,7 @@ class Wallet extends EventEmitter {
assert(address instanceof Address);

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -2670,13 +2670,13 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);

if (state !== states.CLOSED)
throw new Error('Auction is not yet closed.');
throw new Error(`Auction is not yet closed: "${name}".`);

if (!coin.covenant.isRegister()
&& !coin.covenant.isUpdate()
&& !coin.covenant.isRenew()
&& !coin.covenant.isFinalize()) {
throw new Error('Name must be registered.');
throw new Error(`Name must be registered: "${name}".`);
}

const output = new Output();
Expand Down Expand Up @@ -2774,7 +2774,7 @@ class Wallet extends EventEmitter {
assert(typeof name === 'string');

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -2801,10 +2801,10 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);

if (state !== states.CLOSED)
throw new Error('Auction is not yet closed.');
throw new Error(`Auction is not yet closed: "${name}".`);

if (!coin.covenant.isTransfer())
throw new Error('Name is not being transfered.');
throw new Error(`Name is not being transfered: "${name}".`);

const output = new Output();
output.address = coin.address;
Expand Down Expand Up @@ -2892,7 +2892,7 @@ class Wallet extends EventEmitter {
assert(typeof name === 'string');

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -2919,13 +2919,13 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);

if (state !== states.CLOSED)
throw new Error('Auction is not yet closed.');
throw new Error(`Auction is not yet closed: "${name}".`);

if (!coin.covenant.isTransfer())
throw new Error('Name is not being transfered.');
throw new Error(`Name is not being transfered: "${name}".`);

if (height < coin.height + network.names.transferLockup)
throw new Error('Transfer is still locked up.');
throw new Error(`Transfer is still locked up: "${name}".`);

const version = coin.covenant.getU8(2);
const addr = coin.covenant.get(3);
Expand Down Expand Up @@ -3025,7 +3025,7 @@ class Wallet extends EventEmitter {
assert(typeof name === 'string');

if (!rules.verifyName(name))
throw new Error('Invalid name.');
throw new Error(`Invalid name: "${name}".`);

const rawName = Buffer.from(name, 'ascii');
const nameHash = rules.hashName(rawName);
Expand All @@ -3052,14 +3052,14 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);

if (state !== states.CLOSED)
throw new Error('Auction is not yet closed.');
throw new Error(`Auction is not yet closed: "${name}".`);

if (!coin.covenant.isRegister()
&& !coin.covenant.isUpdate()
&& !coin.covenant.isRenew()
&& !coin.covenant.isTransfer()
&& !coin.covenant.isFinalize()) {
throw new Error('Name must be registered.');
throw new Error(`Name must be registered: "${name}".`);
}

const output = new Output();
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "namebase-hsd",
"version": "0.0.24",
"version": "0.0.25",
"private": false,
"description": "Cryptocurrency bike-shed",
"license": "MIT",
Expand Down