mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin into serialize
This commit is contained in:
10
js/remote.js
10
js/remote.js
@@ -82,7 +82,7 @@ Remote.method('connect_helper', function() {
|
||||
self.done(ws.readyState);
|
||||
};
|
||||
|
||||
// XXX Why doesn't onmessage work?
|
||||
// Node's ws module doesn't pass arguments to onmessage.
|
||||
ws.on('message', function(json, flags) {
|
||||
var message = JSON.parse(json);
|
||||
// console.log("message: %s", json);
|
||||
@@ -167,12 +167,16 @@ Remote.method('request', function(command, done) {
|
||||
ws.send(JSON.stringify(command));
|
||||
});
|
||||
|
||||
// Get the current ledger entry (may be live or not).
|
||||
Remote.method('ledger_closed', function(done) {
|
||||
this.request({ 'command' : 'ledger_closed' }, done);
|
||||
});
|
||||
|
||||
// Get the current proposed ledger entry. May be closed (and revised) at any time (even before returning).
|
||||
// Only for use by unit tests.
|
||||
Remote.method('ledger_current', function(done) {
|
||||
this.request({ 'command' : 'ledger_current' }, done);
|
||||
});
|
||||
|
||||
|
||||
// Submit a json transaction.
|
||||
// done(value)
|
||||
// <-> value: { 'status', status, 'result' : result, ... }
|
||||
|
||||
@@ -67,6 +67,11 @@ void NetworkOPs::closeTimeOffset(int offset)
|
||||
Log(lsINFO) << "Close time offset now " << mCloseTimeOffset;
|
||||
}
|
||||
|
||||
uint32 NetworkOPs::getLedgerID(const uint256& hash)
|
||||
{
|
||||
return mLedgerMaster->getLedgerByHash(hash)->getLedgerSeq();
|
||||
}
|
||||
|
||||
uint32 NetworkOPs::getCurrentLedgerID()
|
||||
{
|
||||
return mLedgerMaster->getCurrentLedger()->getLedgerSeq();
|
||||
|
||||
@@ -96,6 +96,7 @@ public:
|
||||
uint32 getValidationTimeNC();
|
||||
void closeTimeOffset(int);
|
||||
boost::posix_time::ptime getNetworkTimePT();
|
||||
uint32 getLedgerID(const uint256& hash);
|
||||
uint32 getCurrentLedgerID();
|
||||
OperatingMode getOperatingMode() { return mMode; }
|
||||
inline bool available() {
|
||||
|
||||
@@ -76,7 +76,9 @@ public:
|
||||
boost::unordered_set<NewcoinAddress> parseAccountIds(const Json::Value& jvArray);
|
||||
|
||||
// Request-Response Commands
|
||||
void doLedgerClosed(Json::Value& jvResult, const Json::Value& jvRequest);
|
||||
void doLedgerCurrent(Json::Value& jvResult, const Json::Value& jvRequest);
|
||||
void doLedgerEntry(Json::Value& jvResult, const Json::Value& jvRequest);
|
||||
|
||||
// Streaming Commands
|
||||
void doAccountInfoSubscribe(Json::Value& jvResult, const Json::Value& jvRequest);
|
||||
@@ -297,7 +299,9 @@ Json::Value WSConnection::invokeCommand(const Json::Value& jvRequest)
|
||||
doFuncPtr dfpFunc;
|
||||
} commandsA[] = {
|
||||
// Request-Response Commands:
|
||||
{ "ledger_current", &WSConnection::doLedgerCurrent },
|
||||
{ "ledger_closed", &WSConnection::doLedgerClosed },
|
||||
{ "ledger_current", &WSConnection::doLedgerCurrent },
|
||||
{ "ledger_entry", &WSConnection::doLedgerEntry },
|
||||
|
||||
// Streaming commands:
|
||||
{ "account_info_subscribe", &WSConnection::doAccountInfoSubscribe },
|
||||
@@ -548,9 +552,55 @@ void WSConnection::doLedgerAccountsUnsubscribe(Json::Value& jvResult, const Json
|
||||
}
|
||||
}
|
||||
|
||||
void WSConnection::doLedgerClosed(Json::Value& jvResult, const Json::Value& jvRequest)
|
||||
{
|
||||
uint256 uLedger = theApp->getOPs().getClosedLedger();
|
||||
|
||||
jvResult["ledger_index"] = theApp->getOPs().getLedgerID(uLedger);
|
||||
jvResult["ledger"] = uLedger.ToString();
|
||||
}
|
||||
|
||||
void WSConnection::doLedgerCurrent(Json::Value& jvResult, const Json::Value& jvRequest)
|
||||
{
|
||||
jvResult["ledger"] = theApp->getOPs().getCurrentLedgerID();
|
||||
jvResult["ledger_index"] = theApp->getOPs().getCurrentLedgerID();
|
||||
}
|
||||
|
||||
void WSConnection::doLedgerEntry(Json::Value& jvResult, const Json::Value& jvRequest)
|
||||
{
|
||||
// Get from request.
|
||||
uint256 uLedger;
|
||||
|
||||
jvResult["ledger_index"] = theApp->getOPs().getLedgerID(uLedger);
|
||||
jvResult["ledger"] = uLedger.ToString();
|
||||
|
||||
if (jvRequest.isMember("index"))
|
||||
{
|
||||
jvResult["error"] = "notImplemented";
|
||||
}
|
||||
else if (jvRequest.isMember("account_root"))
|
||||
{
|
||||
jvResult["error"] = "notImplemented";
|
||||
}
|
||||
else if (jvRequest.isMember("directory"))
|
||||
{
|
||||
jvResult["error"] = "notImplemented";
|
||||
}
|
||||
else if (jvRequest.isMember("generator"))
|
||||
{
|
||||
jvResult["error"] = "notImplemented";
|
||||
}
|
||||
else if (jvRequest.isMember("offer"))
|
||||
{
|
||||
jvResult["error"] = "notImplemented";
|
||||
}
|
||||
else if (jvRequest.isMember("ripple_state"))
|
||||
{
|
||||
jvResult["error"] = "notImplemented";
|
||||
}
|
||||
else
|
||||
{
|
||||
jvResult["error"] = "unknownOption";
|
||||
}
|
||||
}
|
||||
|
||||
void WSConnection::doTransactionSubcribe(Json::Value& jvResult, const Json::Value& jvRequest)
|
||||
|
||||
@@ -92,15 +92,75 @@ buster.testCase("Websocket commands", {
|
||||
});
|
||||
},
|
||||
|
||||
"ledger_current" :
|
||||
'ledger_closed' :
|
||||
function(done) {
|
||||
alpha.ledger_closed(function (r) {
|
||||
console.log(r);
|
||||
|
||||
buster.assert(r.ledger === 1);
|
||||
done();
|
||||
});
|
||||
},
|
||||
|
||||
'ledger_current' :
|
||||
function(done) {
|
||||
alpha.ledger_current(function (r) {
|
||||
console.log(r);
|
||||
|
||||
buster.assert(r.ledger === 2);
|
||||
buster.assert.equals(r.ledger_index, 2);
|
||||
done();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
'ledger_closed' :
|
||||
function(done) {
|
||||
alpha.ledger_closed(function (r) {
|
||||
console.log("result: %s", JSON.stringify(r));
|
||||
|
||||
buster.assert.equals(r.ledger_index, 1);
|
||||
done();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
buster.testCase("// Work in progress", {
|
||||
'setUp' :
|
||||
function(done) {
|
||||
server.start("alpha",
|
||||
function(e) {
|
||||
buster.refute(e);
|
||||
|
||||
alpha = remote.remoteConfig(config, "alpha");
|
||||
|
||||
alpha.connect(function(stat) {
|
||||
buster.assert(1 == stat); // OPEN
|
||||
|
||||
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' :
|
||||
function(done) {
|
||||
alpha.ledger_closed(function (r) {
|
||||
console.log("result: %s", JSON.stringify(r));
|
||||
|
||||
buster.assert.equals(r.ledger_index, 1);
|
||||
done();
|
||||
});
|
||||
},
|
||||
});
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user