Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] remove update raw from hsd #67

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -1370,33 +1370,6 @@ class HTTP extends Server {
return res.json(200, mtx.getJSON(this.network));
});

// Create raw Update
this.post('/wallet/:id/update/raw', async (req, res) => {
const valid = Validator.fromRequest(req);
const name = valid.str('name');
const resourceHex = valid.str('resourceHex');
const passphrase = valid.str('passphrase');
const broadcast = valid.bool('broadcast', true);
const sign = valid.bool('sign', true);

assert(broadcast ? sign : true, 'Must sign when broadcasting.');
assert(name, 'Must pass name.');
assert(resourceHex, 'Must pass resourceHex.');

const options = TransactionOptions.fromValidator(valid);
const mtx = await req.wallet.createRawUpdate(name, resourceHex, options);

if (broadcast) {
const tx = await req.wallet.sendMTX(mtx, passphrase);
return res.json(200, tx.getJSON(this.network));
}

if (sign)
await req.wallet.sign(mtx, passphrase);

return res.json(200, mtx.getJSON(this.network));
});

// Create Renewal
this.post('/wallet/:id/renewal', async (req, res) => {
const valid = Validator.fromRequest(req);
Expand Down
98 changes: 12 additions & 86 deletions lib/wallet/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
'use strict';

const assert = require('bsert');
const {format} = require('util');
const { format } = require('util');
const bweb = require('bweb');
const {Lock} = require('bmutex');
const { Lock } = require('bmutex');
const fs = require('bfile');
const {BufferMap, BufferSet} = require('buffer-map');
const { BufferMap, BufferSet } = require('buffer-map');
const Validator = require('bval');
const blake2b = require('bcrypto/lib/blake2b');
const util = require('../utils/util');
Expand All @@ -28,8 +28,8 @@ const consensus = require('../protocol/consensus');
const pkg = require('../pkg');
const common = require('./common');
const rules = require('../covenants/rules');
const {Resource} = require('../dns/resource');
const {EXP} = consensus;
const { Resource } = require('../dns/resource');
const { EXP } = consensus;
const RPCBase = bweb.RPC;
const RPCError = bweb.RPCError;

Expand Down Expand Up @@ -193,7 +193,6 @@ class RPC extends RPCBase {
this.add('sendreveal', this.sendReveal);
this.add('sendredeem', this.sendRedeem);
this.add('sendupdate', this.sendUpdate);
this.add('sendrawupdate', this.sendRawUpdate);
this.add('sendrenewal', this.sendRenewal);
this.add('sendtransfer', this.sendTransfer);
this.add('sendcancel', this.sendCancel);
Expand All @@ -205,7 +204,6 @@ class RPC extends RPCBase {
this.add('createreveal', this.createReveal);
this.add('createredeem', this.createRedeem);
this.add('createupdate', this.createUpdate);
this.add('createrawupdate', this.createUpdate);
this.add('createrenewal', this.createRenewal);
this.add('createtransfer', this.createTransfer);
this.add('createcancel', this.createCancel);
Expand Down Expand Up @@ -2033,7 +2031,7 @@ class RPC extends RPCBase {
if (!name || !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

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

async sendBid(args, help) {
Expand Down Expand Up @@ -2135,7 +2133,7 @@ class RPC extends RPCBase {
const name = valid.str(0);
const account = valid.str(1);

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

async sendRedeem(args, help) {
Expand Down Expand Up @@ -2188,7 +2186,7 @@ class RPC extends RPCBase {
const name = valid.str(0);
const account = valid.str(1);

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

async sendUpdate(args, help) {
Expand All @@ -2201,16 +2199,6 @@ class RPC extends RPCBase {
return tx.getJSON(this.network);
}

async sendRawUpdate(args, help) {
const opts = this._validateRawUpdate(args, help, 'sendrawupdate');
const wallet = this.wallet;
const tx = await wallet.sendRawUpdate(opts.name, opts.resourceHex, {
account: opts.account
});

return tx.getJSON(this.network);
}

async createUpdate(args, help) {
const opts = this._validateUpdate(args, help, 'createupdate');
const wallet = this.wallet;
Expand All @@ -2222,17 +2210,6 @@ class RPC extends RPCBase {
return mtx.getJSON(this.network);
}

async createRawUpdate(args, help) {
const opts = this._validateRawUpdate(args, help, 'createrawupdate');
const wallet = this.wallet;
const mtx = await wallet.createRawUpdate(opts.name, opts.resourceHex, {
paths: true,
account: opts.account
});

return mtx.getJSON(this.network);
}

_validateUpdate(args, help, method) {
if (help || args.length < 2 || args.length > 3)
throw new RPCError(errs.MISC_ERROR,
Expand All @@ -2258,57 +2235,6 @@ class RPC extends RPCBase {
};
}

_validateUpdateIdempotent(args, help, method) {
const msg = `${method} "name" update value idempotencykey ( "account" )`;

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

const valid = new Validator(args);
const name = valid.str(0);
const data = valid.obj(1);
const idempotencyKey = valid.str(2);
const account = valid.str(3);

if (!name || !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

if (!data)
throw new RPCError(errs.TYPE_ERROR, 'Invalid hex string.');

const resource = Resource.fromJSON(data);

return {
name,
resource,
idempotencyKey,
account
};
}

_validateRawUpdate(args, help, method) {
if (help || args.length < 2 || args.length > 3)
throw new RPCError(errs.MISC_ERROR, method
+ '"name" "resourceHex" ( "account" )');

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

if (!name || !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

if (!resourceHex)
throw new RPCError(errs.TYPE_ERROR, 'Invalid hex string.');

return {
name,
resourceHex,
account
};
}

async sendRenewal(args, help) {
const wallet = this.wallet;
const opts = this._validateRenewal(args, help, 'sendrenewal');
Expand Down Expand Up @@ -2339,7 +2265,7 @@ class RPC extends RPCBase {
if (!name || !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

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

async sendTransfer(args, help) {
Expand Down Expand Up @@ -2420,7 +2346,7 @@ class RPC extends RPCBase {
if (!name || !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

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

async sendFinalize(args, help) {
Expand Down Expand Up @@ -2455,7 +2381,7 @@ class RPC extends RPCBase {
if (!name || !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

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

async sendRevoke(args, help) {
Expand Down Expand Up @@ -2490,7 +2416,7 @@ class RPC extends RPCBase {
if (!name || !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

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

async importNonce(args, help) {
Expand Down