diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 0f7c93c8..3dd56179 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -593,7 +593,8 @@ Chain.prototype._verify = function _verify(block, prev, callback) { * @private * @param {Block} block * @param {ChainBlock} prev - * @param {Function} callback - Returns [{@link VerifyError}, Object]. + * @param {Function} callback - Returns + * [{@link VerifyError}, {@link DeploymentState}]. */ Chain.prototype._checkDeployments = function _checkDeployments(block, prev, callback) { diff --git a/lib/bcoin/mtx.js b/lib/bcoin/mtx.js index 95affd97..52bfe319 100644 --- a/lib/bcoin/mtx.js +++ b/lib/bcoin/mtx.js @@ -1046,12 +1046,7 @@ MTX.prototype.maxSize = function maxSize(options, force) { * @param {BN?} options.fee - Use a hard fee rather than calculating one. * @param {Number|Boolean} options.subtractFee - Whether to subtract the * fee from * existing outputs rather than adding more inputs. - * @returns {Object} { - * chosen: {@link Coin}[], - * change: {@link BN}, - * fee: {@link BN}, - * total: {@link BN} - * } + * @returns {CoinSelection} * @throws on not enough funds available. * @throws on unable to subtract fee. */ @@ -1099,7 +1094,7 @@ MTX.prototype.selectCoins = function selectCoins(coins, options) { var coin; while (index < coins.length) { - coin = coins[index]; + coin = coins[index++]; if (options.confirmed && coin.height === -1) continue; @@ -1114,7 +1109,6 @@ MTX.prototype.selectCoins = function selectCoins(coins, options) { // and fee. tx.addInput(coin); chosen.push(coin); - index++; if (options.selection === 'all') continue; diff --git a/lib/bcoin/types.js b/lib/bcoin/types.js index e0b6ee2f..e617d831 100644 --- a/lib/bcoin/types.js +++ b/lib/bcoin/types.js @@ -1,126 +1,126 @@ /** * An inverse enum. Retrieves key by value. - * @global * @typedef {Object} RevMap + * @global */ /** * @typedef {Object} InvItem - * @global * @property {Number|String} type - Inv type. See {@link constants.inv}. * @property {Hash|Buffer} hash + * @global */ /** * @typedef {Object} Outpoint - * @global * @property {Hash} hash * @property {Number} index + * @global */ /** * Can be `pubkeyhash`, `scripthash`, `witnesspubkeyhash`, * or `witnessscripthash`, or an address prefix * (see {@link network.address}). - * @global * @typedef {String|Number} AddressType + * @global */ /** * @typedef {Object} ParsedAddress - * @global * @property {Number?} version - Witness program version (-1 if not present). * @property {AddressType} type * @property {Buffer} hash + * @global */ /** * A bitfield containing locktime flags. - * @global * @typedef {Number} LockFlags + * @global */ /** * @typedef {Object} Seed - * @global * @property {String} host * @property {Number} port + * @global */ /** * @typedef {EventEmitter} BroadcastPromise - * @global * @emits BroadcastPromise#ack * @emits BroadcastPromise#timeout * @emits BroadcastPromise#reject + * @global */ /** * @typedef {Object} ParsedURI - * @global * @property {Base58Address} address * @property {BN?} amount? - Amount in satoshis. * @property {String?} label * @property {String?} message * @property {String?} request - Payment request URL. + * @global */ /** * Wallet ID - * @global * @typedef {String} WalletID + * @global */ /** * Base58 string. - * @global * @typedef {String} Base58String + * @global */ /** * Base58 address. - * @global * @typedef {String} Base58Address + * @global */ /** * Hex-string hash. - * @global * @typedef {String} Hash + * @global */ /** * Reversed hex-string hash (uint256le). - * @global * @typedef {String} ReversedHash + * @global */ /** * Signature hash type. One of `all`, `single`, `none`, or * one of {@link constants.hashType}. - * @global * @typedef {String|Number} SighashType + * @global */ /** * Wallet balance. - * @global * @typedef {Object} Balance * @property {BN} confirmed * @property {BN} unconfirmed * @property {BN} total + * @global */ /** * A big number (bn.js) - * @global * @typedef {Object} BN + * @global */ /** * A bitfield containing script verify flags. - * @global * @typedef {Number} VerifyFlags + * @global */ /** @@ -130,63 +130,76 @@ * version (treated as anyone-can-spend). Otherwise one of `witnesspubkeyhash` * or `witnessscripthash`. * @property {Buffer} data - Usually the hash. + * @global */ /** * @typedef {Object} Orphan * @property {Hash} hash - Orphan TX hash. * @property {Number} index - Orphan input index. + * @global + */ + +/** + * @typedef {Object} CoinSelection + * @property {Coin[]?} chosen - Selected coins. + * @property {BN} change - Amount of change to add. + * @property {BN} fee - Estimated fee. + * @property {BN} total - Total value. + * @global + */ + +/** + * @typedef {Object} DeploymentState + * @property {VerifyFlags} flags + * @property {LockFlags} lockFlags + * @property {Boolean} coinbaseHeight - Whether coinbase height is enforced. + * @property {Boolean} segwit + * @property {Boolean} csv + * @global */ /** * @typedef {Object} SubmitOrderPacket - * @global * @property {Hash} hash * @property {NakedTX} tx - * @property {Number} _size + * @global */ /** * @typedef {Object} ReplyPacket - * @global * @property {Hash} hash * @property {Number} code * @property {Buffer} publicKey - * @property {Number} _size + * @global */ /** * @typedef {Object} FilterLoadPacket - * @global * @see Bloom * @property {Buffer} filter - Serialized bloom filter. * @property {Number} n - Number of hash functions. * @property {Number} tweak - Bloom filter seed. * @property {String|Number} update (See {@link constants.filterFlags}). - * @property {Number} _size + * @global */ - /** * @typedef {Object} FilterAddPacket - * @global * @see Bloom * @property {Buffer} data - Data to add to filter. - * @property {Number} _size + * @global */ - /** * @typedef {Object} GetUTXOsPacket - * @global * @property {Boolean} mempool - Check mempool. * @property {Outpoint[]} prevout - Outpoints. - * @property {Number} _size + * @global */ /** * @typedef {Object} NakedCoin - * @global * @property {Number} version - Transaction version. * @property {Number} height - Transaction height (-1 if unconfirmed). * @property {BN} value - Output value in satoshis. @@ -195,30 +208,28 @@ * transaction is a coinbase. * @property {Hash} hash - Transaction hash. * @property {Number} index - Output index. + * @global */ /** * @typedef {Object} UTXOsPacket - * @global * @property {Array?} data.hits - Hits (array of * 1s and 0s representing a bit mask). * @property {Buffer?} data.map - Hit map. * @property {Object} data.height - Chain height. * @property {Hash} data.tip - Chain tip hash. * @property {NakedCoin[]} data.coins - * @property {Number} _size + * @global */ /** * @typedef {Object} PingPacket - * @global * @property {BN} nonce - * @property {Number} _size + * @global */ /** * @typedef {Object} NetworkAddress - * @global * @property {Number?} ts - Timestamp. * @property {Number?} services - Service bits. * @property {Buffer?} ipv4 - IPv4 address. @@ -228,12 +239,11 @@ * @property {Boolean?} getutxo - Whether peer supports getutxos. * @property {Boolean?} bloom - Whether peer supports serving FILTERED_BLOCKs. * @property {Boolean?} witness - Whether peer supports segwit. - * @property {Number} _size + * @global */ /** * @typedef {Object} VersionPacket - * @global * @property {Number} version - Protocol version. * @property {Number} services - Service bits. * @property {Number} ts - Timestamp of discovery. @@ -244,21 +254,19 @@ * @property {Number} height - Chain height. * @property {Boolean} relay - Whether transactions * should be relayed immediately. - * @property {Number} _size + * @global */ /** * @typedef {Object} GetBlocksPacket - * @global * @property {Number} version - Protocol version. * @property {Hash[]} locator - Chain locator. * @property {Hash} stop - Hash to stop at. - * @property {Number} _size + * @global */ /** * @typedef {Object} NakedBlock - * @global * @property {Number} version - Transaction version. Note that BCoin reads * versions as unsigned even though they are signed at the protocol level. * This value will never be negative. @@ -273,30 +281,27 @@ * @property {Hash[]?} hashes - Only present on merkleblocks. * @property {Buffer?} flags - Only present on merkleblocks. * @property {Number?} coinbaseHeight - Only present on compactblocks. - * @property {Number} _size + * @global */ /** * @typedef {Object} NakedInput - * @global * @property {Outpoint} prevout * @property {NakedScript} script - Input script. * @property {Number} sequence - nSequence. * @property {NakedWitness} witness - Witness. - * @property {Number} _size + * @global */ /** * @typedef {Object} NakedOutput - * @global * @property {BN} value - Value in satoshis. * @property {NakedScript} script - Output script. - * @property {Number} _size + * @global */ /** * @typedef {Object} NakedCoin - * @global * @property {Number} version - Transaction version. * @property {Number} height - Transaction height (-1 if unconfirmed). * @property {BN} value - Output value in satoshis. @@ -305,49 +310,44 @@ * transaction is a coinbase. * @property {Hash} hash - Transaction hash. * @property {Number} index - Output index. - * @property {Number} _size + * @global */ /** * @typedef {Object} NakedTX - * @global * @property {Number} version * @property {Number} flag * @property {NakedInput[]} inputs * @property {NakedOutput[]} outputs * @property {Number} locktime - * @property {Number} _size + * @global */ /** * @typedef {Object} NakedScript - * @global * @property {Buffer} raw - Raw code. * @property {Array} code - Parsed code. - * @property {Number} _size + * @global */ /** * @typedef {Object} NakedWitness - * @global * @param {Buffer[]} items - Stack items. - * @property {Number} _size + * @global */ /** * @typedef {Object} RejectPacket - * @global * @param {(Number|String)?} ccode - Code * (see {@link constants.reject}). * @param {String?} msg - Message. * @param {String?} reason - Reason. * @param {(Hash|Buffer)?} data - Transaction or block hash. - * @property {Number} _size + * @global */ /** * @typedef {Object} AlertPacket - * @global * @property {Number} version * @property {Number} relayUntil * @property {Number} expiration @@ -364,5 +364,192 @@ * @property {Buffer?} payload - Payload. * @property {Buffer?} signature - Payload signature. * @property {Buffer?} key - Private key to sign with. - * @property {Number} _size + * @global + */ + +/* + * Callbacks & Events + */ + +/** + * @callback TXCallback + * @param {Error?} err + * @param {TX} tx + * @global + */ + +/** + * @callback TXSCallback + * @param {Error?} err + * @param {TX[]} txs + * @global + */ + +/** + * @callback MTXCallback + * @param {Error?} err + * @param {MTX} tx + * @global + */ + +/** + * @callback MTXSCallback + * @param {Error?} err + * @param {MTX[]} txs + * @global + */ + +/** + * @callback CoinCallback + * @param {Error?} err + * @param {Coin} tx + * @global + */ + +/** + * @callback CoinsCallback + * @param {Error?} err + * @param {Coin[]} tx + * @global + */ + +/** + * @callback VerifyCallback + * @param {VerifyError?} err + * @global + */ + +/** + * @callback BlockCallback + * @param {Error?} err + * @param {Block} block + * @global + */ + +/** + * @callback EntryCallback + * @param {Error?} err + * @param {ChainBlock} entry + * @global + */ + +/** + * @callback EntriesCallback + * @param {Error?} err + * @param {ChainBlock[]} entry + * @global + */ + +/** + * @callback BalanceCallback + * @param {Error?} err + * @param {Balance} balance + * @global + */ + +/** + * @callback BooleanCallback + * @param {Error?} err + * @param {Boolean} result + * @global + */ + +/** + * @callback NumberCallback + * @param {Error?} err + * @param {Number} result + * @global + */ + +/** + * @callback HashCallback + * @param {Error?} err + * @param {Hash} hash + * @global + */ + +/** + * @callback HashesCallback + * @param {Error?} err + * @param {Hash[]} hash + * @global + */ + +/** + * @callback WalletCallback + * @param {Error?} err + * @param {Wallet|NakedWallet} wallet + * @global + */ + +/** + * @callback BufferCallback + * @param {Error?} err + * @param {Buffer} data + * @global + */ + +/** + * @callback ObjectCallback + * @param {Error?} err + * @param {Object} obj + * @global + */ + +/** + * @callback DeploymentCallback + * @param {(Error|VerifyError)?} err + * @param {DeploymentState} state + * @global + */ + +/** + * @callback MinerBlockCallback + * @param {Error?} err + * @param {MinerBlock} block + * @global + */ + +/** + * @callback AddressMapCallback + * @param {Error?} err + * @param {AddressMap} map + * @global + */ + +/** + * @callback AddressTableCallback + * @param {Error?} err + * @param {AddressTable} table + * @global + */ + +/** + * @callback OrphanCallback + * @param {Error?} err + * @param {Orphan} orphan + * @global + */ + +/** + * @callback TSHeightCallback + * @param {Error?} err + * @param {Number} ts + * @param {Number} height + * @global + */ + +/** + * @callback ConfidenceCallback + * @param {Error?} err + * @param {Confidence} confidence + * @global + */ + +/** + * @callback HashHeightCallback + * @param {Error?} err + * @param {Hash} hash + * @param {Number} height + * @global */