fix RPC linter issues

This commit is contained in:
Andrew Poelstra 2020-12-04 15:17:46 +00:00
parent 29ab3fdda1
commit 1e98c9fa9e
4 changed files with 47 additions and 42 deletions

View file

@ -41,8 +41,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "sendtoaddress", 5 , "replaceable" },
{ "sendtoaddress", 6 , "conf_target" },
{ "sendtoaddress", 8, "avoid_reuse" },
{ "sendtoaddress", 9, "fee_rate"},
{ "sendtoaddress", 10, "verbose"},
{ "sendtoaddress", 11, "fee_rate"},
{ "sendtoaddress", 12, "verbose"},
{ "settxfee", 0, "amount" },
{ "sethdseed", 0, "newkeypool" },
{ "getreceivedbyaddress", 1, "minconf" },
@ -74,8 +74,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "sendmany", 4, "subtractfeefrom" },
{ "sendmany", 5 , "replaceable" },
{ "sendmany", 6 , "conf_target" },
{ "sendmany", 8, "fee_rate"},
{ "sendmany", 9, "verbose" },
{ "sendmany", 10, "fee_rate"},
{ "sendmany", 11, "verbose" },
{ "deriveaddresses", 1, "range" },
{ "scantxoutset", 1, "scanobjects" },
{ "addmultisigaddress", 0, "nrequired" },
@ -196,6 +196,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "combineblocksigs", 1, "signatures" },
{ "sendtomainchain", 1, "amount" },
{ "sendtomainchain", 2, "subtractfeefromamount" },
{ "sendtomainchain", 3, "verbose"},
{ "dumpissuanceblindingkey", 1, "vin" },
{ "importissuanceblindingkey", 1, "vin" },
{ "rawissueasset", 1, "issuances" },
@ -208,20 +209,24 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "issueasset", 2, "blind" },
{ "reissueasset", 1, "assetamount" },
{ "initpegoutwallet", 1, "bip32_counter"},
{ "rawblindrawtransaction", 1, "inputblinder" },
{ "rawblindrawtransaction", 2, "inputamount" },
{ "rawblindrawtransaction", 3, "inputasset" },
{ "rawblindrawtransaction", 4, "inputassetblinder" },
{ "rawblindrawtransaction", 1, "inputamountblinders" },
{ "rawblindrawtransaction", 2, "inputamounts" },
{ "rawblindrawtransaction", 3, "inputassets" },
{ "rawblindrawtransaction", 4, "inputassetblinders" },
{ "rawblindrawtransaction", 5, "totalblinder" },
{ "rawblindrawtransaction", 6, "ignoreblindfail" },
{ "blindrawtransaction", 1, "ignoreblindfail" },
{ "blindrawtransaction", 2, "asset_commitments" },
{ "blindrawtransaction", 3, "blind_issuances" },
{ "blindrawtransaction", 4, "totalblinder" },
{ "blindpsbt", 1, "ignoreblindfail" },
{ "destroyamount", 1, "amount" },
{ "destroyamount", 3, "verbose"},
{ "sendmany", 8 , "output_assets" },
{ "sendmany", 9 , "ignoreblindfail" },
{ "sendtoaddress", 9 , "ignoreblindfail" },
{ "sendtoaddress", 10, "ignoreblindfail" },
{ "createrawtransaction", 4, "output_assets" },
{ "createpsbt", 4, "output_assets" },
};
// clang-format on

View file

@ -2374,8 +2374,8 @@ struct RawIssuanceDetails
// to exist (the fee output, which must be last).
void issueasset_base(CMutableTransaction& mtx, RawIssuanceDetails& issuance_details, const CAmount asset_amount, const CAmount token_amount, const CTxDestination& asset_dest, const CTxDestination& token_dest, const bool blind_issuance, const uint256& contract_hash)
{
assert(asset_amount > 0 || token_amount > 0);
assert(mtx.vout.size() > 0);
CHECK_NONFATAL(asset_amount > 0 || token_amount > 0);
CHECK_NONFATAL(mtx.vout.size() > 0);
CScript asset_script = GetScriptForDestination(asset_dest);
CScript token_script = GetScriptForDestination(token_dest);
@ -2446,9 +2446,9 @@ void issueasset_base(CMutableTransaction& mtx, RawIssuanceDetails& issuance_deta
// least one output to exist (the fee output, which must be last).
void reissueasset_base(CMutableTransaction& mtx, size_t issuance_input_index, const CAmount asset_amount, const CTxDestination& asset_dest, const uint256& asset_blinder, const uint256& entropy)
{
assert(mtx.vout.size() > 0);
assert(asset_amount > 0);
assert(mtx.vin[issuance_input_index].assetIssuance.IsNull());
CHECK_NONFATAL(mtx.vout.size() > 0);
CHECK_NONFATAL(asset_amount > 0);
CHECK_NONFATAL(mtx.vin[issuance_input_index].assetIssuance.IsNull());
CScript asset_script = GetScriptForDestination(asset_dest);
@ -2726,7 +2726,7 @@ static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "rawtransactions", "getrawtransaction", &getrawtransaction, {"txid","verbose","blockhash"} },
{ "rawtransactions", "createrawtransaction", &createrawtransaction, {"inputs","outputs","locktime","replaceable", "output_assets"} },
{ "rawtransactions", "createrawtransaction", &createrawtransaction, {"inputs","outputs","locktime","replaceable","output_assets"} },
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, {"hexstring","iswitness"} },
{ "rawtransactions", "decodescript", &decodescript, {"hexstring"} },
{ "rawtransactions", "sendrawtransaction", &sendrawtransaction, {"hexstring","maxfeerate"} },
@ -2736,18 +2736,18 @@ static const CRPCCommand commands[] =
{ "rawtransactions", "decodepsbt", &decodepsbt, {"psbt"} },
{ "rawtransactions", "combinepsbt", &combinepsbt, {"txs"} },
{ "rawtransactions", "blindpsbt", &blindpsbt, {"psbt","ignoreblindfail"} },
{ "rawtransactions", "finalizepsbt", &finalizepsbt, {"psbt", "extract"} },
{ "rawtransactions", "finalizepsbt", &finalizepsbt, {"psbt","extract"} },
{ "rawtransactions", "createpsbt", &createpsbt, {"inputs","outputs","locktime","replaceable","output_assets"} },
{ "rawtransactions", "converttopsbt", &converttopsbt, {"hexstring","permitsigdata","iswitness"} },
{ "rawtransactions", "utxoupdatepsbt", &utxoupdatepsbt, {"psbt", "descriptors"} },
{ "rawtransactions", "utxoupdatepsbt", &utxoupdatepsbt, {"psbt","descriptors"} },
{ "rawtransactions", "joinpsbts", &joinpsbts, {"txs"} },
{ "rawtransactions", "analyzepsbt", &analyzepsbt, {"psbt"} },
{ "blockchain", "gettxoutproof", &gettxoutproof, {"txids", "blockhash"} },
{ "blockchain", "gettxoutproof", &gettxoutproof, {"txids","blockhash"} },
{ "blockchain", "verifytxoutproof", &verifytxoutproof, {"proof"} },
{ "rawtransactions", "rawissueasset", &rawissueasset, {"transaction", "issuances"}},
{ "rawtransactions", "rawreissueasset", &rawreissueasset, {"transaction", "reissuances"}},
{ "rawtransactions", "rawblindrawtransaction", &rawblindrawtransaction, {"hexstring", "inputamountblinders", "inputamounts", "inputassets", "inputassetblinders", "totalblinder", "ignoreblindfail"} },
{ "rawtransactions", "rawissueasset", &rawissueasset, {"transaction","issuances"}},
{ "rawtransactions", "rawreissueasset", &rawreissueasset, {"transaction","reissuances"}},
{ "rawtransactions", "rawblindrawtransaction", &rawblindrawtransaction, {"hexstring","inputamountblinders","inputamounts","inputassets","inputassetblinders","totalblinder","ignoreblindfail"} },
};
// clang-format on
for (const auto& c : commands) {

View file

@ -94,7 +94,7 @@ static void CreatePegInInputInner(CMutableTransaction& mtx, uint32_t input_idx,
throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to find output in bitcoinTx to the mainchain_address from getpeginaddress");
}
}
assert(witness_script != CScript());
CHECK_NONFATAL(witness_script != CScript());
int version = -1;
std::vector<unsigned char> witness_program;
@ -518,7 +518,7 @@ bool ValidateTransactionPeginInputs(const CMutableTransaction& mtx, std::map<int
}
// Report warning about immature peg-in though
if(txin.m_is_pegin && !IsValidPeginWitness(mtx.witness.vtxinwit[i].m_pegin_witness, fedpegscripts, txin.prevout, err, true)) {
assert(err == "Needs more confirmations.");
CHECK_NONFATAL(err == "Needs more confirmations.");
immature_pegin = true;
}
}

View file

@ -1896,7 +1896,7 @@ static RPCHelpMan gettransaction()
CAmountMap nCredit = wtx.GetCredit(filter);
CAmountMap nDebit = wtx.GetDebit(filter);
CAmountMap nNet = nCredit - nDebit;
assert(HasValidFee(*wtx.tx));
CHECK_NONFATAL(HasValidFee(*wtx.tx));
CAmountMap nFee = wtx.IsFromMe(filter) ? CAmountMap() - GetFeeMap(*wtx.tx) : CAmountMap();
if (!g_con_elementsmode) {
CAmount total_out = 0;
@ -5303,7 +5303,7 @@ bool DerivePubTweak(const std::vector<uint32_t>& vPath, const CPubKey& keyMaster
return false;
}
keyParent.Derive(keyChild, ccChild, vPath[i], ccParent, &tweak);
assert(tweak.size() == 32);
CHECK_NONFATAL(tweak.size() == 32);
ccParent = ccChild;
keyParent = keyChild;
if (i == 0) {
@ -5485,9 +5485,9 @@ static RPCHelpMan initpegoutwallet()
negatedpubkeybytes.resize(33);
size_t len = 33;
ret = secp256k1_ec_pubkey_serialize(secp256k1_ctx, &negatedpubkeybytes[0], &len, &masterpub_secp, SECP256K1_EC_COMPRESSED);
assert(ret == 1);
assert(len == 33);
assert(negatedpubkeybytes.size() == 33);
CHECK_NONFATAL(ret == 1);
CHECK_NONFATAL(len == 33);
CHECK_NONFATAL(negatedpubkeybytes.size() == 33);
UniValue pak(UniValue::VOBJ);
pak.pushKV("pakentry", "pak=" + HexStr(negatedpubkeybytes) + ":" + HexStr(online_pubkey));
@ -5759,15 +5759,15 @@ static RPCHelpMan sendtomainchain_pak()
throw JSONRPCError(RPC_WALLET_ERROR, "Could not create xpub tweak to generate proof.");
}
ret = secp256k1_ec_pubkey_tweak_add(secp256k1_ctx, &btcpub_secp, tweakSum.data());
assert(ret);
CHECK_NONFATAL(ret);
std::vector<unsigned char> btcpubkeybytes;
btcpubkeybytes.resize(33);
size_t btclen = 33;
ret = secp256k1_ec_pubkey_serialize(secp256k1_ctx, &btcpubkeybytes[0], &btclen, &btcpub_secp, SECP256K1_EC_COMPRESSED);
assert(ret == 1);
assert(btclen == 33);
assert(btcpubkeybytes.size() == 33);
CHECK_NONFATAL(ret == 1);
CHECK_NONFATAL(btclen == 33);
CHECK_NONFATAL(btcpubkeybytes.size() == 33);
//Create, verify whitelist proof
secp256k1_whitelist_signature sig;
@ -5781,11 +5781,11 @@ static RPCHelpMan sendtomainchain_pak()
//Serialize
const size_t expectedOutputSize = 1 + 32 * (1 + paklist.size());
assert(1 + 32 * (1 + 256) >= expectedOutputSize);
CHECK_NONFATAL(1 + 32 * (1 + 256) >= expectedOutputSize);
unsigned char output[1 + 32 * (1 + 256)];
size_t outlen = expectedOutputSize;
secp256k1_whitelist_signature_serialize(secp256k1_ctx, output, &outlen, &sig);
assert(outlen == expectedOutputSize);
CHECK_NONFATAL(outlen == expectedOutputSize);
std::vector<unsigned char> whitelistproof(output, output + expectedOutputSize / sizeof(unsigned char));
// Derive the end address in mainchain
@ -5793,7 +5793,7 @@ static RPCHelpMan sendtomainchain_pak()
if (!descriptor->Expand(counter, provider, scripts, provider)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Could not generate mainchain destination with descriptor. This is a bug.");
}
assert(scripts.size() == 1);
CHECK_NONFATAL(scripts.size() == 1);
CScript mainchain_script = scripts[0];
CTxDestination bitcoin_address;
ExtractDestination(mainchain_script, bitcoin_address);
@ -5805,7 +5805,7 @@ static RPCHelpMan sendtomainchain_pak()
nulldata << btcpubkeybytes;
nulldata << whitelistproof;
CTxDestination address(nulldata);
assert(GetScriptForDestination(nulldata).IsPegoutScript(genesisBlockHash));
CHECK_NONFATAL(GetScriptForDestination(nulldata).IsPegoutScript(genesisBlockHash));
std::vector<CRecipient> recipients;
CRecipient recipient = {GetScriptForDestination(address), nAmount, Params().GetConsensus().pegged_asset, CPubKey(), subtract_fee};
@ -6529,7 +6529,7 @@ static RPCHelpMan issueasset()
// Calculate asset type, assumes first vin is used for issuance
CAsset asset;
CAsset token;
assert(!tx_ref->vin.empty());
CHECK_NONFATAL(!tx_ref->vin.empty());
GenerateAssetEntropy(issuance_details.entropy, tx_ref->vin[0].prevout, uint256());
CalculateAsset(asset, issuance_details.entropy);
CalculateReissuanceToken(token, issuance_details.entropy, blind_issuances);
@ -6623,7 +6623,7 @@ static RPCHelpMan reissueasset()
// Attempt a send.
CTransactionRef tx_ref = SendGenerationTransaction(GetScriptForDestination(asset_dest), asset_dest_blindpub, GetScriptForDestination(token_dest), token_dest_blindpub, nAmount, -1, &issuance_details, pwallet);
assert(!tx_ref->vin.empty());
CHECK_NONFATAL(!tx_ref->vin.empty());
UniValue obj(UniValue::VOBJ);
obj.pushKV("txid", tx_ref->GetHash().GetHex());
@ -6886,10 +6886,10 @@ static RPCHelpMan generatepegoutproof()
//Serialize and return as hex
size_t expectedOutputSize = 1 + 32 * (1 + paklist.size());
const size_t preSize = expectedOutputSize;
assert(1 + 32 * (1 + 256) >= expectedOutputSize);
CHECK_NONFATAL(1 + 32 * (1 + 256) >= expectedOutputSize);
unsigned char output[1 + 32 * (1 + 256)];
secp256k1_whitelist_signature_serialize(secp256k1_ctx, output, &expectedOutputSize, &sig);
assert(expectedOutputSize == preSize);
CHECK_NONFATAL(expectedOutputSize == preSize);
std::vector<unsigned char> voutput(output, output + expectedOutputSize / sizeof(output[0]));
return HexStr(voutput);
@ -6954,7 +6954,7 @@ static RPCHelpMan getpegoutkeys()
}
CPubKey bitcoinpubkey = bitcoinkey.GetPubKey();
assert(bitcoinkey.VerifyPubKey(bitcoinpubkey));
CHECK_NONFATAL(bitcoinkey.VerifyPubKey(bitcoinpubkey));
std::vector<unsigned char> pegoutkeybytes(pegoutkey.begin(), pegoutkey.end());
std::vector<unsigned char> pegoutsubkeybytes(bitcoinkey.begin(), bitcoinkey.end());
@ -7048,7 +7048,7 @@ static const CRPCCommand commands[] =
{ "wallet", "removeprunedfunds", &removeprunedfunds, {"txid"} },
{ "wallet", "rescanblockchain", &rescanblockchain, {"start_height", "stop_height"} },
{ "wallet", "send", &send, {"outputs","conf_target","estimate_mode","fee_rate","options"} },
{ "wallet", "sendmany", &sendmany, {"dummy","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode", "output_assets", "ignoreblindfail", "fee_rate", "verbose"} },
{ "wallet", "sendmany", &sendmany, {"dummy","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode","output_assets","ignoreblindfail","fee_rate","verbose"} },
{ "wallet", "sendtoaddress", &sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount","replaceable","conf_target","estimate_mode","avoid_reuse", "assetlabel", "ignoreblindfail", "fee_rate", "verbose"} },
{ "wallet", "sethdseed", &sethdseed, {"newkeypool","seed"} },
{ "wallet", "setlabel", &setlabel, {"address","label"} },