Skip to content

Commit 1b331ee

Browse files
committed
Merge PR #904 from 'nodech/preferred-inputs-bug'
2 parents 45c6ac1 + 7b5aab1 commit 1b331ee

File tree

2 files changed

+303
-14
lines changed

2 files changed

+303
-14
lines changed

lib/wallet/wallet.js

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ class Wallet extends EventEmitter {
20062006
continue;
20072007

20082008
const {hash, index} = prevout;
2009-
const coin = await this.getCoin(hash, index);
2009+
const coin = await this.getUnspentCoin(hash, index);
20102010

20112011
if (!coin)
20122012
continue;
@@ -2284,7 +2284,7 @@ class Wallet extends EventEmitter {
22842284
if (prevout.equals(ns.owner))
22852285
continue;
22862286

2287-
const coin = await this.getCoin(hash, index);
2287+
const coin = await this.getUnspentCoin(hash, index);
22882288

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

25302530
const {hash, index} = ns.owner;
2531-
const coin = await this.getCoin(hash, index);
2531+
const credit = await this.getCredit(hash, index);
25322532

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

2536+
if (credit.spent)
2537+
throw new Error(`Credit is already pending for: ${name}.`);
2538+
25362539
if (ns.isExpired(height, network))
25372540
throw new Error(`Name has expired: ${name}.`);
25382541

2542+
const coin = credit.coin;
2543+
25392544
// Is local?
25402545
if (coin.height < ns.height)
25412546
throw new Error(`Wallet did not win the auction: ${name}.`);
@@ -2612,14 +2617,19 @@ class Wallet extends EventEmitter {
26122617
throw new Error(`Auction not found: ${name}.`);
26132618

26142619
const {hash, index} = ns.owner;
2615-
const coin = await this.getCoin(hash, index);
2620+
const credit = await this.getCredit(hash, index);
26162621

2617-
if (!coin)
2622+
if (!credit)
26182623
throw new Error(`Wallet does not own name: ${name}.`);
26192624

2625+
if (credit.spent)
2626+
throw new Error(`Credit is already pending for: ${name}.`);
2627+
26202628
if (acct != null && !await this.txdb.hasCoinByAccount(acct, hash, index))
26212629
throw new Error(`Account does not own name: ${name}.`);
26222630

2631+
const coin = credit.coin;
2632+
26232633
if (coin.covenant.isReveal() || coin.covenant.isClaim())
26242634
return this._makeRegister(name, resource, mtx);
26252635

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

27552765
const {hash, index} = ns.owner;
2756-
const coin = await this.getCoin(hash, index);
2766+
const credit = await this.getCredit(hash, index);
27572767

2758-
if (!coin)
2768+
if (!credit)
27592769
throw new Error(`Wallet does not own name: ${name}.`);
27602770

2771+
if (credit.spent) {
2772+
throw new Error(`Credit is already pending for: ${name}.`);
2773+
}
2774+
27612775
if (ns.isExpired(height, network))
27622776
throw new Error(`Name has expired: ${name}.`);
27632777

2778+
const coin = credit.coin;
2779+
27642780
// Is local?
27652781
if (coin.height < ns.height)
27662782
throw new Error(`Wallet does not own name: ${name}.`);
@@ -2968,14 +2984,19 @@ class Wallet extends EventEmitter {
29682984
throw new Error(`Auction not found: ${name}.`);
29692985

29702986
const {hash, index} = ns.owner;
2971-
const coin = await this.getCoin(hash, index);
2987+
const credit = await this.getCredit(hash, index);
29722988

2973-
if (!coin)
2989+
if (!credit)
29742990
throw new Error(`Wallet does not own name: ${name}.`);
29752991

2992+
if (credit.spent)
2993+
throw new Error(`Credit is already pending for: ${name}.`);
2994+
29762995
if (ns.isExpired(height, network))
29772996
throw new Error(`Name has expired: ${name}.`);
29782997

2998+
const coin = credit.coin;
2999+
29793000
// Is local?
29803001
if (coin.height < ns.height)
29813002
throw new Error(`Wallet does not own name: ${name}.`);
@@ -2986,6 +3007,9 @@ class Wallet extends EventEmitter {
29863007
if (!ns.isClosed(height, network))
29873008
throw new Error(`Auction is not yet closed: ${name}.`);
29883009

3010+
if (coin.covenant.isTransfer())
3011+
throw new Error(`Name is already being transferred: ${name}.`);
3012+
29893013
if (!coin.covenant.isRegister()
29903014
&& !coin.covenant.isUpdate()
29913015
&& !coin.covenant.isRenew()
@@ -3230,14 +3254,19 @@ class Wallet extends EventEmitter {
32303254
throw new Error(`Auction not found: ${name}.`);
32313255

32323256
const {hash, index} = ns.owner;
3233-
const coin = await this.getCoin(hash, index);
3257+
const credit = await this.getCredit(hash, index);
32343258

3235-
if (!coin)
3259+
if (!credit)
32363260
throw new Error(`Wallet does not own name: ${name}.`);
32373261

3262+
if (credit.spent)
3263+
throw new Error(`Credit is already pending for: ${name}.`);
3264+
32383265
if (ns.isExpired(height, network))
32393266
throw new Error(`Name has expired: ${name}.`);
32403267

3268+
const coin = credit.coin;
3269+
32413270
// Is local?
32423271
if (coin.height < ns.height)
32433272
throw new Error(`Wallet does not own name: ${name}.`);
@@ -3452,14 +3481,19 @@ class Wallet extends EventEmitter {
34523481
throw new Error(`Auction not found: ${name}.`);
34533482

34543483
const {hash, index} = ns.owner;
3455-
const coin = await this.getCoin(hash, index);
3484+
const credit = await this.getCredit(hash, index);
34563485

3457-
if (!coin)
3486+
if (!credit)
34583487
throw new Error(`Wallet does not own name: ${name}.`);
34593488

3489+
if (credit.spent)
3490+
throw new Error(`Credit is already pending for: ${name}.`);
3491+
34603492
if (acct != null && !await this.txdb.hasCoinByAccount(acct, hash, index))
34613493
throw new Error(`Account does not own name: ${name}.`);
34623494

3495+
const coin = credit.coin;
3496+
34633497
// Is local?
34643498
if (coin.height < ns.height)
34653499
throw new Error(`Wallet does not own name: ${name}.`);
@@ -4632,6 +4666,17 @@ class Wallet extends EventEmitter {
46324666
return credit.coin;
46334667
}
46344668

4669+
/**
4670+
* Get credit from the wallet.
4671+
* @param {Hash} hash
4672+
* @param {Number} index
4673+
* @returns {Promise<Credit>}
4674+
*/
4675+
4676+
getCredit(hash, index) {
4677+
return this.txdb.getCredit(hash, index);
4678+
}
4679+
46354680
/**
46364681
* Get a transaction from the wallet.
46374682
* @param {Hash} hash

0 commit comments

Comments
 (0)