Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
| Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | UniValue importaddress(const Config &config, const JSONRPCRequest &request) { | ||||
| bool fP2SH = false; | bool fP2SH = false; | ||||
| if (request.params.size() > 3) { | if (request.params.size() > 3) { | ||||
| fP2SH = request.params[3].get_bool(); | fP2SH = request.params[3].get_bool(); | ||||
| } | } | ||||
| LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
| CTxDestination dest = | CTxDestination dest = | ||||
| DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), config); | ||||
| if (IsValidDestination(dest)) { | if (IsValidDestination(dest)) { | ||||
| if (fP2SH) { | if (fP2SH) { | ||||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
| "Cannot use the p2sh flag with an address - use " | "Cannot use the p2sh flag with an address - use " | ||||
| "a script instead"); | "a script instead"); | ||||
| } | } | ||||
| ImportAddress(pwallet, dest, strLabel); | ImportAddress(pwallet, dest, strLabel); | ||||
| } else if (IsHex(request.params[0].get_str())) { | } else if (IsHex(request.params[0].get_str())) { | ||||
| ▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | while (file.good()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| CKey key = vchSecret.GetKey(); | CKey key = vchSecret.GetKey(); | ||||
| CPubKey pubkey = key.GetPubKey(); | CPubKey pubkey = key.GetPubKey(); | ||||
| assert(key.VerifyPubKey(pubkey)); | assert(key.VerifyPubKey(pubkey)); | ||||
| CKeyID keyid = pubkey.GetID(); | CKeyID keyid = pubkey.GetID(); | ||||
| if (pwallet->HaveKey(keyid)) { | if (pwallet->HaveKey(keyid)) { | ||||
| LogPrintf("Skipping import of %s (key already present)\n", | LogPrintf("Skipping import of %s (key already present)\n", | ||||
| EncodeDestination(keyid)); | EncodeDestination(keyid, config)); | ||||
| continue; | continue; | ||||
| } | } | ||||
| int64_t nTime = DecodeDumpTime(vstr[1]); | int64_t nTime = DecodeDumpTime(vstr[1]); | ||||
| std::string strLabel; | std::string strLabel; | ||||
| bool fLabel = true; | bool fLabel = true; | ||||
| for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) { | for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) { | ||||
| if (boost::algorithm::starts_with(vstr[nStr], "#")) { | if (boost::algorithm::starts_with(vstr[nStr], "#")) { | ||||
| break; | break; | ||||
| } | } | ||||
| if (vstr[nStr] == "change=1") { | if (vstr[nStr] == "change=1") { | ||||
| fLabel = false; | fLabel = false; | ||||
| } | } | ||||
| if (vstr[nStr] == "reserve=1") { | if (vstr[nStr] == "reserve=1") { | ||||
| fLabel = false; | fLabel = false; | ||||
| } | } | ||||
| if (boost::algorithm::starts_with(vstr[nStr], "label=")) { | if (boost::algorithm::starts_with(vstr[nStr], "label=")) { | ||||
| strLabel = DecodeDumpString(vstr[nStr].substr(6)); | strLabel = DecodeDumpString(vstr[nStr].substr(6)); | ||||
| fLabel = true; | fLabel = true; | ||||
| } | } | ||||
| } | } | ||||
| LogPrintf("Importing %s...\n", EncodeDestination(keyid)); | LogPrintf("Importing %s...\n", EncodeDestination(keyid, config)); | ||||
| if (!pwallet->AddKeyPubKey(key, pubkey)) { | if (!pwallet->AddKeyPubKey(key, pubkey)) { | ||||
| fGood = false; | fGood = false; | ||||
| continue; | continue; | ||||
| } | } | ||||
| pwallet->mapKeyMetadata[keyid].nCreateTime = nTime; | pwallet->mapKeyMetadata[keyid].nCreateTime = nTime; | ||||
| if (fLabel) { | if (fLabel) { | ||||
| pwallet->SetAddressBook(keyid, strLabel, "receive"); | pwallet->SetAddressBook(keyid, strLabel, "receive"); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
| HelpExampleRpc("dumpprivkey", "\"myaddress\"")); | HelpExampleRpc("dumpprivkey", "\"myaddress\"")); | ||||
| } | } | ||||
| LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
| EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
| std::string strAddress = request.params[0].get_str(); | std::string strAddress = request.params[0].get_str(); | ||||
| CTxDestination dest = | CTxDestination dest = DecodeDestination(strAddress, config); | ||||
| DecodeDestination(strAddress, config.GetChainParams()); | |||||
| if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
| "Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
| } | } | ||||
| const CKeyID *keyID = boost::get<CKeyID>(&dest); | const CKeyID *keyID = boost::get<CKeyID>(&dest); | ||||
| if (!keyID) { | if (!keyID) { | ||||
| throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | if (!masterKeyID.IsNull()) { | ||||
| << "\n\n"; | << "\n\n"; | ||||
| } | } | ||||
| } | } | ||||
| for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | ||||
| vKeyBirth.begin(); | vKeyBirth.begin(); | ||||
| it != vKeyBirth.end(); it++) { | it != vKeyBirth.end(); it++) { | ||||
| const CKeyID &keyid = it->second; | const CKeyID &keyid = it->second; | ||||
| std::string strTime = EncodeDumpTime(it->first); | std::string strTime = EncodeDumpTime(it->first); | ||||
| std::string strAddr = EncodeDestination(keyid); | std::string strAddr = EncodeDestination(keyid, config); | ||||
| CKey key; | CKey key; | ||||
| if (pwallet->GetKey(keyid, key)) { | if (pwallet->GetKey(keyid, key)) { | ||||
| file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), | file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), | ||||
| strTime); | strTime); | ||||
| if (pwallet->mapAddressBook.count(keyid)) { | if (pwallet->mapAddressBook.count(keyid)) { | ||||
| file << strprintf( | file << strprintf( | ||||
| "label=%s", | "label=%s", | ||||
| EncodeDumpString(pwallet->mapAddressBook[keyid].name)); | EncodeDumpString(pwallet->mapAddressBook[keyid].name)); | ||||
| Show All 19 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
| UniValue reply(UniValue::VOBJ); | UniValue reply(UniValue::VOBJ); | ||||
| reply.push_back(Pair("filename", filepath.string())); | reply.push_back(Pair("filename", filepath.string())); | ||||
| return reply; | return reply; | ||||
| } | } | ||||
| UniValue ProcessImport(CWallet *const pwallet, const UniValue &data, | UniValue ProcessImport(CWallet *const pwallet, const UniValue &data, | ||||
| const int64_t timestamp) { | const int64_t timestamp, const Config &config) { | ||||
deadalnix: You added a config to the wallet so adding this parameter is redundant (and open the door for… | |||||
| try { | try { | ||||
| bool success = false; | bool success = false; | ||||
| // Required fields. | // Required fields. | ||||
| const UniValue &scriptPubKey = data["scriptPubKey"]; | const UniValue &scriptPubKey = data["scriptPubKey"]; | ||||
| // Should have script or JSON with "address". | // Should have script or JSON with "address". | ||||
| if (!(scriptPubKey.getType() == UniValue::VOBJ && | if (!(scriptPubKey.getType() == UniValue::VOBJ && | ||||
| Show All 22 Lines | try { | ||||
| ? scriptPubKey.get_str() | ? scriptPubKey.get_str() | ||||
| : scriptPubKey["address"].get_str(); | : scriptPubKey["address"].get_str(); | ||||
| // Parse the output. | // Parse the output. | ||||
| CScript script; | CScript script; | ||||
| CTxDestination dest; | CTxDestination dest; | ||||
| if (!isScript) { | if (!isScript) { | ||||
| dest = DecodeDestination(output, pwallet->chainParams); | dest = DecodeDestination(output, config); | ||||
| if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
| "Invalid address"); | "Invalid address"); | ||||
| } | } | ||||
| script = GetScriptForDestination(dest); | script = GetScriptForDestination(dest); | ||||
| } else { | } else { | ||||
| if (!IsHex(output)) { | if (!IsHex(output)) { | ||||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
| ▲ Show 20 Lines • Show All 415 Lines • ▼ Show 20 Lines | if (fRescan && chainActive.Tip()) { | ||||
| fRescan = false; | fRescan = false; | ||||
| } | } | ||||
| UniValue response(UniValue::VARR); | UniValue response(UniValue::VARR); | ||||
| for (const UniValue &data : requests.getValues()) { | for (const UniValue &data : requests.getValues()) { | ||||
| const int64_t timestamp = | const int64_t timestamp = | ||||
| std::max(GetImportTimestamp(data, now), minimumTimestamp); | std::max(GetImportTimestamp(data, now), minimumTimestamp); | ||||
| const UniValue result = ProcessImport(pwallet, data, timestamp); | const UniValue result = ProcessImport(pwallet, data, timestamp, config); | ||||
| response.push_back(result); | response.push_back(result); | ||||
| if (!fRescan) { | if (!fRescan) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| // If at least one request was successful then allow rescan. | // If at least one request was successful then allow rescan. | ||||
| if (result["success"].get_bool()) { | if (result["success"].get_bool()) { | ||||
| ▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines | |||||
You added a config to the wallet so adding this parameter is redundant (and open the door for inconsistencies).