Skip to content

Commit

Permalink
Merge be97a66 into a1409dc
Browse files Browse the repository at this point in the history
  • Loading branch information
HDardenne-HNS committed Jan 5, 2021
2 parents a1409dc + be97a66 commit 06b328f
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 22 deletions.
4 changes: 4 additions & 0 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,10 @@ class HTTP extends Server {
const passphrase = valid.str('passphrase');
const broadcast = valid.bool('broadcast', true);
const sign = valid.bool('sign', true);
const force = valid.bool('force', false);

assert(broadcast ? sign : true, 'Must sign when broadcasting.');
assert(force ? name : true, 'Must specify a name when forcing');

if (!name) {
const tx = await req.wallet.sendRevealAll();
Expand Down Expand Up @@ -1100,8 +1102,10 @@ class HTTP extends Server {
const passphrase = valid.str('passphrase');
const broadcast = valid.bool('broadcast', true);
const sign = valid.bool('sign', true);
const force = valid.bool('force', false);

assert(broadcast ? sign : true, 'Must sign when broadcasting.');
assert(force ? name : true, 'Must specify a name when forcing');

if (!name) {
const tx = await req.wallet.sendRedeemAll();
Expand Down
38 changes: 26 additions & 12 deletions lib/wallet/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2020,23 +2020,25 @@ class RPC extends RPCBase {
const wallet = this.wallet;
const mtx = await wallet.createBid(opts.name, opts.bid, opts.value, {
paths: true,
account: opts.account
account: opts.account,
force: opts.force
});

return mtx.getJSON(this.network);
}

_validateBid(args, help, method) {
const msg = `${method} "name" bid value ( "account" )`;
const msg = `${method} "name" bid value ( "account" ) ("force")`;

if (help || args.length < 3 || args.length > 4)
if (help || args.length < 3 || args.length > 5)
throw new RPCError(errs.MISC_ERROR, msg);

const valid = new Validator(args);
const name = valid.str(0);
const bid = valid.ufixed(1, EXP);
const value = valid.ufixed(2, EXP);
const account = valid.str(3);
const force = valid.bool(4);

if (!name || !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');
Expand All @@ -2051,7 +2053,8 @@ class RPC extends RPCBase {
name,
bid,
value,
account
account,
force
};
}

Expand Down Expand Up @@ -2090,21 +2093,26 @@ class RPC extends RPCBase {

const mtx = await wallet.createReveal(opts.name, {
paths: true,
account: opts.account
account: opts.account,
force: opts.force
});

return mtx.getJSON(this.network);
}

_validateReveal(args, help, method) {
if (help || args.length > 2)
throw new RPCError(errs.MISC_ERROR, `${method} "name" ( "account" )`);
if (help || args.length > 3)
throw new RPCError(
errs.MISC_ERROR,
`${method} "name" ( "account" ) ( "force" )`
);

const valid = new Validator(args);
const name = valid.str(0);
const account = valid.str(1);
const force = valid.bool(2);

return {name, account};
return {name, account, force};
}

async sendRedeem(args, help) {
Expand All @@ -2120,7 +2128,8 @@ class RPC extends RPCBase {
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

const tx = await wallet.sendRedeem(opts.name, {
account: opts.account
account: opts.account,
force : opts.force
});

return tx.getJSON(this.network);
Expand All @@ -2143,21 +2152,26 @@ class RPC extends RPCBase {

const mtx = await wallet.createRedeem(opts.name, {
paths: true,
account: opts.account
account: opts.account,
force : opts.force
});

return mtx.getJSON(this.network);
}

_validateRedeem(args, help, method) {
if (help || args.length < 1 || args.length > 2)
throw new RPCError(errs.MISC_ERROR, `${method} "name" ( "account" )`);
throw new RPCError(
errs.MISC_ERROR,
`${method} "name" ( "account" ) ("force")`
);

const valid = new Validator(args);
const name = valid.str(0);
const account = valid.str(1);
const force = valid.bool(2);

return {name, account};
return {name, account, force};
}

async sendUpdate(args, help) {
Expand Down
26 changes: 16 additions & 10 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1693,10 +1693,11 @@ class Wallet extends EventEmitter {
* @param {Number} value
* @param {Number} lockup
* @param {Number|String} acct
* @param {Boolean} force
* @returns {MTX}
*/

async makeBid(name, value, lockup, acct) {
async makeBid(name, value, lockup, acct, force) {
assert(typeof name === 'string');
assert(Number.isSafeInteger(value) && value >= 0);
assert(Number.isSafeInteger(lockup) && lockup >= 0);
Expand Down Expand Up @@ -1726,10 +1727,10 @@ class Wallet extends EventEmitter {
const state = ns.state(height, network);
const start = ns.height;

if (state === states.OPENING)
if (!force && state === states.OPENING)
throw new Error('Name has not reached the bidding phase yet.');

if (state !== states.BIDDING)
if (!force && state !== states.BIDDING)
throw new Error('Name is not available.');

if (value > lockup)
Expand Down Expand Up @@ -1765,7 +1766,8 @@ class Wallet extends EventEmitter {

async _createBid(name, value, lockup, options) {
const acct = options ? options.account || 0 : 0;
const mtx = await this.makeBid(name, value, lockup, acct);
const force = options ? options.force || false : false;
const mtx = await this.makeBid(name, value, lockup, acct, force);
await this.fill(mtx, options);
return this.finalize(mtx, options);
}
Expand Down Expand Up @@ -1824,10 +1826,11 @@ class Wallet extends EventEmitter {
* Make a reveal MTX.
* @param {String} name
* @param {(Number|String)?} acct
* @param {Boolean} force
* @returns {MTX}
*/

async makeReveal(name, acct) {
async makeReveal(name, acct, force) {
assert(typeof name === 'string');

if (acct != null) {
Expand All @@ -1851,7 +1854,7 @@ class Wallet extends EventEmitter {

const state = ns.state(height, network);

if (state < states.REVEAL)
if (!force && state < states.REVEAL)
throw new Error('Cannot reveal yet.');

if (state > states.REVEAL)
Expand Down Expand Up @@ -1914,7 +1917,8 @@ class Wallet extends EventEmitter {

async _createReveal(name, options) {
const acct = options ? options.account : null;
const mtx = await this.makeReveal(name, acct);
const force = options ? options.force || false : false;
const mtx = await this.makeReveal(name, acct, force);
await this.fill(mtx, options);
return this.finalize(mtx, options);
}
Expand Down Expand Up @@ -2087,10 +2091,11 @@ class Wallet extends EventEmitter {
* Make a redeem MTX.
* @param {String} name
* @param {(Number|String)?} acct
* @param {Boolean} force
* @returns {MTX}
*/

async makeRedeem(name, acct) {
async makeRedeem(name, acct, force) {
assert(typeof name === 'string');

if (!rules.verifyName(name))
Expand All @@ -2115,7 +2120,7 @@ class Wallet extends EventEmitter {

const state = ns.state(height, network);

if (state < states.CLOSED)
if (!force && state < states.CLOSED)
throw new Error('Auction is not yet closed.');

const reveals = await this.txdb.getReveals(nameHash);
Expand Down Expand Up @@ -2172,7 +2177,8 @@ class Wallet extends EventEmitter {

async _createRedeem(name, options) {
const acct = options ? options.account : null;
const mtx = await this.makeRedeem(name, acct);
const force = options ? options.force || false : false;
const mtx = await this.makeRedeem(name, acct, force);
await this.fill(mtx, options);
return this.finalize(mtx, options);
}
Expand Down
Loading

0 comments on commit 06b328f

Please sign in to comment.