Browse Source

- lots of improvements for RPC Browser tool

- fix broken tab styling due to recent commit for "subheader" links
- consistent title for "Mempool Summary"
fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
202eafc862
  1. 46
      app/rpcApi.js
  2. 4
      public/css/styling.css
  3. 41
      routes/baseActionsRouter.js
  4. 87
      views/browser.pug
  5. 4
      views/includes/block-content.pug
  6. 4
      views/mempool.pug
  7. 2
      views/terminal.pug

46
app/rpcApi.js

@ -510,6 +510,9 @@ function getRpcMethodHelp(methodName) {
return;
}
var output = {};
output.string = result;
var str = result;
var lines = str.split("\n");
@ -529,9 +532,48 @@ function getRpcMethodHelp(methodName) {
}
});
console.log("argLines: " + argumentLines);
var args = [];
var argX = null;
// looking for line starting with "N. " where N is an integer (1-2 digits)
argumentLines.forEach(function(line) {
var regex = /^([0-9]+)\.\s*"?(\w+)"?\s*\((\w+),?\s*(\w+),?\s*(.+)?\s*\)\s*(.+)?$/;
resolve(result);
var match = regex.exec(line);
if (match) {
argX = {};
argX.name = match[2];
argX.detailsLines = [];
argX.properties = [];
if (match[3]) {
argX.properties.push(match[3]);
}
if (match[4]) {
argX.properties.push(match[4]);
}
if (match[5]) {
argX.properties.push(match[5]);
}
if (match[6]) {
argX.description = match[6];
}
args.push(argX);
}
if (!match && argX) {
argX.detailsLines.push(line);
}
});
output.args = args;
resolve(output);
});
});
}

4
public/css/styling.css

@ -38,8 +38,4 @@ code, .monospace {
#subheader a {
margin-right: 20px;
}
.nav-link {
padding: 0.5rem 1rem 0.5rem 0;
}

41
routes/baseActionsRouter.js

@ -453,20 +453,41 @@ router.get("/rpc-browser", function(req, res) {
rpcApi.getRpcMethodHelp(req.query.method.trim()).then(function(result2) {
res.locals.methodhelp = result2;
var lines = result2.split("\n");
var params = [];
var line1Parts = lines[0].trim().split(" ");
line1Parts.shift();
if (req.query.execute) {
var argDetails = result2.args;
var argValues = [];
params = line1Parts;
console.log("argA: " + JSON.stringify(result2.args, null, 4));
console.log("argB: " + JSON.stringify(req.query.args, null, 4));
res.locals.methodParams = params;
if (req.query.args) {
for (var i = 0; i < req.query.args.length; i++) {
var argProperties = argDetails[i].properties;
console.log("params: " + params);
for (var j = 0; j < argProperties.length; j++) {
if (argProperties[j] == "numeric") {
if (req.query.args[i] == null || req.query.args[i] == "") {
argValues.push(null);
if (req.query.execute) {
client.cmd([{method:req.query.method, params:[]}], function(err3, result3, resHeaders3) {
} else {
argValues.push(parseInt(req.query.args[i]));
}
break;
} else if (argProperties[j] == "string") {
argValues.push(req.query.args[i]);
break;
}
}
}
}
res.locals.argValues = argValues;
console.log("argV: " + JSON.stringify(argValues, null, 4));
client.cmd([{method:req.query.method, params:argValues}], function(err3, result3, resHeaders3) {
if (err3) {
res.locals.methodResult = err3;

87
views/browser.pug

@ -1,7 +1,7 @@
extends layout
block headContent
title RPC Browser
title RPC Browser #{(method ? (" - " + method) : false)}
style.
pre {
@ -13,44 +13,75 @@ block content
h1 RPC Browser
hr
div(class="row")
div(class="col-md-3")
each section, sectionIndex in gethelp
h4 #{section.name}
small (#{section.methods.length})
hr
div(class="mb-4")
ol(style="padding-left: 30px;")
each methodX, methodIndex in section.methods
li
a(href=("/rpc-browser?method=" + methodX.name), style=(methodX.name == method ? "font-weight: bold; font-style: italic;" : false)) #{methodX.name}
div(class="col-md-9")
if (methodhelp)
div(class="row")
div(class="col-md-6")
h4(style="display: inline-block;") Command: #{method}
div(class="col-md-6")
div(class="col")
h4(style="display: inline-block;")
span(class="text-muted") Command:
span #{method}
div(class="col")
a(href=("https://bitcoin.org/en/developer-reference#" + method), class="float-md-right") See developer docs &raquo;
hr
pre #{methodhelp}
div(class="card bg-light mb-3")
div(class="card-header") Help Content for
strong #{method}
div(class="card-body")
pre #{methodhelp.string}
div(class="card bg-light mb-3")
div(class="card-header") Execute Command:
strong #{method}
div(class="card-body")
form(method="get")
input(type="hidden", name="method", value=method)
each argX, index in methodhelp.args
div(class="form-group")
label(for=("arg_" + argX.name))
strong #{argX.name}
span (#{argX.properties.join(", ")})
if (argX.description)
span - #{argX.description}
hr
- var valX = false;
if (argValues != null)
if (argValues[index] != null)
if (("" + argValues[index]) != NaN)
- valX = argValues[index];
form(method="get")
input(type="hidden", name="method", value=method)
input(type="submit", name="execute", value="Execute", class="btn btn-primary btn-block")
input(id=("arg_" + argX.name), type="text", name=("args[" + index + "]"), placeholder=argX.name, class="form-control", value=valX)
if (methodResult)
h5(class="mt-3") Result
input(type="submit", name="execute", value="Execute", class="btn btn-primary btn-block")
pre
code #{JSON.stringify(methodResult, null, 4)}
if (methodResult)
div(class="mt-4")
hr
h5(class="mt-3") Result
pre(style="border: solid 1px #ccc;")
code #{JSON.stringify(methodResult, null, 4)}
else
:markdown-it
Browse RPC commands from the list. The list is built from the results of the `help` command and organized into sections accordingly.
div(class="col-md-3")
each section, sectionIndex in gethelp
h4 #{section.name}
small (#{section.methods.length})
hr
div(class="mb-4")
ol(style="padding-left: 30px;")
each methodX, methodIndex in section.methods
li
a(href=("/rpc-browser?method=" + methodX.name), style=(methodX.name == method ? "font-weight: bold; font-style: italic;" : false), class="monospace") #{methodX.name}

4
views/includes/block-content.pug

@ -232,4 +232,6 @@ div(class="tab-content")
div(id="tab-raw", class="tab-pane", role="tabpanel")
pre
code #{JSON.stringify(result.getblock, null, 4)}
code #{JSON.stringify(result.getblock, null, 4)}

4
views/mempool.pug

@ -1,10 +1,10 @@
extends layout
block headContent
title Mempool Info
title Mempool Summary
block content
h1 Mempool Info
h1 Mempool Summary
hr
if (getmempoolinfo)

2
views/terminal.pug

@ -5,7 +5,7 @@ block content
hr
:markdown-it
Use this interactive terminal to send RPC commands to your node. Results will be shown inline.
Use this interactive terminal to send RPC commands to your node. Results will be shown inline. To browse all available RPC commands you can use the [RPC Browser](/rpc-browser).
div(class="card mb-3")
div(class="card-body")

Loading…
Cancel
Save