| 43 | } |
| 44 | |
| 45 | Value getnewaddr(const Array& params, bool fHelp) { |
| 46 | if (fHelp || params.size() > 1) |
| 47 | throw runtime_error( |
| 48 | "getnewaddr [\"IsMiner\"]\n" |
| 49 | "\nget a new address\n" |
| 50 | "\nArguments:\n" |
| 51 | "1.\"IsMiner\" (bool, optional) If true, it creates two sets of key-pairs: one for " |
| 52 | "mining and another for receiving miner fees.\n" |
| 53 | "\nResult:\n" |
| 54 | "\nExamples:\n" + |
| 55 | HelpExampleCli("getnewaddr", "") + "\nAs json rpc\n" + |
| 56 | HelpExampleRpc("getnewaddr", "")); |
| 57 | |
| 58 | EnsureWalletIsUnlocked(); |
| 59 | |
| 60 | bool isForMiner = false; |
| 61 | if (params.size() == 1) { |
| 62 | RPCTypeCheck(params, list_of(bool_type)); |
| 63 | isForMiner = params[0].get_bool(); |
| 64 | } |
| 65 | |
| 66 | CKey userkey; |
| 67 | userkey.MakeNewKey(); |
| 68 | |
| 69 | CKey minerKey; |
| 70 | string minerPubKey = "null"; |
| 71 | |
| 72 | if (isForMiner) { |
| 73 | minerKey.MakeNewKey(); |
| 74 | if (!pWalletMain->AddKey(userkey, minerKey)) { |
| 75 | throw runtime_error("add miner key failed "); |
| 76 | } |
| 77 | minerPubKey = minerKey.GetPubKey().ToString(); |
| 78 | } else if (!pWalletMain->AddKey(userkey)) { |
| 79 | throw runtime_error("add user key failed "); |
| 80 | } |
| 81 | |
| 82 | CPubKey userPubKey = userkey.GetPubKey(); |
| 83 | CKeyID userKeyID = userPubKey.GetKeyId(); |
| 84 | |
| 85 | Object obj; |
| 86 | obj.push_back(Pair("addr", userKeyID.ToAddress())); |
| 87 | obj.push_back(Pair("minerpubkey", minerPubKey)); // "null" for non-miner address |
| 88 | |
| 89 | return obj; |
| 90 | } |
| 91 | |
| 92 | Value addmulsigaddr(const Array& params, bool fHelp) { |
| 93 | if (fHelp || params.size() != 2) |
nothing calls this directly
no test coverage detected