added support for tips in RPC, minor cleanup

This commit is contained in:
Brannon King 2019-09-06 12:53:55 -06:00
parent f71d6a4263
commit 1583082acc
5 changed files with 48 additions and 27 deletions

View file

@ -348,8 +348,12 @@ struct CClaimSupportToName
const CClaimNsupports& find(const std::string& partialId) const
{
auto it = std::find_if(claimsNsupports.begin(), claimsNsupports.end(), [&partialId](const CClaimNsupports& value) {
return value.claim.claimId.GetHex().find(partialId) == 0;
std::string lowered(partialId);
for (auto& c: lowered)
c = std::tolower(c);
auto it = std::find_if(claimsNsupports.begin(), claimsNsupports.end(), [&lowered](const CClaimNsupports& value) {
return value.claim.claimId.GetHex().find(lowered) == 0;
});
return it != claimsNsupports.end() ? *it : invalid;
}

View file

@ -61,7 +61,7 @@ enum {
CHECKNORMALIZATION,
GETCLAIMBYBID,
GETCLAIMBYSEQ,
GETCLAIMPROOFBYID,
GETCLAIMPROOFBYBID,
GETCLAIMPROOFBYSEQ,
GETCHANGESINBLOCK,
};
@ -90,7 +90,7 @@ S3(" ", T_HEIGHT, " (numeric) the height of the block in whic
S3(" ", T_VALIDATHEIGHT, " (numeric) the height at which the support became/becomes valid") \
S3(" ", T_AMOUNT, " (numeric) the amount of the claim") \
S3(" ", T_EFFECTIVEAMOUNT, " (numeric) the amount plus amount from all supports associated with the claim") \
S3(" ", T_PENDINGAMOUNT, " (numeric) expected amount when claim and its support got valid") \
S3(" ", T_PENDINGAMOUNT, " (numeric) expected amount when claim and its supports are all valid") \
S3(" ", T_SUPPORTS, ": [ (array of object) supports for this claim") \
S3(" ", T_VALUE, " (string) the metadata of the support if any") \
S3(" ", T_ADDRESS, " (string) the destination address of the support") \
@ -305,7 +305,7 @@ S1("Result: [")
CLAIM_OUTPUT
"]",
// GETCLAIMPROOFBYID
// GETCLAIMPROOFBYBID
S1(R"(getclaimproofbyid
Return the cryptographic proof that a name maps to a value or doesn't by a bid.
Arguments:)")
@ -329,7 +329,8 @@ PROOF_OUTPUT
// GETCHANGESINBLOCK
S1(R"(getchangesinblock
Return the list of claims added, updated, and removed in a block or doesn't."
Return the list of claims added, updated, and removed as pulled from the queued work for that block."
Use this method to determine which claims or supports went live on a given block."
Arguments:)")
S3("1. ", T_BLOCKHASH, BLOCKHASH_TEXT)
S1("Result: [")

View file

@ -770,7 +770,7 @@ UniValue getnameproof(const JSONRPCRequest& request)
UniValue getclaimproofbybid(const JSONRPCRequest& request)
{
validateRequest(request, GETCLAIMPROOFBYID, 1, 2);
validateRequest(request, GETCLAIMPROOFBYBID, 1, 2);
LOCK(cs_main);
CCoinsViewCache coinsCache(pcoinsTip.get());

View file

@ -174,6 +174,11 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listnameclaims", 0, "includesupports"},
{ "listnameclaims", 1, "activeonly"},
{ "listnameclaims", 2, "minconf"},
{ "getclaimbybid", 1, "bid"},
{ "getclaimbyseq", 1, "sequence"},
{ "getclaimproofbybid", 1, "bid"},
{ "getclaimproofbyseq", 1, "sequence"},
{ "supportclaim", 4, "isTip"},
};
class CRPCConvertTable

View file

@ -889,9 +889,10 @@ UniValue supportclaim(const JSONRPCRequest& request)
+ HelpRequiringPassphrase(pwallet) +
"\nArguments:\n"
"1. \"name\" (string, required) The name claimed by the claim to support.\n"
"2. \"claimid\" (string, optional) The claimid, partialid or best claim to support.\n"
"2. \"claimid\" (string, optional) The claimid or partialid of the claim to support.\n"
"3. \"amount\" (numeric, optional) The amount in LBC to use to support the claim.\n"
"4. \"value\" (string, optional) The metadata of the support encoded in hexadecimal.\n"
"5. \"isTip\" (boolean, optional, defaults to false) spendable by owning claim's address when true.\n"
"\nResult: [\n"
"\"txId\" (string) The transaction id of the support.\n"
"\"address\" (string) The destination address of the claim.\n"
@ -914,19 +915,14 @@ UniValue supportclaim(const JSONRPCRequest& request)
LOCK2(cs_main, pwallet->cs_wallet);
EnsureWalletIsUnlocked(pwallet);
uint160 claimId;
if (sClaimId.length() != claimLength) {
CClaimTrieCache trieCache(pclaimTrie);
auto csToName = trieCache.getClaimsForName(sName);
if (csToName.claimsNsupports.empty())
return NullUniValue;
auto& claimNsupports = !sClaimId.empty() ? csToName.find(sClaimId) : csToName.claimsNsupports[0];
if (claimNsupports.IsNull())
return NullUniValue;
claimId = claimNsupports.claim.claimId;
} else {
claimId.SetHex(sClaimId);
}
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Unable to find a claimid that starts with %s", sClaimId));
auto& claimId = claimNsupports.claim.claimId;
std::vector<unsigned char> vchName (sName.begin(), sName.end());
std::vector<unsigned char> vchClaimId (claimId.begin(), claimId.end());
@ -948,13 +944,28 @@ UniValue supportclaim(const JSONRPCRequest& request)
supportScript = supportScript << OP_2DROP << lastOp;
auto isTip = false;
if (request.params.size() > 4)
isTip = request.params[4].get_bool();
CTxDestination dest;
if (isTip) {
CTransactionRef ref;
uint256 block;
if (!GetTransaction(claimNsupports.claim.outPoint.hash, ref, Params().GetConsensus(), block, true))
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unable to locate the TX with the claim's output.");
if (!ExtractDestination(ref->vout[claimNsupports.claim.outPoint.n].scriptPubKey, dest))
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unable to extract the destination from the chosen claim.");
}
else {
CPubKey newKey;
if (!pwallet->GetKeyFromPool(newKey))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
OutputType output_type = pwallet->m_default_address_type;
pwallet->LearnRelatedScripts(newKey, output_type);
CTxDestination dest = GetDestinationForKey(newKey, output_type);
dest = GetDestinationForKey(newKey, output_type);
}
CCoinControl cc;
cc.m_change_type = pwallet->m_default_change_type;