browser: add rpc.
This commit is contained in:
parent
3e59282c66
commit
41b342350f
1
bin/cli
1
bin/cli
@ -427,6 +427,7 @@ CLI.prototype.handleNode = co(function* handleNode() {
|
||||
this.log(' $ tx [hash/address]: View transactions.');
|
||||
this.log(' $ coin [hash+index/address]: View coins.');
|
||||
this.log(' $ block [hash/height]: View block.');
|
||||
this.log(' $ rpc [command] [args]: Execute RPC command.');
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
margin-top: 10px;
|
||||
font: 1em monospace;
|
||||
}
|
||||
.send {
|
||||
.rpc, .send {
|
||||
padding: 5px;
|
||||
margin-left: 5px;
|
||||
margin-top: 10px;
|
||||
@ -84,6 +84,10 @@ more bitcoin magic).</small>
|
||||
<div id="tx"></div>
|
||||
</div>
|
||||
<div id="log" class="log"></div>
|
||||
<form id="rpc" class="rpc" action="#">
|
||||
<input type="text" name="cmd" id="cmd"
|
||||
placeholder="RPC command (e.g. getblockchaininfo)">
|
||||
</form>
|
||||
<div id="wallet" class="wallet"></div>
|
||||
<form id="send" class="send" action="#">
|
||||
<input type="text" name="address" id="address" placeholder="Address">
|
||||
|
||||
@ -11,6 +11,8 @@ var floating = document.getElementById('floating');
|
||||
var send = document.getElementById('send');
|
||||
var newaddr = document.getElementById('newaddr');
|
||||
var chainState = document.getElementById('state');
|
||||
var rpc = document.getElementById('rpc');
|
||||
var cmd = document.getElementById('cmd');
|
||||
var items = [];
|
||||
var scrollback = 0;
|
||||
var logger, node, options;
|
||||
@ -45,6 +47,33 @@ logger.writeConsole = function(level, args) {
|
||||
log.scrollTop = log.scrollHeight;
|
||||
};
|
||||
|
||||
rpc.onsubmit = function(ev) {
|
||||
var text = cmd.value || '';
|
||||
var argv = text.trim().split(/\s+/);
|
||||
var method = argv.shift();
|
||||
var params = [];
|
||||
var i, arg, param;
|
||||
|
||||
cmd.value = '';
|
||||
|
||||
for (i = 0; i < argv.length; i++) {
|
||||
arg = argv[i];
|
||||
try {
|
||||
param = JSON.parse(arg);
|
||||
} catch (e) {
|
||||
param = arg;
|
||||
}
|
||||
params.push(param);
|
||||
}
|
||||
|
||||
node.rpc.execute({ method: method, params: params }).then(show, show);
|
||||
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
send.onsubmit = function(ev) {
|
||||
var value = document.getElementById('amount').value;
|
||||
var address = document.getElementById('address').value;
|
||||
@ -194,6 +223,7 @@ options = bcoin.config({
|
||||
bcoin.set(options);
|
||||
|
||||
node = new bcoin.fullnode(options);
|
||||
node.rpc = new bcoin.rpc(node);
|
||||
|
||||
node.on('error', function(err) {
|
||||
;
|
||||
|
||||
@ -301,7 +301,7 @@ RPC.prototype.execute = function execute(json) {
|
||||
return this.getmemory(json.params);
|
||||
|
||||
default:
|
||||
throw new Error('Method not found: ' + json.method + '.');
|
||||
return Promise.reject(new Error('Method not found: ' + json.method + '.'));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -65,7 +65,6 @@
|
||||
"./lib/http/client": "./browser/empty.js",
|
||||
"./lib/http/request": "./browser/empty.js",
|
||||
"./lib/http/rpcclient": "./browser/empty.js",
|
||||
"./lib/http/rpc": "./browser/empty.js",
|
||||
"./lib/http/server": "./browser/empty.js",
|
||||
"./lib/http/wallet": "./browser/empty.js",
|
||||
"fs": "./browser/empty.js",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user