mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 18:45:55 +00:00
WS: Add support for ledger_entry to return an account_root.
This commit is contained in:
23
js/remote.js
23
js/remote.js
@@ -168,6 +168,8 @@ Remote.method('request', function(command, done) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Remote.method('ledger_closed', function(done) {
|
Remote.method('ledger_closed', function(done) {
|
||||||
|
assert(this.trusted); // If not trusted, need to check proof.
|
||||||
|
|
||||||
this.request({ 'command' : 'ledger_closed' }, done);
|
this.request({ 'command' : 'ledger_closed' }, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -177,6 +179,17 @@ Remote.method('ledger_current', function(done) {
|
|||||||
this.request({ 'command' : 'ledger_current' }, done);
|
this.request({ 'command' : 'ledger_current' }, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// <-> params:
|
||||||
|
// --> ledger : optional
|
||||||
|
// --> ledger_index : optional
|
||||||
|
Remote.method('ledger_entry', function(params, done) {
|
||||||
|
assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol.
|
||||||
|
|
||||||
|
params.command = 'ledger_entry';
|
||||||
|
|
||||||
|
this.request(params, done);
|
||||||
|
});
|
||||||
|
|
||||||
// Submit a json transaction.
|
// Submit a json transaction.
|
||||||
// done(value)
|
// done(value)
|
||||||
// <-> value: { 'status', status, 'result' : result, ... }
|
// <-> value: { 'status', status, 'result' : result, ... }
|
||||||
@@ -186,16 +199,6 @@ Remote.method('submit', function(json, done) {
|
|||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
// done(value)
|
|
||||||
// --> value: { 'status', status, 'result' : result, ... }
|
|
||||||
// done may be called up to 3 times.
|
|
||||||
Remote.method('account_root', function(account_id, done) {
|
|
||||||
this.request({
|
|
||||||
'command' : 'ledger_current',
|
|
||||||
}, function() {
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
exports.Remote = Remote;
|
exports.Remote = Remote;
|
||||||
exports.remoteConfig = remoteConfig;
|
exports.remoteConfig = remoteConfig;
|
||||||
|
|
||||||
|
|||||||
@@ -567,11 +567,46 @@ void WSConnection::doLedgerCurrent(Json::Value& jvResult, const Json::Value& jvR
|
|||||||
|
|
||||||
void WSConnection::doLedgerEntry(Json::Value& jvResult, const Json::Value& jvRequest)
|
void WSConnection::doLedgerEntry(Json::Value& jvResult, const Json::Value& jvRequest)
|
||||||
{
|
{
|
||||||
// Get from request.
|
NetworkOPs& noNetwork = theApp->getOPs();
|
||||||
uint256 uLedger;
|
uint256 uLedger = jvRequest.isMember("ledger") ? uint256(jvRequest["ledger"].asString()) : 0;
|
||||||
|
uint32 uLedgerIndex = jvRequest.isMember("ledger_index") && jvRequest["ledger_index"].isNumeric() ? jvRequest["ledger_index"].asUInt() : 0;
|
||||||
|
|
||||||
jvResult["ledger_index"] = theApp->getOPs().getLedgerID(uLedger);
|
Ledger::pointer lpLedger;
|
||||||
jvResult["ledger"] = uLedger.ToString();
|
|
||||||
|
if (!!uLedger)
|
||||||
|
{
|
||||||
|
// Ledger directly specified.
|
||||||
|
lpLedger = noNetwork.getLedgerByHash(uLedger);
|
||||||
|
|
||||||
|
if (!lpLedger)
|
||||||
|
{
|
||||||
|
jvResult["error"] = "ledgerNotFound";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uLedgerIndex = lpLedger->getLedgerSeq(); // Set the current index, override if needed.
|
||||||
|
}
|
||||||
|
else if (!!uLedgerIndex)
|
||||||
|
{
|
||||||
|
lpLedger = noNetwork.getLedgerBySeq(uLedgerIndex);
|
||||||
|
|
||||||
|
if (!lpLedger)
|
||||||
|
{
|
||||||
|
jvResult["error"] = "ledgerNotFound"; // ledger_index from future?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Default to current ledger.
|
||||||
|
lpLedger = noNetwork.getCurrentLedger();
|
||||||
|
uLedgerIndex = lpLedger->getLedgerSeq(); // Set the current index.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!!uLedger)
|
||||||
|
jvResult["ledger"] = uLedger.ToString();
|
||||||
|
|
||||||
|
jvResult["ledger_index"] = uLedgerIndex;
|
||||||
|
|
||||||
if (jvRequest.isMember("index"))
|
if (jvRequest.isMember("index"))
|
||||||
{
|
{
|
||||||
@@ -579,7 +614,28 @@ void WSConnection::doLedgerEntry(Json::Value& jvResult, const Json::Value& jvReq
|
|||||||
}
|
}
|
||||||
else if (jvRequest.isMember("account_root"))
|
else if (jvRequest.isMember("account_root"))
|
||||||
{
|
{
|
||||||
jvResult["error"] = "notImplemented";
|
NewcoinAddress naAccount = NewcoinAddress::createAccountID(jvRequest["account_root"].asString());
|
||||||
|
|
||||||
|
if (!naAccount.isValid())
|
||||||
|
{
|
||||||
|
jvResult["error"] = "malformedAddress";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint256 accountRootIndex = Ledger::getAccountRootIndex(naAccount.getAccountID());
|
||||||
|
|
||||||
|
SLE::pointer sleNode = noNetwork.getSLE(lpLedger, accountRootIndex);
|
||||||
|
|
||||||
|
if (!sleNode)
|
||||||
|
{
|
||||||
|
// Not found.
|
||||||
|
// XXX We should also provide proof.
|
||||||
|
jvResult["error"] = "entryNotFound";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jvResult["node"] = sleNode->getJson(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (jvRequest.isMember("directory"))
|
else if (jvRequest.isMember("directory"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// console.log("standalone-test.js>");
|
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var buster = require("buster");
|
var buster = require("buster");
|
||||||
|
|
||||||
@@ -59,9 +57,6 @@ buster.testCase("WebSocket connection", {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// XXX Figure out a way to stuff this into the test case.
|
|
||||||
var alpha;
|
|
||||||
|
|
||||||
buster.testCase("Websocket commands", {
|
buster.testCase("Websocket commands", {
|
||||||
'setUp' :
|
'setUp' :
|
||||||
function(done) {
|
function(done) {
|
||||||
@@ -92,16 +87,6 @@ buster.testCase("Websocket commands", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
'ledger_closed' :
|
|
||||||
function(done) {
|
|
||||||
alpha.ledger_closed(function (r) {
|
|
||||||
console.log(r);
|
|
||||||
|
|
||||||
buster.assert(r.ledger === 1);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
'ledger_current' :
|
'ledger_current' :
|
||||||
function(done) {
|
function(done) {
|
||||||
alpha.ledger_current(function (r) {
|
alpha.ledger_current(function (r) {
|
||||||
@@ -112,7 +97,7 @@ buster.testCase("Websocket commands", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
'ledger_closed' :
|
'// ledger_closed' :
|
||||||
function(done) {
|
function(done) {
|
||||||
alpha.ledger_closed(function (r) {
|
alpha.ledger_closed(function (r) {
|
||||||
console.log("result: %s", JSON.stringify(r));
|
console.log("result: %s", JSON.stringify(r));
|
||||||
@@ -121,46 +106,63 @@ buster.testCase("Websocket commands", {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
|
||||||
|
|
||||||
buster.testCase("// Work in progress", {
|
'account_root success' :
|
||||||
'setUp' :
|
|
||||||
function(done) {
|
function(done) {
|
||||||
server.start("alpha",
|
alpha.ledger_closed(function (r) {
|
||||||
function(e) {
|
// console.log("result: %s", JSON.stringify(r));
|
||||||
buster.refute(e);
|
|
||||||
|
|
||||||
alpha = remote.remoteConfig(config, "alpha");
|
buster.refute('error' in r);
|
||||||
|
|
||||||
alpha.connect(function(stat) {
|
alpha.ledger_entry({
|
||||||
buster.assert(1 == stat); // OPEN
|
'ledger_index' : r.ledger_index,
|
||||||
|
'account_root' : 'iHb9CJAWyB4ij91VRWn96DkukG4bwdtyTh'
|
||||||
|
} , function (r) {
|
||||||
|
// console.log("account_root: %s", JSON.stringify(r));
|
||||||
|
|
||||||
|
buster.assert('node' in r);
|
||||||
done();
|
done();
|
||||||
}, serverDelay);
|
});
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
'tearDown' :
|
|
||||||
function(done) {
|
|
||||||
alpha.disconnect(function(stat) {
|
|
||||||
buster.assert(3 == stat); // CLOSED
|
|
||||||
|
|
||||||
server.stop("alpha", function(e) {
|
|
||||||
buster.refute(e);
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
'ledger_closed' :
|
'account_root malformedAddress' :
|
||||||
function(done) {
|
function(done) {
|
||||||
alpha.ledger_closed(function (r) {
|
alpha.ledger_closed(function (r) {
|
||||||
console.log("result: %s", JSON.stringify(r));
|
// console.log("result: %s", JSON.stringify(r));
|
||||||
|
|
||||||
buster.assert.equals(r.ledger_index, 2);
|
buster.refute('error' in r);
|
||||||
done();
|
|
||||||
|
alpha.ledger_entry({
|
||||||
|
'ledger_index' : r.ledger_index,
|
||||||
|
'account_root' : 'foobar'
|
||||||
|
} , function (r) {
|
||||||
|
// console.log("account_root: %s", JSON.stringify(r));
|
||||||
|
|
||||||
|
buster.assert.equals(r.error, 'malformedAddress');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
'account_root entryNotFound' :
|
||||||
|
function(done) {
|
||||||
|
alpha.ledger_closed(function (r) {
|
||||||
|
// console.log("result: %s", JSON.stringify(r));
|
||||||
|
|
||||||
|
buster.refute('error' in r);
|
||||||
|
|
||||||
|
alpha.ledger_entry({
|
||||||
|
'ledger_index' : r.ledger_index,
|
||||||
|
'account_root' : 'iG1QQv2nh2gi7RCZ1P8YYcBUKCCN633jCn'
|
||||||
|
} , function (r) {
|
||||||
|
// console.log("account_root: %s", JSON.stringify(r));
|
||||||
|
|
||||||
|
buster.assert.equals(r.error, 'entryNotFound');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
Reference in New Issue
Block a user