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

Add more specific error when linked inputs are pending. #904

Merged
merged 1 commit into from
Oct 7, 2024
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
73 changes: 59 additions & 14 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ class Wallet extends EventEmitter {
continue;

const {hash, index} = prevout;
const coin = await this.getCoin(hash, index);
const coin = await this.getUnspentCoin(hash, index);

if (!coin)
continue;
Expand Down Expand Up @@ -2284,7 +2284,7 @@ class Wallet extends EventEmitter {
if (prevout.equals(ns.owner))
continue;

const coin = await this.getCoin(hash, index);
const coin = await this.getUnspentCoin(hash, index);

if (!coin)
continue;
Expand Down Expand Up @@ -2528,14 +2528,19 @@ class Wallet extends EventEmitter {
throw new Error(`Auction not found: ${name}.`);

const {hash, index} = ns.owner;
const coin = await this.getCoin(hash, index);
const credit = await this.getCredit(hash, index);

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

if (credit.spent)
throw new Error(`Credit is already pending for: ${name}.`);

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

const coin = credit.coin;

// Is local?
if (coin.height < ns.height)
throw new Error(`Wallet did not win the auction: ${name}.`);
Expand Down Expand Up @@ -2612,14 +2617,19 @@ class Wallet extends EventEmitter {
throw new Error(`Auction not found: ${name}.`);

const {hash, index} = ns.owner;
const coin = await this.getCoin(hash, index);
const credit = await this.getCredit(hash, index);

if (!coin)
if (!credit)
throw new Error(`Wallet does not own name: ${name}.`);

if (credit.spent)
throw new Error(`Credit is already pending for: ${name}.`);

if (acct != null && !await this.txdb.hasCoinByAccount(acct, hash, index))
throw new Error(`Account does not own name: ${name}.`);

const coin = credit.coin;

if (coin.covenant.isReveal() || coin.covenant.isClaim())
return this._makeRegister(name, resource, mtx);

Expand Down Expand Up @@ -2753,14 +2763,20 @@ class Wallet extends EventEmitter {
throw new Error(`Auction not found: ${name}.`);

const {hash, index} = ns.owner;
const coin = await this.getCoin(hash, index);
const credit = await this.getCredit(hash, index);

if (!coin)
if (!credit)
throw new Error(`Wallet does not own name: ${name}.`);

if (credit.spent) {
throw new Error(`Credit is already pending for: ${name}.`);
}

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

const coin = credit.coin;

// Is local?
if (coin.height < ns.height)
throw new Error(`Wallet does not own name: ${name}.`);
Expand Down Expand Up @@ -2968,14 +2984,19 @@ class Wallet extends EventEmitter {
throw new Error(`Auction not found: ${name}.`);

const {hash, index} = ns.owner;
const coin = await this.getCoin(hash, index);
const credit = await this.getCredit(hash, index);

if (!coin)
if (!credit)
throw new Error(`Wallet does not own name: ${name}.`);

if (credit.spent)
throw new Error(`Credit is already pending for: ${name}.`);

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

const coin = credit.coin;

// Is local?
if (coin.height < ns.height)
throw new Error(`Wallet does not own name: ${name}.`);
Expand All @@ -2986,6 +3007,9 @@ class Wallet extends EventEmitter {
if (!ns.isClosed(height, network))
throw new Error(`Auction is not yet closed: ${name}.`);

if (coin.covenant.isTransfer())
throw new Error(`Name is already being transferred: ${name}.`);

if (!coin.covenant.isRegister()
&& !coin.covenant.isUpdate()
&& !coin.covenant.isRenew()
Expand Down Expand Up @@ -3230,14 +3254,19 @@ class Wallet extends EventEmitter {
throw new Error(`Auction not found: ${name}.`);

const {hash, index} = ns.owner;
const coin = await this.getCoin(hash, index);
const credit = await this.getCredit(hash, index);

if (!coin)
if (!credit)
throw new Error(`Wallet does not own name: ${name}.`);

if (credit.spent)
throw new Error(`Credit is already pending for: ${name}.`);

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

const coin = credit.coin;

// Is local?
if (coin.height < ns.height)
throw new Error(`Wallet does not own name: ${name}.`);
Expand Down Expand Up @@ -3452,14 +3481,19 @@ class Wallet extends EventEmitter {
throw new Error(`Auction not found: ${name}.`);

const {hash, index} = ns.owner;
const coin = await this.getCoin(hash, index);
const credit = await this.getCredit(hash, index);

if (!coin)
if (!credit)
throw new Error(`Wallet does not own name: ${name}.`);

if (credit.spent)
throw new Error(`Credit is already pending for: ${name}.`);

if (acct != null && !await this.txdb.hasCoinByAccount(acct, hash, index))
throw new Error(`Account does not own name: ${name}.`);

const coin = credit.coin;

// Is local?
if (coin.height < ns.height)
throw new Error(`Wallet does not own name: ${name}.`);
Expand Down Expand Up @@ -4632,6 +4666,17 @@ class Wallet extends EventEmitter {
return credit.coin;
}

/**
* Get credit from the wallet.
* @param {Hash} hash
* @param {Number} index
* @returns {Promise<Credit>}
*/

getCredit(hash, index) {
return this.txdb.getCredit(hash, index);
}

/**
* Get a transaction from the wallet.
* @param {Hash} hash
Expand Down
Loading
Loading