From 868977e331b4157ec948592291135d151a62ffd1 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Tue, 15 Feb 2022 07:09:35 +0800 Subject: [PATCH 01/20] Created the RPC command --- src/rpc/client.cpp | 1 + src/wallet/rpcwallet.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 65a91916a..3d8656a03 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -116,6 +116,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "listsinceblock", 1 }, { "listsinceblock", 2 }, { "listtokens", 0 }, + { "listnames", 0 }, { "listtransactions", 1 }, { "listtransactions", 2 }, { "listtransactions", 3 }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8a5dafa6f..48e140e9c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5984,6 +5984,44 @@ UniValue listproposals(const UniValue& params, bool fHelp) return ret; } +UniValue listnames(const UniValue& params, bool fHelp) +{ + if (fHelp) + throw std::runtime_error( + "listnames (mine)\n" + "\nList dotNav names.\n" + "\nArguments:\n" + "1. mine (bool, optional, default=false) Set mine to true to show only names you own.\n" + + + HelpExampleCli("listnames", "") + + HelpExampleCli("listnames", "true") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + UniValue ret(UniValue::VARR); + + // Check "mine" argument is boolean + if (params.size() == 1 && !params[0].isBool()) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, argument 1 must be a boolean"); + + UniValue ret(UniValue::VARR); + /* NameRecordMap mapNames; */ + /* CStateViewCache view(pcoinsTip); */ + + /* if(view.GetAllNameRecords(mapTokens)) */ + /* { */ + /* for (NameRecordMap::iterator it = mapNames.begin(); it != mapNames.end(); it++) */ + /* { */ + /* NameRecordValue nameRecord; */ + /* if (!view.GetNameRecord(it->first, nameRecord)) */ + /* continue; */ + /* } */ + /* } */ + + return ret; +} + UniValue listtokens(const UniValue& params, bool fHelp) { if (fHelp) @@ -6165,6 +6203,7 @@ static const CRPCCommand commands[] = { "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true }, { "wallet", "listprivateaddresses", &listprivateaddresses, true }, { "wallet", "listtokens", &listtokens, true }, + { "wallet", "listnames", &listnames, true }, { "wallet", "gettoken", &gettoken, true }, { "wallet", "getbalance", &getbalance, false }, { "wallet", "getnewaddress", &getnewaddress, true }, From 46941da93dfc288539e268c527a1f4d01c21d8fc Mon Sep 17 00:00:00 2001 From: mxaddict Date: Fri, 4 Mar 2022 07:01:03 +0800 Subject: [PATCH 02/20] Ocd --- src/wallet/rpcwallet.cpp | 1224 +++++++++++++++++++------------------- 1 file changed, 607 insertions(+), 617 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 48e140e9c..18182459e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -38,9 +38,7 @@ static CCriticalSection cs_nWalletUnlockTime; std::string HelpRequiringPassphrase() { - return pwalletMain && pwalletMain->IsCrypted() - ? "\nRequires wallet passphrase to be set with walletpassphrase call." - : ""; + return pwalletMain && pwalletMain->IsCrypted() ? "\nRequires wallet passphrase to be set with walletpassphrase call." : ""; } bool EnsureWalletIsAvailable(bool avoidException) @@ -168,12 +166,12 @@ UniValue listprivateunspent(const UniValue& params, bool fHelp) " \"txid\" : \"txid\", (string) the transaction id \n" " \"vout\" : n, (numeric) the vout value\n" " \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n" - " \"confirmations\" : n (numeric) The number of confirmations\n" - " }\n" - " ,...\n" - "]\n" + " \"confirmations\" : n (numeric) The number of confirmations\n" + " }\n" + " ,...\n" + "]\n" - "\nExamples\n" + "\nExamples\n" + HelpExampleCli("listprivateunspent", "") + HelpExampleCli("listprivateunspent", "6 9999999") ); @@ -257,29 +255,25 @@ UniValue getcoldstakingaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2) throw std::runtime_error( "getcoldstakingaddress \"stakingaddress\" \"spendingaddress\" ( \"votingaddress\" )\n" - "Returns a coldstaking address based on the address inputs\n" - "Arguments:\n" - "1. \"stakingaddress\" (string, required) The navcoin staking address.\n" - "2. \"spendingaddress\" (string, required) The navcoin spending address.\n\n" - "3. \"voting\" (string, optional) The navcoin voting address.\n\n" - "\nExamples:\n" - + HelpExampleCli("getcoldstakingaddress", "\"mqyGZvLYfEH27Zk3z6JkwJgB1zpjaEHfiW\" \"mrfjgazyerYxDQHJAPDdUcC3jpmi8WZ2uv\"") + + "Returns a coldstaking address based on the address inputs\n" + "Arguments:\n" + "1. \"stakingaddress\" (string, required) The navcoin staking address.\n" + "2. \"spendingaddress\" (string, required) The navcoin spending address.\n\n" + "3. \"voting\" (string, optional) The navcoin voting address.\n\n" + "\nExamples:\n" + + HelpExampleCli("getcoldstakingaddress", "\"mqyGZvLYfEH27Zk3z6JkwJgB1zpjaEHfiW\" \"mrfjgazyerYxDQHJAPDdUcC3jpmi8WZ2uv\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("getcoldstakingaddress", "\"mqyGZvLYfEH27Zk3z6JkwJgB1zpjaEHfiW\", \"mrfjgazyerYxDQHJAPDdUcC3jpmi8WZ2uv\"") + + HelpExampleRpc("getcoldstakingaddress", "\"mqyGZvLYfEH27Zk3z6JkwJgB1zpjaEHfiW\", \"mrfjgazyerYxDQHJAPDdUcC3jpmi8WZ2uv\"") ); if (!IsColdStakingEnabled(chainActive.Tip(),Params().GetConsensus())) - throw std::runtime_error( - "Cold Staking is not active yet."); + throw std::runtime_error("Cold Staking is not active yet."); if (!IsColdStakingv2Enabled(chainActive.Tip(), Params().GetConsensus()) && params.size() == 3) - throw std::runtime_error( - "Cold Staking v2 is not active yet."); + throw std::runtime_error("Cold Staking v2 is not active yet."); if (params[0].get_str() == params[1].get_str()) - throw std::runtime_error( - "The staking address should be different to the spending address" - ); + throw std::runtime_error("The staking address should be different to the spending address"); CNavcoinAddress stakingAddress(params[0].get_str()); @@ -665,17 +659,17 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) "\nArguments:\n" "1. \"navcoinaddress\" (string, required) The navcoin address to send to.\n" "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n" - "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" - " This is not part of the transaction, just kept in your wallet.\n" - "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n" - " to which you're sending the transaction. This is not part of the \n" - " transaction, just kept in your wallet.\n" - "5. \"strdzeel\" (string, optional) Attached string metadata \n" - "6. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n" - " The recipient will receive less navcoins than you enter in the amount field.\n" - "\nResult:\n" - "\"transactionid\" (string) The transaction id.\n" - "\nExamples:\n" + "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" + " This is not part of the transaction, just kept in your wallet.\n" + "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n" + " to which you're sending the transaction. This is not part of the \n" + " transaction, just kept in your wallet.\n" + "5. \"strdzeel\" (string, optional) Attached string metadata \n" + "6. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n" + " The recipient will receive less navcoins than you enter in the amount field.\n" + "\nResult:\n" + "\"transactionid\" (string) The transaction id.\n" + "\nExamples:\n" + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1") + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"donation\" \"seans outpost\"") + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"\" \"\" \"\" true") @@ -754,17 +748,17 @@ UniValue privatesendtoaddress(const UniValue& params, bool fHelp) "\nArguments:\n" "1. \"navcoinaddress\" (string, required) The navcoin address to send to.\n" "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n" - "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" - " This is part of the transaction and will be seen by the receiver. Max 54 chars.\n" - "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n" - " to which you're sending the transaction. This is not part of the \n" - " transaction, just kept in your wallet.\n" - "5. \"strdzeel\" (string, optional) Attached string metadata \n" - "6. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n" - " The recipient will receive less navcoins than you enter in the amount field.\n" - "\nResult:\n" - "\"transactionid\" (string) The transaction id.\n" - "\nExamples:\n" + "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" + " This is part of the transaction and will be seen by the receiver. Max 54 chars.\n" + "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n" + " to which you're sending the transaction. This is not part of the \n" + " transaction, just kept in your wallet.\n" + "5. \"strdzeel\" (string, optional) Attached string metadata \n" + "6. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n" + " The recipient will receive less navcoins than you enter in the amount field.\n" + "\nResult:\n" + "\"transactionid\" (string) The transaction id.\n" + "\nExamples:\n" + HelpExampleCli("privatesendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1") + HelpExampleCli("privatesendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"donation\" \"seans outpost\"") + HelpExampleCli("privatesendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"\" \"\" true") @@ -886,12 +880,8 @@ UniValue privatesendmixtoaddress(const UniValue& params, bool fHelp) else if (!dnssec_valid && GetBoolArg("-requirednssec",true)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "OpenAlias Address does not support DNS Sec"); else - { - address_str = addresses.front(); - } - } CNavcoinAddress address(address_str); @@ -1002,22 +992,22 @@ UniValue createproposal(const UniValue& params, bool fHelp) if (fHelp || params.size() < 4) throw std::runtime_error( "createproposal \"navcoinaddress\" \"amount\" duration \"desc\" ( fee dump_raw )\n" - "\nCreates a proposal for the community fund. Min fee of " + FormatMoney(GetConsensusParameter(Consensus::CONSENSUS_PARAM_PROPOSAL_MIN_FEE, view)) + "NAV is required.\n" - + HelpRequiringPassphrase() + + "\nCreates a proposal for the community fund. Min fee of " + FormatMoney(GetConsensusParameter(Consensus::CONSENSUS_PARAM_PROPOSAL_MIN_FEE, view)) + "NAV is required.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"navcoinaddress\" (string, required) The navcoin address where coins would be sent if proposal is approved.\n" - "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to request. eg 0.1\n" - "3. duration (numeric, required) Number of seconds the proposal will exist after being accepted.\n" - "4. \"desc\" (string, required) Short description of the proposal.\n" - "5. fee (numeric, optional) Contribution to the fund used as fee.\n" - "6. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" - "7. \"owneraddress\" (string, optional) The owner of the proposal who will sign the payment requests. Default: the payment address\n" - "8. super_proposal (bool, optional) Creates a super proposal which would print new coins instead of taking from the fund. Default: false\n" - "\nResult:\n" - "\"{ hash: proposalid,\" (string) The proposal id.\n" - "\" strDZeel: string }\" (string) The attached strdzeel property.\n" - "\nExamples:\n" - + HelpExampleCli("createproposal", "\"NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ\" 1000 86400 \"Development\"") + "1. \"navcoinaddress\" (string, required) The navcoin address where coins would be sent if proposal is approved.\n" + "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to request. eg 0.1\n" + "3. duration (numeric, required) Number of seconds the proposal will exist after being accepted.\n" + "4. \"desc\" (string, required) Short description of the proposal.\n" + "5. fee (numeric, optional) Contribution to the fund used as fee.\n" + "6. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" + "7. \"owneraddress\" (string, optional) The owner of the proposal who will sign the payment requests. Default: the payment address\n" + "8. super_proposal (bool, optional) Creates a super proposal which would print new coins instead of taking from the fund. Default: false\n" + "\nResult:\n" + "\"{ hash: proposalid,\" (string) The proposal id.\n" + "\" strDZeel: string }\" (string) The attached strdzeel property.\n" + "\nExamples:\n" + + HelpExampleCli("createproposal", "\"NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ\" 1000 86400 \"Development\"") + HelpExampleCli("createproposal", "\"NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ\" 12000 3600 \"Promotional stickers for everyone\" 100") ); @@ -1116,14 +1106,14 @@ UniValue createtoken(const UniValue& params, bool fHelp) if (fHelp || params.size() < 3) throw std::runtime_error( - "createtoken \"name\" \"token_code\" max_supply\n" - "\nCreates a confidential token.\n" - + HelpRequiringPassphrase() + + "createtoken \"name\" \"token_code\" max_supply\n" + "\nCreates a confidential token.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"name\" (string, required) The name of the token\n" - "2. max_supply (numeric, optional) The max supply of the token.\n" - "\nExamples:\n" - + HelpExampleCli("createtoken", "\"BabyNAV\" \"BNAV\" 1000") + "1. \"name\" (string, required) The name of the token\n" + "2. max_supply (numeric, optional) The max supply of the token.\n" + "\nExamples:\n" + + HelpExampleCli("createtoken", "\"BabyNAV\" \"BNAV\" 1000") + HelpExampleCli("createtoken", "\"Wrapped Bitcoin\" \"wBTC\" 21000000") ); @@ -1176,13 +1166,13 @@ UniValue registername(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1) throw std::runtime_error( - "registername \"name\"\n" - "\nRegister a dotNav name.\n" - + HelpRequiringPassphrase() + + "registername \"name\"\n" + "\nRegister a dotNav name.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"name\" (string, required) The name to register\n" - "\nExamples:\n" - + HelpExampleCli("registername", "satoshi.nav") + "1. \"name\" (string, required) The name to register\n" + "\nExamples:\n" + + HelpExampleCli("registername", "satoshi.nav") ); @@ -1233,13 +1223,13 @@ UniValue genkeyname(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1) throw std::runtime_error( - "genkeyname \"name\"\n" - "\nGenerates a public key for receiving a dotNav name.\n" - + HelpRequiringPassphrase() + + "genkeyname \"name\"\n" + "\nGenerates a public key for receiving a dotNav name.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"name\" (string, required) The name \n" - "\nExamples:\n" - + HelpExampleCli("genkeyname", "satoshi.nav") + "1. \"name\" (string, required) The name \n" + "\nExamples:\n" + + HelpExampleCli("genkeyname", "satoshi.nav") ); if (!params[0].isStr() ) @@ -1275,13 +1265,13 @@ UniValue renewname(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1) throw std::runtime_error( - "renewname \"name\"\n" - "\nRenews a dotNav name.\n" - + HelpRequiringPassphrase() + + "renewname \"name\"\n" + "\nRenews a dotNav name.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"name\" (string, required) The name to renew\n" - "\nExamples:\n" - + HelpExampleCli("renewname", "satoshi.nav") + "1. \"name\" (string, required) The name to renew\n" + "\nExamples:\n" + + HelpExampleCli("renewname", "satoshi.nav") ); @@ -1318,15 +1308,15 @@ UniValue resolvename(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1) throw std::runtime_error( - "resolvename \"name\"\n" - "\nResolves a dotNav name.\n" - + HelpRequiringPassphrase() + + "resolvename \"name\"\n" + "\nResolves a dotNav name.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"name\" (string, required) The name to resolve\n" - "2. \"subdomains\" (boolean, optional) Include subdomains\n" - "\nExamples:\n" - + HelpExampleCli("resolvename", "satoshi.nav") - + HelpExampleCli("resolvename", "satoshi.nav true") + "1. \"name\" (string, required) The name to resolve\n" + "2. \"subdomains\" (boolean, optional) Include subdomains\n" + "\nExamples:\n" + + HelpExampleCli("resolvename", "satoshi.nav") + + HelpExampleCli("resolvename", "satoshi.nav true") ); if (!params[0].isStr()) @@ -1410,15 +1400,15 @@ UniValue updatename(const UniValue& params, bool fHelp) if (fHelp || params.size() < 3) throw std::runtime_error( - "updatename \"name\" \"key\" \"value\"\n" - "\nUpdates a dotNav name.\n" - + HelpRequiringPassphrase() + + "updatename \"name\" \"key\" \"value\"\n" + "\nUpdates a dotNav name.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"name\" (string, required) The name to update\n" - "1. \"key\" (string, required) The parameter to update\n" - "1. \"value\" (string, required) The value to set\n" - "\nExamples:\n" - + HelpExampleCli("updatename", "satoshi.nav nav NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ") + "1. \"name\" (string, required) The name to update\n" + "1. \"key\" (string, required) The parameter to update\n" + "1. \"value\" (string, required) The value to set\n" + "\nExamples:\n" + + HelpExampleCli("updatename", "satoshi.nav nav NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ") ); @@ -1527,16 +1517,16 @@ UniValue createnft(const UniValue& params, bool fHelp) if (fHelp || params.size() < 3) throw std::runtime_error( - "createnft \"name\" \"scheme\" max_supply\n" - "\nCreates a nft.\n" - + HelpRequiringPassphrase() + + "createnft \"name\" \"scheme\" max_supply\n" + "\nCreates a nft.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"name\" (string, required) The name of the NFT\n" - "1. \"scheme\" (string, required) The scheme for the NFT metadata\n" - "2. max_supply (numeric, optional) The max supply of the NFT.\n" - "\nExamples:\n" - + HelpExampleCli("createnft", "\"NAV Artwork\" \"{'resource': 'url'}\" 1000") - + HelpExampleCli("createnft", "\"Game Item\" \"{'type': 'string', 'power': 'int'}\" 100") + "1. \"name\" (string, required) The name of the NFT\n" + "1. \"scheme\" (string, required) The scheme for the NFT metadata\n" + "2. max_supply (numeric, optional) The max supply of the NFT.\n" + "\nExamples:\n" + + HelpExampleCli("createnft", "\"NAV Artwork\" \"{'resource': 'url'}\" 1000") + + HelpExampleCli("createnft", "\"Game Item\" \"{'type': 'string', 'power': 'int'}\" 100") ); @@ -1588,15 +1578,15 @@ UniValue minttoken(const UniValue& params, bool fHelp) if (fHelp || params.size() < 3) throw std::runtime_error( - "minttoken \"tokenid\" \"destination\" amount\n" - "\nMints confidential tokens.\n" - + HelpRequiringPassphrase() + + "minttoken \"tokenid\" \"destination\" amount\n" + "\nMints confidential tokens.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"tokenid\" (string, required) The token id\n" - "2. \"destination\" (string, required) The xNAV destination addressn" - "3. amount (string, required) The amount to mint\n" - "\nExamples:\n" - + HelpExampleCli("minttoken", "\"a7be93b41e708d21d6c94920401ca5fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" \"xNUNs2vtjr6QDL1NiL8TDHgmbuEo5WcY2K2jQ8ATj9pko8wkJ9RutkFQKBCtn6SsBjy6nK5ftofFyLFnAHAynreQCZjuE7dCWVxCX5DCFB2bjx87KvbqVVRCs3KBzdDre7c5FUy7QLo\" 1000") + "1. \"tokenid\" (string, required) The token id\n" + "2. \"destination\" (string, required) The xNAV destination addressn" + "3. amount (string, required) The amount to mint\n" + "\nExamples:\n" + + HelpExampleCli("minttoken", "\"a7be93b41e708d21d6c94920401ca5fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" \"xNUNs2vtjr6QDL1NiL8TDHgmbuEo5WcY2K2jQ8ATj9pko8wkJ9RutkFQKBCtn6SsBjy6nK5ftofFyLFnAHAynreQCZjuE7dCWVxCX5DCFB2bjx87KvbqVVRCs3KBzdDre7c5FUy7QLo\" 1000") ); @@ -1675,16 +1665,16 @@ UniValue mintnft(const UniValue& params, bool fHelp) if (fHelp || params.size() < 4) throw std::runtime_error( - "mintnft \"tokenid\" \"nftid\" \"destination\" \"metadata\"\n" - "\nMints nft.\n" - + HelpRequiringPassphrase() + + "mintnft \"tokenid\" \"nftid\" \"destination\" \"metadata\"\n" + "\nMints nft.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"tokenid\" (string, required) The token id\n" - "1. \"nftid\" (int, required) The ntf id\n" - "2. \"destination\" (string, required) The xNAV destination addressn" - "3. \"metadata\" (string, required) The nft metadata\n" - "\nExamples:\n" - + HelpExampleCli("mintnft", "\"a7be93b41e708d21d6c94920401ca5fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" 1 \"xNUNs2vtjr6QDL1NiL8TDHgmbuEo5WcY2K2jQ8ATj9pko8wkJ9RutkFQKBCtn6SsBjy6nK5ftofFyLFnAHAynreQCZjuE7dCWVxCX5DCFB2bjx87KvbqVVRCs3KBzdDre7c5FUy7QLo\" \"{'resource':'https://navcoin.org/logo.png'}\"") + "1. \"tokenid\" (string, required) The token id\n" + "1. \"nftid\" (int, required) The ntf id\n" + "2. \"destination\" (string, required) The xNAV destination addressn" + "3. \"metadata\" (string, required) The nft metadata\n" + "\nExamples:\n" + + HelpExampleCli("mintnft", "\"a7be93b41e708d21d6c94920401ca5fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" 1 \"xNUNs2vtjr6QDL1NiL8TDHgmbuEo5WcY2K2jQ8ATj9pko8wkJ9RutkFQKBCtn6SsBjy6nK5ftofFyLFnAHAynreQCZjuE7dCWVxCX5DCFB2bjx87KvbqVVRCs3KBzdDre7c5FUy7QLo\" \"{'resource':'https://navcoin.org/logo.png'}\"") ); @@ -1768,14 +1758,14 @@ UniValue burntoken(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2) throw std::runtime_error( - "burntoken \"tokenid\" amount\n" - "\nBurns confidential tokens.\n" - + HelpRequiringPassphrase() + + "burntoken \"tokenid\" amount\n" + "\nBurns confidential tokens.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"tokenid\" (string, required) The token id\n" - "3. amount (string, required) The amount to burn\n" - "\nExamples:\n" - + HelpExampleCli("burntoken", "\"a7be93b41e708d21d6c94920401ca5fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" 1000") + "1. \"tokenid\" (string, required) The token id\n" + "3. amount (string, required) The amount to burn\n" + "\nExamples:\n" + + HelpExampleCli("burntoken", "\"a7be93b41e708d21d6c94920401ca5fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" 1000") ); @@ -1840,15 +1830,15 @@ UniValue sendtoken(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2) throw std::runtime_error( - "sendtoken \"tokenid\" \"destination\" amount\n" - "\nSends confidential tokens.\n" - + HelpRequiringPassphrase() + + "sendtoken \"tokenid\" \"destination\" amount\n" + "\nSends confidential tokens.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"tokenid\" (string, required) The token id\n" - "2. \"destination\" (string, required) The xNAV destination addressn" - "3. amount (string, required) The amount to mint\n" - "\nExamples:\n" - + HelpExampleCli("sendtoken", "\"a7be93fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" \"xNUNs2vtjr6QDL1NiL8TDHgmbuEo5WcY2K2jQ8ATj9pko8wkJ9RutkFQKBCtn6SsBjy6nK5ftofFyLFnAHAynreQCZjuE7dCWVxCX5DCFB2bjx87KvbqVVRCs3KBzdDre7c5FUy7QLo\" 1000") + "1. \"tokenid\" (string, required) The token id\n" + "2. \"destination\" (string, required) The xNAV destination addressn" + "3. amount (string, required) The amount to mint\n" + "\nExamples:\n" + + HelpExampleCli("sendtoken", "\"a7be93fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" \"xNUNs2vtjr6QDL1NiL8TDHgmbuEo5WcY2K2jQ8ATj9pko8wkJ9RutkFQKBCtn6SsBjy6nK5ftofFyLFnAHAynreQCZjuE7dCWVxCX5DCFB2bjx87KvbqVVRCs3KBzdDre7c5FUy7QLo\" 1000") ); @@ -1902,15 +1892,15 @@ UniValue sendnft(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2) throw std::runtime_error( - "sendnft \"tokenid\" \"nftid\" \"destination\"\n" - "\nSends nft.\n" - + HelpRequiringPassphrase() + + "sendnft \"tokenid\" \"nftid\" \"destination\"\n" + "\nSends nft.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"tokenid\" (string, required) The token id\n" - "2. \"nftid\" (int, required) The nft id\n" - "3. \"destination\" (string, required) The xNAV destination addressn" - "\nExamples:\n" - + HelpExampleCli("sendnft", "\"a7be93fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" 1 \"xNUNs2vtjr6QDL1NiL8TDHgmbuEo5WcY2K2jQ8ATj9pko8wkJ9RutkFQKBCtn6SsBjy6nK5ftofFyLFnAHAynreQCZjuE7dCWVxCX5DCFB2bjx87KvbqVVRCs3KBzdDre7c5FUy7QLo\"") + "1. \"tokenid\" (string, required) The token id\n" + "2. \"nftid\" (int, required) The nft id\n" + "3. \"destination\" (string, required) The xNAV destination addressn" + "\nExamples:\n" + + HelpExampleCli("sendnft", "\"a7be93fd93dffe33d2bc197077e3b4fafcc8fe45eebb359b4c8f6bc15a303cc2971a0c48\" 1 \"xNUNs2vtjr6QDL1NiL8TDHgmbuEo5WcY2K2jQ8ATj9pko8wkJ9RutkFQKBCtn6SsBjy6nK5ftofFyLFnAHAynreQCZjuE7dCWVxCX5DCFB2bjx87KvbqVVRCs3KBzdDre7c5FUy7QLo\"") ); @@ -1964,7 +1954,7 @@ UniValue getconsensusparameters(const UniValue& params, bool fHelp) "1. extended (bool, optional, default false) Show a more detailed output.\n" "\nReturns a list containing the current values of the consensus parameters which can be voted in the DAO.\n" - ); + ); LOCK(cs_main); CStateViewCache view(pcoinsTip); @@ -2005,18 +1995,18 @@ UniValue proposeconsensuschange(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2 || !params[0].isNum() || !params[1].isNum()) throw std::runtime_error( "proposeconsensuschange parameter value ( fee dump_raw )\n" - "\nCreates a proposal to the DAO for changing a consensus paremeter. Min fee of " + FormatMoney(nMinFee) + "NAV is required.\n" - + HelpRequiringPassphrase() + + "\nCreates a proposal to the DAO for changing a consensus paremeter. Min fee of " + FormatMoney(nMinFee) + "NAV is required.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. parameter (numeric, required) The parameter id as specified in the output of the getconsensusparameters rpc command.\n" - "2. value (numeric, optional) The proposed value.\n" - "3. fee (numeric, optional) Contribution to the fund used as fee.\n" - "4. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" - "\nResult:\n" - "\"{ hash: consultation_id,\" (string) The consultation id.\n" - "\" strDZeel: string }\" (string) The attached strdzeel property.\n" - "\nExamples:\n" - + HelpExampleCli("proposeconsensuschange", "1 10") + "1. parameter (numeric, required) The parameter id as specified in the output of the getconsensusparameters rpc command.\n" + "2. value (numeric, optional) The proposed value.\n" + "3. fee (numeric, optional) Contribution to the fund used as fee.\n" + "4. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" + "\nResult:\n" + "\"{ hash: consultation_id,\" (string) The consultation id.\n" + "\" strDZeel: string }\" (string) The attached strdzeel property.\n" + "\nExamples:\n" + + HelpExampleCli("proposeconsensuschange", "1 10") ); CNavcoinAddress address("NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ"); // Dummy address @@ -2102,18 +2092,18 @@ UniValue proposecombinedconsensuschange(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2) throw std::runtime_error( "proposecombinedconsensuschange parameters values ( fee dump_raw )\n" - "\nCreates a proposal to the DAO for changing various consensus paremeters.\n" - + HelpRequiringPassphrase() + + "\nCreates a proposal to the DAO for changing various consensus paremeters.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. parameter (array, required) The parameter ids as specified in the output of the getconsensusparameters rpc command.\n" - "2. value (array, optional) The proposed values.\n" - "3. fee (numeric, optional) Contribution to the fund used as fee.\n" - "4. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" - "\nResult:\n" - "\"{ hash: consultation_id,\" (string) The consultation id.\n" - "\" strDZeel: string }\" (string) The attached strdzeel property.\n" - "\nExamples:\n" - + HelpExampleCli("proposecombinedconsensuschange", "[1] [10]") + "1. parameter (array, required) The parameter ids as specified in the output of the getconsensusparameters rpc command.\n" + "2. value (array, optional) The proposed values.\n" + "3. fee (numeric, optional) Contribution to the fund used as fee.\n" + "4. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" + "\nResult:\n" + "\"{ hash: consultation_id,\" (string) The consultation id.\n" + "\" strDZeel: string }\" (string) The attached strdzeel property.\n" + "\nExamples:\n" + + HelpExampleCli("proposecombinedconsensuschange", "[1] [10]") ); if (!params[0].isArray() || !params[1].isArray()) @@ -2216,20 +2206,20 @@ UniValue createconsultation(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1) throw std::runtime_error( "createconsultation \"question\" ( min max range fee dump_raw )\n" - "\nCreates a consultation for the DAO. Min fee of " + FormatMoney(GetConsensusParameter(Consensus::CONSENSUS_PARAM_CONSULTATION_MIN_FEE, view)) + "NAV is required.\n" - + HelpRequiringPassphrase() + + "\nCreates a consultation for the DAO. Min fee of " + FormatMoney(GetConsensusParameter(Consensus::CONSENSUS_PARAM_CONSULTATION_MIN_FEE, view)) + "NAV is required.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"question\" (string, required) The question of the new consultation.\n" - "2. min (numeric, optional) The minimum amount for the range. Only used if range equals true.\n" - "3. max (numeric, optional) The maximum amount of answers a block can vote for.\n" - "4. range (bool, optional) The consultation answers are exclusively in the range min-max.\n" - "5. fee (numeric, optional) Contribution to the fund used as fee.\n" - "6. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" - "\nResult:\n" - "\"{ hash: consultation_id,\" (string) The consultation id.\n" - "\" strDZeel: string }\" (string) The attached strdzeel property.\n" - "\nExamples:\n" - + HelpExampleCli("createconsultation", "\"Who should be the CEO of Navcoin? /s\" 1 1") + "1. \"question\" (string, required) The question of the new consultation.\n" + "2. min (numeric, optional) The minimum amount for the range. Only used if range equals true.\n" + "3. max (numeric, optional) The maximum amount of answers a block can vote for.\n" + "4. range (bool, optional) The consultation answers are exclusively in the range min-max.\n" + "5. fee (numeric, optional) Contribution to the fund used as fee.\n" + "6. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" + "\nResult:\n" + "\"{ hash: consultation_id,\" (string) The consultation id.\n" + "\" strDZeel: string }\" (string) The attached strdzeel property.\n" + "\nExamples:\n" + + HelpExampleCli("createconsultation", "\"Who should be the CEO of Navcoin? /s\" 1 1") + HelpExampleCli("createconsultation", "\"How much should Navcoin's CEO earn per month? /s\" 1000 5000 true") ); @@ -2312,20 +2302,20 @@ UniValue createconsultationwithanswers(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2) throw std::runtime_error( "createconsultationwithanswers \"question\" \"[answers]\" ( maxanswers admitsanswerproposals fee dump_raw )\n" - "\nCreates a consultation for the DAO. Min fee of " + FormatMoney(GetConsensusParameter(Consensus::CONSENSUS_PARAM_CONSULTATION_MIN_FEE, view)) + "NAV is required.\n" - + HelpRequiringPassphrase() + + "\nCreates a consultation for the DAO. Min fee of " + FormatMoney(GetConsensusParameter(Consensus::CONSENSUS_PARAM_CONSULTATION_MIN_FEE, view)) + "NAV is required.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"question\" (string, required) The question of the new consultation.\n" - "2. \"[answers]\" (array of strings, required) An array of strings with the proposed answers.\n" - "3. maxanswers (numeric, optional) The maximum amount of answers a block can vote for at the same time.\n" - "4. admitsanswerproposals (bool, optional) Stakers are allowed to propose new answers.\n" - "5. fee (numeric, optional) Contribution to the fund used as fee.\n" - "6. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" - "\nResult:\n" - "\"{ hash: consultation_id,\" (string) The consultation id.\n" - "\" strDZeel: string }\" (string) The attached strdzeel property.\n" - "\nExamples:\n" - + HelpExampleCli("createconsultationwithanswers", "\"Who should be the CEO of Navcoin? /s\" \"[\\\"Craig Wright\\\",\\\"Loomdart\\\"]\"") + "1. \"question\" (string, required) The question of the new consultation.\n" + "2. \"[answers]\" (array of strings, required) An array of strings with the proposed answers.\n" + "3. maxanswers (numeric, optional) The maximum amount of answers a block can vote for at the same time.\n" + "4. admitsanswerproposals (bool, optional) Stakers are allowed to propose new answers.\n" + "5. fee (numeric, optional) Contribution to the fund used as fee.\n" + "6. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" + "\nResult:\n" + "\"{ hash: consultation_id,\" (string) The consultation id.\n" + "\" strDZeel: string }\" (string) The attached strdzeel property.\n" + "\nExamples:\n" + + HelpExampleCli("createconsultationwithanswers", "\"Who should be the CEO of Navcoin? /s\" \"[\\\"Craig Wright\\\",\\\"Loomdart\\\"]\"") ); CNavcoinAddress address("NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ"); // Dummy address @@ -2402,7 +2392,7 @@ std::string random_string( size_t length ) auto randchar = []() -> char { const char charset[] = - "0123456789" + "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; const size_t max_index = (sizeof(charset) - 1); @@ -2421,18 +2411,18 @@ UniValue createpaymentrequest(const UniValue& params, bool fHelp) if (fHelp || params.size() < 3) throw std::runtime_error( "createpaymentrequest \"hash\" \"amount\" \"id\" ( fee dump_raw )\n" - "\nCreates a proposal to withdraw funds from the community fund. Fee: 0.0001 NAV\n" - + HelpRequiringPassphrase() + + "\nCreates a proposal to withdraw funds from the community fund. Fee: 0.0001 NAV\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"hash\" (string, required) The hash of the proposal from which you want to withdraw funds. It must be approved.\n" - "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to withdraw. eg 10\n" - "3. \"id\" (string, required) Unique id to identify the payment request\n" - "4. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" - "\nResult:\n" - "\"{ hash: prequestid,\" (string) The payment request id.\n" - "\" strDZeel: string }\" (string) The attached strdzeel property.\n" - "\nExamples:\n" - + HelpExampleCli("createpaymentrequest", "\"196a4c2115d3c1c1dce1156eb2404ad77f3c5e9f668882c60cb98d638313dbd3\" 1000 \"Invoice March 2017\"") + "1. \"hash\" (string, required) The hash of the proposal from which you want to withdraw funds. It must be approved.\n" + "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to withdraw. eg 10\n" + "3. \"id\" (string, required) Unique id to identify the payment request\n" + "4. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" + "\nResult:\n" + "\"{ hash: prequestid,\" (string) The payment request id.\n" + "\" strDZeel: string }\" (string) The attached strdzeel property.\n" + "\nExamples:\n" + + HelpExampleCli("createpaymentrequest", "\"196a4c2115d3c1c1dce1156eb2404ad77f3c5e9f668882c60cb98d638313dbd3\" 1000 \"Invoice March 2017\"") ); if (!Params().GetConsensus().fDaoClientActivated) @@ -2477,8 +2467,8 @@ UniValue createpaymentrequest(const UniValue& params, bool fHelp) std::string sRandom = random_string(16); std::string Secret = sRandom + "I kindly ask to withdraw " + - std::to_string(nReqAmount) + "NAV from the proposal " + - proposal.hash.ToString() + ". Payment request id: " + id; + std::to_string(nReqAmount) + "NAV from the proposal " + + proposal.hash.ToString() + ". Payment request id: " + id; CHashWriter ss(SER_GETHASH, 0); ss << strMessageMagic; @@ -2557,18 +2547,18 @@ UniValue proposeanswer(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2) throw std::runtime_error( "proposeanswer \"hash\" \"answer\" ( fee dump_raw )\n" - "\nProposes an answer for an already existing consultation of the DAO. Min fee of " + FormatMoney(GetConsensusParameter(Consensus::CONSENSUS_PARAM_CONSULTATION_ANSWER_MIN_FEE, view)) + "NAV is required.\n" - + HelpRequiringPassphrase() + + "\nProposes an answer for an already existing consultation of the DAO. Min fee of " + FormatMoney(GetConsensusParameter(Consensus::CONSENSUS_PARAM_CONSULTATION_ANSWER_MIN_FEE, view)) + "NAV is required.\n" + + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"hash\" (string, required) The hash of the already existing consultation.\n" - "2. \"answer\" (string, required) The proposed answer.\n" - "3. fee (numeric, optional) Contribution to the fund used as fee.\n" - "4. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" - "\nResult:\n" - "\"{ hash: consultation_id,\" (string) The consultation id.\n" - "\" strDZeel: string }\" (string) The attached strdzeel property.\n" - "\nExamples:\n" - + HelpExampleCli("proposeanswer", "\"196a4c2115d3c1c1dce1156eb2404ad77f3c5e9f668882c60cb98d638313dbd3\" \"Vitalik Buterin\"") + "1. \"hash\" (string, required) The hash of the already existing consultation.\n" + "2. \"answer\" (string, required) The proposed answer.\n" + "3. fee (numeric, optional) Contribution to the fund used as fee.\n" + "4. dump_raw (bool, optional) Dump the raw transaction instead of sending. Default: false\n" + "\nResult:\n" + "\"{ hash: consultation_id,\" (string) The consultation id.\n" + "\" strDZeel: string }\" (string) The attached strdzeel property.\n" + "\nExamples:\n" + + HelpExampleCli("proposeanswer", "\"196a4c2115d3c1c1dce1156eb2404ad77f3c5e9f668882c60cb98d638313dbd3\" \"Vitalik Buterin\"") + HelpExampleCli("proposeanswer", "\"196a4c2115d3c1c1dce1156eb2404ad77f3c5e9f668882c60cb98d638313dbd3\" \"Satoshi Nakamoto\"") + HelpExampleCli("proposeanswer", "\"196a4c2115d3c1c1dce1156eb2404ad77f3c5e9f668882c60cb98d638313dbd3\" \"Charlie Lee\"") + HelpExampleCli("proposeanswer", "\"196a4c2115d3c1c1dce1156eb2404ad77f3c5e9f668882c60cb98d638313dbd3\" \"Riccardo Fluffypony\"") @@ -2678,11 +2668,11 @@ UniValue donatefund(const UniValue& params, bool fHelp) + HelpRequiringPassphrase() + "\nArguments:\n" "1. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to donate. eg 0.1\n" - "2. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n" - " The fund will receive less navcoins than you enter in the amount field.\n" - "\nResult:\n" - "\"transactionid\" (string) The transaction id.\n" - "\nExamples:\n" + "2. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n" + " The fund will receive less navcoins than you enter in the amount field.\n" + "\nResult:\n" + "\"transactionid\" (string) The transaction id.\n" + "\nExamples:\n" + HelpExampleCli("donatefund", "0.1") + HelpExampleCli("donatefund", "0.1 true") @@ -2726,13 +2716,13 @@ UniValue listaddressgroupings(const UniValue& params, bool fHelp) " [\n" " \"navcoinaddress\", (string) The navcoin address\n" " amount, (numeric) The amount in " + CURRENCY_UNIT + "\n" - " \"account\" (string, optional) The account (DEPRECATED)\n" - " ]\n" - " ,...\n" - " ]\n" - " ,...\n" - "]\n" - "\nExamples:\n" + " \"account\" (string, optional) The account (DEPRECATED)\n" + " ]\n" + " ,...\n" + " ]\n" + " ,...\n" + "]\n" + "\nExamples:\n" + HelpExampleCli("listaddressgroupings", "") + HelpExampleRpc("listaddressgroupings", "") ); @@ -2770,13 +2760,13 @@ UniValue signmessage(const UniValue& params, bool fHelp) "signmessage \"navcoinaddress\" \"message\"\n" "\nSign a message with the private key of an address" + HelpRequiringPassphrase() + "\n" - "\nArguments:\n" - "1. \"navcoinaddress\" (string, required) The navcoin address to use for the private key.\n" - "2. \"message\" (string, required) The message to create a signature of.\n" - "\nResult:\n" - "\"signature\" (string) The signature of the message encoded in base 64\n" - "\nExamples:\n" - "\nUnlock the wallet for 30 seconds\n" + "\nArguments:\n" + "1. \"navcoinaddress\" (string, required) The navcoin address to use for the private key.\n" + "2. \"message\" (string, required) The message to create a signature of.\n" + "\nResult:\n" + "\"signature\" (string) The signature of the message encoded in base 64\n" + "\nExamples:\n" + "\nUnlock the wallet for 30 seconds\n" + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + "\nCreate the signature\n" + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") + @@ -2830,8 +2820,8 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n" - "\nExamples:\n" - "\nThe amount from transactions with at least 1 confirmation\n" + "\nExamples:\n" + "\nThe amount from transactions with at least 1 confirmation\n" + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\"") + "\nThe amount including unconfirmed transactions, zero confirmations\n" + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" 0") + @@ -2888,8 +2878,8 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n" - "\nExamples:\n" - "\nAmount received by the default account with at least 1 confirmation\n" + "\nExamples:\n" + "\nAmount received by the default account with at least 1 confirmation\n" + HelpExampleCli("getreceivedbyaccount", "\"\"") + "\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n" + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") + @@ -2949,8 +2939,8 @@ UniValue getbalance(const UniValue& params, bool fHelp) "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n" - "\nExamples:\n" - "\nThe total amount in the wallet\n" + "\nExamples:\n" + "\nThe total amount in the wallet\n" + HelpExampleCli("getbalance", "") + "\nThe total amount in the wallet at least 5 blocks confirmed\n" + HelpExampleCli("getbalance", "\"*\" 6") + @@ -3037,12 +3027,12 @@ UniValue movecmd(const UniValue& params, bool fHelp) "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n" "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n" "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n" - "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" - "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n" - "\nResult:\n" - "true|false (boolean) true if successful.\n" - "\nExamples:\n" - "\nMove 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby\n" + "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" + "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n" + "\nResult:\n" + "true|false (boolean) true if successful.\n" + "\nExamples:\n" + "\nMove 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby\n" + HelpExampleCli("move", "\"\" \"tabby\" 0.01") + "\nMove 0.01 " + CURRENCY_UNIT + " timotei to akiko with a comment and funds have 6 confirmations\n" + HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") + @@ -3081,20 +3071,20 @@ UniValue sendfrom(const UniValue& params, bool fHelp) "sendfrom \"fromaccount\" \"tonavcoinaddress\" amount ( minconf \"comment\" \"comment-to\" )\n" "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a navcoin address." + HelpRequiringPassphrase() + "\n" - "\nArguments:\n" - "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n" - "2. \"tonavcoinaddress\" (string, required) The navcoin address to send funds to.\n" - "3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n" - "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" - "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" - " This is not part of the transaction, just kept in your wallet.\n" - "6. \"comment-to\" (string, optional) An optional comment to store the name of the person or organization \n" - " to which you're sending the transaction. This is not part of the transaction, \n" - " it is just kept in your wallet.\n" - "\nResult:\n" - "\"transactionid\" (string) The transaction id.\n" - "\nExamples:\n" - "\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n" + "\nArguments:\n" + "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n" + "2. \"tonavcoinaddress\" (string, required) The navcoin address to send funds to.\n" + "3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n" + "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" + "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" + " This is not part of the transaction, just kept in your wallet.\n" + "6. \"comment-to\" (string, optional) An optional comment to store the name of the person or organization \n" + " to which you're sending the transaction. This is not part of the transaction, \n" + " it is just kept in your wallet.\n" + "\nResult:\n" + "\"transactionid\" (string) The transaction id.\n" + "\nExamples:\n" + "\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n" + HelpExampleCli("sendfrom", "\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") + "\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n" + HelpExampleCli("sendfrom", "\"tabby\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 6 \"donation\" \"seans outpost\"") + @@ -3145,28 +3135,28 @@ UniValue sendmany(const UniValue& params, bool fHelp) "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] )\n" "\nSend multiple times. Amounts are double-precision floating point numbers." + HelpRequiringPassphrase() + "\n" - "\nArguments:\n" - "1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n" - "2. \"amounts\" (string, required) A json object with addresses and amounts\n" - " {\n" - " \"address\":amount (numeric or string) The navcoin address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value\n" - " ,...\n" - " }\n" - "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n" - "4. \"comment\" (string, optional) A comment\n" - "5. subtractfeefromamount (string, optional) A json array with addresses.\n" - " The fee will be equally deducted from the amount of each selected address.\n" - " Those recipients will receive less navcoins than you enter in their corresponding amount field.\n" - " If no addresses are specified here, the sender pays the fee.\n" - " [\n" - " \"address\" (string) Subtract fee from this address\n" - " ,...\n" - " ]\n" - "\nResult:\n" - "\"transactionid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n" - " the number of addresses.\n" - "\nExamples:\n" - "\nSend two amounts to two different addresses:\n" + "\nArguments:\n" + "1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n" + "2. \"amounts\" (string, required) A json object with addresses and amounts\n" + " {\n" + " \"address\":amount (numeric or string) The navcoin address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value\n" + " ,...\n" + " }\n" + "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n" + "4. \"comment\" (string, optional) A comment\n" + "5. subtractfeefromamount (string, optional) A json array with addresses.\n" + " The fee will be equally deducted from the amount of each selected address.\n" + " Those recipients will receive less navcoins than you enter in their corresponding amount field.\n" + " If no addresses are specified here, the sender pays the fee.\n" + " [\n" + " \"address\" (string) Subtract fee from this address\n" + " ,...\n" + " ]\n" + "\nResult:\n" + "\"transactionid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n" + " the number of addresses.\n" + "\nExamples:\n" + "\nSend two amounts to two different addresses:\n" + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"") + "\nSend two amounts to two different addresses setting the confirmation and comment:\n" + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 6 \"testing\"") + @@ -3338,28 +3328,28 @@ UniValue addmultisigaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2 || params.size() > 3) { std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n" - "\nAdd a nrequired-to-sign multisignature address to the wallet.\n" - "Each key is a Navcoin address or hex-encoded public key.\n" - "If 'account' is specified (DEPRECATED), assign address to that account.\n" - - "\nArguments:\n" - "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n" - "2. \"keysobject\" (string, required) A json array of navcoin addresses or hex-encoded public keys\n" - " [\n" - " \"address\" (string) navcoin address or hex-encoded public key\n" - " ...,\n" - " ]\n" - "3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n" - - "\nResult:\n" - "\"navcoinaddress\" (string) A navcoin address associated with the keys.\n" - - "\nExamples:\n" - "\nAdd a multisig address from 2 addresses\n" - + HelpExampleCli("addmultisigaddress", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + - "\nAs json rpc call\n" - + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") - ; + "\nAdd a nrequired-to-sign multisignature address to the wallet.\n" + "Each key is a Navcoin address or hex-encoded public key.\n" + "If 'account' is specified (DEPRECATED), assign address to that account.\n" + + "\nArguments:\n" + "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n" + "2. \"keysobject\" (string, required) A json array of navcoin addresses or hex-encoded public keys\n" + " [\n" + " \"address\" (string) navcoin address or hex-encoded public key\n" + " ...,\n" + " ]\n" + "3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n" + + "\nResult:\n" + "\"navcoinaddress\" (string) A navcoin address associated with the keys.\n" + + "\nExamples:\n" + "\nAdd a multisig address from 2 addresses\n" + + HelpExampleCli("addmultisigaddress", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + + "\nAs json rpc call\n" + + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + ; throw std::runtime_error(msg); } @@ -3380,46 +3370,46 @@ UniValue addmultisigaddress(const UniValue& params, bool fHelp) class Witnessifier : public boost::static_visitor { -public: - CScriptID result; + public: + CScriptID result; - bool operator()(const CNoDestination &dest) const { return false; } + bool operator()(const CNoDestination &dest) const { return false; } - bool operator()(const blsctDoublePublicKey &dest) const { return false; } + bool operator()(const blsctDoublePublicKey &dest) const { return false; } - bool operator()(const std::pair &dest) const { return false; } + bool operator()(const std::pair &dest) const { return false; } - bool operator()(const std::pair> &dest) const { return false; } + bool operator()(const std::pair> &dest) const { return false; } - bool operator()(const CKeyID &keyID) { - CPubKey pubkey; - if (pwalletMain && pwalletMain->GetPubKey(keyID, pubkey)) { - CScript basescript; - basescript << ToByteVector(pubkey) << OP_CHECKSIG; - CScript witscript = GetScriptForWitness(basescript); - pwalletMain->AddCScript(witscript); - result = CScriptID(witscript); - return true; + bool operator()(const CKeyID &keyID) { + CPubKey pubkey; + if (pwalletMain && pwalletMain->GetPubKey(keyID, pubkey)) { + CScript basescript; + basescript << ToByteVector(pubkey) << OP_CHECKSIG; + CScript witscript = GetScriptForWitness(basescript); + pwalletMain->AddCScript(witscript); + result = CScriptID(witscript); + return true; + } + return false; } - return false; - } - bool operator()(const CScriptID &scriptID) { - CScript subscript; - if (pwalletMain && pwalletMain->GetCScript(scriptID, subscript)) { - int witnessversion; - std::vector witprog; - if (subscript.IsWitnessProgram(witnessversion, witprog)) { - result = scriptID; + bool operator()(const CScriptID &scriptID) { + CScript subscript; + if (pwalletMain && pwalletMain->GetCScript(scriptID, subscript)) { + int witnessversion; + std::vector witprog; + if (subscript.IsWitnessProgram(witnessversion, witprog)) { + result = scriptID; + return true; + } + CScript witscript = GetScriptForWitness(subscript); + pwalletMain->AddCScript(witscript); + result = CScriptID(witscript); return true; } - CScript witscript = GetScriptForWitness(subscript); - pwalletMain->AddCScript(witscript); - result = CScriptID(witscript); - return true; + return false; } - return false; - } }; UniValue addwitnessaddress(const UniValue& params, bool fHelp) @@ -3430,16 +3420,16 @@ UniValue addwitnessaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 1) { std::string msg = "addwitnessaddress \"address\"\n" - "\nAdd a witness address for a script (with pubkey or redeemscript known).\n" - "It returns the witness script.\n" + "\nAdd a witness address for a script (with pubkey or redeemscript known).\n" + "It returns the witness script.\n" - "\nArguments:\n" - "1. \"address\" (string, required) An address known to the wallet\n" + "\nArguments:\n" + "1. \"address\" (string, required) An address known to the wallet\n" - "\nResult:\n" - "\"witnessaddress\", (string) The value of the new address (P2SH of witness script).\n" - "}\n" - ; + "\nResult:\n" + "\"witnessaddress\", (string) The value of the new address (P2SH of witness script).\n" + "}\n" + ; throw std::runtime_error(msg); } @@ -3626,13 +3616,13 @@ UniValue listreceivedbyaddress(const UniValue& params, bool fHelp) " \"address\" : \"receivingaddress\", (string) The receiving address\n" " \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n" " \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address\n" - " \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n" - " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" - " }\n" - " ,...\n" - "]\n" + " \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n" + " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" + " }\n" + " ,...\n" + "]\n" - "\nExamples:\n" + "\nExamples:\n" + HelpExampleCli("listreceivedbyaddress", "") + HelpExampleCli("listreceivedbyaddress", "6 true") + HelpExampleRpc("listreceivedbyaddress", "6, true, true") @@ -3716,9 +3706,9 @@ void GetReceived(const COutputEntry& r, const CWalletTx& wtx, const std::string& entry.pushKV("amount", ValueFromAmount(r.amount)); entry.pushKV("canStake", (::IsMine(*pwalletMain, r.destination) & ISMINE_STAKABLE || - (::IsMine(*pwalletMain, r.destination) & ISMINE_SPENDABLE && - !CNavcoinAddress(r.destination).IsColdStakingAddress(Params()) && - !CNavcoinAddress(r.destination).IsColdStakingv2Address(Params()))) ? true : false); + (::IsMine(*pwalletMain, r.destination) & ISMINE_SPENDABLE && + !CNavcoinAddress(r.destination).IsColdStakingAddress(Params()) && + !CNavcoinAddress(r.destination).IsColdStakingv2Address(Params()))) ? true : false); entry.pushKV("canSpend", ((::IsMine(*pwalletMain, r.destination) & ISMINE_SPENDABLE) || (pwalletMain->IsMine(wtx.vout[r.vout]) & ISMINE_SPENDABLE_PRIVATE)) ? true : false); if (pwalletMain->mapAddressBook.count(r.destination)) entry.pushKV("label", account); @@ -3826,37 +3816,37 @@ UniValue listtransactions(const UniValue& params, bool fHelp) " transaction id or block. 'send' and 'receive' transactions are \n" " associated with an address, transaction id and block details\n" " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the\n" - " 'move' category for moves outbound. It is positive for the 'receive' category,\n" - " and for the 'move' category for inbound funds.\n" - " \"vout\": n, (numeric) the vout value\n" - " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n" - " 'send' category of transactions.\n" - " \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable).\n" - " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n" - " 'receive' category of transactions. Negative confirmations indicate the\n" - " transaction conflicts with the block chain\n" - " \"trusted\": xxx (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n" - " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n" - " category of transactions.\n" - " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n" - " category of transactions.\n" - " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" - " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" - " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n" - " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n" - " for 'send' and 'receive' category of transactions.\n" - " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" - " \"label\": \"label\" (string) A comment for the address/transaction, if any\n" - " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n" - " from (for receiving funds, positive amounts), or went to (for sending funds,\n" - " negative amounts).\n" - " \"bip125-replaceable\": \"yes|no|unknown\" (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n" - " may be unknown for unconfirmed transactions not in the mempool\n" - " }\n" - "]\n" - - "\nExamples:\n" - "\nList the most recent 10 transactions in the systems\n" + " 'move' category for moves outbound. It is positive for the 'receive' category,\n" + " and for the 'move' category for inbound funds.\n" + " \"vout\": n, (numeric) the vout value\n" + " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n" + " 'send' category of transactions.\n" + " \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable).\n" + " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n" + " 'receive' category of transactions. Negative confirmations indicate the\n" + " transaction conflicts with the block chain\n" + " \"trusted\": xxx (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n" + " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n" + " category of transactions.\n" + " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n" + " category of transactions.\n" + " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" + " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" + " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n" + " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n" + " for 'send' and 'receive' category of transactions.\n" + " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" + " \"label\": \"label\" (string) A comment for the address/transaction, if any\n" + " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n" + " from (for receiving funds, positive amounts), or went to (for sending funds,\n" + " negative amounts).\n" + " \"bip125-replaceable\": \"yes|no|unknown\" (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n" + " may be unknown for unconfirmed transactions not in the mempool\n" + " }\n" + "]\n" + + "\nExamples:\n" + "\nList the most recent 10 transactions in the systems\n" + HelpExampleCli("listtransactions", "") + "\nList transactions 100 to 120\n" + HelpExampleCli("listtransactions", "\"*\" 20 100") + @@ -4029,23 +4019,23 @@ UniValue listsinceblock(const UniValue& params, bool fHelp) " \"address\":\"navcoinaddress\", (string) The navcoin address of the transaction. Not present for move transactions (category = move).\n" " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n" " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n" - " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n" - " \"vout\" : n, (numeric) the vout value\n" - " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n" - " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" - " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n" - " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions.\n" - " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" - " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" - " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n" - " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n" - " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" - " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" - " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n" - " ],\n" - " \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n" - "}\n" - "\nExamples:\n" + " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n" + " \"vout\" : n, (numeric) the vout value\n" + " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n" + " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" + " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n" + " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions.\n" + " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" + " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" + " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n" + " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n" + " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" + " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" + " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n" + " ],\n" + " \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n" + "}\n" + "\nExamples:\n" + HelpExampleCli("listsinceblock", "") + HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6") + HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6") @@ -4116,30 +4106,30 @@ UniValue gettransaction(const UniValue& params, bool fHelp) "\nResult:\n" "{\n" " \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n" - " \"confirmations\" : n, (numeric) The number of confirmations\n" - " \"blockhash\" : \"hash\", (string) The block hash\n" - " \"blockindex\" : xx, (numeric) The index of the transaction in the block that includes it\n" - " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n" - " \"txid\" : \"transactionid\", (string) The transaction id.\n" - " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n" - " \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n" - " \"bip125-replaceable\": \"yes|no|unknown\" (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n" - " may be unknown for unconfirmed transactions not in the mempool\n" - " \"details\" : [\n" - " {\n" - " \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n" - " \"address\" : \"navcoinaddress\", (string) The navcoin address involved in the transaction\n" - " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n" - " \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + "\n" - " \"label\" : \"label\", (string) A comment for the address/transaction, if any\n" - " \"vout\" : n, (numeric) the vout value\n" - " }\n" - " ,...\n" - " ],\n" - " \"hex\" : \"data\" (string) Raw data for transaction\n" - "}\n" - - "\nExamples:\n" + " \"confirmations\" : n, (numeric) The number of confirmations\n" + " \"blockhash\" : \"hash\", (string) The block hash\n" + " \"blockindex\" : xx, (numeric) The index of the transaction in the block that includes it\n" + " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n" + " \"txid\" : \"transactionid\", (string) The transaction id.\n" + " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n" + " \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n" + " \"bip125-replaceable\": \"yes|no|unknown\" (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n" + " may be unknown for unconfirmed transactions not in the mempool\n" + " \"details\" : [\n" + " {\n" + " \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n" + " \"address\" : \"navcoinaddress\", (string) The navcoin address involved in the transaction\n" + " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n" + " \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + "\n" + " \"label\" : \"label\", (string) A comment for the address/transaction, if any\n" + " \"vout\" : n, (numeric) the vout value\n" + " }\n" + " ,...\n" + " ],\n" + " \"hex\" : \"data\" (string) Raw data for transaction\n" + "}\n" + + "\nExamples:\n" + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true") + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") @@ -4255,9 +4245,9 @@ UniValue keypoolrefill(const UniValue& params, bool fHelp) "keypoolrefill ( newsize )\n" "\nFills the keypool." + HelpRequiringPassphrase() + "\n" - "\nArguments\n" - "1. newsize (numeric, optional, default=100) The new keypool size\n" - "\nExamples:\n" + "\nArguments\n" + "1. newsize (numeric, optional, default=100) The new keypool size\n" + "\nExamples:\n" + HelpExampleCli("keypoolrefill", "") + HelpExampleRpc("keypoolrefill", "") ); @@ -4511,17 +4501,17 @@ UniValue encrypttxdata(const UniValue& params, bool fHelp) if (fHelp || params.size() != 1) throw std::runtime_error( "encrypttxdata \"passphrase\"\n" - "\nEncrypts the wallet database using \"passphrase\", effectively encrypting your\n" - "transaction data and addressbook, you can also use this rpc command to change the\n" - "encryption \"passphrase\" of an already encrypted wallet database.\n" - "Note that this will shutdown the server.\n" - "\nArguments:\n" - "1. \"passphrase\" (string) The pass phrase to encrypt the wallet database with. It must be at least 1 character, but should be long.\n" - "\nExamples:\n" - "\nEncrypt you wallet\n" - + HelpExampleCli("encrypttxdata", "\"my pass phrase\"") + + "\nEncrypts the wallet database using \"passphrase\", effectively encrypting your\n" + "transaction data and addressbook, you can also use this rpc command to change the\n" + "encryption \"passphrase\" of an already encrypted wallet database.\n" + "Note that this will shutdown the server.\n" + "\nArguments:\n" + "1. \"passphrase\" (string) The pass phrase to encrypt the wallet database with. It must be at least 1 character, but should be long.\n" + "\nExamples:\n" + "\nEncrypt you wallet\n" + + HelpExampleCli("encrypttxdata", "\"my pass phrase\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("encrypttxdata", "\"my pass phrase\"") + + HelpExampleRpc("encrypttxdata", "\"my pass phrase\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4538,7 +4528,7 @@ UniValue encrypttxdata(const UniValue& params, bool fHelp) if (strWalletPass.length() < 1) throw std::runtime_error( "encrypttxdata \n" - "Encrypts the txdata with ."); + "Encrypts the txdata with ."); if (!pwalletMain->EncryptTx(strWalletPass)) throw JSONRPCError(RPC_TXDATA_ENCRYPTION_FAILED, "Error: Failed to encrypt the txdata."); @@ -4614,10 +4604,10 @@ UniValue lockunspent(const UniValue& params, bool fHelp) const UniValue& o = output.get_obj(); RPCTypeCheckObj(o, - { - {"txid", UniValueType(UniValue::VSTR)}, - {"vout", UniValueType(UniValue::VNUM)}, - }); + { + {"txid", UniValueType(UniValue::VSTR)}, + {"vout", UniValueType(UniValue::VNUM)}, + }); std::string txid = find_value(o, "txid").get_str(); if (!IsHex(txid)) @@ -4698,9 +4688,9 @@ UniValue settxfee(const UniValue& params, bool fHelp) "\nSet the transaction fee per kB. Overwrites the paytxfee parameter.\n" "\nArguments:\n" "1. amount (numeric or string, required) The transaction fee in " + CURRENCY_UNIT + "/kB\n" - "\nResult\n" - "true|false (boolean) Returns true if successful\n" - "\nExamples:\n" + "\nResult\n" + "true|false (boolean) Returns true if successful\n" + "\nExamples:\n" + HelpExampleCli("settxfee", "0.00001") + HelpExampleRpc("settxfee", "0.00001") ); @@ -4820,15 +4810,15 @@ UniValue listunspent(const UniValue& params, bool fHelp) " \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n" " \"scriptPubKey\" : \"key\", (string) the script key\n" " \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n" - " \"confirmations\" : n, (numeric) The number of confirmations\n" - " \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n" - " \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n" - " \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n" - " }\n" - " ,...\n" - "]\n" - - "\nExamples\n" + " \"confirmations\" : n, (numeric) The number of confirmations\n" + " \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n" + " \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n" + " \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n" + " }\n" + " ,...\n" + "]\n" + + "\nExamples\n" + HelpExampleCli("listunspent", "") + HelpExampleCli("listunspent", "6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"") + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"") @@ -4930,17 +4920,17 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp) " \"includeWatching\" (boolean, optional, default false) Also select inputs which are watch only\n" " \"lockUnspents\" (boolean, optional, default false) Lock selected unspent outputs\n" " \"feeRate\" (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate (" + CURRENCY_UNIT + " per KB)\n" - " }\n" - " for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n" - "\nResult:\n" - "{\n" - " \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n" - " \"fee\": n, (numeric) Fee in " + CURRENCY_UNIT + " the resulting transaction pays\n" - " \"changepos\": n (numeric) The position of the added change output, or -1\n" - "}\n" - "\"hex\" \n" - "\nExamples:\n" - "\nCreate a transaction with no inputs\n" + " }\n" + " for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n" + "\nResult:\n" + "{\n" + " \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n" + " \"fee\": n, (numeric) Fee in " + CURRENCY_UNIT + " the resulting transaction pays\n" + " \"changepos\": n (numeric) The position of the added change output, or -1\n" + "}\n" + "\"hex\" \n" + "\nExamples:\n" + "\nCreate a transaction with no inputs\n" + HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") + "\nAdd sufficient unsigned inputs to meet the output value\n" + HelpExampleCli("fundrawtransaction", "\"rawtransactionhex\"") + @@ -4971,15 +4961,15 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp) UniValue options = params[1]; RPCTypeCheckObj(options, - { - {"changeAddress", UniValueType(UniValue::VSTR)}, - {"changePosition", UniValueType(UniValue::VNUM)}, - {"includeWatching", UniValueType(UniValue::VBOOL)}, - {"lockUnspents", UniValueType(UniValue::VBOOL)}, - {"private", UniValueType(UniValue::VBOOL)}, - {"feeRate", UniValueType()}, // will be checked below - }, - true, true); + { + {"changeAddress", UniValueType(UniValue::VSTR)}, + {"changePosition", UniValueType(UniValue::VNUM)}, + {"includeWatching", UniValueType(UniValue::VBOOL)}, + {"lockUnspents", UniValueType(UniValue::VBOOL)}, + {"private", UniValueType(UniValue::VBOOL)}, + {"feeRate", UniValueType()}, // will be checked below + }, + true, true); if (options.exists("changeAddress")) { CNavcoinAddress address(options["changeAddress"].get_str()); @@ -5125,8 +5115,8 @@ int GetsStakeSubTotal(vStakeRange& vRange) // scan the entire wallet transactions for (std::map::const_iterator it = pwalletMain->mapWallet.begin(); - it != pwalletMain->mapWallet.end(); - ++it) + it != pwalletMain->mapWallet.end(); + ++it) { pcoin = &(*it).second; @@ -5280,8 +5270,8 @@ UniValue getstakereport(const UniValue& params, bool fHelp) vIt--; result.pushKV("Latest Time", - vIt->Start ? DateTimeStrFormat("%Y-%m-%d %H:%M:%S",vIt->Start).c_str() : - "Never"); + vIt->Start ? DateTimeStrFormat("%Y-%m-%d %H:%M:%S",vIt->Start).c_str() : + "Never"); // Moved nTook call down here to be more accurate nTook = GetTimeMillis() - nTook; @@ -5403,11 +5393,11 @@ UniValue support(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1) throw std::runtime_error( "support \"hash\" ( add )\n" - "\nShows support for the consultation or consultation answer identified by \"hash\".\n" - "\nArguments:\n" - "1. \"hash\" (string, required) The hash\n" - "2. \"add\" (bool, optional) Set to false to remove support (Default: true)\n" - ); + "\nShows support for the consultation or consultation answer identified by \"hash\".\n" + "\nArguments:\n" + "1. \"hash\" (string, required) The hash\n" + "2. \"add\" (bool, optional) Set to false to remove support (Default: true)\n" + ); LOCK(cs_main); @@ -5466,13 +5456,13 @@ UniValue consultationvote(const UniValue& params, bool fHelp) (strCommand != "yes" && strCommand != "value" && strCommand != "abs" && strCommand != "remove")) throw std::runtime_error( "consultationvote \"hash\" \"yes|value|abs|remove\" ( value )\n" - "\nArguments:\n" - "1. \"hash\" (string, required) The consultation/answer hash\n" - "2. \"command\" (string, required) 'yes' to vote yes, 'value' to vote for a range,\n" - " 'abs' to abstain, 'remove' to remove a vote from the list\n" - "3. \"value\" (integer, required) For consultations where the answer is a range,\n" - " this sets the value to vote for\n" - ); + "\nArguments:\n" + "1. \"hash\" (string, required) The consultation/answer hash\n" + "2. \"command\" (string, required) 'yes' to vote yes, 'value' to vote for a range,\n" + " 'abs' to abstain, 'remove' to remove a vote from the list\n" + "3. \"value\" (integer, required) For consultations where the answer is a range,\n" + " this sets the value to vote for\n" + ); LOCK(cs_main); @@ -5581,7 +5571,7 @@ UniValue supportlist(const UniValue& params, bool fHelp) "\nReturns a list containing the wallet's current support status for all active consultations.\n" - ); + ); LOCK(cs_main); @@ -5616,7 +5606,7 @@ UniValue consultationvotelist(const UniValue& params, bool fHelp) "\nReturns a list containing the wallet's current voting status for all active consultations.\n" - ); + ); LOCK(cs_main); @@ -5657,12 +5647,12 @@ UniValue proposalvote(const UniValue& params, bool fHelp) (strCommand != "yes" && strCommand != "no" && strCommand != "abs" && strCommand != "remove")) throw std::runtime_error( "proposalvote \"proposal_hash\" \"yes|no|abs|remove\"\n" - "\nAdds a proposal to the list of votes.\n" - "\nArguments:\n" - "1. \"proposal_hash\" (string, required) The proposal hash\n" - "2. \"command\" (string, required) 'yes' to vote yes, 'no' to vote no,\n" - " 'abs' to abstain, 'remove' to remove a proposal from the list\n" - ); + "\nAdds a proposal to the list of votes.\n" + "\nArguments:\n" + "1. \"proposal_hash\" (string, required) The proposal hash\n" + "2. \"command\" (string, required) 'yes' to vote yes, 'no' to vote no,\n" + " 'abs' to abstain, 'remove' to remove a proposal from the list\n" + ); LOCK(cs_main); @@ -5839,12 +5829,12 @@ UniValue paymentrequestvote(const UniValue& params, bool fHelp) (strCommand != "yes" && strCommand != "no" && strCommand != "abs" && strCommand != "remove")) throw std::runtime_error( "paymentrequestvote \"request_hash\" \"yes|no|abs|remove\"\n" - "\nAdds/removes a proposal to the list of votes.\n" - "\nArguments:\n" - "1. \"request_hash\" (string, required) The payment request hash\n" - "2. \"command\" (string, required) 'yes' to vote yes, 'no' to vote no,\n" - " 'abs' to abstain, 'remove' to remove a proposal from the list\n" - ); + "\nAdds/removes a proposal to the list of votes.\n" + "\nArguments:\n" + "1. \"request_hash\" (string, required) The payment request hash\n" + "2. \"command\" (string, required) 'yes' to vote yes, 'no' to vote no,\n" + " 'abs' to abstain, 'remove' to remove a proposal from the list\n" + ); LOCK(cs_main); @@ -5970,7 +5960,7 @@ UniValue listproposals(const UniValue& params, bool fHelp) if(showAll || (showMine && fIsMine) || (showPending && (fLastState == DAOFlags::NIL || fLastState == DAOFlags::PENDING_VOTING_PREQ - || fLastState == DAOFlags::PENDING_FUNDS)) + || fLastState == DAOFlags::PENDING_FUNDS)) || (showAccepted && (fLastState == DAOFlags::ACCEPTED)) || (showAcceptedExpired && (fLastState == DAOFlags::ACCEPTED_EXPIRED)) || (showRejected && (fLastState == DAOFlags::REJECTED)) @@ -6173,106 +6163,106 @@ extern UniValue removeprunedfunds(const UniValue& params, bool fHelp); static const CRPCCommand commands[] = { // category name actor (function) okSafeMode - // --------------------- ------------------------ ----------------------- ---------- - { "wallet", "getnewprivateaddress", &getnewprivateaddress, true }, - { "wallet", "listprivateunspent", &listprivateunspent, false }, - { "wallet", "privatesendtoaddress", &privatesendtoaddress, false }, - { "wallet", "privatesendmixtoaddress", &privatesendmixtoaddress, false }, - { "rawtransactions", "fundrawtransaction", &fundrawtransaction, false }, - { "hidden", "resendwallettransactions", &resendwallettransactions, true }, - { "wallet", "abandontransaction", &abandontransaction, false }, - { "wallet", "addmultisigaddress", &addmultisigaddress, true }, - { "wallet", "addwitnessaddress", &addwitnessaddress, true }, - { "wallet", "backupwallet", &backupwallet, true }, - { "wallet", "createrawscriptaddress", &createrawscriptaddress, true }, - { "wallet", "dumpprivkey", &dumpprivkey, true }, - { "wallet", "dumpmasterprivkey", &dumpmasterprivkey, true }, - { "wallet", "dumpmnemonic", &dumpmnemonic, true }, - { "wallet", "dumpwallet", &dumpwallet, true }, - { "wallet", "burntoken", &burntoken, true }, - { "wallet", "minttoken", &minttoken, true }, - { "wallet", "mintnft", &mintnft, true }, - { "wallet", "sendtoken", &sendtoken, true }, - { "wallet", "sendnft", &sendnft, true }, - { "wallet", "createtoken", &createtoken, true }, - { "wallet", "createnft", &createnft, true }, - { "wallet", "encryptwallet", &encryptwallet, true }, - { "wallet", "encrypttxdata", &encrypttxdata, true }, - { "wallet", "getaccountaddress", &getaccountaddress, true }, - { "wallet", "getaccount", &getaccount, true }, - { "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true }, - { "wallet", "listprivateaddresses", &listprivateaddresses, true }, - { "wallet", "listtokens", &listtokens, true }, - { "wallet", "listnames", &listnames, true }, - { "wallet", "gettoken", &gettoken, true }, - { "wallet", "getbalance", &getbalance, false }, - { "wallet", "getnewaddress", &getnewaddress, true }, - { "wallet", "getcoldstakingaddress", &getcoldstakingaddress, true }, - { "wallet", "getrawchangeaddress", &getrawchangeaddress, true }, - { "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false }, - { "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false }, - { "wallet", "getstakereport", &getstakereport, false }, - { "wallet", "gettransaction", &gettransaction, false }, - { "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false }, - { "wallet", "getwalletinfo", &getwalletinfo, false }, - { "wallet", "importprivkey", &importprivkey, true }, - { "wallet", "importwallet", &importwallet, true }, - { "wallet", "importaddress", &importaddress, true }, - { "wallet", "importprunedfunds", &importprunedfunds, true }, - { "wallet", "importpubkey", &importpubkey, true }, - { "wallet", "keypoolrefill", &keypoolrefill, true }, - { "wallet", "listaccounts", &listaccounts, false }, - { "wallet", "listaddressgroupings", &listaddressgroupings, false }, - { "wallet", "listlockunspent", &listlockunspent, false }, - { "wallet", "listreceivedbyaccount", &listreceivedbyaccount, false }, - { "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false }, - { "wallet", "listsinceblock", &listsinceblock, false }, - { "wallet", "listtransactions", &listtransactions, false }, - { "wallet", "listunspent", &listunspent, false }, - { "wallet", "lockunspent", &lockunspent, true }, - { "wallet", "move", &movecmd, false }, - { "wallet", "sendfrom", &sendfrom, false }, - { "wallet", "sendmany", &sendmany, false }, - { "wallet", "sendtoaddress", &sendtoaddress, false }, - { "communityfund", "donatefund", &donatefund, false }, - { "communityfund", "createpaymentrequest", &createpaymentrequest, false }, - { "communityfund", "createproposal", &createproposal, false }, - { "dao", "createconsultation", &createconsultation, false }, - { "dao", "createconsultationwithanswers", - &createconsultationwithanswers, - false }, - { "dao", "getstakervote", &getstakervote, false }, - { "dao", "proposeanswer", &proposeanswer, false }, - { "dao", "proposeconsensuschange", &proposeconsensuschange, false }, - { "dao", "proposecombinedconsensuschange", &proposecombinedconsensuschange, false }, - { "dao", "getconsensusparameters", &getconsensusparameters, false }, - { "dao", "setexclude", &setexclude, false }, - { "wallet", "stakervote", &stakervote, false }, - { "dao", "support", &support, false }, - { "dao", "supportlist", &supportlist, false }, - { "dao", "consultationvote", &consultationvote, false }, - { "dao", "consultationvotelist", &consultationvotelist, false }, - { "communityfund", "proposalvote", &proposalvote, false }, - { "communityfund", "proposalvotelist", &proposalvotelist, false }, - { "communityfund", "listproposals", &listproposals, true }, - { "communityfund", "paymentrequestvote", &paymentrequestvote, false }, - { "communityfund", "paymentrequestvotelist", &paymentrequestvotelist, false }, - { "communityfund", "proposalvote", &proposalvote, false }, - { "communityfund", "proposalvotelist", &proposalvotelist, false }, - { "wallet", "generateblsctkeys", &generateblsctkeys, true }, - { "wallet", "setaccount", &setaccount, true }, - { "wallet", "settxfee", &settxfee, true }, - { "wallet", "signmessage", &signmessage, true }, - { "wallet", "walletlock", &walletlock, true }, - { "wallet", "walletpassphrasechange", &walletpassphrasechange, true }, - { "wallet", "walletpassphrase", &walletpassphrase, true }, - { "wallet", "removeprunedfunds", &removeprunedfunds, true }, - { "wallet", "resolveopenalias", &resolveopenalias, true }, - { "dotnav", "registername", ®istername, true }, - { "dotnav", "renewname", &renewname, true }, - { "dotnav", "updatename", &updatename, true }, - { "dotnav", "resolvename", &resolvename, true }, - { "dotnav", "genkeyname", &genkeyname, true }, + // --------------------- ------------------------ ----------------------- ---------- + { "wallet", "getnewprivateaddress", &getnewprivateaddress, true }, + { "wallet", "listprivateunspent", &listprivateunspent, false }, + { "wallet", "privatesendtoaddress", &privatesendtoaddress, false }, + { "wallet", "privatesendmixtoaddress", &privatesendmixtoaddress, false }, + { "rawtransactions", "fundrawtransaction", &fundrawtransaction, false }, + { "hidden", "resendwallettransactions", &resendwallettransactions, true }, + { "wallet", "abandontransaction", &abandontransaction, false }, + { "wallet", "addmultisigaddress", &addmultisigaddress, true }, + { "wallet", "addwitnessaddress", &addwitnessaddress, true }, + { "wallet", "backupwallet", &backupwallet, true }, + { "wallet", "createrawscriptaddress", &createrawscriptaddress, true }, + { "wallet", "dumpprivkey", &dumpprivkey, true }, + { "wallet", "dumpmasterprivkey", &dumpmasterprivkey, true }, + { "wallet", "dumpmnemonic", &dumpmnemonic, true }, + { "wallet", "dumpwallet", &dumpwallet, true }, + { "wallet", "burntoken", &burntoken, true }, + { "wallet", "minttoken", &minttoken, true }, + { "wallet", "mintnft", &mintnft, true }, + { "wallet", "sendtoken", &sendtoken, true }, + { "wallet", "sendnft", &sendnft, true }, + { "wallet", "createtoken", &createtoken, true }, + { "wallet", "createnft", &createnft, true }, + { "wallet", "encryptwallet", &encryptwallet, true }, + { "wallet", "encrypttxdata", &encrypttxdata, true }, + { "wallet", "getaccountaddress", &getaccountaddress, true }, + { "wallet", "getaccount", &getaccount, true }, + { "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true }, + { "wallet", "listprivateaddresses", &listprivateaddresses, true }, + { "wallet", "listtokens", &listtokens, true }, + { "wallet", "listnames", &listnames, true }, + { "wallet", "gettoken", &gettoken, true }, + { "wallet", "getbalance", &getbalance, false }, + { "wallet", "getnewaddress", &getnewaddress, true }, + { "wallet", "getcoldstakingaddress", &getcoldstakingaddress, true }, + { "wallet", "getrawchangeaddress", &getrawchangeaddress, true }, + { "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false }, + { "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false }, + { "wallet", "getstakereport", &getstakereport, false }, + { "wallet", "gettransaction", &gettransaction, false }, + { "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false }, + { "wallet", "getwalletinfo", &getwalletinfo, false }, + { "wallet", "importprivkey", &importprivkey, true }, + { "wallet", "importwallet", &importwallet, true }, + { "wallet", "importaddress", &importaddress, true }, + { "wallet", "importprunedfunds", &importprunedfunds, true }, + { "wallet", "importpubkey", &importpubkey, true }, + { "wallet", "keypoolrefill", &keypoolrefill, true }, + { "wallet", "listaccounts", &listaccounts, false }, + { "wallet", "listaddressgroupings", &listaddressgroupings, false }, + { "wallet", "listlockunspent", &listlockunspent, false }, + { "wallet", "listreceivedbyaccount", &listreceivedbyaccount, false }, + { "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false }, + { "wallet", "listsinceblock", &listsinceblock, false }, + { "wallet", "listtransactions", &listtransactions, false }, + { "wallet", "listunspent", &listunspent, false }, + { "wallet", "lockunspent", &lockunspent, true }, + { "wallet", "move", &movecmd, false }, + { "wallet", "sendfrom", &sendfrom, false }, + { "wallet", "sendmany", &sendmany, false }, + { "wallet", "sendtoaddress", &sendtoaddress, false }, + { "communityfund", "donatefund", &donatefund, false }, + { "communityfund", "createpaymentrequest", &createpaymentrequest, false }, + { "communityfund", "createproposal", &createproposal, false }, + { "dao", "createconsultation", &createconsultation, false }, + { "dao", "createconsultationwithanswers", + &createconsultationwithanswers, + false }, + { "dao", "getstakervote", &getstakervote, false }, + { "dao", "proposeanswer", &proposeanswer, false }, + { "dao", "proposeconsensuschange", &proposeconsensuschange, false }, + { "dao", "proposecombinedconsensuschange", &proposecombinedconsensuschange, false }, + { "dao", "getconsensusparameters", &getconsensusparameters, false }, + { "dao", "setexclude", &setexclude, false }, + { "wallet", "stakervote", &stakervote, false }, + { "dao", "support", &support, false }, + { "dao", "supportlist", &supportlist, false }, + { "dao", "consultationvote", &consultationvote, false }, + { "dao", "consultationvotelist", &consultationvotelist, false }, + { "communityfund", "proposalvote", &proposalvote, false }, + { "communityfund", "proposalvotelist", &proposalvotelist, false }, + { "communityfund", "listproposals", &listproposals, true }, + { "communityfund", "paymentrequestvote", &paymentrequestvote, false }, + { "communityfund", "paymentrequestvotelist", &paymentrequestvotelist, false }, + { "communityfund", "proposalvote", &proposalvote, false }, + { "communityfund", "proposalvotelist", &proposalvotelist, false }, + { "wallet", "generateblsctkeys", &generateblsctkeys, true }, + { "wallet", "setaccount", &setaccount, true }, + { "wallet", "settxfee", &settxfee, true }, + { "wallet", "signmessage", &signmessage, true }, + { "wallet", "walletlock", &walletlock, true }, + { "wallet", "walletpassphrasechange", &walletpassphrasechange, true }, + { "wallet", "walletpassphrase", &walletpassphrase, true }, + { "wallet", "removeprunedfunds", &removeprunedfunds, true }, + { "wallet", "resolveopenalias", &resolveopenalias, true }, + { "dotnav", "registername", ®istername, true }, + { "dotnav", "renewname", &renewname, true }, + { "dotnav", "updatename", &updatename, true }, + { "dotnav", "resolvename", &resolvename, true }, + { "dotnav", "genkeyname", &genkeyname, true }, }; void RegisterWalletRPCCommands(CRPCTable &tableRPC) From ab5ca3789591a87509e3dde1e70c0d1106e12be5 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Sat, 5 Mar 2022 04:30:04 +0800 Subject: [PATCH 03/20] Added some stateview logic for caching names of name records --- src/Makefile.am | 1 + src/coins.cpp | 130 ++++++++++++++++++++++++++++++++++-- src/coins.h | 40 +++++++++-- src/dotnav/namerecordname.h | 57 ++++++++++++++++ 4 files changed, 219 insertions(+), 9 deletions(-) create mode 100644 src/dotnav/namerecordname.h diff --git a/src/Makefile.am b/src/Makefile.am index 2c9a61b91..0f263c27f 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -336,6 +336,7 @@ libnavcoin_consensus_a_SOURCES = \ ctokens/tokenid.h \ dotnav/namedata.h \ dotnav/namerecord.h \ + dotnav/namerecordname.h \ dotnav/names.h \ dotnav/names.cpp \ aes_helper.c \ diff --git a/src/coins.cpp b/src/coins.cpp index 33d6526ff..cf0db855d 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -54,6 +54,7 @@ bool CStateView::GetConsultationAnswer(const uint256 &cid, CConsultationAnswer& bool CStateView::GetConsensusParameter(const int &pid, CConsensusParameter& cparameter) const { return false; } bool CStateView::GetToken(const uint256 &id, TokenInfo& token) const { return false; } bool CStateView::GetNameRecord(const uint256 &id, NameRecordValue& height) const { return false; } +bool CStateView::GetNameRecordName(const uint256 &id, NameRecordNameValue& name) const { return false; } bool CStateView::GetNameData(const uint256 &id, NameDataValues& data) { return false; } bool CStateView::HaveCoins(const uint256 &txid) const { return false; } bool CStateView::HaveProposal(const uint256 &pid) const { return false; } @@ -64,6 +65,7 @@ bool CStateView::HaveConsultationAnswer(const uint256 &cid) const { return false bool CStateView::HaveConsensusParameter(const int &pid) const { return false; } bool CStateView::HaveToken(const uint256 &id) const { return false; } bool CStateView::HaveNameRecord(const uint256 &id) const { return false; } +bool CStateView::HaveNameRecordName(const uint256 &id) const { return false; } bool CStateView::HaveNameData(const uint256 &id) const { return false; } bool CStateView::GetAllProposals(CProposalMap& map) { return false; } int CStateView::GetExcludeVotes() const { return 0; } @@ -74,12 +76,13 @@ bool CStateView::GetAllConsultations(CConsultationMap& map) { return false; } bool CStateView::GetAllConsultationAnswers(CConsultationAnswerMap& map) { return false; } bool CStateView::GetAllTokens(TokenMap& map) { return false; } bool CStateView::GetAllNameRecords(NameRecordMap& map) { return false; } +bool CStateView::GetAllNameRecordNames(NameRecordNameMap& map) { return false; } uint256 CStateView::GetBestBlock() const { return uint256(); } bool CStateView::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, CConsultationMap& mapConsultations, CConsultationAnswerMap& mapAnswers, CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, - NameRecordMap& mapNameRecords, NameDataMap& mapNameData, + NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, const uint256 &hashBlock, const int& nCacheExcludeVotes) { return false; } CStateViewCursor *CStateView::Cursor() const { return 0; } @@ -93,6 +96,7 @@ bool CStateViewBacked::GetConsultationAnswer(const uint256 &cid, CConsultationAn bool CStateViewBacked::GetConsensusParameter(const int &pid, CConsensusParameter& cparameter) const { return base->GetConsensusParameter(pid, cparameter); } bool CStateViewBacked::GetToken(const uint256 &id, TokenInfo& token) const { return base->GetToken(id, token); } bool CStateViewBacked::GetNameRecord(const uint256 &id, NameRecordValue& height) const { return base->GetNameRecord(id, height); } +bool CStateViewBacked::GetNameRecordName(const uint256 &id, NameRecordNameValue& name) const { return base->GetNameRecordName(id, name); } bool CStateViewBacked::GetNameData(const uint256 &id, NameDataValues& data) { return base->GetNameData(id, data); } bool CStateViewBacked::HaveCoins(const uint256 &txid) const { return base->HaveCoins(txid); } bool CStateViewBacked::HaveProposal(const uint256 &pid) const { return base->HaveProposal(pid); } @@ -103,6 +107,7 @@ bool CStateViewBacked::HaveConsultationAnswer(const uint256 &cid) const { return bool CStateViewBacked::HaveConsensusParameter(const int &pid) const { return base->HaveConsensusParameter(pid); } bool CStateViewBacked::HaveToken(const uint256 &id) const { return base->HaveToken(id); } bool CStateViewBacked::HaveNameRecord(const uint256 &id) const { return base->HaveNameRecord(id); } +bool CStateViewBacked::HaveNameRecordName(const uint256 &id) const { return base->HaveNameRecordName(id); } bool CStateViewBacked::HaveNameData(const uint256 &id) const { return base->HaveNameData(id); } int CStateViewBacked::GetExcludeVotes() const { return base->GetExcludeVotes(); } bool CStateViewBacked::SetExcludeVotes(int count) { return base->SetExcludeVotes(count); } @@ -114,15 +119,16 @@ bool CStateViewBacked::GetAllConsultations(CConsultationMap& map) { return base- bool CStateViewBacked::GetAllConsultationAnswers(CConsultationAnswerMap& map) { return base->GetAllConsultationAnswers(map); } bool CStateViewBacked::GetAllTokens(TokenMap& map) { return base->GetAllTokens(map); } bool CStateViewBacked::GetAllNameRecords(NameRecordMap& map) { return base->GetAllNameRecords(map); } +bool CStateViewBacked::GetAllNameRecordNames(NameRecordNameMap& map) { return base->GetAllNameRecordNames(map); } uint256 CStateViewBacked::GetBestBlock() const { return base->GetBestBlock(); } void CStateViewBacked::SetBackend(CStateView &viewIn) { base = &viewIn; } bool CStateViewBacked::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, - NameRecordMap& mapNameRecords, NameDataMap& mapNameData, + NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, const uint256 &hashBlock, const int &nCacheExcludeVotes) { - return base->BatchWrite(mapCoins, mapProposals, mapPaymentRequests, mapVotes, mapConsultations, mapAnswers, mapConsensus, mapTokens, mapNameRecords, mapNameData, hashBlock, nCacheExcludeVotes); + return base->BatchWrite(mapCoins, mapProposals, mapPaymentRequests, mapVotes, mapConsultations, mapAnswers, mapConsensus, mapTokens, mapNameRecords, mapNameRecordNames, mapNameData, hashBlock, nCacheExcludeVotes); } CStateViewCursor *CStateViewBacked::Cursor() const { return base->Cursor(); } @@ -299,6 +305,23 @@ NameRecordMap::const_iterator CStateViewCache::FetchNameRecord(const uint256 &id return ret; } +NameRecordNameMap::const_iterator CStateViewCache::FetchNameRecordName(const uint256 &id) const { + NameRecordNameMap::iterator it = cacheNameRecordNames.find(id); + + if (it != cacheNameRecordNames.end()) + return it; + + NameRecordNameValue tmp; + + if (!base->GetNameRecordName(id, tmp) || tmp.IsNull()) + return cacheNameRecordNames.end(); + + NameRecordNameMap::iterator ret = cacheNameRecordNames.insert(std::make_pair(id, NameRecordNameValue())).first; + tmp.swap(ret->second); + + return ret; +} + NameDataMap::const_iterator CStateViewCache::FetchNameData(const uint256 &id) const { NameDataMap::iterator it = cacheNameData.find(id); @@ -399,6 +422,16 @@ bool CStateViewCache::GetNameRecord(const uint256 &id, NameRecordValue &height) return false; } +bool CStateViewCache::GetNameRecordName(const uint256 &id, NameRecordNameValue &name) const { + NameRecordNameMap::const_iterator it = FetchNameRecordName(id); + if (it != cacheNameRecordNames.end() && !it->second.IsNull()) { + height = it->second; + return true; + } + + return false; +} + bool CStateViewCache::GetNameData(const uint256 &id, NameDataValues &data) { NameDataMap::const_iterator it = FetchNameData(id); if (it != cacheNameData.end() && it->second.size() > 0) { @@ -494,6 +527,25 @@ bool CStateViewCache::GetAllNameRecords(NameRecordMap& mapNameRecords) { return true; } +bool CStateViewCache::GetAllNameRecordNames(NameRecordNameMap& mapNameRecordNames) { + mapNameRecordNames.clear(); + mapNameRecordNames.insert(cacheNameRecordNames.begin(), cacheNameRecordNames.end()); + + NameRecordNameMap baseMap; + + if (!base->GetAllNameRecordNames(baseMap)) + return false; + + for (NameRecordNameMap::iterator it = baseMap.begin(); it != baseMap.end(); it++) + if (!it->second.IsNull()) + mapNameRecordNames.insert(std::make_pair(it->first, it->second)); + + for (auto it = mapNameRecordNames.begin(); it != mapNameRecordNames.end();) + it->second == 0 ? mapNameRecordNames.erase(it++) : ++it; + + return true; +} + bool CStateViewCache::GetAllVotes(CVoteMap& mapVotes) { mapVotes.clear(); mapVotes.insert(cacheVotes.begin(), cacheVotes.end()); @@ -627,6 +679,17 @@ NameRecordModifier CStateViewCache::ModifyNameRecord(const uint256 &id, int nHei return NameRecordModifier(*this, ret.first, nHeight); } +NameRecordNameModifier CStateViewCache::ModifyNameRecordName(const uint256 &id, int nHeight) { + assert(!hasModifier); + std::pair ret = cacheNameRecordNames.insert(std::make_pair(id, 0)); + if (ret.second) { + if (!base->GetNameRecordName(id, ret.first->second)) { + ret.first->second = 0; + } + } + return NameRecordNameModifier(*this, ret.first, nHeight); +} + NameDataModifier CStateViewCache::ModifyNameData(const uint256 &id, int nHeight) { assert(!hasModifier); std::pair ret = cacheNameData.insert(std::make_pair(id, NameDataValues())); @@ -785,6 +848,18 @@ bool CStateViewCache::AddNameRecord(const NameRecord& namerecord) const { return true; } +bool CStateViewCache::AddNameRecordName(const NameRecordName& name) const { + if (HaveNameRecordName(name.first)) + return false; + + if (cacheNameRecordNames.count(name.first)) + cacheNameRecordNames[name.first]=name.second; + else + cacheNameRecordNames.insert(std::make_pair(name.first, name.second)); + + return true; +} + bool CStateViewCache::AddNameData(const uint256& id, const NameDataEntry& namerecord) const { if (cacheNameData.count(id)) { cacheNameData[id].erase( @@ -837,6 +912,17 @@ bool CStateViewCache::RemoveNameRecord(const uint256 &id) const { return true; } +bool CStateViewCache::RemoveNameRecordName(const uint256 &id) const { + if (!HaveNameRecordName(id)) + return false; + + cacheNameRecordNames[id] = NameRecordNameValue(); + + assert(cacheNameRecordNames[id].IsNull()); + + return true; +} + bool CStateViewCache::RemoveNameData(const NameDataKey &id) const { if (!HaveNameData(id.id)) return false; @@ -965,6 +1051,11 @@ bool CStateViewCache::HaveNameRecord(const uint256 &id) const { return (it != cacheNameRecords.end() && !it->second.IsNull()); } +bool CStateViewCache::HaveNameRecordName(const uint256 &id) const { + NameRecordNameMap::const_iterator it = FetchNameRecordName(id); + return (it != cacheNameRecordNames.end() && !it->second.IsNull()); +} + bool CStateViewCache::HaveNameData(const uint256 &id) const { NameDataMap::const_iterator it = FetchNameData(id); return (it != cacheNameData.end() && it->second.size()); @@ -1016,7 +1107,7 @@ void CStateViewCache::SetBestBlock(const uint256 &hashBlockIn) { bool CStateViewCache::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, CPaymentRequestMap &mapPaymentRequests, CVoteMap& mapVotes, CConsultationMap& mapConsultations, CConsultationAnswerMap& mapAnswers, - CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, NameRecordMap& mapNameRecords, + CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, const uint256 &hashBlockIn, const int &nCacheExcludeVotesIn) { assert(!hasModifier); assert(!hasModifierConsensus); @@ -1128,6 +1219,13 @@ bool CStateViewCache::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals mapNameRecords.erase(itOld); } + for (NameRecordNameMap::iterator it = mapNameRecordNames.begin(); it != mapNameRecordNames.end();) { + NameRecordNameValue& entry = cacheNameRecordNames[it->first]; + entry.swap(it->second); + NameRecordNameMap::iterator itOld = it++; + mapNameRecordNames.erase(itOld); + } + for (NameDataMap::iterator it = mapNameData.begin(); it != mapNameData.end();) { NameDataValues& entry = cacheNameData[it->first]; entry.swap(it->second); @@ -1141,7 +1239,7 @@ bool CStateViewCache::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals } bool CStateViewCache::Flush() { - bool fOk = base->BatchWrite(cacheCoins, cacheProposals, cachePaymentRequests, cacheVotes, cacheConsultations, cacheAnswers, cacheConsensus, cacheTokens, cacheNameRecords, cacheNameData, hashBlock, nCacheExcludeVotes); + bool fOk = base->BatchWrite(cacheCoins, cacheProposals, cachePaymentRequests, cacheVotes, cacheConsultations, cacheAnswers, cacheConsensus, cacheTokens, cacheNameRecords, cacheNameRecordNames, cacheNameData, hashBlock, nCacheExcludeVotes); cacheCoins.clear(); cacheProposals.clear(); cachePaymentRequests.clear(); @@ -1151,6 +1249,7 @@ bool CStateViewCache::Flush() { cacheConsensus.clear(); cacheTokens.clear(); cacheNameRecords.clear(); + cacheNameRecordNames.clear(); cacheNameData.clear(); cachedCoinsUsage = 0; nCacheExcludeVotes = -1; @@ -1403,6 +1502,12 @@ NameRecordModifier::NameRecordModifier(CStateViewCache& cache_, NameRecordMap::i prev = it->second; } +NameRecordNameModifier::NameRecordNameModifier(CStateViewCache& cache_, NameRecordNameMap::iterator it_, int height_) : cache(cache_), it(it_), height(height_) { + assert(!cache.hasModifier); + cache.hasModifier = true; + prev = it->second; +} + NameRecordModifier::~NameRecordModifier() { assert(cache.hasModifier); @@ -1418,6 +1523,21 @@ NameRecordModifier::~NameRecordModifier() } } +NameRecordNameModifier::~NameRecordNameModifier() +{ + assert(cache.hasModifier); + cache.hasModifier = false; + + if (it->second.IsNull()) { + cache.cacheNameRecordNames[it->first].SetNull(); + } + + if (!(prev == it->second)) + { + LogPrint("daoextra", "%s: Modified %sname record name %s\n", __func__, height>0?strprintf("at height %d ",height):"",it->first.ToString()); + } +} + NameDataModifier::NameDataModifier(CStateViewCache& cache_, NameDataMap::iterator it_, int height_) : cache(cache_), it(it_), height(height_) { assert(!cache.hasModifier); cache.hasModifier = true; diff --git a/src/coins.h b/src/coins.h index df5df0fcd..718d60f83 100644 --- a/src/coins.h +++ b/src/coins.h @@ -391,6 +391,10 @@ class CStateView virtual bool GetAllNameRecords(NameRecordMap& map); virtual bool HaveNameRecord(const uint256 &id) const; + virtual bool GetNameRecordName(const uint256 &id, NameRecordNameValue& name) const; + virtual bool GetAllNameRecordNames(NameRecordNameMap& map); + virtual bool HaveNameRecordName(const uint256 &id) const; + virtual bool GetNameData(const uint256& id, NameDataValues& data); virtual bool HaveNameData(const uint256& id) const; @@ -406,7 +410,7 @@ class CStateView CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, - NameRecordMap& mapNameRecords, NameDataMap& mapNameData, + NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, const uint256 &hashBlock, const int &nCacheExcludeVotes); //! Get a cursor to iterate over the whole state @@ -452,6 +456,10 @@ class CStateViewBacked : public CStateView bool GetAllNameRecords(NameRecordMap& map); bool HaveNameRecord(const uint256 &id) const; + bool GetNameRecordName(const uint256 &id, NameRecordNameValue& name) const; + bool GetAllNameRecords(NameRecordNameMap& map); + bool HaveNameRecordName(const uint256 &id) const; + bool GetNameData(const uint256 &id, NameDataValues& data); bool HaveNameData(const uint256 &id) const; @@ -464,7 +472,7 @@ class CStateViewBacked : public CStateView CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, - NameRecordMap& mapNameRecords, NameDataMap& mapNameData, + NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, const uint256 &hashBlock, const int &nCacheExcludeVotes); CStateViewCursor *Cursor() const; }; @@ -605,6 +613,22 @@ class NameRecordModifier friend class CStateViewCache; }; +class NameRecordNameModifier +{ +private: + CStateViewCache& cache; + NameRecordNameMap::iterator it; + NameRecordNameModifier(CStateViewCache& cache_, NameRecordNameMap::iterator it_, int height=0); + NameRecordNameValue prev; + int height; + +public: + NameRecordNameValue* operator->() { return &it->second; } + NameRecordNameValue& operator*() { return it->second; } + ~NameRecordNameModifier(); + friend class CStateViewCache; +}; + class NameDataModifier { private: @@ -659,6 +683,7 @@ class CStateViewCache : public CStateViewBacked mutable CConsensusParameterMap cacheConsensus; mutable TokenMap cacheTokens; mutable NameRecordMap cacheNameRecords; + mutable NameRecordNameMap cacheNameRecordNames; mutable NameDataMap cacheNameData; mutable int nCacheExcludeVotes; @@ -680,6 +705,7 @@ class CStateViewCache : public CStateViewBacked bool HaveConsensusParameter(const int& pid) const; bool HaveToken(const uint256& id) const; bool HaveNameRecord(const uint256& id) const; + bool HaveNameRecordName(const uint256& id) const; bool HaveNameData(const uint256& id) const; bool GetProposal(const uint256 &txid, CProposal &proposal) const; bool GetPaymentRequest(const uint256 &txid, CPaymentRequest &prequest) const; @@ -688,7 +714,7 @@ class CStateViewCache : public CStateViewBacked bool GetConsultationAnswer(const uint256 &cid, CConsultationAnswer& answer) const; bool GetConsensusParameter(const int& pid, CConsensusParameter& cparameter) const; bool GetToken(const uint256& pid, TokenInfo& token) const; - bool GetNameRecord(const uint256& pid, NameRecordValue& height) const; + bool GetNameRecordName(const uint256& pid, NameRecordNameValue& name) const; bool GetNameData(const uint256& pid, NameDataValues& data); bool GetAllProposals(CProposalMap& map); bool GetAllPaymentRequests(CPaymentRequestMap& map); @@ -697,6 +723,7 @@ class CStateViewCache : public CStateViewBacked bool GetAllConsultationAnswers(CConsultationAnswerMap& map); bool GetAllTokens(TokenMap& map); bool GetAllNameRecords(NameRecordMap& map); + bool GetAllNameRecordNames(NameRecordNameMap& map); bool GetAnswersForConsultation(CConsultationAnswerMap& map, const uint256& parent); uint256 GetBestBlock() const; void SetBestBlock(const uint256 &hashBlock); @@ -704,7 +731,7 @@ class CStateViewCache : public CStateViewBacked CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, - NameRecordMap& mapNameRecords, NameDataMap& mapNameData, + NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, const uint256 &hashBlockIn, const int &nCacheExcludeVotes); bool AddProposal(const CProposal& proposal) const; bool AddPaymentRequest(const CPaymentRequest& prequest) const; @@ -712,6 +739,7 @@ class CStateViewCache : public CStateViewBacked bool AddConsultation(const CConsultation& consultation) const; bool AddToken(const Token& token) const; bool AddNameRecord(const NameRecord& record) const; + bool AddNameRecordName(const NameRecordName& name) const; bool AddNameData(const uint256& id, const NameDataEntry& record) const; bool AddConsultationAnswer(const CConsultationAnswer& answer); bool RemoveProposal(const uint256 &pid) const; @@ -719,6 +747,7 @@ class CStateViewCache : public CStateViewBacked bool RemoveCachedVoter(const CVoteMapKey &voter) const; bool RemoveToken(const uint256 &pid) const; bool RemoveNameRecord(const uint256 &pid) const; + bool RemoveNameRecordName(const uint256 &id) const; bool RemoveNameData(const NameDataKey &id) const; bool RemoveConsultation(const uint256 &cid); bool RemoveConsultationAnswer(const uint256 &cid); @@ -757,6 +786,7 @@ class CStateViewCache : public CStateViewBacked CConsensusParameterModifier ModifyConsensusParameter(const int &pid, int nHeight = 0); TokenModifier ModifyToken(const uint256 &id, int nHeight = 0); NameRecordModifier ModifyNameRecord(const uint256 &id, int nHeight = 0); + NameRecordNameModifier ModifyNameRecordName(const uint256 &id, int nHeight = 0); NameDataModifier ModifyNameData(const uint256& id, int nHeight = 0); /** @@ -820,6 +850,7 @@ class CStateViewCache : public CStateViewBacked friend class CConsensusParameterModifier; friend class TokenModifier; friend class NameRecordModifier; + friend class NameRecordNameModifier; friend class NameDataModifier; private: @@ -833,6 +864,7 @@ class CStateViewCache : public CStateViewBacked CConsensusParameterMap::const_iterator FetchConsensusParameter(const int &pid) const; TokenMap::const_iterator FetchToken(const uint256 &id) const; NameRecordMap::const_iterator FetchNameRecord(const uint256 &id) const; + NameRecordNameMap::const_iterator FetchNameRecordName(const uint256 &id) const; NameDataMap::const_iterator FetchNameData(const uint256 &id) const; /** diff --git a/src/dotnav/namerecordname.h b/src/dotnav/namerecordname.h new file mode 100644 index 000000000..0d2897d7e --- /dev/null +++ b/src/dotnav/namerecordname.h @@ -0,0 +1,57 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2015 The Bitcoin Core developers +// Copyright (c) 2021 The Navcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef NAVCOIN_NAME_RECORD_NAME_H +#define NAVCOIN_NAME_RECORD_NAME_H + +#include + +class NameRecordNameValue { +public: + std::string domain; + std::string subdomain; + + NameRecordNameValue() { + SetNull(); + } + + NameRecordNameValue(const std::string domain_, const std::string subdomain_) { + domain = domain_; + subdomain = subdomain_; + }; + + void SetNull() { + domain = ""; + subdomain = ""; + } + + bool IsNull() const { + return domain == ""; + } + + bool operator==(const NameRecordNameValue& other) { + return (domain == other.domain && subdomain == other.subdomain); + } + + void swap(NameRecordNameValue &to) { + std::swap(to.domain, domain); + std::swap(to.subdomain, subdomain); + } + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(domain); + READWRITE(subdomain); + } +}; + +typedef std::map NameRecordNameMap; +typedef std::pair NameRecordName; + + +#endif // NAVCOIN_NAME_RECORD_NAME_H From 4e587d351d7b5348ce98b01918b4affcf190e713 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Sat, 5 Mar 2022 06:47:52 +0800 Subject: [PATCH 04/20] Added some stateview logic for caching names of name records --- src/coins.cpp | 8 ++++---- src/coins.h | 12 +++++++----- src/txdb.cpp | 28 ++++++++++++++++++++++++++++ src/txdb.h | 1 + src/wallet/rpcwallet.cpp | 32 +++++++++++++++++++------------- 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index cf0db855d..a3160e87b 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -425,7 +425,7 @@ bool CStateViewCache::GetNameRecord(const uint256 &id, NameRecordValue &height) bool CStateViewCache::GetNameRecordName(const uint256 &id, NameRecordNameValue &name) const { NameRecordNameMap::const_iterator it = FetchNameRecordName(id); if (it != cacheNameRecordNames.end() && !it->second.IsNull()) { - height = it->second; + name = it->second; return true; } @@ -541,7 +541,7 @@ bool CStateViewCache::GetAllNameRecordNames(NameRecordNameMap& mapNameRecordName mapNameRecordNames.insert(std::make_pair(it->first, it->second)); for (auto it = mapNameRecordNames.begin(); it != mapNameRecordNames.end();) - it->second == 0 ? mapNameRecordNames.erase(it++) : ++it; + it->second.IsNull() ? mapNameRecordNames.erase(it++) : ++it; return true; } @@ -681,10 +681,10 @@ NameRecordModifier CStateViewCache::ModifyNameRecord(const uint256 &id, int nHei NameRecordNameModifier CStateViewCache::ModifyNameRecordName(const uint256 &id, int nHeight) { assert(!hasModifier); - std::pair ret = cacheNameRecordNames.insert(std::make_pair(id, 0)); + std::pair ret = cacheNameRecordNames.insert(std::make_pair(id, NameRecordNameValue())); if (ret.second) { if (!base->GetNameRecordName(id, ret.first->second)) { - ret.first->second = 0; + ret.first->second.SetNull(); } } return NameRecordNameModifier(*this, ret.first, nHeight); diff --git a/src/coins.h b/src/coins.h index 718d60f83..e5fe88a9c 100644 --- a/src/coins.h +++ b/src/coins.h @@ -13,10 +13,11 @@ #include #include -#include "consensus/dao.h" -#include "ctokens/ctokens.h" -#include "dotnav/namerecord.h" -#include "dotnav/namedata.h" +#include +#include +#include +#include +#include #include #include @@ -457,7 +458,7 @@ class CStateViewBacked : public CStateView bool HaveNameRecord(const uint256 &id) const; bool GetNameRecordName(const uint256 &id, NameRecordNameValue& name) const; - bool GetAllNameRecords(NameRecordNameMap& map); + bool GetAllNameRecordNames(NameRecordNameMap& map); bool HaveNameRecordName(const uint256 &id) const; bool GetNameData(const uint256 &id, NameDataValues& data); @@ -714,6 +715,7 @@ class CStateViewCache : public CStateViewBacked bool GetConsultationAnswer(const uint256 &cid, CConsultationAnswer& answer) const; bool GetConsensusParameter(const int& pid, CConsensusParameter& cparameter) const; bool GetToken(const uint256& pid, TokenInfo& token) const; + bool GetNameRecord(const uint256& pid, NameRecordValue& height) const; bool GetNameRecordName(const uint256& pid, NameRecordNameValue& name) const; bool GetNameData(const uint256& pid, NameDataValues& data); bool GetAllProposals(CProposalMap& map); diff --git a/src/txdb.cpp b/src/txdb.cpp index 35bf1e2dd..ff0f0815f 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -41,6 +41,7 @@ static const char DB_EXCLUDE_VOTES = 'X'; static const char DB_TOKENS = 'T'; static const char DB_NAME_RECORDS = 'n'; +static const char DB_NAME_RECORD_NAMES = 'm'; static const char DB_NAME_DATA = 'N'; CStateViewDB::CStateViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe, true, false, 64) @@ -219,6 +220,7 @@ bool CStateViewDB::GetNameData(const uint256& id, NameDataValues& map) { return true; } + bool CStateViewDB::GetAllNameRecords(NameRecordMap &map) { map.clear(); @@ -245,6 +247,32 @@ bool CStateViewDB::GetAllNameRecords(NameRecordMap &map) { return true; } +bool CStateViewDB::GetAllNameRecordNames(NameRecordNameMap &map) { + map.clear(); + + boost::scoped_ptr pcursor(db.NewIterator()); + + pcursor->Seek(std::make_pair(DB_NAME_RECORD_NAMES, uint256())); + + while (pcursor->Valid()) { + boost::this_thread::interruption_point(); + std::pair key; + if (pcursor->GetKey(key) && key.first == DB_NAME_RECORD_NAMES) { + NameRecordNameValue name; + if (pcursor->GetValue(name)) { + map.insert(std::make_pair(key.second, name)); + pcursor->Next(); + } else { + return error("GetAllNameRecordNames() : failed to read value"); + } + } else { + break; + } + } + + return true; +} + bool CStateViewDB::GetAllPaymentRequests(CPaymentRequestMap &map) { map.clear(); diff --git a/src/txdb.h b/src/txdb.h index c84528c5c..9abbc0875 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -135,6 +135,7 @@ class CStateViewDB : public CStateView bool GetAllConsultationAnswers(CConsultationAnswerMap &map); bool GetAllTokens(TokenMap &map); bool GetAllNameRecords(NameRecordMap &map); + bool GetAllNameRecordNames(NameRecordNameMap &map); int GetExcludeVotes() const; CStateViewCursor *Cursor() const; }; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 18182459e..3f9e861ac 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5995,19 +5995,25 @@ UniValue listnames(const UniValue& params, bool fHelp) if (params.size() == 1 && !params[0].isBool()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, argument 1 must be a boolean"); - UniValue ret(UniValue::VARR); - /* NameRecordMap mapNames; */ - /* CStateViewCache view(pcoinsTip); */ - - /* if(view.GetAllNameRecords(mapTokens)) */ - /* { */ - /* for (NameRecordMap::iterator it = mapNames.begin(); it != mapNames.end(); it++) */ - /* { */ - /* NameRecordValue nameRecord; */ - /* if (!view.GetNameRecord(it->first, nameRecord)) */ - /* continue; */ - /* } */ - /* } */ + NameRecordNameMap mapNames; + CStateViewCache view(pcoinsTip); + + if(view.GetAllNameRecordNames(mapNames)) + { + for (NameRecordNameMap::iterator it = mapNames.begin(); it != mapNames.end(); it++) + { + NameRecordNameValue name; + if (!view.GetNameRecordName(it->first, name)) + continue; + + std::string finalName = name.domain + ".nav"; + + if (name.subdomain != "") + finalName = name.subdomain + "." + finalName; + + LogPrint("token", "%s: finalName %s\n", __func__, finalName); + } + } return ret; } From e32d6891aca2bbb540c329abc6c1db381619c0ef Mon Sep 17 00:00:00 2001 From: mxaddict Date: Sat, 5 Mar 2022 10:24:54 +0800 Subject: [PATCH 05/20] Added BatchWrite support for namerecordname --- src/coins.cpp | 3 --- src/dotnav/namerecordname.h | 2 +- src/main.cpp | 2 ++ src/txdb.cpp | 12 +++++++++++- src/txdb.h | 2 +- src/wallet/rpcwallet.cpp | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index a3160e87b..98f9eb246 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -849,9 +849,6 @@ bool CStateViewCache::AddNameRecord(const NameRecord& namerecord) const { } bool CStateViewCache::AddNameRecordName(const NameRecordName& name) const { - if (HaveNameRecordName(name.first)) - return false; - if (cacheNameRecordNames.count(name.first)) cacheNameRecordNames[name.first]=name.second; else diff --git a/src/dotnav/namerecordname.h b/src/dotnav/namerecordname.h index 0d2897d7e..9e33391b5 100644 --- a/src/dotnav/namerecordname.h +++ b/src/dotnav/namerecordname.h @@ -18,7 +18,7 @@ class NameRecordNameValue { SetNull(); } - NameRecordNameValue(const std::string domain_, const std::string subdomain_) { + NameRecordNameValue(const std::string& domain_, const std::string& subdomain_) { domain = domain_; subdomain = subdomain_; }; diff --git a/src/main.cpp b/src/main.cpp index 99e5db517..e6b68cab6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4907,6 +4907,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, false, REJECT_INVALID, strprintf("could-not-verify-written-data:%s", program.sParameters[0])); } + view.AddNameRecordName(std::make_pair(DotNav::GetHashName(program.sParameters[0]), NameRecordNameValue(program.sParameters[0], program.sParameters[1]))); + LogPrint("dotnav", "%s: updated name first %s %s %s %s\n", __func__, program.sParameters[1], program.sParameters[0], program.sParameters[2], program.sParameters[3]); } else if (program.action == RENEW_NAME) { if (!(vout.scriptPubKey.IsCommunityFundContribution() && vout.nValue >= GetConsensusParameter(Consensus::CONSENSUS_PARAM_NAVNS_FEE, view))) diff --git a/src/txdb.cpp b/src/txdb.cpp index ff0f0815f..6fbfee983 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -381,7 +381,7 @@ bool CStateViewDB::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, CConsensusParameterMap &mapConsensus, - TokenMap &mapTokens, NameRecordMap &mapNameRecords, + TokenMap &mapTokens, NameRecordMap &mapNameRecords, NameRecordNameMap &mapNameRecordNames, NameDataMap& mapNameData, const uint256 &hashBlock, const int &nExcludeVotes) { @@ -496,6 +496,16 @@ bool CStateViewDB::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, mapNameRecords.erase(itOld); } + for (NameRecordNameMap::iterator it = mapNameRecordNames.begin(); it != mapNameRecordNames.end();) { + if (it->second.IsNull()) { + batch.Erase(std::make_pair(DB_NAME_RECORD_NAMES, it->first)); + } else { + batch.Write(std::make_pair(DB_NAME_RECORD_NAMES, it->first), it->second); + } + NameRecordNameMap::iterator itOld = it++; + mapNameRecordNames.erase(itOld); + } + for (NameDataMap::iterator it = mapNameData.begin(); it != mapNameData.end();) { if (it->second.size() == 0) { batch.Erase(std::make_pair(DB_NAME_DATA, it->first)); diff --git a/src/txdb.h b/src/txdb.h index 9abbc0875..0032550fd 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -126,7 +126,7 @@ class CStateViewDB : public CStateView CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, - NameRecordMap& mapNameRecords, NameDataMap& mapNameData, + NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, const uint256 &hashBlock, const int &nExcludeVotes); bool GetAllProposals(CProposalMap& map); bool GetAllPaymentRequests(CPaymentRequestMap& map); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3f9e861ac..2de0547a6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6011,7 +6011,7 @@ UniValue listnames(const UniValue& params, bool fHelp) if (name.subdomain != "") finalName = name.subdomain + "." + finalName; - LogPrint("token", "%s: finalName %s\n", __func__, finalName); + LogPrint("dotnav", "%s: finalName %s\n", __func__, finalName); } } From 391d256e1e9adcf4c27d06e0f31d05a783eb499e Mon Sep 17 00:00:00 2001 From: mxaddict Date: Sat, 5 Mar 2022 13:19:00 +0800 Subject: [PATCH 06/20] Updates --- src/coins.cpp | 22 +++++++++++++++++++++- src/main.cpp | 1 + src/txdb.cpp | 1 + src/wallet/rpcwallet.cpp | 12 ++++-------- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 98f9eb246..1234ac7c7 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -531,18 +531,33 @@ bool CStateViewCache::GetAllNameRecordNames(NameRecordNameMap& mapNameRecordName mapNameRecordNames.clear(); mapNameRecordNames.insert(cacheNameRecordNames.begin(), cacheNameRecordNames.end()); + LogPrint("dotnav", "%s: first\n", __func__); + for (auto& i: mapNameRecordNames) { + LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, i.second.domain, i.second.subdomain); + } + NameRecordNameMap baseMap; if (!base->GetAllNameRecordNames(baseMap)) return false; - for (NameRecordNameMap::iterator it = baseMap.begin(); it != baseMap.end(); it++) + LogPrint("dotnav", "%s: second\n", __func__); + for (auto& i: baseMap) { + LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, i.second.domain, i.second.subdomain); + } + + for (auto it = baseMap.begin(); it != baseMap.end(); it++) if (!it->second.IsNull()) mapNameRecordNames.insert(std::make_pair(it->first, it->second)); for (auto it = mapNameRecordNames.begin(); it != mapNameRecordNames.end();) it->second.IsNull() ? mapNameRecordNames.erase(it++) : ++it; + LogPrint("dotnav", "%s: third\n", __func__); + for (auto& i: mapNameRecordNames) { + LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, i.second.domain, i.second.subdomain); + } + return true; } @@ -849,11 +864,16 @@ bool CStateViewCache::AddNameRecord(const NameRecord& namerecord) const { } bool CStateViewCache::AddNameRecordName(const NameRecordName& name) const { + LogPrint("dotnav", "%s: CALLED!!!\n", __func__); if (cacheNameRecordNames.count(name.first)) cacheNameRecordNames[name.first]=name.second; else cacheNameRecordNames.insert(std::make_pair(name.first, name.second)); + for (auto& i: cacheNameRecordNames) { + LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, i.second.domain, i.second.subdomain); + } + return true; } diff --git a/src/main.cpp b/src/main.cpp index e6b68cab6..f7f22772d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4907,6 +4907,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, false, REJECT_INVALID, strprintf("could-not-verify-written-data:%s", program.sParameters[0])); } + LogPrint("dotnav", "%s: AddNameRecordName() called!!!\n", __func__); view.AddNameRecordName(std::make_pair(DotNav::GetHashName(program.sParameters[0]), NameRecordNameValue(program.sParameters[0], program.sParameters[1]))); LogPrint("dotnav", "%s: updated name first %s %s %s %s\n", __func__, program.sParameters[1], program.sParameters[0], program.sParameters[2], program.sParameters[3]); diff --git a/src/txdb.cpp b/src/txdb.cpp index 6fbfee983..07e060e09 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -497,6 +497,7 @@ bool CStateViewDB::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, } for (NameRecordNameMap::iterator it = mapNameRecordNames.begin(); it != mapNameRecordNames.end();) { + LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, it->second.domain, it->second.subdomain); if (it->second.IsNull()) { batch.Erase(std::make_pair(DB_NAME_RECORD_NAMES, it->first)); } else { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2de0547a6..38e9c5160 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6002,16 +6002,12 @@ UniValue listnames(const UniValue& params, bool fHelp) { for (NameRecordNameMap::iterator it = mapNames.begin(); it != mapNames.end(); it++) { - NameRecordNameValue name; - if (!view.GetNameRecordName(it->first, name)) - continue; - - std::string finalName = name.domain + ".nav"; + std::string finalName = it->second.domain; - if (name.subdomain != "") - finalName = name.subdomain + "." + finalName; + if (it->second.subdomain != "") + finalName = it->second.subdomain + "." + finalName; - LogPrint("dotnav", "%s: finalName %s\n", __func__, finalName); + ret.push_back(finalName); } } From 292766912acdb0399720c87d98647f2c068c6338 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Sat, 5 Mar 2022 13:26:10 +0800 Subject: [PATCH 07/20] Updates --- src/coins.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 1234ac7c7..18a0fa3c1 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -527,36 +527,23 @@ bool CStateViewCache::GetAllNameRecords(NameRecordMap& mapNameRecords) { return true; } -bool CStateViewCache::GetAllNameRecordNames(NameRecordNameMap& mapNameRecordNames) { - mapNameRecordNames.clear(); - mapNameRecordNames.insert(cacheNameRecordNames.begin(), cacheNameRecordNames.end()); +bool CStateViewCache::GetAllNameRecordNames(NameRecordNameMap& map) { + map.clear(); + map.insert(cacheNameRecordNames.begin(), cacheNameRecordNames.end()); LogPrint("dotnav", "%s: first\n", __func__); - for (auto& i: mapNameRecordNames) { - LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, i.second.domain, i.second.subdomain); - } NameRecordNameMap baseMap; if (!base->GetAllNameRecordNames(baseMap)) return false; - LogPrint("dotnav", "%s: second\n", __func__); - for (auto& i: baseMap) { - LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, i.second.domain, i.second.subdomain); - } - for (auto it = baseMap.begin(); it != baseMap.end(); it++) if (!it->second.IsNull()) - mapNameRecordNames.insert(std::make_pair(it->first, it->second)); - - for (auto it = mapNameRecordNames.begin(); it != mapNameRecordNames.end();) - it->second.IsNull() ? mapNameRecordNames.erase(it++) : ++it; + map.insert(std::make_pair(it->first, it->second)); - LogPrint("dotnav", "%s: third\n", __func__); - for (auto& i: mapNameRecordNames) { - LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, i.second.domain, i.second.subdomain); - } + for (auto it = map.begin(); it != map.end();) + it->second.IsNull() ? map.erase(it++) : ++it; return true; } From d9ba894efca66b22e7b64de99e1dcbedb7e3b208 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Mon, 7 Mar 2022 23:17:49 +0800 Subject: [PATCH 08/20] Updates --- src/main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f7f22772d..f07872633 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2991,6 +2991,9 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI } else if (program.action == UPDATE_NAME_FIRST || program.action == UPDATE_NAME || program.action == RENEW_NAME) { view.RemoveNameData(NameDataKey(program.sParameters[0], pindex->nHeight)); LogPrint("dotnav", "%s: removing name data for %s %d\n", __func__, program.sParameters[0], pindex->nHeight); + + if (!view.HaveNameData(DotNav::GetHashName(program.sParameters[0]))) + view.RemoveNameRecordName(DotNav::GetHashName(program.sParameters[0])); } } } catch(...) { @@ -4907,9 +4910,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, false, REJECT_INVALID, strprintf("could-not-verify-written-data:%s", program.sParameters[0])); } - LogPrint("dotnav", "%s: AddNameRecordName() called!!!\n", __func__); - view.AddNameRecordName(std::make_pair(DotNav::GetHashName(program.sParameters[0]), NameRecordNameValue(program.sParameters[0], program.sParameters[1]))); - LogPrint("dotnav", "%s: updated name first %s %s %s %s\n", __func__, program.sParameters[1], program.sParameters[0], program.sParameters[2], program.sParameters[3]); } else if (program.action == RENEW_NAME) { if (!(vout.scriptPubKey.IsCommunityFundContribution() && vout.nValue >= GetConsensusParameter(Consensus::CONSENSUS_PARAM_NAVNS_FEE, view))) @@ -4972,6 +4972,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("dotnav", "%s: updated name %s %s %s %s\n", __func__, program.sParameters[1], program.sParameters[0], program.sParameters[2], program.sParameters[3]); } + + if (program.action == UPDATE_NAME_FIRST || program.action == UPDATE_NAME || program.action == RENEW_NAME) { + if (!view.HaveNameRecordName(DotNav::GetHashName(program.sParameters[0]))) + view.AddNameRecordName(std::make_pair(DotNav::GetHashName(program.sParameters[0]), NameRecordNameValue(program.sParameters[0], program.sParameters[1]))); + } } } catch(...) { return state.DoS(100, false, REJECT_INVALID, "error-program-vdata"); From 455710a51f14f406f29acaf689984d96c4025592 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Thu, 10 Mar 2022 10:05:30 +0800 Subject: [PATCH 09/20] Updated the BatchWrite calls to be multiline --- src/coins.cpp | 98 ++++++++++++++++++++++++++++++++-------- src/coins.h | 63 ++++++++++++++++++-------- src/test/coins_tests.cpp | 13 ++++-- src/txdb.cpp | 24 ++++++---- src/txdb.h | 21 ++++++--- 5 files changed, 164 insertions(+), 55 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index db7b0e76c..c806949d9 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -80,12 +80,22 @@ bool CStateView::GetAllTokens(TokenMap& map) { return false; } bool CStateView::GetAllNameRecords(NameRecordMap& map) { return false; } bool CStateView::GetAllNameRecordNames(NameRecordNameMap& map) { return false; } uint256 CStateView::GetBestBlock() const { return uint256(); } -bool CStateView::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, - CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, - CConsultationMap& mapConsultations, CConsultationAnswerMap& mapAnswers, - CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, TokenUtxoMap& mapTokenUtxos, - NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, - const uint256 &hashBlock, const int& nCacheExcludeVotes) { return false; } +bool CStateView::BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap &mapVotes, + CConsultationMap& mapConsultations, + CConsultationAnswerMap& mapAnswers, + CConsensusParameterMap& mapConsensus, + TokenMap& mapTokens, + TokenUtxoMap& mapTokenUtxos, + NameRecordMap& mapNameRecords, + NameRecordNameMap& mapNameRecordNames, + NameDataMap& mapNameData, + const uint256 &hashBlock, + const int& nCacheExcludeVotes) +{ return false; } CStateViewCursor *CStateView::Cursor() const { return 0; } @@ -126,13 +136,37 @@ bool CStateViewBacked::GetAllNameRecords(NameRecordMap& map) { return base->GetA bool CStateViewBacked::GetAllNameRecordNames(NameRecordNameMap& map) { return base->GetAllNameRecordNames(map); } uint256 CStateViewBacked::GetBestBlock() const { return base->GetBestBlock(); } void CStateViewBacked::SetBackend(CStateView &viewIn) { base = &viewIn; } -bool CStateViewBacked::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, - CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, - CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, - CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, TokenUtxoMap& mapTokenUtxos, - NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, - const uint256 &hashBlock, const int &nCacheExcludeVotes) { - return base->BatchWrite(mapCoins, mapProposals, mapPaymentRequests, mapVotes, mapConsultations, mapAnswers, mapConsensus, mapTokens, mapTokenUtxos, mapNameRecords, mapNameRecordNames, mapNameData, hashBlock, nCacheExcludeVotes); +bool CStateViewBacked::BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap &mapVotes, + CConsultationMap &mapConsultations, + CConsultationAnswerMap &mapAnswers, + CConsensusParameterMap& mapConsensus, + TokenMap& mapTokens, + TokenUtxoMap& mapTokenUtxos, + NameRecordMap& mapNameRecords, + NameRecordNameMap& mapNameRecordNames, + NameDataMap& mapNameData, + const uint256 &hashBlock, + const int &nCacheExcludeVotes) +{ + return base->BatchWrite( + mapCoins, + mapProposals, + mapPaymentRequests, + mapVotes, + mapConsultations, + mapAnswers, + mapConsensus, + mapTokens, + mapTokenUtxos, + mapNameRecords, + mapNameRecordNames, + mapNameData, + hashBlock, + nCacheExcludeVotes); } CStateViewCursor *CStateViewBacked::Cursor() const { return base->Cursor(); } @@ -1192,11 +1226,22 @@ void CStateViewCache::SetBestBlock(const uint256 &hashBlockIn) { hashBlock = hashBlockIn; } -bool CStateViewCache::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, CPaymentRequestMap &mapPaymentRequests, - CVoteMap& mapVotes, CConsultationMap& mapConsultations, CConsultationAnswerMap& mapAnswers, - CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, TokenUtxoMap& mapTokenUtxos, - NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, - NameDataMap& mapNameData, const uint256 &hashBlockIn, const int &nCacheExcludeVotesIn) { +bool CStateViewCache::BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap& mapVotes, + CConsultationMap& mapConsultations, + CConsultationAnswerMap& mapAnswers, + CConsensusParameterMap& mapConsensus, + TokenMap& mapTokens, + TokenUtxoMap& mapTokenUtxos, + NameRecordMap& mapNameRecords, + NameRecordNameMap& mapNameRecordNames, + NameDataMap& mapNameData, + const uint256 &hashBlockIn, + const int &nCacheExcludeVotesIn) +{ assert(!hasModifier); assert(!hasModifierConsensus); for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { @@ -1334,7 +1379,22 @@ bool CStateViewCache::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals } bool CStateViewCache::Flush() { - bool fOk = base->BatchWrite(cacheCoins, cacheProposals, cachePaymentRequests, cacheVotes, cacheConsultations, cacheAnswers, cacheConsensus, cacheTokens, cacheTokenUtxos, cacheNameRecords, cacheNameRecordNames, cacheNameData, hashBlock, nCacheExcludeVotes); + bool fOk = base->BatchWrite( + cacheCoins, + cacheProposals, + cachePaymentRequests, + cacheVotes, + cacheConsultations, + cacheAnswers, + cacheConsensus, + cacheTokens, + cacheTokenUtxos, + cacheNameRecords, + cacheNameRecordNames, + cacheNameData, + hashBlock, + nCacheExcludeVotes + ); cacheCoins.clear(); cacheProposals.clear(); cachePaymentRequests.clear(); diff --git a/src/coins.h b/src/coins.h index 04f3f9b78..aa4b01b49 100644 --- a/src/coins.h +++ b/src/coins.h @@ -412,12 +412,21 @@ class CStateView //! Do a bulk modification (multiple CCoins changes + BestBlock change). //! The passed mapCoins can be modified. - virtual bool BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, - CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, - CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, - CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, TokenUtxoMap& mapTokenUtxos, - NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, - const uint256 &hashBlock, const int &nCacheExcludeVotes); + virtual bool BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap &mapVotes, + CConsultationMap &mapConsultations, + CConsultationAnswerMap &mapAnswers, + CConsensusParameterMap& mapConsensus, + TokenMap& mapTokens, + TokenUtxoMap& mapTokenUtxos, + NameRecordMap& mapNameRecords, + NameRecordNameMap& mapNameRecordNames, + NameDataMap& mapNameData, + const uint256 &hashBlock, + const int &nCacheExcludeVotes); //! Get a cursor to iterate over the whole state virtual CStateViewCursor *Cursor() const; @@ -477,12 +486,21 @@ class CStateViewBacked : public CStateView uint256 GetBestBlock() const; void SetBackend(CStateView &viewIn); - bool BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, - CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, - CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, - CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, TokenUtxoMap& mapTokenUtxos, - NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, - const uint256 &hashBlock, const int &nCacheExcludeVotes); + bool BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap &mapVotes, + CConsultationMap &mapConsultations, + CConsultationAnswerMap &mapAnswers, + CConsensusParameterMap& mapConsensus, + TokenMap& mapTokens, + TokenUtxoMap& mapTokenUtxos, + NameRecordMap& mapNameRecords, + NameRecordNameMap& mapNameRecordNames, + NameDataMap& mapNameData, + const uint256 &hashBlock, + const int &nCacheExcludeVotes); CStateViewCursor *Cursor() const; }; @@ -756,12 +774,21 @@ class CStateViewCache : public CStateViewBacked bool GetAnswersForConsultation(CConsultationAnswerMap& map, const uint256& parent); uint256 GetBestBlock() const; void SetBestBlock(const uint256 &hashBlock); - bool BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, - CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, - CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, - CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, TokenUtxoMap& mapTokenUtxos, - NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, - const uint256 &hashBlockIn, const int &nCacheExcludeVotes); + bool BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap &mapVotes, + CConsultationMap &mapConsultations, + CConsultationAnswerMap &mapAnswers, + CConsensusParameterMap& mapConsensus, + TokenMap& mapTokens, + TokenUtxoMap& mapTokenUtxos, + NameRecordMap& mapNameRecords, + NameRecordNameMap& mapNameRecordNames, + NameDataMap& mapNameData, + const uint256 &hashBlockIn, + const int &nCacheExcludeVotes); bool AddProposal(const CProposal& proposal) const; bool AddPaymentRequest(const CPaymentRequest& prequest) const; bool AddCachedVoter(const CVoteMapKey &voter, CVoteMapValue& vote) const; diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 71d4dffde..3d25051a7 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -48,10 +48,15 @@ class CStateViewTest : public CStateView uint256 GetBestBlock() const { return hashBestBlock_; } - bool BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, - CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, - CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, - CConsensusParameterMap& mapConsensus, const uint256 &hashBlock) + bool BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap &mapVotes, + CConsultationMap &mapConsultations, + CConsultationAnswerMap &mapAnswers, + CConsensusParameterMap& mapConsensus, + const uint256 &hashBlock) { for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) { if (it->second.flags & CCoinsCacheEntry::DIRTY) { diff --git a/src/txdb.cpp b/src/txdb.cpp index 5e4b42add..e11c9878f 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -412,14 +412,22 @@ bool CStateViewDB::GetAllConsultationAnswers(CConsultationAnswerMap &map) { return true; } -bool CStateViewDB::BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, - CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, - CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, - CConsensusParameterMap &mapConsensus, - TokenMap &mapTokens, TokenUtxoMap &mapTokenUtxos, - NameRecordMap &mapNameRecords, NameRecordNameMap &mapNameRecordNames, - NameDataMap& mapNameData, - const uint256 &hashBlock, const int &nExcludeVotes) { +bool CStateViewDB::BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap &mapVotes, + CConsultationMap &mapConsultations, + CConsultationAnswerMap &mapAnswers, + CConsensusParameterMap &mapConsensus, + TokenMap &mapTokens, + TokenUtxoMap &mapTokenUtxos, + NameRecordMap &mapNameRecords, + NameRecordNameMap &mapNameRecordNames, + NameDataMap& mapNameData, + const uint256 &hashBlock, + const int &nExcludeVotes) +{ CDBBatch batch(db); size_t count = 0; diff --git a/src/txdb.h b/src/txdb.h index a15f2b0b4..f5c4befc5 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -124,12 +124,21 @@ class CStateViewDB : public CStateView bool HaveNameData(const uint256& id) const; uint256 GetBestBlock() const; - bool BatchWrite(CCoinsMap &mapCoins, CProposalMap &mapProposals, - CPaymentRequestMap &mapPaymentRequests, CVoteMap &mapVotes, - CConsultationMap &mapConsultations, CConsultationAnswerMap &mapAnswers, - CConsensusParameterMap& mapConsensus, TokenMap& mapTokens, TokenUtxoMap &mapTokenUtxos, - NameRecordMap& mapNameRecords, NameRecordNameMap& mapNameRecordNames, NameDataMap& mapNameData, - const uint256 &hashBlock, const int &nExcludeVotes); + bool BatchWrite( + CCoinsMap &mapCoins, + CProposalMap &mapProposals, + CPaymentRequestMap &mapPaymentRequests, + CVoteMap &mapVotes, + CConsultationMap &mapConsultations, + CConsultationAnswerMap &mapAnswers, + CConsensusParameterMap& mapConsensus, + TokenMap& mapTokens, + TokenUtxoMap &mapTokenUtxos, + NameRecordMap& mapNameRecords, + NameRecordNameMap& mapNameRecordNames, + NameDataMap& mapNameData, + const uint256 &hashBlock, + const int &nExcludeVotes); bool GetAllProposals(CProposalMap& map); bool GetAllPaymentRequests(CPaymentRequestMap& map); bool GetAllVotes(CVoteMap &map); From 832257bdda2f7f55b87f55dc3d5c286bf492017e Mon Sep 17 00:00:00 2001 From: mxaddict Date: Fri, 11 Mar 2022 21:33:52 +0800 Subject: [PATCH 10/20] Added -nameindex flag --- src/init.cpp | 6 ++++++ src/main.cpp | 26 ++++++++++++++++++++------ src/main.h | 1 + 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 8ed2f530f..5b8ac2d8f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1636,6 +1636,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler, const std break; } + // Check for changed -nameindex state + if (fNftIndex != GetBoolArg("-nameindex", DEFAULT_NAMEINDEX)) { + strLoadError = _("You need to rebuild the database using -reindex-chainstate to change -nameindex"); + break; + } + // Check for changed -addressindex state if (fAddressIndex != GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) { strLoadError = _("You need to rebuild the database using -reindex-chainstate to change -addressindex"); diff --git a/src/main.cpp b/src/main.cpp index 65c2ad662..a2e250d9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,6 +79,7 @@ bool fReindex = false; bool fVerifyChain = false; bool fTxIndex = false; bool fNftIndex = false; +bool fNameIndex = false; bool fAddressIndex = false; bool fTimestampIndex = false; bool fSpentIndex = false; @@ -2994,8 +2995,10 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI view.RemoveNameData(NameDataKey(program.sParameters[0], pindex->nHeight)); LogPrint("dotnav", "%s: removing name data for %s %d\n", __func__, program.sParameters[0], pindex->nHeight); - if (!view.HaveNameData(DotNav::GetHashName(program.sParameters[0]))) - view.RemoveNameRecordName(DotNav::GetHashName(program.sParameters[0])); + if (fNameIndex) { + if (!view.HaveNameData(DotNav::GetHashName(program.sParameters[0]))) + view.RemoveNameRecordName(DotNav::GetHashName(program.sParameters[0])); + } } } } catch(...) { @@ -4999,9 +5002,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("dotnav", "%s: updated name %s %s %s %s\n", __func__, program.sParameters[1], program.sParameters[0], program.sParameters[2], program.sParameters[3]); } - if (program.action == UPDATE_NAME_FIRST || program.action == UPDATE_NAME || program.action == RENEW_NAME) { - if (!view.HaveNameRecordName(DotNav::GetHashName(program.sParameters[0]))) - view.AddNameRecordName(std::make_pair(DotNav::GetHashName(program.sParameters[0]), NameRecordNameValue(program.sParameters[0], program.sParameters[1]))); + if (fNameIndex) { + if (program.action == UPDATE_NAME_FIRST || program.action == UPDATE_NAME || program.action == RENEW_NAME) { + if (!view.HaveNameRecordName(DotNav::GetHashName(program.sParameters[0]))) + view.AddNameRecordName(std::make_pair(DotNav::GetHashName(program.sParameters[0]), NameRecordNameValue(program.sParameters[0], program.sParameters[1]))); + } } } } catch(...) { @@ -7360,6 +7365,10 @@ bool static LoadBlockIndexDB() pblocktree->ReadFlag("nftindex", fNftIndex); LogPrintf("%s: nft index %s\n", __func__, fNftIndex ? "enabled" : "disabled"); + // Check whether we have a name index + pblocktree->ReadFlag("nameindex", fNameIndex); + LogPrintf("%s: name index %s\n", __func__, fNameIndex ? "enabled" : "disabled"); + // Check whether we have an address index pblocktree->ReadFlag("addressindex", fAddressIndex); LogPrintf("%s: address index %s\n", __func__, fAddressIndex ? "enabled" : "disabled"); @@ -7784,6 +7793,7 @@ bool InitBlockIndex(const CChainParams& chainparams) // Load the flag values | use DEFAULT_* values if not set fTxIndex = GetBoolArg("-txindex", DEFAULT_TXINDEX); fNftIndex = GetBoolArg("-nftindex", DEFAULT_NFTINDEX); + fNameIndex = GetBoolArg("-nameindex", DEFAULT_NAMEINDEX); fAddressIndex = GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX); fTimestampIndex = GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX); fSpentIndex = GetBoolArg("-spentindex", DEFAULT_SPENTINDEX); @@ -7791,7 +7801,7 @@ bool InitBlockIndex(const CChainParams& chainparams) // Check if we want all indexes if (GetBoolArg("-allindex", DEFAULT_ALLINDEX)) { - fTxIndex = fNftIndex = fAddressIndex = fTimestampIndex = fSpentIndex = true; + fTxIndex = fNftIndex = fNameIndex = fAddressIndex = fTimestampIndex = fSpentIndex = true; } // Use the provided setting for -txindex in the new database @@ -7802,6 +7812,10 @@ bool InitBlockIndex(const CChainParams& chainparams) pblocktree->WriteFlag("nftindex", fNftIndex); LogPrintf("%s: nft index %s\n", __func__, fNftIndex ? "enabled" : "disabled"); + // Use the provided setting for -nameindex in the new database + pblocktree->WriteFlag("nameindex", fNameIndex); + LogPrintf("%s: name index %s\n", __func__, fNameIndex ? "enabled" : "disabled"); + // Use the provided setting for -addressindex in the new database pblocktree->WriteFlag("addressindex", fAddressIndex); LogPrintf("%s: address index %s\n", __func__, fAddressIndex ? "enabled" : "disabled"); diff --git a/src/main.h b/src/main.h index 094392880..15782be6a 100644 --- a/src/main.h +++ b/src/main.h @@ -206,6 +206,7 @@ extern bool fVerifyChain; extern int nScriptCheckThreads; extern bool fTxIndex; extern bool fNftIndex; +extern bool fNameIndex; extern bool fAddressIndex; extern bool fSpentIndex; extern bool fTimestampIndex; From 61fa02a5c9df9340c7f50ec87ef281408bae55c4 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Fri, 11 Mar 2022 21:37:19 +0800 Subject: [PATCH 11/20] Added -nameindex flag default value --- src/main.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.h b/src/main.h index 15782be6a..3410ab242 100644 --- a/src/main.h +++ b/src/main.h @@ -148,6 +148,7 @@ static const bool DEFAULT_CHECKPOINTS_ENABLED = true; static const bool DEFAULT_ALLINDEX = false; static const bool DEFAULT_TXINDEX = false; static const bool DEFAULT_NFTINDEX = false; +static const bool DEFAULT_NAMEINDEX = false; static const bool DEFAULT_ADDRESSINDEX = false; static const bool DEFAULT_TIMESTAMPINDEX = false; static const bool DEFAULT_SPENTINDEX = false; From 3153be764e2da79b86297467c2a286927442caf6 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Fri, 11 Mar 2022 22:57:19 +0800 Subject: [PATCH 12/20] Updated nameindex to create a unique index entry for each FULL name (including subdomain) --- src/coins.cpp | 16 ++++++++-------- src/coins.h | 2 +- src/dotnav/namerecordname.h | 9 +++++++-- src/main.cpp | 12 +++++++----- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index c806949d9..4039c19a4 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -941,16 +941,11 @@ bool CStateViewCache::AddNameRecord(const NameRecord& namerecord) const { } bool CStateViewCache::AddNameRecordName(const NameRecordName& name) const { - LogPrint("dotnav", "%s: CALLED!!!\n", __func__); if (cacheNameRecordNames.count(name.first)) cacheNameRecordNames[name.first]=name.second; else cacheNameRecordNames.insert(std::make_pair(name.first, name.second)); - for (auto& i: cacheNameRecordNames) { - LogPrint("dotnav", "%s: domain %s subdomain %s\n", __func__, i.second.domain, i.second.subdomain); - } - return true; } @@ -1028,13 +1023,18 @@ bool CStateViewCache::RemoveNameRecord(const uint256 &id) const { return true; } -bool CStateViewCache::RemoveNameRecordName(const uint256 &id) const { +bool CStateViewCache::RemoveNameRecordName(const uint256 &id, const int64_t& height) const { if (!HaveNameRecordName(id)) return false; - cacheNameRecordNames[id] = NameRecordNameValue(); + if (cacheNameRecordNames.count(id)) + { + if (cacheNameRecordNames[id].height == height) { + cacheNameRecordNames[id] = NameRecordNameValue(); - assert(cacheNameRecordNames[id].IsNull()); + assert(cacheNameRecordNames[id].IsNull()); + } + } return true; } diff --git a/src/coins.h b/src/coins.h index aa4b01b49..dddaa0d0e 100644 --- a/src/coins.h +++ b/src/coins.h @@ -805,7 +805,7 @@ class CStateViewCache : public CStateViewBacked bool RemoveToken(const uint256 &pid) const; bool RemoveTokenUtxo(const TokenUtxoKey &key) const; bool RemoveNameRecord(const uint256 &pid) const; - bool RemoveNameRecordName(const uint256 &id) const; + bool RemoveNameRecordName(const uint256 &id, const int64_t& height) const; bool RemoveNameData(const NameDataKey &id) const; bool RemoveConsultation(const uint256 &cid); bool RemoveConsultationAnswer(const uint256 &cid); diff --git a/src/dotnav/namerecordname.h b/src/dotnav/namerecordname.h index 9e33391b5..89793fb1c 100644 --- a/src/dotnav/namerecordname.h +++ b/src/dotnav/namerecordname.h @@ -13,19 +13,22 @@ class NameRecordNameValue { public: std::string domain; std::string subdomain; + int64_t height; NameRecordNameValue() { SetNull(); } - NameRecordNameValue(const std::string& domain_, const std::string& subdomain_) { + NameRecordNameValue(const std::string& domain_, const std::string& subdomain_, const int64_t& height_) { domain = domain_; subdomain = subdomain_; + height = height_; }; void SetNull() { domain = ""; subdomain = ""; + height = 0; } bool IsNull() const { @@ -33,12 +36,13 @@ class NameRecordNameValue { } bool operator==(const NameRecordNameValue& other) { - return (domain == other.domain && subdomain == other.subdomain); + return (domain == other.domain && subdomain == other.subdomain && height == other.height); } void swap(NameRecordNameValue &to) { std::swap(to.domain, domain); std::swap(to.subdomain, subdomain); + std::swap(to.height, height); } ADD_SERIALIZE_METHODS; @@ -47,6 +51,7 @@ class NameRecordNameValue { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(domain); READWRITE(subdomain); + READWRITE(height); } }; diff --git a/src/main.cpp b/src/main.cpp index a2e250d9c..68df15467 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2994,10 +2994,12 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI } else if (program.action == UPDATE_NAME_FIRST || program.action == UPDATE_NAME || program.action == RENEW_NAME) { view.RemoveNameData(NameDataKey(program.sParameters[0], pindex->nHeight)); LogPrint("dotnav", "%s: removing name data for %s %d\n", __func__, program.sParameters[0], pindex->nHeight); + } - if (fNameIndex) { - if (!view.HaveNameData(DotNav::GetHashName(program.sParameters[0]))) - view.RemoveNameRecordName(DotNav::GetHashName(program.sParameters[0])); + if (fNameIndex) { + if (program.action == UPDATE_NAME_FIRST || program.action == UPDATE_NAME || program.action == RENEW_NAME) { + if (view.HaveNameRecordName(DotNav::GetHashName(program.sParameters[1] + "." + program.sParameters[0]))) + view.RemoveNameRecordName(DotNav::GetHashName(program.sParameters[1] + "." + program.sParameters[0]), pindex->nHeight); } } } @@ -5004,8 +5006,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (fNameIndex) { if (program.action == UPDATE_NAME_FIRST || program.action == UPDATE_NAME || program.action == RENEW_NAME) { - if (!view.HaveNameRecordName(DotNav::GetHashName(program.sParameters[0]))) - view.AddNameRecordName(std::make_pair(DotNav::GetHashName(program.sParameters[0]), NameRecordNameValue(program.sParameters[0], program.sParameters[1]))); + if (!view.HaveNameRecordName(DotNav::GetHashName(program.sParameters[1] + "." + program.sParameters[0]))) + view.AddNameRecordName(std::make_pair(DotNav::GetHashName(program.sParameters[1] + "." + program.sParameters[0]), NameRecordNameValue(program.sParameters[0], program.sParameters[1], pindex->nHeight))); } } } From 4b5e3161c68b7e304e2cc7c5c97dc1170141915b Mon Sep 17 00:00:00 2001 From: mxaddict Date: Fri, 11 Mar 2022 23:34:31 +0800 Subject: [PATCH 13/20] Filtered results that were expired in listnames rpc command --- src/wallet/rpcwallet.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7fbd9303c..68072a7c2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5998,10 +5998,39 @@ UniValue listnames(const UniValue& params, bool fHelp) NameRecordNameMap mapNames; CStateViewCache view(pcoinsTip); + std::map expiryHeights; + if(view.GetAllNameRecordNames(mapNames)) { + auto activeHeight = chainActive.Tip()->nHeight; + for (NameRecordNameMap::iterator it = mapNames.begin(); it != mapNames.end(); it++) { + auto id = DotNav::GetHashName(it->second.domain); + + if (expiryHeights.count(id) == 0) { + if (!view.HaveNameData(id)) { + expiryHeights.insert(std::make_pair(id, 0)); + continue; + } + + NameDataValues data; + + if (!view.GetNameData(DotNav::GetHashName(it->second.domain), data)) { + expiryHeights.insert(std::make_pair(id, 0)); + continue; + } + + for (auto &i: data) { + if (i.second.key == "_expiry") { + expiryHeights.insert(std::make_pair(id, stoll(i.second.value))); + } + } + } + + if (activeHeight >= expiryHeights[id]) + continue; + std::string finalName = it->second.domain; if (it->second.subdomain != "") From 764485510b3360f94abc77dcb95d6f94593f69e0 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Fri, 11 Mar 2022 23:34:42 +0800 Subject: [PATCH 14/20] Removed log --- src/coins.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 4039c19a4..bfc834b1c 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -595,8 +595,6 @@ bool CStateViewCache::GetAllNameRecordNames(NameRecordNameMap& map) { map.clear(); map.insert(cacheNameRecordNames.begin(), cacheNameRecordNames.end()); - LogPrint("dotnav", "%s: first\n", __func__); - NameRecordNameMap baseMap; if (!base->GetAllNameRecordNames(baseMap)) From b1f43841aab05d62ac16cbe3287ddb156f0b9eaf Mon Sep 17 00:00:00 2001 From: mxaddict Date: Mon, 14 Mar 2022 17:38:27 +0800 Subject: [PATCH 15/20] Add -nameindex to help text for navcoind --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index 5b8ac2d8f..d67493341 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -428,6 +428,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-allindex", strprintf(_("Maintain all indexes supported (default: %u)"), DEFAULT_ALLINDEX)); strUsage += HelpMessageOpt("-txindex", strprintf(_("Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u)"), DEFAULT_TXINDEX)); strUsage += HelpMessageOpt("-nftindex", strprintf(_("Maintain an index of ntf data, used by the nft related rpc calls (default: %u)"), DEFAULT_NFTINDEX)); + strUsage += HelpMessageOpt("-nameindex", strprintf(_("Maintain an index of names, used by the `listnames` rpc call (default: %u)"), DEFAULT_NAMEINDEX)); strUsage += HelpMessageOpt("-addressindex", strprintf(_("Maintain a full address index, used to query for the balance, txids and unspent outputs for addresses (default: %u)"), DEFAULT_ADDRESSINDEX)); strUsage += HelpMessageOpt("-timestampindex", strprintf(_("Maintain a timestamp index for block hashes, used to query blocks hashes by a range of timestamps (default: %u)"), DEFAULT_TIMESTAMPINDEX)); From 1cf3fcf5cc608a25d68a8ebe9dfca5aa86736d07 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Mon, 21 Mar 2022 22:31:07 +0800 Subject: [PATCH 16/20] Updated listnames true to work --- src/wallet/rpcwallet.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 68072a7c2..436823b18 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5995,6 +5995,8 @@ UniValue listnames(const UniValue& params, bool fHelp) if (params.size() == 1 && !params[0].isBool()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, argument 1 must be a boolean"); + bool fIsMine = params.size() == 1 ? params[0].get_bool() : false; + NameRecordNameMap mapNames; CStateViewCache view(pcoinsTip); @@ -6036,6 +6038,19 @@ UniValue listnames(const UniValue& params, bool fHelp) if (it->second.subdomain != "") finalName = it->second.subdomain + "." + finalName; + if (fIsMine) { + blsctKey sk; + + if (!pwalletMain->GetBLSCTSpendKey(sk)) + throw JSONRPCError(RPC_TYPE_ERROR, "Wallet not available"); + + blsctKey pk = sk.PrivateChildHash(SerializeHash("name/"+DotNav::GetHashName(it->second.domain).ToString())); + bls::G1Element pkg1 = pk.GetG1Element(); + + if (!view.HaveNameRecord(DotNav::GetHashIdName(it->second.domain, pkg1))) + continue; + } + ret.push_back(finalName); } } From 33fb6116b72d55d3ca322f92d34297a6427b2a4e Mon Sep 17 00:00:00 2001 From: mxaddict Date: Tue, 29 Mar 2022 07:40:56 +0800 Subject: [PATCH 17/20] Updated the fNameIndex check --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index d67493341..440f4d6a9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1638,7 +1638,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler, const std } // Check for changed -nameindex state - if (fNftIndex != GetBoolArg("-nameindex", DEFAULT_NAMEINDEX)) { + if (fNameIndex != GetBoolArg("-nameindex", DEFAULT_NAMEINDEX)) { strLoadError = _("You need to rebuild the database using -reindex-chainstate to change -nameindex"); break; } From 14dc474155bc1f9c8302e2ffeb529680a482a171 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Tue, 29 Mar 2022 14:17:21 +0800 Subject: [PATCH 18/20] Added warning about nameindex in listnames RPC help text --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 436823b18..9a6a9c94b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5982,6 +5982,7 @@ UniValue listnames(const UniValue& params, bool fHelp) "\nList dotNav names.\n" "\nArguments:\n" "1. mine (bool, optional, default=false) Set mine to true to show only names you own.\n" + "\n NOTE: Requires -nameindex=1 to work\n" + HelpExampleCli("listnames", "") + HelpExampleCli("listnames", "true") From 6cd2b4d56fa2ac19297dc1265c0f136fb0e09e59 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Tue, 29 Mar 2022 14:23:19 +0800 Subject: [PATCH 19/20] Added warning about nameindex in listnames RPC help text --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9a6a9c94b..2524165c6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5982,7 +5982,7 @@ UniValue listnames(const UniValue& params, bool fHelp) "\nList dotNav names.\n" "\nArguments:\n" "1. mine (bool, optional, default=false) Set mine to true to show only names you own.\n" - "\n NOTE: Requires -nameindex=1 to work\n" + "\n NOTE: Requires -nameindex to be enabled\n" + HelpExampleCli("listnames", "") + HelpExampleCli("listnames", "true") From 5e7370a71f1be6d1aab024ff116501e54fd5fda2 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Thu, 31 Mar 2022 15:07:29 +0800 Subject: [PATCH 20/20] Updated the listnames to only show own names --- src/wallet/rpcwallet.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2524165c6..8c039244b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5978,10 +5978,9 @@ UniValue listnames(const UniValue& params, bool fHelp) { if (fHelp) throw std::runtime_error( - "listnames (mine)\n" - "\nList dotNav names.\n" + "listnames\n" + "\nList your dotNav names.\n" "\nArguments:\n" - "1. mine (bool, optional, default=false) Set mine to true to show only names you own.\n" "\n NOTE: Requires -nameindex to be enabled\n" + HelpExampleCli("listnames", "") @@ -5996,8 +5995,6 @@ UniValue listnames(const UniValue& params, bool fHelp) if (params.size() == 1 && !params[0].isBool()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, argument 1 must be a boolean"); - bool fIsMine = params.size() == 1 ? params[0].get_bool() : false; - NameRecordNameMap mapNames; CStateViewCache view(pcoinsTip); @@ -6039,18 +6036,16 @@ UniValue listnames(const UniValue& params, bool fHelp) if (it->second.subdomain != "") finalName = it->second.subdomain + "." + finalName; - if (fIsMine) { - blsctKey sk; + blsctKey sk; - if (!pwalletMain->GetBLSCTSpendKey(sk)) - throw JSONRPCError(RPC_TYPE_ERROR, "Wallet not available"); + if (!pwalletMain->GetBLSCTSpendKey(sk)) + throw JSONRPCError(RPC_TYPE_ERROR, "Wallet not available"); - blsctKey pk = sk.PrivateChildHash(SerializeHash("name/"+DotNav::GetHashName(it->second.domain).ToString())); - bls::G1Element pkg1 = pk.GetG1Element(); + blsctKey pk = sk.PrivateChildHash(SerializeHash("name/"+DotNav::GetHashName(it->second.domain).ToString())); + bls::G1Element pkg1 = pk.GetG1Element(); - if (!view.HaveNameRecord(DotNav::GetHashIdName(it->second.domain, pkg1))) - continue; - } + if (!view.HaveNameRecord(DotNav::GetHashIdName(it->second.domain, pkg1))) + continue; ret.push_back(finalName); }