Merge pull request #4045
a3e192areplaced MINE_ with ISMINE_ (JaSK)53a2148fixed bug where validateaddress doesn't display information (JaSK)f28707afixed bug in ListReceived() (JaSK)519dd1cAdded MINE_ALL = (spendable|watchonly) (JaSK)23b0506Fixed some stuff in TransactionDesc (JaSK)80dda36removed default argument values for ismine filter (JaSK)d5087d1Use script matching rather than destination matching for watch-only. (Pieter Wuille)0fa2f88added includedWatchonly argument to listreceivedbyaddress/...account (JaSK)f87ba3dadded includeWatchonly argument to 'gettransaction' because it affects balance calculation (JaSK)a5c6c5dfixed tiny glitch and improved readability like laanwj suggested (JaSK)d7d5d23Added argument to listtransactions and listsinceblock to include watchonly addresses (JaSK)952877eShowing 'involvesWatchonly' property for transactions returned by 'listtransactions' and 'listsinceblock'. It is only appended when the transaction involves a watchonly address. (JaSK)83f3543Added argument to listaccounts to include watchonly addresses (JaSK)d4640d7Added argument to getbalance to include watchonly addresses and fixed errors in balance calculation. (JaSK)d2692f6Watchonly transactions are marked in transaction history (JaSK)ffd40daWatchonly balances are shown separately in gui. (JaSK)2935b21qt: Hide unspendable outputs in coin control (Wladimir J. van der Laan)c898846Add support for watch-only addresses (Pieter Wuille)
This commit is contained in:
@@ -133,6 +133,60 @@ Value importprivkey(const Array& params, bool fHelp)
|
||||
return Value::null;
|
||||
}
|
||||
|
||||
Value importaddress(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 3)
|
||||
throw runtime_error(
|
||||
"importaddress <address> [label] [rescan=true]\n"
|
||||
"Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend.");
|
||||
|
||||
CScript script;
|
||||
|
||||
CBitcoinAddress address(params[0].get_str());
|
||||
if (address.IsValid()) {
|
||||
script.SetDestination(address.Get());
|
||||
} else if (IsHex(params[0].get_str())) {
|
||||
std::vector<unsigned char> data(ParseHex(params[0].get_str()));
|
||||
script = CScript(data.begin(), data.end());
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address or script");
|
||||
}
|
||||
|
||||
string strLabel = "";
|
||||
if (params.size() > 1)
|
||||
strLabel = params[1].get_str();
|
||||
|
||||
// Whether to perform rescan after import
|
||||
bool fRescan = true;
|
||||
if (params.size() > 2)
|
||||
fRescan = params[2].get_bool();
|
||||
|
||||
{
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
// add to address book or update label
|
||||
if (address.IsValid())
|
||||
pwalletMain->SetAddressBook(address.Get(), strLabel, "receive");
|
||||
|
||||
// Don't throw error in case an address is already there
|
||||
if (pwalletMain->HaveWatchOnly(script))
|
||||
return Value::null;
|
||||
|
||||
pwalletMain->MarkDirty();
|
||||
|
||||
if (!pwalletMain->AddWatchOnly(script))
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
|
||||
|
||||
if (fRescan)
|
||||
{
|
||||
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true);
|
||||
pwalletMain->ReacceptWalletTransactions();
|
||||
}
|
||||
}
|
||||
|
||||
return Value::null;
|
||||
}
|
||||
|
||||
Value importwallet(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
|
||||
Reference in New Issue
Block a user