|
|
@ -74,7 +74,9 @@ std::string DecodeDumpString(const std::string &str) { |
|
|
|
|
|
|
|
|
|
|
|
UniValue importprivkey(const JSONRPCRequest& request) |
|
|
|
UniValue importprivkey(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) |
|
|
@ -98,9 +100,9 @@ UniValue importprivkey(const JSONRPCRequest& request) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
|
|
|
|
|
|
|
|
string strSecret = request.params[0].get_str(); |
|
|
|
string strSecret = request.params[0].get_str(); |
|
|
|
string strLabel = ""; |
|
|
|
string strLabel = ""; |
|
|
@ -127,23 +129,23 @@ UniValue importprivkey(const JSONRPCRequest& request) |
|
|
|
assert(key.VerifyPubKey(pubkey)); |
|
|
|
assert(key.VerifyPubKey(pubkey)); |
|
|
|
CKeyID vchAddress = pubkey.GetID(); |
|
|
|
CKeyID vchAddress = pubkey.GetID(); |
|
|
|
{ |
|
|
|
{ |
|
|
|
pwalletMain->MarkDirty(); |
|
|
|
pwallet->MarkDirty(); |
|
|
|
pwalletMain->SetAddressBook(vchAddress, strLabel, "receive"); |
|
|
|
pwallet->SetAddressBook(vchAddress, strLabel, "receive"); |
|
|
|
|
|
|
|
|
|
|
|
// Don't throw error in case a key is already there
|
|
|
|
// Don't throw error in case a key is already there
|
|
|
|
if (pwalletMain->HaveKey(vchAddress)) |
|
|
|
if (pwallet->HaveKey(vchAddress)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1; |
|
|
|
pwallet->mapKeyMetadata[vchAddress].nCreateTime = 1; |
|
|
|
|
|
|
|
|
|
|
|
if (!pwalletMain->AddKeyPubKey(key, pubkey)) |
|
|
|
if (!pwallet->AddKeyPubKey(key, pubkey)) |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet"); |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet"); |
|
|
|
|
|
|
|
|
|
|
|
// whenever a key is imported, we need to scan the whole chain
|
|
|
|
// whenever a key is imported, we need to scan the whole chain
|
|
|
|
pwalletMain->UpdateTimeFirstKey(1); |
|
|
|
pwallet->UpdateTimeFirstKey(1); |
|
|
|
|
|
|
|
|
|
|
|
if (fRescan) { |
|
|
|
if (fRescan) { |
|
|
|
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true); |
|
|
|
pwallet->ScanForWalletTransactions(chainActive.Genesis(), true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -184,7 +186,9 @@ void ImportAddress(CWallet * const pwallet, const CBitcoinAddress& address, cons |
|
|
|
|
|
|
|
|
|
|
|
UniValue importaddress(const JSONRPCRequest& request) |
|
|
|
UniValue importaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) |
|
|
@ -227,24 +231,24 @@ UniValue importaddress(const JSONRPCRequest& request) |
|
|
|
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, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
CBitcoinAddress address(request.params[0].get_str()); |
|
|
|
CBitcoinAddress address(request.params[0].get_str()); |
|
|
|
if (address.IsValid()) { |
|
|
|
if (address.IsValid()) { |
|
|
|
if (fP2SH) |
|
|
|
if (fP2SH) |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Cannot use the p2sh flag with an address - use a script instead"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Cannot use the p2sh flag with an address - use a script instead"); |
|
|
|
ImportAddress(pwalletMain, address, strLabel); |
|
|
|
ImportAddress(pwallet, address, strLabel); |
|
|
|
} else if (IsHex(request.params[0].get_str())) { |
|
|
|
} else if (IsHex(request.params[0].get_str())) { |
|
|
|
std::vector<unsigned char> data(ParseHex(request.params[0].get_str())); |
|
|
|
std::vector<unsigned char> data(ParseHex(request.params[0].get_str())); |
|
|
|
ImportScript(pwalletMain, CScript(data.begin(), data.end()), strLabel, fP2SH); |
|
|
|
ImportScript(pwallet, CScript(data.begin(), data.end()), strLabel, fP2SH); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address or script"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address or script"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fRescan) |
|
|
|
if (fRescan) |
|
|
|
{ |
|
|
|
{ |
|
|
|
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true); |
|
|
|
pwallet->ScanForWalletTransactions(chainActive.Genesis(), true); |
|
|
|
pwalletMain->ReacceptWalletTransactions(); |
|
|
|
pwallet->ReacceptWalletTransactions(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
@ -252,7 +256,9 @@ UniValue importaddress(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
UniValue importprunedfunds(const JSONRPCRequest& request) |
|
|
|
UniValue importprunedfunds(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 2) |
|
|
|
if (request.fHelp || request.params.size() != 2) |
|
|
@ -268,7 +274,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request) |
|
|
|
if (!DecodeHexTx(tx, request.params[0].get_str())) |
|
|
|
if (!DecodeHexTx(tx, request.params[0].get_str())) |
|
|
|
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); |
|
|
|
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); |
|
|
|
uint256 hashTx = tx.GetHash(); |
|
|
|
uint256 hashTx = tx.GetHash(); |
|
|
|
CWalletTx wtx(pwalletMain, MakeTransactionRef(std::move(tx))); |
|
|
|
CWalletTx wtx(pwallet, MakeTransactionRef(std::move(tx))); |
|
|
|
|
|
|
|
|
|
|
|
CDataStream ssMB(ParseHexV(request.params[1], "proof"), SER_NETWORK, PROTOCOL_VERSION); |
|
|
|
CDataStream ssMB(ParseHexV(request.params[1], "proof"), SER_NETWORK, PROTOCOL_VERSION); |
|
|
|
CMerkleBlock merkleBlock; |
|
|
|
CMerkleBlock merkleBlock; |
|
|
@ -299,10 +305,10 @@ UniValue importprunedfunds(const JSONRPCRequest& request) |
|
|
|
wtx.nIndex = txnIndex; |
|
|
|
wtx.nIndex = txnIndex; |
|
|
|
wtx.hashBlock = merkleBlock.header.GetHash(); |
|
|
|
wtx.hashBlock = merkleBlock.header.GetHash(); |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
if (pwalletMain->IsMine(wtx)) { |
|
|
|
if (pwallet->IsMine(wtx)) { |
|
|
|
pwalletMain->AddToWallet(wtx, false); |
|
|
|
pwallet->AddToWallet(wtx, false); |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -311,7 +317,9 @@ UniValue importprunedfunds(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
UniValue removeprunedfunds(const JSONRPCRequest& request) |
|
|
|
UniValue removeprunedfunds(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
@ -326,7 +334,7 @@ UniValue removeprunedfunds(const JSONRPCRequest& request) |
|
|
|
+ HelpExampleRpc("removprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") |
|
|
|
+ HelpExampleRpc("removprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
uint256 hash; |
|
|
|
uint256 hash; |
|
|
|
hash.SetHex(request.params[0].get_str()); |
|
|
|
hash.SetHex(request.params[0].get_str()); |
|
|
@ -334,7 +342,7 @@ UniValue removeprunedfunds(const JSONRPCRequest& request) |
|
|
|
vHash.push_back(hash); |
|
|
|
vHash.push_back(hash); |
|
|
|
vector<uint256> vHashOut; |
|
|
|
vector<uint256> vHashOut; |
|
|
|
|
|
|
|
|
|
|
|
if(pwalletMain->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) { |
|
|
|
if(pwallet->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) { |
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not properly delete the transaction."); |
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not properly delete the transaction."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -347,7 +355,9 @@ UniValue removeprunedfunds(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
UniValue importpubkey(const JSONRPCRequest& request) |
|
|
|
UniValue importpubkey(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) |
|
|
@ -388,15 +398,15 @@ UniValue importpubkey(const JSONRPCRequest& request) |
|
|
|
if (!pubKey.IsFullyValid()) |
|
|
|
if (!pubKey.IsFullyValid()) |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key"); |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
ImportAddress(pwalletMain, CBitcoinAddress(pubKey.GetID()), strLabel); |
|
|
|
ImportAddress(pwallet, CBitcoinAddress(pubKey.GetID()), strLabel); |
|
|
|
ImportScript(pwalletMain, GetScriptForRawPubKey(pubKey), strLabel, false); |
|
|
|
ImportScript(pwallet, GetScriptForRawPubKey(pubKey), strLabel, false); |
|
|
|
|
|
|
|
|
|
|
|
if (fRescan) |
|
|
|
if (fRescan) |
|
|
|
{ |
|
|
|
{ |
|
|
|
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true); |
|
|
|
pwallet->ScanForWalletTransactions(chainActive.Genesis(), true); |
|
|
|
pwalletMain->ReacceptWalletTransactions(); |
|
|
|
pwallet->ReacceptWalletTransactions(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
@ -405,7 +415,9 @@ UniValue importpubkey(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
UniValue importwallet(const JSONRPCRequest& request) |
|
|
|
UniValue importwallet(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
@ -426,9 +438,9 @@ UniValue importwallet(const JSONRPCRequest& request) |
|
|
|
if (fPruneMode) |
|
|
|
if (fPruneMode) |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled in pruned mode"); |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled in pruned mode"); |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
|
|
|
|
|
|
|
|
ifstream file; |
|
|
|
ifstream file; |
|
|
|
file.open(request.params[0].get_str().c_str(), std::ios::in | std::ios::ate); |
|
|
|
file.open(request.params[0].get_str().c_str(), std::ios::in | std::ios::ate); |
|
|
@ -442,9 +454,9 @@ UniValue importwallet(const JSONRPCRequest& request) |
|
|
|
int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg()); |
|
|
|
int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg()); |
|
|
|
file.seekg(0, file.beg); |
|
|
|
file.seekg(0, file.beg); |
|
|
|
|
|
|
|
|
|
|
|
pwalletMain->ShowProgress(_("Importing..."), 0); // show progress dialog in GUI
|
|
|
|
pwallet->ShowProgress(_("Importing..."), 0); // show progress dialog in GUI
|
|
|
|
while (file.good()) { |
|
|
|
while (file.good()) { |
|
|
|
pwalletMain->ShowProgress("", std::max(1, std::min(99, (int)(((double)file.tellg() / (double)nFilesize) * 100)))); |
|
|
|
pwallet->ShowProgress("", std::max(1, std::min(99, (int)(((double)file.tellg() / (double)nFilesize) * 100)))); |
|
|
|
std::string line; |
|
|
|
std::string line; |
|
|
|
std::getline(file, line); |
|
|
|
std::getline(file, line); |
|
|
|
if (line.empty() || line[0] == '#') |
|
|
|
if (line.empty() || line[0] == '#') |
|
|
@ -461,7 +473,7 @@ UniValue importwallet(const JSONRPCRequest& request) |
|
|
|
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 (pwalletMain->HaveKey(keyid)) { |
|
|
|
if (pwallet->HaveKey(keyid)) { |
|
|
|
LogPrintf("Skipping import of %s (key already present)\n", CBitcoinAddress(keyid).ToString()); |
|
|
|
LogPrintf("Skipping import of %s (key already present)\n", CBitcoinAddress(keyid).ToString()); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -481,27 +493,27 @@ UniValue importwallet(const JSONRPCRequest& request) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
LogPrintf("Importing %s...\n", CBitcoinAddress(keyid).ToString()); |
|
|
|
LogPrintf("Importing %s...\n", CBitcoinAddress(keyid).ToString()); |
|
|
|
if (!pwalletMain->AddKeyPubKey(key, pubkey)) { |
|
|
|
if (!pwallet->AddKeyPubKey(key, pubkey)) { |
|
|
|
fGood = false; |
|
|
|
fGood = false; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
pwalletMain->mapKeyMetadata[keyid].nCreateTime = nTime; |
|
|
|
pwallet->mapKeyMetadata[keyid].nCreateTime = nTime; |
|
|
|
if (fLabel) |
|
|
|
if (fLabel) |
|
|
|
pwalletMain->SetAddressBook(keyid, strLabel, "receive"); |
|
|
|
pwallet->SetAddressBook(keyid, strLabel, "receive"); |
|
|
|
nTimeBegin = std::min(nTimeBegin, nTime); |
|
|
|
nTimeBegin = std::min(nTimeBegin, nTime); |
|
|
|
} |
|
|
|
} |
|
|
|
file.close(); |
|
|
|
file.close(); |
|
|
|
pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI
|
|
|
|
pwallet->ShowProgress("", 100); // hide progress dialog in GUI
|
|
|
|
|
|
|
|
|
|
|
|
CBlockIndex *pindex = chainActive.Tip(); |
|
|
|
CBlockIndex *pindex = chainActive.Tip(); |
|
|
|
while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200) |
|
|
|
while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200) |
|
|
|
pindex = pindex->pprev; |
|
|
|
pindex = pindex->pprev; |
|
|
|
|
|
|
|
|
|
|
|
pwalletMain->UpdateTimeFirstKey(nTimeBegin); |
|
|
|
pwallet->UpdateTimeFirstKey(nTimeBegin); |
|
|
|
|
|
|
|
|
|
|
|
LogPrintf("Rescanning last %i blocks\n", chainActive.Height() - pindex->nHeight + 1); |
|
|
|
LogPrintf("Rescanning last %i blocks\n", chainActive.Height() - pindex->nHeight + 1); |
|
|
|
pwalletMain->ScanForWalletTransactions(pindex); |
|
|
|
pwallet->ScanForWalletTransactions(pindex); |
|
|
|
pwalletMain->MarkDirty(); |
|
|
|
pwallet->MarkDirty(); |
|
|
|
|
|
|
|
|
|
|
|
if (!fGood) |
|
|
|
if (!fGood) |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet"); |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet"); |
|
|
@ -511,7 +523,9 @@ UniValue importwallet(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
UniValue dumpprivkey(const JSONRPCRequest& request) |
|
|
|
UniValue dumpprivkey(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
@ -529,9 +543,9 @@ UniValue dumpprivkey(const JSONRPCRequest& request) |
|
|
|
+ HelpExampleRpc("dumpprivkey", "\"myaddress\"") |
|
|
|
+ HelpExampleRpc("dumpprivkey", "\"myaddress\"") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
|
|
|
|
|
|
|
|
string strAddress = request.params[0].get_str(); |
|
|
|
string strAddress = request.params[0].get_str(); |
|
|
|
CBitcoinAddress address; |
|
|
|
CBitcoinAddress address; |
|
|
@ -541,7 +555,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request) |
|
|
|
if (!address.GetKeyID(keyID)) |
|
|
|
if (!address.GetKeyID(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"); |
|
|
|
CKey vchSecret; |
|
|
|
CKey vchSecret; |
|
|
|
if (!pwalletMain->GetKey(keyID, vchSecret)) |
|
|
|
if (!pwallet->GetKey(keyID, vchSecret)) |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known"); |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known"); |
|
|
|
return CBitcoinSecret(vchSecret).ToString(); |
|
|
|
return CBitcoinSecret(vchSecret).ToString(); |
|
|
|
} |
|
|
|
} |
|
|
@ -549,7 +563,9 @@ UniValue dumpprivkey(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
UniValue dumpwallet(const JSONRPCRequest& request) |
|
|
|
UniValue dumpwallet(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
@ -563,9 +579,9 @@ UniValue dumpwallet(const JSONRPCRequest& request) |
|
|
|
+ HelpExampleRpc("dumpwallet", "\"test\"") |
|
|
|
+ HelpExampleRpc("dumpwallet", "\"test\"") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
|
|
|
|
|
|
|
|
ofstream file; |
|
|
|
ofstream file; |
|
|
|
file.open(request.params[0].get_str().c_str()); |
|
|
|
file.open(request.params[0].get_str().c_str()); |
|
|
@ -574,8 +590,8 @@ UniValue dumpwallet(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
std::map<CTxDestination, int64_t> mapKeyBirth; |
|
|
|
std::map<CTxDestination, int64_t> mapKeyBirth; |
|
|
|
std::set<CKeyID> setKeyPool; |
|
|
|
std::set<CKeyID> setKeyPool; |
|
|
|
pwalletMain->GetKeyBirthTimes(mapKeyBirth); |
|
|
|
pwallet->GetKeyBirthTimes(mapKeyBirth); |
|
|
|
pwalletMain->GetAllReserveKeys(setKeyPool); |
|
|
|
pwallet->GetAllReserveKeys(setKeyPool); |
|
|
|
|
|
|
|
|
|
|
|
// sort time/key pairs
|
|
|
|
// sort time/key pairs
|
|
|
|
std::vector<std::pair<int64_t, CKeyID> > vKeyBirth; |
|
|
|
std::vector<std::pair<int64_t, CKeyID> > vKeyBirth; |
|
|
@ -595,11 +611,11 @@ UniValue dumpwallet(const JSONRPCRequest& request) |
|
|
|
file << "\n"; |
|
|
|
file << "\n"; |
|
|
|
|
|
|
|
|
|
|
|
// add the base58check encoded extended master if the wallet uses HD
|
|
|
|
// add the base58check encoded extended master if the wallet uses HD
|
|
|
|
CKeyID masterKeyID = pwalletMain->GetHDChain().masterKeyID; |
|
|
|
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; |
|
|
|
if (!masterKeyID.IsNull()) |
|
|
|
if (!masterKeyID.IsNull()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CKey key; |
|
|
|
CKey key; |
|
|
|
if (pwalletMain->GetKey(masterKeyID, key)) |
|
|
|
if (pwallet->GetKey(masterKeyID, key)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CExtKey masterKey; |
|
|
|
CExtKey masterKey; |
|
|
|
masterKey.SetMaster(key.begin(), key.size()); |
|
|
|
masterKey.SetMaster(key.begin(), key.size()); |
|
|
@ -615,20 +631,20 @@ UniValue dumpwallet(const JSONRPCRequest& request) |
|
|
|
std::string strTime = EncodeDumpTime(it->first); |
|
|
|
std::string strTime = EncodeDumpTime(it->first); |
|
|
|
std::string strAddr = CBitcoinAddress(keyid).ToString(); |
|
|
|
std::string strAddr = CBitcoinAddress(keyid).ToString(); |
|
|
|
CKey key; |
|
|
|
CKey key; |
|
|
|
if (pwalletMain->GetKey(keyid, key)) { |
|
|
|
if (pwallet->GetKey(keyid, key)) { |
|
|
|
file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), strTime); |
|
|
|
file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), strTime); |
|
|
|
if (pwalletMain->mapAddressBook.count(keyid)) { |
|
|
|
if (pwallet->mapAddressBook.count(keyid)) { |
|
|
|
file << strprintf("label=%s", EncodeDumpString(pwalletMain->mapAddressBook[keyid].name)); |
|
|
|
file << strprintf("label=%s", EncodeDumpString(pwallet->mapAddressBook[keyid].name)); |
|
|
|
} else if (keyid == masterKeyID) { |
|
|
|
} else if (keyid == masterKeyID) { |
|
|
|
file << "hdmaster=1"; |
|
|
|
file << "hdmaster=1"; |
|
|
|
} else if (setKeyPool.count(keyid)) { |
|
|
|
} else if (setKeyPool.count(keyid)) { |
|
|
|
file << "reserve=1"; |
|
|
|
file << "reserve=1"; |
|
|
|
} else if (pwalletMain->mapKeyMetadata[keyid].hdKeypath == "m") { |
|
|
|
} else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "m") { |
|
|
|
file << "inactivehdmaster=1"; |
|
|
|
file << "inactivehdmaster=1"; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
file << "change=1"; |
|
|
|
file << "change=1"; |
|
|
|
} |
|
|
|
} |
|
|
|
file << strprintf(" # addr=%s%s\n", strAddr, (pwalletMain->mapKeyMetadata[keyid].hdKeypath.size() > 0 ? " hdkeypath="+pwalletMain->mapKeyMetadata[keyid].hdKeypath : "")); |
|
|
|
file << strprintf(" # addr=%s%s\n", strAddr, (pwallet->mapKeyMetadata[keyid].hdKeypath.size() > 0 ? " hdkeypath="+pwallet->mapKeyMetadata[keyid].hdKeypath : "")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
file << "\n"; |
|
|
|
file << "\n"; |
|
|
@ -971,6 +987,8 @@ int64_t GetImportTimestamp(const UniValue& data, int64_t now) |
|
|
|
|
|
|
|
|
|
|
|
UniValue importmulti(const JSONRPCRequest& mainRequest) |
|
|
|
UniValue importmulti(const JSONRPCRequest& mainRequest) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(mainRequest); |
|
|
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
// clang-format off
|
|
|
|
if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2) |
|
|
|
if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1009,7 +1027,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest) |
|
|
|
" [{ \"success\": true } , { \"success\": false, \"error\": { \"code\": -1, \"message\": \"Internal Server Error\"} }, ... ]\n"); |
|
|
|
" [{ \"success\": true } , { \"success\": false, \"error\": { \"code\": -1, \"message\": \"Internal Server Error\"} }, ... ]\n"); |
|
|
|
|
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
// clang-format on
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, mainRequest.fHelp)) { |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, mainRequest.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1028,8 +1046,8 @@ UniValue importmulti(const JSONRPCRequest& mainRequest) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
|
|
|
|
|
|
|
|
// Verify all timestamps are present before importing any keys.
|
|
|
|
// Verify all timestamps are present before importing any keys.
|
|
|
|
const int64_t now = chainActive.Tip() ? chainActive.Tip()->GetMedianTimePast() : 0; |
|
|
|
const int64_t now = chainActive.Tip() ? chainActive.Tip()->GetMedianTimePast() : 0; |
|
|
@ -1051,7 +1069,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest) |
|
|
|
|
|
|
|
|
|
|
|
BOOST_FOREACH (const UniValue& data, requests.getValues()) { |
|
|
|
BOOST_FOREACH (const UniValue& data, requests.getValues()) { |
|
|
|
const int64_t timestamp = std::max(GetImportTimestamp(data, now), minimumTimestamp); |
|
|
|
const int64_t timestamp = std::max(GetImportTimestamp(data, now), minimumTimestamp); |
|
|
|
const UniValue result = ProcessImport(pwalletMain, data, timestamp); |
|
|
|
const UniValue result = ProcessImport(pwallet, data, timestamp); |
|
|
|
response.push_back(result); |
|
|
|
response.push_back(result); |
|
|
|
|
|
|
|
|
|
|
|
if (!fRescan) { |
|
|
|
if (!fRescan) { |
|
|
@ -1073,8 +1091,8 @@ UniValue importmulti(const JSONRPCRequest& mainRequest) |
|
|
|
CBlockIndex* pindex = nLowestTimestamp > minimumTimestamp ? chainActive.FindEarliestAtLeast(std::max<int64_t>(nLowestTimestamp - 7200, 0)) : chainActive.Genesis(); |
|
|
|
CBlockIndex* pindex = nLowestTimestamp > minimumTimestamp ? chainActive.FindEarliestAtLeast(std::max<int64_t>(nLowestTimestamp - 7200, 0)) : chainActive.Genesis(); |
|
|
|
CBlockIndex* scannedRange = nullptr; |
|
|
|
CBlockIndex* scannedRange = nullptr; |
|
|
|
if (pindex) { |
|
|
|
if (pindex) { |
|
|
|
scannedRange = pwalletMain->ScanForWalletTransactions(pindex, true); |
|
|
|
scannedRange = pwallet->ScanForWalletTransactions(pindex, true); |
|
|
|
pwalletMain->ReacceptWalletTransactions(); |
|
|
|
pwallet->ReacceptWalletTransactions(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!scannedRange || scannedRange->nHeight > pindex->nHeight) { |
|
|
|
if (!scannedRange || scannedRange->nHeight > pindex->nHeight) { |
|
|
|