MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / getnewaddr

Function getnewaddr

src/rpc/rpcwallet.cpp:45–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45Value 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
92Value addmulsigaddr(const Array& params, bool fHelp) {
93 if (fHelp || params.size() != 2)

Callers

nothing calls this directly

Calls 14

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
EnsureWalletIsUnlockedFunction · 0.85
RPCTypeCheckFunction · 0.85
PairClass · 0.85
get_boolMethod · 0.80
MakeNewKeyMethod · 0.80
push_backMethod · 0.80
ToAddressMethod · 0.80
sizeMethod · 0.45
AddKeyMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected