192
199
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
193
200
"4. p2sh (boolean, optional, default=false) Add the P2SH version of the script as well\n"
194
201
"\nNote: This call can take minutes to complete if rescan is true.\n"
195
"If you have the full public key, you should call importpublickey instead of this.\n"
202
"If you have the full public key, you should call importpubkey instead of this.\n"
203
"\nNote: If you import a non-standard raw script in hex form, outputs sending to it will be treated\n"
204
"as change, and not show up in many RPCs.\n"
197
206
"\nImport a script with rescan\n"
198
207
+ HelpExampleCli("importaddress", "\"myscript\"") +
243
252
return NullUniValue;
255
UniValue importprunedfunds(const UniValue& params, bool fHelp)
257
if (!EnsureWalletIsAvailable(fHelp))
260
if (fHelp || params.size() < 2 || params.size() > 3)
262
"importprunedfunds\n"
263
"\nImports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n"
265
"1. \"rawtransaction\" (string, required) A raw transaction in hex funding an already-existing address in wallet\n"
266
"2. \"txoutproof\" (string, required) The hex output from gettxoutproof that contains the transaction\n"
267
"3. \"label\" (string, optional) An optional label\n"
271
if (!DecodeHexTx(tx, params[0].get_str()))
272
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
273
uint256 hashTx = tx.GetHash();
274
CWalletTx wtx(pwalletMain,tx);
276
CDataStream ssMB(ParseHexV(params[1], "proof"), SER_NETWORK, PROTOCOL_VERSION);
277
CMerkleBlock merkleBlock;
280
string strLabel = "";
281
if (params.size() == 3)
282
strLabel = params[2].get_str();
284
//Search partial merkle tree in proof for our transaction and index in valid block
285
vector<uint256> vMatch;
286
vector<unsigned int> vIndex;
287
unsigned int txnIndex = 0;
288
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == merkleBlock.header.hashMerkleRoot) {
292
if (!mapBlockIndex.count(merkleBlock.header.GetHash()) || !chainActive.Contains(mapBlockIndex[merkleBlock.header.GetHash()]))
293
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain");
295
vector<uint256>::const_iterator it;
296
if ((it = std::find(vMatch.begin(), vMatch.end(), hashTx))==vMatch.end()) {
297
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction given doesn't exist in proof");
300
txnIndex = vIndex[it - vMatch.begin()];
303
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Something wrong with merkleblock");
306
wtx.nIndex = txnIndex;
307
wtx.hashBlock = merkleBlock.header.GetHash();
309
LOCK2(cs_main, pwalletMain->cs_wallet);
311
if (pwalletMain->IsMine(tx)) {
312
CWalletDB walletdb(pwalletMain->strWalletFile, "r+", false);
313
pwalletMain->AddToWallet(wtx, false, &walletdb);
317
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No addresses in wallet correspond to included transaction");
320
UniValue removeprunedfunds(const UniValue& params, bool fHelp)
322
if (!EnsureWalletIsAvailable(fHelp))
325
if (fHelp || params.size() != 1)
327
"removeprunedfunds \"txid\"\n"
328
"\nDeletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will effect wallet balances.\n"
330
"1. \"txid\" (string, required) The hex-encoded id of the transaction you are deleting\n"
332
+ HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") +
333
"\nAs a JSON-RPC call\n"
334
+ HelpExampleRpc("removprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"")
337
LOCK2(cs_main, pwalletMain->cs_wallet);
340
hash.SetHex(params[0].get_str());
341
vector<uint256> vHash;
342
vHash.push_back(hash);
343
vector<uint256> vHashOut;
345
if(pwalletMain->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) {
346
throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not properly delete the transaction.");
349
if(vHashOut.empty()) {
350
throw JSONRPCError(RPC_INTERNAL_ERROR, "Transaction does not exist in wallet.");
353
ThreadFlushWalletDB(pwalletMain->strWalletFile);
246
358
UniValue importpubkey(const UniValue& params, bool fHelp)
248
360
if (!EnsureWalletIsAvailable(fHelp))
485
597
std::sort(vKeyBirth.begin(), vKeyBirth.end());
487
599
// produce output
488
file << strprintf("# Wallet dump created by Bitcoin %s (%s)\n", CLIENT_BUILD, CLIENT_DATE);
600
file << strprintf("# Wallet dump created by Bitcoin %s\n", CLIENT_BUILD);
489
601
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
490
602
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
491
603
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
606
// add the base58check encoded extended master if the wallet uses HD
607
CKeyID masterKeyID = pwalletMain->GetHDChain().masterKeyID;
608
if (!masterKeyID.IsNull())
611
if (pwalletMain->GetKey(masterKeyID, key))
614
masterKey.SetMaster(key.begin(), key.size());
616
CBitcoinExtKey b58extkey;
617
b58extkey.SetKey(masterKey);
619
file << "# extended private masterkey: " << b58extkey.ToString() << "\n\n";
493
622
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
494
623
const CKeyID &keyid = it->second;
495
624
std::string strTime = EncodeDumpTime(it->first);
496
625
std::string strAddr = CBitcoinAddress(keyid).ToString();
498
627
if (pwalletMain->GetKey(keyid, key)) {
628
file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), strTime);
499
629
if (pwalletMain->mapAddressBook.count(keyid)) {
500
file << strprintf("%s %s label=%s # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, EncodeDumpString(pwalletMain->mapAddressBook[keyid].name), strAddr);
630
file << strprintf("label=%s", EncodeDumpString(pwalletMain->mapAddressBook[keyid].name));
631
} else if (keyid == masterKeyID) {
632
file << "hdmaster=1";
501
633
} else if (setKeyPool.count(keyid)) {
502
file << strprintf("%s %s reserve=1 # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, strAddr);
635
} else if (pwalletMain->mapKeyMetadata[keyid].hdKeypath == "m") {
636
file << "inactivehdmaster=1";
504
file << strprintf("%s %s change=1 # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, strAddr);
640
file << strprintf(" # addr=%s%s\n", strAddr, (pwalletMain->mapKeyMetadata[keyid].hdKeypath.size() > 0 ? " hdkeypath="+pwalletMain->mapKeyMetadata[keyid].hdKeypath : ""));