mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Preliminary work on RPC send.
This commit is contained in:
@@ -354,63 +354,62 @@ Json::Value RPCServer::doPeers(Json::Value& params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// send regular_seed paying_account account_id amount [currency] [send_max] [send_currency]
|
||||||
Json::Value RPCServer::doSend(Json::Value& params)
|
Json::Value RPCServer::doSend(Json::Value& params)
|
||||||
{ // Implement simple sending without gathering
|
{
|
||||||
// sendto <destination> <amount>
|
NewcoinAddress naSeed;
|
||||||
// sendto <destination> <amount> <tag>
|
NewcoinAddress naSrcAccountID;
|
||||||
if (!params.isArray() || (params.size()<2))
|
NewcoinAddress naDstAccountID;
|
||||||
|
STAmount saSrcAmount;
|
||||||
|
STAmount saDstAmount;
|
||||||
|
std::string sSrcCurrency;
|
||||||
|
std::string sDstCurrency;
|
||||||
|
|
||||||
|
if (params.size() >= 5)
|
||||||
|
sDstCurrency = params[4u].asString();
|
||||||
|
|
||||||
|
if (params.size() >= 7)
|
||||||
|
sSrcCurrency = params[6u].asString();
|
||||||
|
|
||||||
|
if (!params.isArray() || params.size() < 3 || params.size() > 7)
|
||||||
|
{
|
||||||
return JSONRPCError(500, "Invalid parameters");
|
return JSONRPCError(500, "Invalid parameters");
|
||||||
|
|
||||||
int paramCount=getParamCount(params);
|
|
||||||
if ((paramCount<2)||(paramCount>3))
|
|
||||||
return JSONRPCError(500, "Invalid parameters");
|
|
||||||
|
|
||||||
std::string sDest, sAmount;
|
|
||||||
if (!extractString(sDest, params, 0) || !extractString(sAmount, params, 1))
|
|
||||||
return JSONRPCError(500, "Invalid parameters");
|
|
||||||
|
|
||||||
NewcoinAddress destAccount;
|
|
||||||
|
|
||||||
destAccount.setAccountID(sDest) || destAccount.setAccountPublic(sDest);
|
|
||||||
if (!destAccount.isValid())
|
|
||||||
return JSONRPCError(500, "Unable to parse destination account");
|
|
||||||
|
|
||||||
uint64 iAmount;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
iAmount=boost::lexical_cast<uint64>(sAmount);
|
|
||||||
if (iAmount<=0) return JSONRPCError(500, "Invalid amount");
|
|
||||||
}
|
}
|
||||||
catch (...)
|
else if (!naSeed.setFamilySeedGeneric(params[0u].asString()))
|
||||||
{
|
{
|
||||||
return JSONRPCError(500, "Invalid amount");
|
return JSONRPCError(500, "disallowed seed");
|
||||||
}
|
}
|
||||||
|
else if (!naSrcAccountID.setAccountID(params[1u].asString()))
|
||||||
uint32 iTag(0);
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (paramCount>2)
|
return JSONRPCError(500, "source account id needed");
|
||||||
{
|
|
||||||
std::string sTag;
|
|
||||||
extractString(sTag, params, 2);
|
|
||||||
iTag=boost::lexical_cast<uint32>(sTag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (...)
|
else if (!naDstAccountID.setAccountID(params[2u].asString()))
|
||||||
{
|
{
|
||||||
return JSONRPCError(500, "Invalid tag");
|
return JSONRPCError(500, "create account id needed");
|
||||||
}
|
}
|
||||||
|
else if (!saDstAmount.setValue(params[3u].asString(), sDstCurrency))
|
||||||
|
{
|
||||||
|
return JSONRPCError(500, "bad dst amount/currency");
|
||||||
|
}
|
||||||
|
else if (!saSrcAmount.setValue(params[5u].asString(), sSrcCurrency))
|
||||||
|
{
|
||||||
|
return JSONRPCError(500, "bad src amount/currency");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Json::Value obj(Json::objectValue);
|
||||||
|
|
||||||
#ifdef DEBUG
|
// obj["transaction"] = trans->getSTransaction()->getJson(0);
|
||||||
std::cerr << "SendTo(" << destAccount.humanAccountID() << ") amount=" << iAmount <<
|
obj["seed"] = naSeed.humanFamilySeed();
|
||||||
", tag=" << iTag << std::endl;
|
obj["srcAccountID"] = naSrcAccountID.humanAccountID();
|
||||||
#endif
|
obj["dstAccountID"] = naDstAccountID.humanAccountID();
|
||||||
|
obj["srcAmount"] = saSrcAmount.getText();
|
||||||
|
obj["srcISO"] = saSrcAmount.getCurrencyHuman();
|
||||||
|
obj["dstAmount"] = saDstAmount.getText();
|
||||||
|
obj["dstISO"] = saDstAmount.getCurrencyHuman();
|
||||||
|
|
||||||
LocalTransaction::pointer lt(new LocalTransaction(destAccount, iAmount, iTag));
|
return obj;
|
||||||
if (!lt->makeTransaction())
|
}
|
||||||
return JSONRPCError(500, "Insufficient funds in unlocked accounts");
|
|
||||||
lt->performTransaction();
|
|
||||||
return lt->getTransaction()->getJson(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value RPCServer::doTx(Json::Value& params)
|
Json::Value RPCServer::doTx(Json::Value& params)
|
||||||
@@ -584,7 +583,7 @@ Json::Value RPCServer::doWalletClaim(Json::Value& params)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Trying to build:
|
// Building:
|
||||||
// peer_wallet_claim <account_id> <authorized_key> <encrypted_master_public_generator> <generator_pubkey> <generator_signature>
|
// peer_wallet_claim <account_id> <authorized_key> <encrypted_master_public_generator> <generator_pubkey> <generator_signature>
|
||||||
// <source_tag> [<annotation>]
|
// <source_tag> [<annotation>]
|
||||||
//
|
//
|
||||||
@@ -657,31 +656,31 @@ Json::Value RPCServer::doWalletClaim(Json::Value& params)
|
|||||||
// YYY Need annotation and source tag
|
// YYY Need annotation and source tag
|
||||||
Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
||||||
{
|
{
|
||||||
NewcoinAddress naSourceID;
|
NewcoinAddress naSrcAccountID;
|
||||||
NewcoinAddress naCreateID;
|
NewcoinAddress naDstAccountID;
|
||||||
NewcoinAddress naRegularSeed;
|
NewcoinAddress naRegularSeed;
|
||||||
|
|
||||||
if (params.size() < 3 || params.size() > 4)
|
if (params.size() < 3 || params.size() > 4)
|
||||||
{
|
{
|
||||||
return "invalid params";
|
return "invalid params";
|
||||||
}
|
}
|
||||||
else if (!naSourceID.setAccountID(params[1u].asString()))
|
|
||||||
{
|
|
||||||
return "source account id needed";
|
|
||||||
}
|
|
||||||
else if (!naCreateID.setAccountID(params[2u].asString()))
|
|
||||||
{
|
|
||||||
return "create account id needed";
|
|
||||||
}
|
|
||||||
else if (!naRegularSeed.setFamilySeedGeneric(params[0u].asString()))
|
else if (!naRegularSeed.setFamilySeedGeneric(params[0u].asString()))
|
||||||
{
|
{
|
||||||
return "disallowed seed";
|
return "disallowed seed";
|
||||||
}
|
}
|
||||||
|
else if (!naSrcAccountID.setAccountID(params[1u].asString()))
|
||||||
|
{
|
||||||
|
return "source account id needed";
|
||||||
|
}
|
||||||
|
else if (!naDstAccountID.setAccountID(params[2u].asString()))
|
||||||
|
{
|
||||||
|
return "create account id needed";
|
||||||
|
}
|
||||||
else if (!theApp->getOPs().available()) {
|
else if (!theApp->getOPs().available()) {
|
||||||
// We require access to the paying account's sequence number and key information.
|
// We require access to the paying account's sequence number and key information.
|
||||||
return "network not available";
|
return "network not available";
|
||||||
}
|
}
|
||||||
else if (theApp->getMasterLedger().getCurrentLedger()->getAccountState(naCreateID))
|
else if (theApp->getMasterLedger().getCurrentLedger()->getAccountState(naDstAccountID))
|
||||||
{
|
{
|
||||||
return "account already exists";
|
return "account already exists";
|
||||||
}
|
}
|
||||||
@@ -695,7 +694,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|||||||
|
|
||||||
Ledger::pointer ledger = theApp->getMasterLedger().getCurrentLedger();
|
Ledger::pointer ledger = theApp->getMasterLedger().getCurrentLedger();
|
||||||
LedgerStateParms qry = lepNONE;
|
LedgerStateParms qry = lepNONE;
|
||||||
SerializedLedgerEntry::pointer sleSrc = ledger->getAccountRoot(qry, naSourceID);
|
SerializedLedgerEntry::pointer sleSrc = ledger->getAccountRoot(qry, naSrcAccountID);
|
||||||
|
|
||||||
if (!sleSrc)
|
if (!sleSrc)
|
||||||
{
|
{
|
||||||
@@ -752,7 +751,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|||||||
do {
|
do {
|
||||||
++iIndex;
|
++iIndex;
|
||||||
naMasterAccountPublic.setAccountPublic(naMasterGenerator, iIndex);
|
naMasterAccountPublic.setAccountPublic(naMasterGenerator, iIndex);
|
||||||
} while (naSourceID.getAccountID() != naMasterAccountPublic.getAccountID());
|
} while (naSrcAccountID.getAccountID() != naMasterAccountPublic.getAccountID());
|
||||||
|
|
||||||
NewcoinAddress naRegularAccountPublic;
|
NewcoinAddress naRegularAccountPublic;
|
||||||
NewcoinAddress naRegularAccountPrivate;
|
NewcoinAddress naRegularAccountPrivate;
|
||||||
@@ -771,11 +770,11 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|||||||
|
|
||||||
Transaction::pointer trans = Transaction::sharedCreate(
|
Transaction::pointer trans = Transaction::sharedCreate(
|
||||||
naRegularAccountPublic, naRegularAccountPrivate,
|
naRegularAccountPublic, naRegularAccountPrivate,
|
||||||
naSourceID,
|
naSrcAccountID,
|
||||||
sleSrc->getIFieldU32(sfSequence),
|
sleSrc->getIFieldU32(sfSequence),
|
||||||
theConfig.FEE_CREATE,
|
theConfig.FEE_CREATE,
|
||||||
0, // YYY No source tag
|
0, // YYY No source tag
|
||||||
naCreateID,
|
naDstAccountID,
|
||||||
saInitialFunds); // Initial funds in XNC.
|
saInitialFunds); // Initial funds in XNC.
|
||||||
|
|
||||||
(void) theApp->getOPs().processTransaction(trans);
|
(void) theApp->getOPs().processTransaction(trans);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
|
|||||||
Json::Value doConnect(Json::Value& params);
|
Json::Value doConnect(Json::Value& params);
|
||||||
Json::Value doLedger(Json::Value& params);
|
Json::Value doLedger(Json::Value& params);
|
||||||
Json::Value doPeers(Json::Value& params);
|
Json::Value doPeers(Json::Value& params);
|
||||||
Json::Value doSendTo(Json::Value& params);
|
Json::Value doSend(Json::Value& params);
|
||||||
Json::Value doSessionClose(Json::Value& params);
|
Json::Value doSessionClose(Json::Value& params);
|
||||||
Json::Value doSessionOpen(Json::Value& params);
|
Json::Value doSessionOpen(Json::Value& params);
|
||||||
Json::Value doStop(Json::Value& params);
|
Json::Value doStop(Json::Value& params);
|
||||||
@@ -52,12 +52,14 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
|
|||||||
Json::Value doValidatorCreate(Json::Value& params);
|
Json::Value doValidatorCreate(Json::Value& params);
|
||||||
|
|
||||||
Json::Value doWalletAccounts(Json::Value& params);
|
Json::Value doWalletAccounts(Json::Value& params);
|
||||||
|
Json::Value doWalletAdd(Json::Value& params);
|
||||||
Json::Value doWalletClaim(Json::Value& params);
|
Json::Value doWalletClaim(Json::Value& params);
|
||||||
Json::Value doWalletCreate(Json::Value& params);
|
Json::Value doWalletCreate(Json::Value& params);
|
||||||
Json::Value doWalletLock(Json::Value& params);
|
Json::Value doWalletLock(Json::Value& params);
|
||||||
Json::Value doWalletPropose(Json::Value& params);
|
Json::Value doWalletPropose(Json::Value& params);
|
||||||
Json::Value doWalletSeed(Json::Value& params);
|
Json::Value doWalletSeed(Json::Value& params);
|
||||||
Json::Value doWalletUnlock(Json::Value& params);
|
Json::Value doWalletUnlock(Json::Value& params);
|
||||||
|
Json::Value doWalletVerify(Json::Value& params);
|
||||||
|
|
||||||
void validatorsResponse(const boost::system::error_code& err, std::string strResponse);
|
void validatorsResponse(const boost::system::error_code& err, std::string strResponse);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user