Preliminary work on RPC send.

This commit is contained in:
Arthur Britto
2012-05-19 18:18:20 -07:00
parent 5cba2b4497
commit 5fa2042cc6
2 changed files with 64 additions and 63 deletions

View File

@@ -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)
{ // Implement simple sending without gathering
// sendto <destination> <amount>
// sendto <destination> <amount> <tag>
if (!params.isArray() || (params.size()<2))
{
NewcoinAddress naSeed;
NewcoinAddress naSrcAccountID;
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");
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()))
{
return JSONRPCError(500, "source account id needed");
}
else if (!naDstAccountID.setAccountID(params[2u].asString()))
{
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);
uint32 iTag(0);
try
{
if (paramCount>2)
{
std::string sTag;
extractString(sTag, params, 2);
iTag=boost::lexical_cast<uint32>(sTag);
}
}
catch (...)
{
return JSONRPCError(500, "Invalid tag");
}
// obj["transaction"] = trans->getSTransaction()->getJson(0);
obj["seed"] = naSeed.humanFamilySeed();
obj["srcAccountID"] = naSrcAccountID.humanAccountID();
obj["dstAccountID"] = naDstAccountID.humanAccountID();
obj["srcAmount"] = saSrcAmount.getText();
obj["srcISO"] = saSrcAmount.getCurrencyHuman();
obj["dstAmount"] = saDstAmount.getText();
obj["dstISO"] = saDstAmount.getCurrencyHuman();
#ifdef DEBUG
std::cerr << "SendTo(" << destAccount.humanAccountID() << ") amount=" << iAmount <<
", tag=" << iTag << std::endl;
#endif
LocalTransaction::pointer lt(new LocalTransaction(destAccount, iAmount, iTag));
if (!lt->makeTransaction())
return JSONRPCError(500, "Insufficient funds in unlocked accounts");
lt->performTransaction();
return lt->getTransaction()->getJson(true);
return obj;
}
}
Json::Value RPCServer::doTx(Json::Value& params)
@@ -584,7 +583,7 @@ Json::Value RPCServer::doWalletClaim(Json::Value& params)
}
else
{
// Trying to build:
// Building:
// peer_wallet_claim <account_id> <authorized_key> <encrypted_master_public_generator> <generator_pubkey> <generator_signature>
// <source_tag> [<annotation>]
//
@@ -657,31 +656,31 @@ Json::Value RPCServer::doWalletClaim(Json::Value& params)
// YYY Need annotation and source tag
Json::Value RPCServer::doWalletCreate(Json::Value& params)
{
NewcoinAddress naSourceID;
NewcoinAddress naCreateID;
NewcoinAddress naSrcAccountID;
NewcoinAddress naDstAccountID;
NewcoinAddress naRegularSeed;
if (params.size() < 3 || params.size() > 4)
{
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()))
{
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()) {
// We require access to the paying account's sequence number and key information.
return "network not available";
}
else if (theApp->getMasterLedger().getCurrentLedger()->getAccountState(naCreateID))
else if (theApp->getMasterLedger().getCurrentLedger()->getAccountState(naDstAccountID))
{
return "account already exists";
}
@@ -695,7 +694,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
Ledger::pointer ledger = theApp->getMasterLedger().getCurrentLedger();
LedgerStateParms qry = lepNONE;
SerializedLedgerEntry::pointer sleSrc = ledger->getAccountRoot(qry, naSourceID);
SerializedLedgerEntry::pointer sleSrc = ledger->getAccountRoot(qry, naSrcAccountID);
if (!sleSrc)
{
@@ -752,7 +751,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
do {
++iIndex;
naMasterAccountPublic.setAccountPublic(naMasterGenerator, iIndex);
} while (naSourceID.getAccountID() != naMasterAccountPublic.getAccountID());
} while (naSrcAccountID.getAccountID() != naMasterAccountPublic.getAccountID());
NewcoinAddress naRegularAccountPublic;
NewcoinAddress naRegularAccountPrivate;
@@ -771,11 +770,11 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
Transaction::pointer trans = Transaction::sharedCreate(
naRegularAccountPublic, naRegularAccountPrivate,
naSourceID,
naSrcAccountID,
sleSrc->getIFieldU32(sfSequence),
theConfig.FEE_CREATE,
0, // YYY No source tag
naCreateID,
naDstAccountID,
saInitialFunds); // Initial funds in XNC.
(void) theApp->getOPs().processTransaction(trans);

View File

@@ -35,7 +35,7 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
Json::Value doConnect(Json::Value& params);
Json::Value doLedger(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 doSessionOpen(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 doWalletAccounts(Json::Value& params);
Json::Value doWalletAdd(Json::Value& params);
Json::Value doWalletClaim(Json::Value& params);
Json::Value doWalletCreate(Json::Value& params);
Json::Value doWalletLock(Json::Value& params);
Json::Value doWalletPropose(Json::Value& params);
Json::Value doWalletSeed(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);