wdb: update wallet types.
This commit is contained in:
parent
dd36a772b4
commit
ebf0ec0c06
5 changed files with 485 additions and 297 deletions
|
|
@ -314,6 +314,7 @@ class Coin extends Output {
|
|||
* @param {TX} tx
|
||||
* @param {Number} index
|
||||
* @param {Number} height
|
||||
* @returns {this}
|
||||
*/
|
||||
|
||||
fromTX(tx, index, height) {
|
||||
|
|
|
|||
|
|
@ -450,6 +450,7 @@ class MapRecord extends bio.Struct {
|
|||
|
||||
constructor() {
|
||||
super();
|
||||
/** @type {Set<Number>} */
|
||||
this.wids = new Set();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,20 @@ const NameUndo = require('../covenants/undo');
|
|||
const {TXRecord} = require('./records');
|
||||
const {types} = rules;
|
||||
|
||||
/** @typedef {import('bdb').DB} DB */
|
||||
/** @typedef {ReturnType<DB['batch']>} Batch */
|
||||
/** @typedef {import('../types').Hash} Hash */
|
||||
/** @typedef {import('../types').BufioWriter} BufioWriter */
|
||||
/** @typedef {import('../types').NetworkType} NetworkType */
|
||||
/** @typedef {import('../types').Amount} AmountValue */
|
||||
/** @typedef {import('../types').Rate} Rate */
|
||||
/** @typedef {import('../protocol/network')} Network */
|
||||
/** @typedef {import('../primitives/output')} Output */
|
||||
/** @typedef {import('../primitives/tx')} TX */
|
||||
/** @typedef {import('./records').BlockMeta} BlockMeta */
|
||||
/** @typedef {import('./walletdb')} WalletDB */
|
||||
/** @typedef {import('./wallet')} Wallet */
|
||||
/** @typedef {import('./path')} Path */
|
||||
|
||||
/**
|
||||
* @typedef {Object} BlockExtraInfo
|
||||
|
|
@ -71,6 +83,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Open TXDB.
|
||||
* @param {Wallet} wallet
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
|
|
@ -87,7 +100,7 @@ class TXDB {
|
|||
* @private
|
||||
* @param {String} event
|
||||
* @param {Object} data
|
||||
* @param {Details} details
|
||||
* @param {Details} [details]
|
||||
*/
|
||||
|
||||
emit(event, data, details) {
|
||||
|
|
@ -116,7 +129,7 @@ class TXDB {
|
|||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
|
||||
hasPath(output) {
|
||||
async hasPath(output) {
|
||||
const hash = output.getHash();
|
||||
|
||||
if (!hash)
|
||||
|
|
@ -127,6 +140,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Save credit.
|
||||
* @param {Batch} b
|
||||
* @param {Credit} credit
|
||||
* @param {Path} path
|
||||
*/
|
||||
|
|
@ -142,6 +156,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove credit.
|
||||
* @param {Batch} b
|
||||
* @param {Credit} credit
|
||||
* @param {Path} path
|
||||
*/
|
||||
|
|
@ -157,6 +172,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Spend credit.
|
||||
* @param {Batch} b
|
||||
* @param {Credit} credit
|
||||
* @param {TX} tx
|
||||
* @param {Number} index
|
||||
|
|
@ -171,6 +187,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Unspend credit.
|
||||
* @param {Batch} b
|
||||
* @param {TX} tx
|
||||
* @param {Number} index
|
||||
*/
|
||||
|
|
@ -185,6 +202,7 @@ class TXDB {
|
|||
/**
|
||||
* Spend credit by spender/input record.
|
||||
* Add undo coin to the input record.
|
||||
* @param {Batch} b
|
||||
* @param {Credit} credit
|
||||
* @param {Outpoint} spender
|
||||
*/
|
||||
|
|
@ -195,6 +213,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Write input record.
|
||||
* @param {Batch} b
|
||||
* @param {TX} tx
|
||||
* @param {Number} index
|
||||
*/
|
||||
|
|
@ -208,6 +227,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove input record.
|
||||
* @param {Batch} b
|
||||
* @param {TX} tx
|
||||
* @param {Number} index
|
||||
*/
|
||||
|
|
@ -220,6 +240,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Update wallet balance.
|
||||
* @param {Batch} b
|
||||
* @param {BalanceDelta} state
|
||||
*/
|
||||
|
||||
|
|
@ -234,7 +255,8 @@ class TXDB {
|
|||
* Update account balance.
|
||||
* @param {Batch} b
|
||||
* @param {Number} acct
|
||||
* @param {BalanceDelta} delta
|
||||
* @param {Balance} delta - account balance
|
||||
* @returns {Promise<Balance>}
|
||||
*/
|
||||
|
||||
async updateAccountBalance(b, acct, delta) {
|
||||
|
|
@ -273,6 +295,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Append to global map.
|
||||
* @param {Batch} b
|
||||
* @param {Number} height
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
|
@ -283,6 +306,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove from global map.
|
||||
* @param {Batch} b
|
||||
* @param {Number} height
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
|
@ -293,6 +317,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Append to global map.
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
|
@ -303,6 +328,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove from global map.
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
|
@ -313,6 +339,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Append to global map.
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @returns {Promise}
|
||||
|
|
@ -324,6 +351,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove from global map.
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @returns {Promise}
|
||||
|
|
@ -335,8 +363,8 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Append to global map.
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @param {Batch} b
|
||||
* @param {Hash} nameHash
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
|
|
@ -346,8 +374,8 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove from global map.
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @param {Batch} b
|
||||
* @param {Hash} nameHash
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
|
|
@ -420,8 +448,8 @@ class TXDB {
|
|||
const raw = Buffer.allocUnsafe(data.length + 32);
|
||||
data.copy(raw, 0);
|
||||
|
||||
const size = raw.readUInt32LE(40, true);
|
||||
raw.writeUInt32LE(size + 1, 40, true);
|
||||
const size = raw.readUInt32LE(40);
|
||||
raw.writeUInt32LE(size + 1, 40);
|
||||
hash.copy(raw, data.length);
|
||||
|
||||
b.put(key, raw);
|
||||
|
|
@ -429,6 +457,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove from the global block record.
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} height
|
||||
* @returns {Promise}
|
||||
|
|
@ -459,6 +488,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove from the global block record.
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} height
|
||||
* @returns {Promise}
|
||||
|
|
@ -600,7 +630,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Get all bids for name.
|
||||
* @param {Buffer} nameHash
|
||||
* @param {Buffer} [nameHash]
|
||||
* @returns {Promise<BlindBid[]>}
|
||||
*/
|
||||
|
||||
|
|
@ -633,6 +663,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Remove all bids for name.
|
||||
* @param {Batch} b
|
||||
* @param {Buffer} nameHash
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
|
@ -719,8 +750,8 @@ class TXDB {
|
|||
* @param {Buffer} nameHash
|
||||
* @param {Outpoint} outpoint
|
||||
* @param {Object} options
|
||||
* @param {String} options.name
|
||||
* @param {Amount} options.value
|
||||
* @param {Buffer} options.name
|
||||
* @param {AmountValue} options.value
|
||||
* @param {Number} options.height
|
||||
* @param {Boolean} options.own
|
||||
* @param {Outpoint} options.bidPrevout
|
||||
|
|
@ -758,7 +789,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Get all reveals by name.
|
||||
* @param {Buffer} nameHash
|
||||
* @param {Buffer} [nameHash]
|
||||
* @returns {Promise<BidReveal[]>}
|
||||
*/
|
||||
|
||||
|
|
@ -918,7 +949,7 @@ class TXDB {
|
|||
/**
|
||||
* Test whether the transaction
|
||||
* has a duplicate open.
|
||||
* @param {TX}
|
||||
* @param {TX} tx
|
||||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
|
||||
|
|
@ -1591,7 +1622,6 @@ class TXDB {
|
|||
* remove all of its spenders.
|
||||
* @private
|
||||
* @param {TXRecord} wtx
|
||||
* @param {Number} medianTime
|
||||
* @returns {Promise<Details?>}
|
||||
*/
|
||||
|
||||
|
|
@ -1994,11 +2024,11 @@ class TXDB {
|
|||
b.put(layout.Oc.encode(hash), count.encode());
|
||||
|
||||
b.put(layout.Oe.encode(hash), fromU32(time));
|
||||
b.put(layout.Om.encode(time, count.index, hash));
|
||||
b.put(layout.Om.encode(time, count.index, hash), null);
|
||||
|
||||
for (const [acct] of accounts) {
|
||||
b.put(layout.OT.encode(acct, count.height, count.index), hash);
|
||||
b.put(layout.OM.encode(acct, time, count.index, hash));
|
||||
b.put(layout.OM.encode(acct, time, count.index, hash), null);
|
||||
}
|
||||
|
||||
this.incrementLatestUnconfirmedTXCount(b, count.index);
|
||||
|
|
@ -2068,11 +2098,11 @@ class TXDB {
|
|||
b.del(layout.Ou.encode(hash));
|
||||
|
||||
const time = await this.getUnconfirmedTimeForTX(hash);
|
||||
b.put(layout.Om.encode(time, count.index, hash));
|
||||
b.put(layout.Om.encode(time, count.index, hash), null);
|
||||
|
||||
for (const [acct] of accounts) {
|
||||
b.put(layout.OT.encode(acct, count.height, count.index), hash);
|
||||
b.put(layout.OM.encode(acct, time, count.index, hash));
|
||||
b.put(layout.OM.encode(acct, time, count.index, hash), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2135,11 +2165,11 @@ class TXDB {
|
|||
b.put(layout.Oc.encode(hash), count.encode());
|
||||
|
||||
const time = blockextra.medianTime;
|
||||
b.put(layout.Oi.encode(time, height, index, hash));
|
||||
b.put(layout.Oi.encode(time, height, index, hash), null);
|
||||
|
||||
for (const [acct] of accounts) {
|
||||
b.put(layout.OT.encode(acct, height, index), hash);
|
||||
b.put(layout.OI.encode(acct, time, height, index, hash));
|
||||
b.put(layout.OI.encode(acct, time, height, index, hash), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2229,7 +2259,7 @@ class TXDB {
|
|||
* configurable max of transactions.
|
||||
* @param {Number} acct
|
||||
* @param {Object} options
|
||||
* @param {Buffer} options.time
|
||||
* @param {Number} options.time
|
||||
* @param {Number} options.limit
|
||||
* @param {Boolean} options.reverse
|
||||
* @returns {Promise<TXRecord[]>}
|
||||
|
|
@ -2347,7 +2377,7 @@ class TXDB {
|
|||
* and limited at a configurable max of transactions.
|
||||
* @private
|
||||
* @param {Number} acct
|
||||
* @param {Number} options
|
||||
* @param {Object} options
|
||||
* @param {Buffer} options.hash
|
||||
* @param {Number} options.limit
|
||||
* @param {Boolean} options.reverse
|
||||
|
|
@ -2455,6 +2485,7 @@ class TXDB {
|
|||
* max transactions.
|
||||
* @param {Number} acct
|
||||
* @param {Object} options
|
||||
* @param {Number} options.time
|
||||
* @param {Number} options.limit
|
||||
* @param {Boolean} options.reverse
|
||||
* @returns {Promise<TXRecord[]>}
|
||||
|
|
@ -2575,7 +2606,7 @@ class TXDB {
|
|||
* of transactions
|
||||
* @private
|
||||
* @param {Number} acct
|
||||
* @param {Number} options
|
||||
* @param {Object} options
|
||||
* @param {Buffer} options.hash
|
||||
* @param {Number} options.limit
|
||||
* @param {Boolean} options.reverse
|
||||
|
|
@ -2644,9 +2675,8 @@ class TXDB {
|
|||
* of that coin that are _not_ confirmed will be removed from
|
||||
* the database.
|
||||
* @private
|
||||
* @param {Hash} hash
|
||||
* @param {TX} ref - Reference tx, the tx that double-spent.
|
||||
* @returns {Promise<Details?>} - Returns Boolean.
|
||||
* @param {TXRecord} wtx
|
||||
* @returns {Promise<Details?>}
|
||||
*/
|
||||
|
||||
async removeConflict(wtx) {
|
||||
|
|
@ -2721,7 +2751,7 @@ class TXDB {
|
|||
* Lock balances according to covenant.
|
||||
* Inserting or confirming: TX outputs.
|
||||
* Removing or undoing: Coins spent by the wallet in tx inputs.
|
||||
* @param {State} state
|
||||
* @param {BalanceDelta} state
|
||||
* @param {Credit} credit
|
||||
* @param {Path} path
|
||||
* @param {Number} height
|
||||
|
|
@ -2757,7 +2787,7 @@ class TXDB {
|
|||
* Unlock balances according to covenants.
|
||||
* Inserting or confirming: Coins spent by the wallet in TX inputs.
|
||||
* Removing or undoing: TX outputs.
|
||||
* @param {State} state
|
||||
* @param {BalanceDelta} state
|
||||
* @param {Credit} credit
|
||||
* @param {Path} path
|
||||
* @param {Number} height
|
||||
|
|
@ -2793,8 +2823,7 @@ class TXDB {
|
|||
* This does not check if the name is owned by the wallet.
|
||||
* @private
|
||||
* @param {Batch} b
|
||||
* @param {Output} tx
|
||||
* @param {Path} path
|
||||
* @param {Output} output
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
|
|
@ -3141,9 +3170,6 @@ class TXDB {
|
|||
* Handle reorg'd covenant.
|
||||
* @param {Object} b
|
||||
* @param {TX} tx
|
||||
* @param {Number} i
|
||||
* @param {Path} path
|
||||
* @param {Number} height
|
||||
* @returns {Promise<Boolean>} applied undo.
|
||||
*/
|
||||
|
||||
|
|
@ -3347,7 +3373,8 @@ class TXDB {
|
|||
/**
|
||||
* Filter array of coins or outpoints
|
||||
* for only unlocked ones.
|
||||
* @param {Coin[]|Outpoint[]}
|
||||
* jsdoc can't express this type.
|
||||
* @param {Coin[]|Outpoint[]} coins
|
||||
* @returns {Coin[]|Outpoint[]}
|
||||
*/
|
||||
|
||||
|
|
@ -3380,7 +3407,7 @@ class TXDB {
|
|||
* Test whether an account owns a coin.
|
||||
* @param {Number} acct
|
||||
* @param {Hash} hash
|
||||
* @param {Index} number
|
||||
* @param {Number} index
|
||||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
|
||||
|
|
@ -3538,20 +3565,10 @@ class TXDB {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TX hashes by height.
|
||||
* @param {Number} height
|
||||
* @returns {Promise<Hash[]>}
|
||||
*/
|
||||
|
||||
getHeightHashes(height) {
|
||||
return this.getHeightRangeHashes({ start: height, end: height });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unconfirmed transactions.
|
||||
* @param {Number} acct
|
||||
* @returns {Promise<TX[]>}
|
||||
* @returns {Promise<TXRecord[]>}
|
||||
*/
|
||||
|
||||
async getPending(acct) {
|
||||
|
|
@ -3649,7 +3666,7 @@ class TXDB {
|
|||
/**
|
||||
* Get coins.
|
||||
* @param {Number} acct
|
||||
* @returns {Promise<Credit[]>}
|
||||
* @returns {Promise<Coin[]>}
|
||||
*/
|
||||
|
||||
async getCoins(acct) {
|
||||
|
|
@ -3926,6 +3943,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Update spent coin height in storage.
|
||||
* @param {Batch} b
|
||||
* @param {TX} tx - Sending transaction.
|
||||
* @param {Number} index
|
||||
* @param {Number} height
|
||||
|
|
@ -3952,6 +3970,7 @@ class TXDB {
|
|||
/**
|
||||
* Test whether the database has a transaction.
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
|
||||
|
|
@ -3961,7 +3980,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Calculate balance.
|
||||
* @param {Number?} account
|
||||
* @param {Number} acct
|
||||
* @returns {Promise<Balance>}
|
||||
*/
|
||||
|
||||
|
|
@ -4059,7 +4078,7 @@ class TXDB {
|
|||
|
||||
/**
|
||||
* Dump database (for debugging).
|
||||
* @returns {bdb.Iterator}
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
|
||||
async dump() {
|
||||
|
|
@ -4085,7 +4104,7 @@ class Balance extends bio.Struct {
|
|||
/**
|
||||
* Create a balance.
|
||||
* @constructor
|
||||
* @param {Number} account
|
||||
* @param {Number} acct
|
||||
*/
|
||||
|
||||
constructor(acct = -1) {
|
||||
|
|
@ -4134,7 +4153,8 @@ class Balance extends bio.Struct {
|
|||
|
||||
/**
|
||||
* Serialize balance.
|
||||
* @returns {Buffer}
|
||||
* @param {BufioWriter} bw
|
||||
* @returns {BufioWriter}
|
||||
*/
|
||||
|
||||
write(bw) {
|
||||
|
|
@ -4149,9 +4169,8 @@ class Balance extends bio.Struct {
|
|||
|
||||
/**
|
||||
* Inject properties from serialized data.
|
||||
* @private
|
||||
* @param {Buffer} data
|
||||
* @returns {Balance}
|
||||
* @param {bio.BufferReader} br
|
||||
* @returns {this}
|
||||
*/
|
||||
|
||||
read(br) {
|
||||
|
|
@ -4184,7 +4203,7 @@ class Balance extends bio.Struct {
|
|||
|
||||
/**
|
||||
* Inspect balance.
|
||||
* @param {String}
|
||||
* @returns {String}
|
||||
*/
|
||||
|
||||
format() {
|
||||
|
|
@ -4205,19 +4224,16 @@ class Balance extends bio.Struct {
|
|||
*/
|
||||
|
||||
class BalanceDelta {
|
||||
/** @type {Balance} */
|
||||
wallet;
|
||||
|
||||
/** @type {Map<Number, Balance>} */
|
||||
accounts;
|
||||
|
||||
/**
|
||||
* Create a balance delta.
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
constructor() {
|
||||
/** @type {Balance} */
|
||||
this.wallet = new Balance();
|
||||
|
||||
/** @type {Map<Number, Balance>} */
|
||||
this.accounts = new Map();
|
||||
}
|
||||
|
||||
|
|
@ -4225,6 +4241,10 @@ class BalanceDelta {
|
|||
return this.wallet.tx !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Balance} balance
|
||||
*/
|
||||
|
||||
applyTo(balance) {
|
||||
this.wallet.applyTo(balance);
|
||||
}
|
||||
|
|
@ -4284,8 +4304,8 @@ class Credit extends bio.Struct {
|
|||
/**
|
||||
* Create a credit.
|
||||
* @constructor
|
||||
* @param {Coin} coin
|
||||
* @param {Boolean?} spent
|
||||
* @param {Coin?} [coin]
|
||||
* @param {Boolean?} [spent]
|
||||
*/
|
||||
|
||||
constructor(coin, spent) {
|
||||
|
|
@ -4297,8 +4317,8 @@ class Credit extends bio.Struct {
|
|||
|
||||
/**
|
||||
* Inject properties from serialized data.
|
||||
* @private
|
||||
* @param {Buffer} data
|
||||
* @param {bio.BufferReader} br
|
||||
* @returns {this}
|
||||
*/
|
||||
|
||||
read(br) {
|
||||
|
|
@ -4319,7 +4339,8 @@ class Credit extends bio.Struct {
|
|||
|
||||
/**
|
||||
* Serialize credit.
|
||||
* @returns {Buffer}
|
||||
* @param {BufioWriter} bw
|
||||
* @returns {BufioWriter}
|
||||
*/
|
||||
|
||||
write(bw) {
|
||||
|
|
@ -4334,6 +4355,7 @@ class Credit extends bio.Struct {
|
|||
* @private
|
||||
* @param {TX} tx
|
||||
* @param {Number} index
|
||||
* @param {Number} height
|
||||
* @returns {Credit}
|
||||
*/
|
||||
|
||||
|
|
@ -4348,6 +4370,7 @@ class Credit extends bio.Struct {
|
|||
* Instantiate credit from transaction.
|
||||
* @param {TX} tx
|
||||
* @param {Number} index
|
||||
* @param {Number} height
|
||||
* @returns {Credit}
|
||||
*/
|
||||
|
||||
|
|
@ -4447,6 +4470,7 @@ class Details {
|
|||
|
||||
/**
|
||||
* Calculate confirmations.
|
||||
* @param {Number} height
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
|
|
@ -4468,7 +4492,7 @@ class Details {
|
|||
/**
|
||||
* Calculate fee. Only works if wallet
|
||||
* owns all inputs. Returns 0 otherwise.
|
||||
* @returns {Amount}
|
||||
* @returns {AmountValue}
|
||||
*/
|
||||
|
||||
getFee() {
|
||||
|
|
@ -4491,7 +4515,7 @@ class Details {
|
|||
/**
|
||||
* Calculate fee rate. Only works if wallet
|
||||
* owns all inputs. Returns 0 otherwise.
|
||||
* @param {Amount} fee
|
||||
* @param {AmountValue} fee
|
||||
* @returns {Rate}
|
||||
*/
|
||||
|
||||
|
|
@ -4501,6 +4525,8 @@ class Details {
|
|||
|
||||
/**
|
||||
* Convert details to a more json-friendly object.
|
||||
* @param {(Network|NetworkType)?} [network]
|
||||
* @param {Number} [height]
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
|
|
@ -4572,7 +4598,7 @@ class DetailsMember {
|
|||
|
||||
/**
|
||||
* Convert the member to a more json-friendly object.
|
||||
* @param {Network} network
|
||||
* @param {(Network|NetworkType)?} [network]
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
|
|
@ -4601,9 +4627,9 @@ class BlockRecord extends bio.Struct {
|
|||
/**
|
||||
* Create a block record.
|
||||
* @constructor
|
||||
* @param {Hash} hash
|
||||
* @param {Number} height
|
||||
* @param {Number} time
|
||||
* @param {Hash} [hash]
|
||||
* @param {Number} [height]
|
||||
* @param {Number} [time]
|
||||
*/
|
||||
|
||||
constructor(hash, height, time) {
|
||||
|
|
@ -4641,8 +4667,8 @@ class BlockRecord extends bio.Struct {
|
|||
|
||||
/**
|
||||
* Instantiate wallet block from serialized tip data.
|
||||
* @private
|
||||
* @param {bio.BufferReader} br
|
||||
* @returns {this}
|
||||
*/
|
||||
|
||||
read(br) {
|
||||
|
|
@ -4671,7 +4697,8 @@ class BlockRecord extends bio.Struct {
|
|||
|
||||
/**
|
||||
* Serialize the wallet block as a tip (hash and height).
|
||||
* @returns {Buffer}
|
||||
* @param {BufioWriter} bw
|
||||
* @returns {BufioWriter}
|
||||
*/
|
||||
|
||||
write(bw) {
|
||||
|
|
@ -4751,10 +4778,19 @@ class BlindBid extends bio.Struct {
|
|||
this.own = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
getSize() {
|
||||
return 1 + this.name.length + 45;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {BufioWriter} bw
|
||||
* @returns {BufioWriter}
|
||||
*/
|
||||
|
||||
write(bw) {
|
||||
let height = this.height;
|
||||
|
||||
|
|
@ -4770,6 +4806,11 @@ class BlindBid extends bio.Struct {
|
|||
return bw;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {bio.BufferReader} br
|
||||
* @returns {this}
|
||||
*/
|
||||
|
||||
read(br) {
|
||||
this.name = br.readBytes(br.readU8());
|
||||
this.lockup = br.readU64();
|
||||
|
|
@ -4812,12 +4853,22 @@ class BlindValue extends bio.Struct {
|
|||
return 40;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {BufioWriter} bw
|
||||
* @returns {BufioWriter}
|
||||
*/
|
||||
|
||||
write(bw) {
|
||||
bw.writeU64(this.value);
|
||||
bw.writeBytes(this.nonce);
|
||||
return bw;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {bio.BufferReader} br
|
||||
* @returns {this}
|
||||
*/
|
||||
|
||||
read(br) {
|
||||
this.value = br.readU64();
|
||||
this.nonce = br.readBytes(32);
|
||||
|
|
@ -4852,6 +4903,11 @@ class BidReveal extends bio.Struct {
|
|||
return 1 + this.name.length + 13 + 36;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {BufioWriter} bw
|
||||
* @returns {BufioWriter}
|
||||
*/
|
||||
|
||||
write(bw) {
|
||||
let height = this.height;
|
||||
|
||||
|
|
@ -4868,6 +4924,11 @@ class BidReveal extends bio.Struct {
|
|||
return bw;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {bio.BufferReader} br
|
||||
* @returns {this}
|
||||
*/
|
||||
|
||||
read(br) {
|
||||
this.name = br.readBytes(br.readU8());
|
||||
this.value = br.readU64();
|
||||
|
|
@ -4906,13 +4967,13 @@ class TXCount {
|
|||
/**
|
||||
* Create tx count record.
|
||||
* @constructor
|
||||
* @param {Number} height
|
||||
* @param {Number} index
|
||||
* @param {Number} [height]
|
||||
* @param {Number} [index]
|
||||
*/
|
||||
|
||||
constructor(height, index) {
|
||||
this.height = height;
|
||||
this.index = index;
|
||||
this.height = height || 0;
|
||||
this.index = index || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -4962,7 +5023,7 @@ class TXCount {
|
|||
|
||||
function fromU32(num) {
|
||||
const data = Buffer.allocUnsafe(4);
|
||||
data.writeUInt32LE(num, 0, true);
|
||||
data.writeUInt32LE(num, 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -40,6 +40,9 @@ const {scanActions} = require('../blockchain/common');
|
|||
/** @typedef {import('../primitives/tx')} TX */
|
||||
/** @typedef {import('../primitives/claim')} Claim */
|
||||
/** @typedef {import('../blockchain/common').ScanAction} ScanAction */
|
||||
/** @typedef {import('../blockchain/chainentry')} ChainEntry */
|
||||
/** @typedef {import('./records').BlockMeta} BlockMeta */
|
||||
/** @typedef {import('./txdb').BlockExtraInfo} BlockExtraInfo */
|
||||
/** @typedef {import('./walletkey')} WalletKey */
|
||||
|
||||
const {
|
||||
|
|
@ -49,9 +52,6 @@ const {
|
|||
MapRecord
|
||||
} = records;
|
||||
|
||||
/** @typedef {import('./records').BlockMeta} BlockMeta */
|
||||
/** @typedef {import('./txdb').BlockExtraInfo} BlockExtraInfo */
|
||||
|
||||
/**
|
||||
* @typedef {Object} AddBlockResult
|
||||
* @property {Number} txs - Number of transactions added on this add.
|
||||
|
|
@ -60,7 +60,7 @@ const {
|
|||
|
||||
/**
|
||||
* @typedef {Object} AddTXResult
|
||||
* @property {Number} wids - Wallet IDs affected.
|
||||
* @property {Set<Number>} wids - Wallet IDs affected.
|
||||
* @property {Boolean} filterUpdated - Whether the bloom filter was updated.
|
||||
|
||||
/**
|
||||
|
|
@ -1222,6 +1222,7 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Rename an account.
|
||||
* @param {Batch} b
|
||||
* @param {Account} account
|
||||
* @param {String} name
|
||||
*/
|
||||
|
|
@ -1390,7 +1391,7 @@ class WalletDB extends EventEmitter {
|
|||
* Get a wallet with token auth first.
|
||||
* @param {Number|String} id
|
||||
* @param {Buffer} token
|
||||
* @returns {Promise} - Returns {@link Wallet}.
|
||||
* @returns {Promise<Wallet|null>}
|
||||
*/
|
||||
|
||||
async auth(id, token) {
|
||||
|
|
@ -1456,7 +1457,7 @@ class WalletDB extends EventEmitter {
|
|||
/**
|
||||
* Test for the existence of a wallet.
|
||||
* @param {Number|String} id
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
|
||||
async has(id) {
|
||||
|
|
@ -1467,7 +1468,7 @@ class WalletDB extends EventEmitter {
|
|||
/**
|
||||
* Attempt to create wallet, return wallet if already exists.
|
||||
* @param {Object} options - See {@link Wallet}.
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<Wallet>}
|
||||
*/
|
||||
|
||||
async ensure(options) {
|
||||
|
|
@ -1485,7 +1486,7 @@ class WalletDB extends EventEmitter {
|
|||
* Get an account from the database by wid.
|
||||
* @param {Number} wid
|
||||
* @param {Number} index - Account index.
|
||||
* @returns {Promise} - Returns {@link Wallet}.
|
||||
* @returns {Promise<Account>}
|
||||
*/
|
||||
|
||||
async getAccount(wid, index) {
|
||||
|
|
@ -1671,7 +1672,7 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get all address hashes.
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<Hash[]>}
|
||||
*/
|
||||
|
||||
async getHashes() {
|
||||
|
|
@ -1684,7 +1685,7 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get all outpoints.
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<Outpoint[]>}
|
||||
*/
|
||||
|
||||
async getOutpoints() {
|
||||
|
|
@ -1701,7 +1702,7 @@ class WalletDB extends EventEmitter {
|
|||
/**
|
||||
* Get all address hashes.
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<Hash[]>}
|
||||
*/
|
||||
|
||||
async getWalletHashes(wid) {
|
||||
|
|
@ -1770,6 +1771,7 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Encrypt all imported keys for a wallet.
|
||||
* @param {Batch} b
|
||||
* @param {Number} wid
|
||||
* @param {Buffer} key
|
||||
* @returns {Promise}
|
||||
|
|
@ -1802,6 +1804,7 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Decrypt all imported keys for a wallet.
|
||||
* @param {Batch} b
|
||||
* @param {Number} wid
|
||||
* @param {Buffer} key
|
||||
* @returns {Promise}
|
||||
|
|
@ -1897,11 +1900,12 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get all wallet ids by output addresses and outpoints.
|
||||
* @param {Hash[]} hashes
|
||||
* @returns {Promise}
|
||||
* @param {TX} tx
|
||||
* @returns {Promise<Set<Number>>}
|
||||
*/
|
||||
|
||||
async getWalletsByTX(tx) {
|
||||
/** @type {Set<Number>} */
|
||||
const wids = new Set();
|
||||
|
||||
if (!tx.isCoinbase()) {
|
||||
|
|
@ -1962,7 +1966,7 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get the best block hash.
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<records.ChainState|null>}
|
||||
*/
|
||||
|
||||
async getState() {
|
||||
|
|
@ -2042,7 +2046,7 @@ class WalletDB extends EventEmitter {
|
|||
/**
|
||||
* Get a wallet map.
|
||||
* @param {Buffer} key
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<records.MapRecord|null>}
|
||||
*/
|
||||
|
||||
async getMap(key) {
|
||||
|
|
@ -2103,6 +2107,7 @@ class WalletDB extends EventEmitter {
|
|||
* @param {Batch} b
|
||||
* @param {Buffer} key
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async removeMap(b, key, wid) {
|
||||
|
|
@ -2124,8 +2129,8 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get a wallet map.
|
||||
* @param {Buffer} key
|
||||
* @returns {Promise}
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise<records.MapRecord|null>}
|
||||
*/
|
||||
|
||||
async getPathMap(hash) {
|
||||
|
|
@ -2134,9 +2139,10 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Add wid to a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async addPathMap(b, hash, wid) {
|
||||
|
|
@ -2146,9 +2152,10 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Remove wid from a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async removePathMap(b, hash, wid) {
|
||||
|
|
@ -2157,8 +2164,8 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get a wallet map.
|
||||
* @param {Buffer} key
|
||||
* @returns {Promise}
|
||||
* @param {Number} height
|
||||
* @returns {Promise<records.MapRecord|null>}
|
||||
*/
|
||||
|
||||
async getBlockMap(height) {
|
||||
|
|
@ -2167,9 +2174,10 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Add wid to a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Number} height
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async addBlockMap(b, height, wid) {
|
||||
|
|
@ -2178,9 +2186,10 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Remove wid from a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Number} height
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async removeBlockMap(b, height, wid) {
|
||||
|
|
@ -2189,8 +2198,8 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get a wallet map.
|
||||
* @param {Buffer} key
|
||||
* @returns {Promise}
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise<records.MapRecord|null>}
|
||||
*/
|
||||
|
||||
async getTXMap(hash) {
|
||||
|
|
@ -2199,9 +2208,10 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Add wid to a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async addTXMap(b, hash, wid) {
|
||||
|
|
@ -2210,9 +2220,10 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Remove wid from a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async removeTXMap(b, hash, wid) {
|
||||
|
|
@ -2221,8 +2232,9 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get a wallet map.
|
||||
* @param {Buffer} key
|
||||
* @returns {Promise}
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @returns {Promise<records.MapRecord|null>}
|
||||
*/
|
||||
|
||||
async getOutpointMap(hash, index) {
|
||||
|
|
@ -2231,9 +2243,11 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Add wid to a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async addOutpointMap(b, hash, index, wid) {
|
||||
|
|
@ -2243,9 +2257,11 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Remove wid from a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async removeOutpointMap(b, hash, index, wid) {
|
||||
|
|
@ -2254,8 +2270,8 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get a wallet map.
|
||||
* @param {Buffer} key
|
||||
* @returns {Promise}
|
||||
* @param {Hash} nameHash
|
||||
* @returns {Promise<records.MapRecord|null>}
|
||||
*/
|
||||
|
||||
async getNameMap(nameHash) {
|
||||
|
|
@ -2275,9 +2291,10 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Add wid to a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Hash} nameHash
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async addNameMap(b, nameHash, wid) {
|
||||
|
|
@ -2287,9 +2304,10 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Remove wid from a wallet map.
|
||||
* @param {Wallet} wallet
|
||||
* @param {Buffer} key
|
||||
* @param {Batch} b
|
||||
* @param {Hash} nameHash
|
||||
* @param {Number} wid
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
async removeNameMap(b, nameHash, wid) {
|
||||
|
|
@ -2313,7 +2331,6 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get wallet tip.
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise<BlockMeta>}
|
||||
*/
|
||||
|
||||
|
|
@ -2328,7 +2345,7 @@ class WalletDB extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Get renewal block hash.
|
||||
* @returns {Buffer}
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
|
||||
async getRenewalBlock() {
|
||||
|
|
@ -3018,12 +3035,22 @@ class WalletOptions {
|
|||
* Helpers
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Number} num
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
function fromU32(num) {
|
||||
const data = Buffer.allocUnsafe(4);
|
||||
data.writeUInt32LE(num, 0, true);
|
||||
data.writeUInt32LE(num, 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} str
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
function fromString(str) {
|
||||
const buf = Buffer.alloc(1 + str.length);
|
||||
buf[0] = str.length;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue