Skip to content

Commit

Permalink
wallet: fix some styles and jsdocs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Nov 3, 2023
1 parent 6446828 commit ea34e2b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 46 deletions.
8 changes: 4 additions & 4 deletions lib/wallet/txdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class TXDB {

/**
* Get all names.
* @returns {NameState[]}
* @returns {Promise<NameState[]>}
*/

async getNames() {
Expand Down Expand Up @@ -568,7 +568,7 @@ class TXDB {
/**
* Get all bids for name.
* @param {Buffer} nameHash
* @returns {BlindBid[]}
* @returns {Promise<BlindBid[]>}
*/

async getBids(nameHash) {
Expand Down Expand Up @@ -679,7 +679,7 @@ class TXDB {
/**
* Get all reveals by name.
* @param {Buffer} nameHash
* @returns {BidReveal[]}
* @returns {Promise<BidReveal[]>}
*/

async getReveals(nameHash) {
Expand Down Expand Up @@ -730,7 +730,7 @@ class TXDB {
/**
* Get a blind value if present.
* @param {Buffer} blind - Blind hash.
* @returns {BlindValue}
* @returns {Promise<BlindValue?>}
*/

async getBlind(blind) {
Expand Down
99 changes: 57 additions & 42 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ class Wallet extends EventEmitter {
* @param {String} name
* @param {(Number|String)?} acct
* @param {MTX?} mtx
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeReveal(name, acct, mtx) {
Expand Down Expand Up @@ -2102,7 +2102,7 @@ class Wallet extends EventEmitter {
* Make a reveal MTX.
* @param {MTX?} mtx
* @param {Number?} witnessSize
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeRevealAll(mtx, witnessSize) {
Expand Down Expand Up @@ -2234,7 +2234,7 @@ class Wallet extends EventEmitter {
* @param {String} name
* @param {(Number|String)?} acct
* @param {MTX?} mtx
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeRedeem(name, acct, mtx) {
Expand Down Expand Up @@ -2374,7 +2374,7 @@ class Wallet extends EventEmitter {
* @param {String} name
* @param {MTX?} mtx
* @param {Number?} witnessSize
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeRedeemAll(mtx, witnessSize) {
Expand Down Expand Up @@ -2582,7 +2582,7 @@ class Wallet extends EventEmitter {
* @param {Resource} resource
* @param {(Number|String)?} acct
* @param {MTX?} mtx
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeUpdate(name, resource, acct, mtx) {
Expand Down Expand Up @@ -2724,7 +2724,7 @@ class Wallet extends EventEmitter {
* @param {String} name
* @param {(Number|String)?} acct
* @param {MTX?} mtx
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeRenewal(name, acct, mtx) {
Expand Down Expand Up @@ -2794,7 +2794,7 @@ class Wallet extends EventEmitter {
* Make a renewal MTX for all expiring names.
* @param {MTX?} mtx
* @param {Number?} witnessSize
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeRenewalAll(mtx, witnessSize) {
Expand Down Expand Up @@ -2938,7 +2938,7 @@ class Wallet extends EventEmitter {
* @param {Address} address
* @param {(Number|String)?} acct
* @param {MTX?} mtx
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeTransfer(name, address, acct, mtx) {
Expand Down Expand Up @@ -3076,7 +3076,7 @@ class Wallet extends EventEmitter {
* @param {String} name
* @param {(Number|String)?} acct
* @param {MTX?} mtx
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeCancel(name, acct, mtx) {
Expand Down Expand Up @@ -3201,7 +3201,7 @@ class Wallet extends EventEmitter {
* @param {String} name
* @param {(Number|String)?} acct
* @param {MTX?} mtx
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeFinalize(name, acct, mtx) {
Expand Down Expand Up @@ -3284,7 +3284,7 @@ class Wallet extends EventEmitter {
* @private
* @param {MTX?} mtx
* @param {Number?} witnessSize
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeFinalizeAll(mtx, witnessSize) {
Expand Down Expand Up @@ -3423,7 +3423,7 @@ class Wallet extends EventEmitter {
* @param {String} name
* @param {(Number|String)?} acct
* @param {MTX?} mtx
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeRevoke(name, acct, mtx) {
Expand Down Expand Up @@ -3551,7 +3551,7 @@ class Wallet extends EventEmitter {
/**
* Get account by address.
* @param {Address} address
* @returns {Account}
* @returns {Promise<Account?>}
*/

async getAccountByAddress(address) {
Expand All @@ -3575,7 +3575,7 @@ class Wallet extends EventEmitter {
* vsize. Input data like prevout and sequence count as base data
* and must be added in outside this function.
* @param {Address} addr
* @returns {Number}
* @returns {Promise<Number>}
*/

async estimateSize(addr) {
Expand Down Expand Up @@ -3689,7 +3689,7 @@ class Wallet extends EventEmitter {
* Make a batch transaction with multiple actions.
* @param {Array} actions
* @param {Object} options
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async makeBatch(actions, options) {
Expand Down Expand Up @@ -3741,71 +3741,86 @@ class Wallet extends EventEmitter {
assert(typeof type === 'string');

switch (type) {
case 'NONE':
case 'NONE': {
assert(action.length === 2);
this.makeTX([{
address: action[0],
value: action[1]
}], mtx);

break;
case 'OPEN':
}
case 'OPEN': {
assert(action.length === 1, 'Bad arguments for OPEN.');
await this.makeOpen(...action, acct, mtx);
break;
}
case 'BID': {
assert(action.length === 3, 'Bad arguments for BID.');
const address = account.deriveReceive(receiveIndex++).getAddress();
await this.makeBid(...action, acct, mtx, address);
break;
}
case 'REVEAL':
case 'REVEAL': {
if (action.length === 1) {
await this.makeReveal(...action, acct, mtx);
} else {
assert(action.length === 0, 'Bad arguments for REVEAL.');
await this.makeRevealAll(mtx, witnessSize);
break;
}

assert(action.length === 0, 'Bad arguments for REVEAL.');
await this.makeRevealAll(mtx, witnessSize);
break;
case 'REDEEM':
}
case 'REDEEM': {
if (action.length === 1) {
await this.makeRedeem(...action, acct, mtx);
} else {
assert(action.length === 0, 'Bad arguments for REDEEM.');
await this.makeRedeemAll(mtx, witnessSize);
break;
}

assert(action.length === 0, 'Bad arguments for REDEEM.');
await this.makeRedeemAll(mtx, witnessSize);
break;
case 'UPDATE':
}
case 'UPDATE': {
assert(action.length === 2, 'Bad arguments for UPDATE.');
await this.makeUpdate(...action, acct, mtx);
break;
case 'RENEW':
}
case 'RENEW': {
if (action.length === 1) {
await this.makeRenewal(...action, acct, mtx);
} else {
assert(action.length === 0, 'Bad arguments for RENEW.');
await this.makeRenewalAll(mtx, witnessSize);
break;
}

assert(action.length === 0, 'Bad arguments for RENEW.');
await this.makeRenewalAll(mtx, witnessSize);
break;
case 'TRANSFER':
}
case 'TRANSFER': {
assert(action.length === 2, 'Bad arguments for TRANSFER.');
await this.makeTransfer(...action, acct, mtx);
break;
case 'FINALIZE':
}
case 'FINALIZE': {
if (action.length === 1) {
await this.makeFinalize(...action, acct, mtx);
} else {
assert(action.length === 0, 'Bad arguments for FINALIZE.');
await this.makeFinalizeAll(mtx, witnessSize);
break;
}

assert(action.length === 0, 'Bad arguments for FINALIZE.');
await this.makeFinalizeAll(mtx, witnessSize);
break;
case 'CANCEL':
}
case 'CANCEL': {
assert(action.length === 1, 'Bad arguments for CANCEL.');
await this.makeCancel(...action, acct, mtx);
break;
case 'REVOKE':
}
case 'REVOKE': {
assert(action.length === 1, 'Bad arguments for REVOKE.');
await this.makeRevoke(...action, acct, mtx);
break;
}
default:
throw new Error(`Unknown action type: ${type}`);
}
Expand Down Expand Up @@ -3867,7 +3882,7 @@ class Wallet extends EventEmitter {
* Make a batch transaction with multiple actions.
* @param {Array} actions
* @param {Object} options
* @returns {MTX}
* @returns {Promise<MTX>}
*/

async _createBatch(actions, options) {
Expand Down Expand Up @@ -4643,7 +4658,7 @@ class Wallet extends EventEmitter {

/**
* Get all names.
* @returns {NameState[]}
* @returns {Promise<NameState[]>}
*/

async getNames() {
Expand Down Expand Up @@ -4683,7 +4698,7 @@ class Wallet extends EventEmitter {
/**
* Get all bids for name.
* @param {Buffer} nameHash
* @returns {BlindBid[]}
* @returns {Promise<BlindBid[]>}
*/

async getBids(nameHash) {
Expand Down Expand Up @@ -5065,7 +5080,7 @@ class Wallet extends EventEmitter {
/**
* Get current receive address.
* @param {Number} [acct=0]
* @returns {Address}
* @returns {Promise<Address>}
*/

async receiveAddress(acct = 0) {
Expand All @@ -5078,7 +5093,7 @@ class Wallet extends EventEmitter {
/**
* Get current change address.
* @param {Number} [acct=0]
* @returns {Address}
* @returns {Promise<Address>}
*/

async changeAddress(acct = 0) {
Expand Down

0 comments on commit ea34e2b

Please sign in to comment.