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

Function importwallet

src/rpc/rpcdump.cpp:84–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84Value importwallet(const Array& params, bool fHelp) {
85 if (fHelp || params.size() != 1)
86 throw runtime_error(
87 "importwallet \"filename\"\n"
88 "\nImports keys from a wallet dump file (see dumpwallet).\n"
89 "\nArguments:\n"
90 "1. \"filename\" (string, required) The wallet file to be imported\n"
91 "\nExamples:\n"
92 "\nDump the wallet first\n" +
93 HelpExampleCli("dumpwallet", "\"target_dumpwallet_filepath\"") + "\nImport the wallet\n" +
94 HelpExampleCli("importwallet", "\"target_dumpwallet_filepath\"") + "\nAs a json rpc call\n" +
95 HelpExampleRpc("importwallet", "\"target_dumpwallet_filepath\""));
96
97 EnsureWalletIsUnlocked();
98
99 LOCK2(cs_main, pWalletMain->cs_wallet);
100
101 ifstream file;
102 file.open(params[0].get_str().c_str(), ios::in | ios::ate);
103 if (!file.is_open())
104 throw JSONRPCError(RPC_INVALID_PARAMETER, "Fail to open dump file");
105
106 file.seekg(0, file.beg);
107 int importedKeySize = 0;
108 if (file.good()) {
109 Value reply;
110 json_spirit::read(file, reply);
111 const Value& keyObj = find_value(reply.get_obj(), "key");
112 const Array& keyArray = keyObj.get_array();
113 for (auto const& keyItem : keyArray) {
114 CKeyCombi keyCombi;
115 const Value& obj = find_value(keyItem.get_obj(), "keyid");
116 if (obj.type() == null_type)
117 continue;
118
119 string strKeyId = find_value(keyItem.get_obj(), "keyid").get_str();
120 CKeyID keyId(uint160(ParseHex(strKeyId)));
121 keyCombi.UnSerializeFromJson(keyItem.get_obj());
122 if (!keyCombi.HasMainKey() && !keyCombi.HaveMinerKey())
123 continue;
124
125 if (pWalletMain->AddKey(keyId, keyCombi))
126 importedKeySize++;
127 }
128 }
129 file.close();
130
131 Object reply2;
132 reply2.push_back(Pair("info", "successfully imported wallet"));
133 reply2.push_back(Pair("count", importedKeySize));
134 return reply2;
135}
136
137Value dumpprivkey(const Array& params, bool fHelp) {
138 if (fHelp || params.size() != 1)

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
EnsureWalletIsUnlockedFunction · 0.85
JSONRPCErrorFunction · 0.85
ParseHexFunction · 0.85
PairClass · 0.85
openMethod · 0.80
typeMethod · 0.80
UnSerializeFromJsonMethod · 0.80
HaveMinerKeyMethod · 0.80
push_backMethod · 0.80
uint160Class · 0.50

Tested by

no test coverage detected