mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
update rpc call value/currency/issuer
This commit is contained in:
committed by
Richard Holland
parent
f6c64e1c80
commit
ccb3f36245
@@ -149,35 +149,32 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Build an object or string
|
||||
// Build an object
|
||||
// { "currency" : "XYZ", "issuer" : "rXYX", "value": 1000 }
|
||||
// "1000"
|
||||
static Json::Value
|
||||
jvParseAmount(std::string const& strAmount)
|
||||
jvParseSTAmount(std::string const& strIC)
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value jv;
|
||||
Json::Value jv1{Json::objectValue};
|
||||
if (to_uint64(strAmount))
|
||||
return strAmount;
|
||||
|
||||
bool valid_parse = reader.parse(strAmount, jv);
|
||||
if (valid_parse)
|
||||
static boost::regex reCurIss("\\`(0|[1-9][0-9]*)(?:/([[:alpha:]]{3}))(?:/(.+))?\\'");
|
||||
|
||||
boost::smatch icMatch;
|
||||
|
||||
Json::Value jvResult(Json::objectValue);
|
||||
if (boost::regex_match(strIC, icMatch, reCurIss))
|
||||
{
|
||||
if (jv.isObject())
|
||||
std::string strAmount = icMatch[1];
|
||||
std::string strCurrency = icMatch[2];
|
||||
std::string strIssuer = icMatch[3];
|
||||
|
||||
jvResult[jss::currency] = strCurrency;
|
||||
jvResult[jss::value] = strAmount;
|
||||
|
||||
if (strIssuer.length())
|
||||
{
|
||||
if (jv.isMember(jss::params))
|
||||
{
|
||||
auto const& params = jv[jss::params];
|
||||
for (auto i = params.begin(); i != params.end(); ++i)
|
||||
jv1[i.key().asString()] = *i;
|
||||
}
|
||||
jv1[jss::issuer] = jv[jss::issuer];
|
||||
jv1[jss::currency] = jv[jss::currency];
|
||||
jv1[jss::value] = jv[jss::value];
|
||||
// Could confirm issuer is a valid Ripple address.
|
||||
jvResult[jss::issuer] = strIssuer;
|
||||
}
|
||||
}
|
||||
return jv1;
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -849,7 +846,7 @@ private:
|
||||
return parseAccountRaw2(jvParams, jss::destination_account);
|
||||
}
|
||||
|
||||
// channel_authorize: <private_key> [<key_type>] <channel_id> <drops>
|
||||
// channel_authorize: <private_key> [<key_type>] <channel_id> <drops | amount>
|
||||
Json::Value
|
||||
parseChannelAuthorize(Json::Value const& jvParams)
|
||||
{
|
||||
@@ -886,16 +883,29 @@ private:
|
||||
// validate amount string | json
|
||||
if (!jvParams[index].isString())
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
Json::Value amountJson = jvParseAmount(jvParams[index].asString());
|
||||
if (!amountJson)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
STAmount amount;
|
||||
if (!amountFromJsonNoThrow(amount, amountJson))
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
jvRequest[jss::amount] = amountJson;
|
||||
// parse string
|
||||
Json::Value amountJson = jvParseSTAmount(jvParams[index].asString());
|
||||
// std::cout << "AMT JSON: " << amountJson << "\n";
|
||||
if (!amountJson) {
|
||||
// amount is string
|
||||
// std::cout << "IS STRING: " << "\n";
|
||||
if (!to_uint64(jvParams[index].asString()))
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
jvRequest[jss::amount] = jvParams[index].asString();
|
||||
}
|
||||
else
|
||||
{
|
||||
// amount is json
|
||||
// std::cout << "IS JSON: " << "\n";
|
||||
STAmount amount;
|
||||
bool isAmount = amountFromJsonNoThrow(amount, amountJson);
|
||||
if (!isAmount)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
jvRequest[jss::amount] = amountJson;
|
||||
}
|
||||
}
|
||||
|
||||
// If additional parameters are appended, be sure to increment index
|
||||
@@ -927,16 +937,26 @@ private:
|
||||
// validate amount string | json
|
||||
if (!jvParams[2u].isString())
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
Json::Value amountJson = jvParseAmount(jvParams[2u].asString());
|
||||
if (!amountJson)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
STAmount amount;
|
||||
if (!amountFromJsonNoThrow(amount, amountJson))
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
jvRequest[jss::amount] = amountJson;
|
||||
// parse string
|
||||
Json::Value amountJson = jvParseSTAmount(jvParams[2u].asString());
|
||||
// std::cout << "AMT JSON: " << amountJson << "\n";
|
||||
if (!amountJson) {
|
||||
// amount is string
|
||||
if (!to_uint64(jvParams[2u].asString()))
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
jvRequest[jss::amount] = jvParams[2u].asString();
|
||||
}
|
||||
else
|
||||
{
|
||||
// amount is json
|
||||
STAmount amount;
|
||||
bool isAmount = amountFromJsonNoThrow(amount, amountJson);
|
||||
if (!isAmount)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
jvRequest[jss::amount] = amountJson;
|
||||
}
|
||||
}
|
||||
|
||||
jvRequest[jss::signature] = jvParams[3u].asString();
|
||||
|
||||
@@ -63,18 +63,30 @@ doChannelAuthorize(RPC::JsonContext& context)
|
||||
if (!channelId.parseHex(params[jss::channel_id].asString()))
|
||||
return rpcError(rpcCHANNEL_MALFORMED);
|
||||
|
||||
STAmount amount;
|
||||
bool isAmount = amountFromJsonNoThrow(amount, params[jss::amount]);
|
||||
if (!isAmount)
|
||||
Serializer msg;
|
||||
|
||||
if (params[jss::amount].isNumeric())
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
Serializer msg;
|
||||
if (isXRP(amount))
|
||||
if (params[jss::amount].isString())
|
||||
{
|
||||
serializePayChanAuthorization(msg, channelId, amount.xrp());
|
||||
std::optional<std::uint64_t> const optDrops = params[jss::amount].isString()
|
||||
? to_uint64(params[jss::amount].asString())
|
||||
: std::nullopt;
|
||||
|
||||
if (!optDrops)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
std::uint64_t const drops = *optDrops;
|
||||
serializePayChanAuthorization(msg, channelId, XRPAmount(drops));
|
||||
}
|
||||
else
|
||||
{
|
||||
STAmount amount;
|
||||
bool isAmount = amountFromJsonNoThrow(amount, params[jss::amount]);
|
||||
if (!isAmount)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
serializePayChanAuthorization(
|
||||
msg,
|
||||
channelId,
|
||||
@@ -133,18 +145,31 @@ doChannelVerify(RPC::JsonContext& context)
|
||||
if (!channelId.parseHex(params[jss::channel_id].asString()))
|
||||
return rpcError(rpcCHANNEL_MALFORMED);
|
||||
|
||||
STAmount amount;
|
||||
bool isAmount = amountFromJsonNoThrow(amount, params[jss::amount]);
|
||||
if (!isAmount)
|
||||
Serializer msg;
|
||||
|
||||
if (params[jss::amount].isNumeric())
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
Serializer msg;
|
||||
if (isXRP(amount))
|
||||
if (params[jss::amount].isString())
|
||||
{
|
||||
serializePayChanAuthorization(msg, channelId, amount.xrp());
|
||||
std::optional<std::uint64_t> const optDrops = params[jss::amount].isString()
|
||||
? to_uint64(params[jss::amount].asString())
|
||||
: std::nullopt;
|
||||
|
||||
if (!optDrops)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
std::uint64_t const drops = *optDrops;
|
||||
serializePayChanAuthorization(msg, channelId, XRPAmount(drops));
|
||||
}
|
||||
else
|
||||
{
|
||||
STAmount amount;
|
||||
bool isAmount = amountFromJsonNoThrow(amount, params[jss::amount]);
|
||||
|
||||
if (!isAmount)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
serializePayChanAuthorization(
|
||||
msg,
|
||||
channelId,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2023,6 +2023,28 @@ static RPCCallTestData const rpcCallTestArray[] = {
|
||||
}
|
||||
]
|
||||
})"},
|
||||
{"channel_authorize: ic.",
|
||||
__LINE__,
|
||||
{"channel_authorize",
|
||||
"secret_can_be_anything",
|
||||
"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
|
||||
"1000/USD/rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA"},
|
||||
RPCCallTestData::no_exception,
|
||||
R"({
|
||||
"method" : "channel_authorize",
|
||||
"params" : [
|
||||
{
|
||||
"api_version" : %MAX_API_VER%,
|
||||
"amount" : {
|
||||
"value: "1000",
|
||||
"currency: "USD",
|
||||
"issuer: "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA"
|
||||
},
|
||||
"channel_id" : "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
|
||||
"secret" : "secret_can_be_anything"
|
||||
}
|
||||
]
|
||||
})"},
|
||||
{"channel_authorize: too few arguments.",
|
||||
__LINE__,
|
||||
{
|
||||
@@ -2186,6 +2208,30 @@ static RPCCallTestData const rpcCallTestArray[] = {
|
||||
}
|
||||
]
|
||||
})"},
|
||||
{"channel_verify: ic public key.",
|
||||
__LINE__,
|
||||
{"channel_verify",
|
||||
"aB4BXXLuPu8DpVuyq1DBiu3SrPdtK9AYZisKhu8mvkoiUD8J9Gov",
|
||||
"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
|
||||
"1000/USD/rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
|
||||
"DEADBEEF"},
|
||||
RPCCallTestData::no_exception,
|
||||
R"({
|
||||
"method" : "channel_verify",
|
||||
"params" : [
|
||||
{
|
||||
"api_version" : %MAX_API_VER%,
|
||||
"amount" : {
|
||||
"value: "1000",
|
||||
"currency: "USD",
|
||||
"issuer: "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA"
|
||||
},
|
||||
"channel_id" : "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
|
||||
"public_key" : "aB4BXXLuPu8DpVuyq1DBiu3SrPdtK9AYZisKhu8mvkoiUD8J9Gov",
|
||||
"signature" : "DEADBEEF"
|
||||
}
|
||||
]
|
||||
})"},
|
||||
{"channel_verify: public key hex.",
|
||||
__LINE__,
|
||||
{"channel_verify",
|
||||
|
||||
Reference in New Issue
Block a user