@ -936,7 +936,77 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp)
}
return result ;
}
//void ImportAddress(CWallet*, const CTxDestination& dest, const std::string& strLabel);
void ImportAddress ( CWallet * , const CBitcoinAddress & address , const std : : string & strLabel ) ;
UniValue importpubkey ( const UniValue & params , bool fHelp )
{
CWallet * const pwallet = vpwallets [ 0 ] ;
if ( ! pwallet ) {
return NullUniValue ;
}
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 4 )
throw std : : runtime_error (
" importpubkey \" pubkey \" ( \" label \" rescan ) \n "
" \n Adds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup. \n "
" \n Arguments: \n "
" 1. \" pubkey \" (string, required) The hex-encoded public key \n "
" 2. \" label \" (string, optional, default= \" \" ) An optional label \n "
" 3. rescan (boolean, optional, default=true) Rescan the wallet for transactions \n "
" \n Note: This call can take minutes to complete if rescan is true, during that time, other rpc calls \n "
" may report that the imported pubkey exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes. \n "
" \n Examples: \n "
" \n Import a public key with rescan \n "
+ HelpExampleCli ( " importpubkey " , " \" mypubkey \" " ) +
" \n Import using a label without rescan \n "
+ HelpExampleCli ( " importpubkey " , " \" mypubkey \" \" testing \" false " ) +
" \n As a JSON-RPC call \n "
+ HelpExampleRpc ( " importpubkey " , " \" mypubkey \" , \" testing \" , false " )
) ;
std : : string strLabel ;
if ( ! params [ 1 ] . isNull ( ) )
strLabel = params [ 1 ] . get_str ( ) ;
// Whether to perform rescan after import
bool fRescan = true ;
if ( ! params [ 2 ] . isNull ( ) )
fRescan = params [ 2 ] . get_bool ( ) ;
if ( fRescan & & fPruneMode )
throw JSONRPCError ( RPC_WALLET_ERROR , " Rescan is disabled in pruned mode " ) ;
WalletRescanReserver reserver ( pwallet ) ;
if ( fRescan & & ! reserver . reserve ( ) ) {
throw JSONRPCError ( RPC_WALLET_ERROR , " Wallet is currently rescanning. Abort existing rescan or wait. " ) ;
}
if ( ! IsHex ( params [ 0 ] . get_str ( ) ) )
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Pubkey must be a hex string " ) ;
std : : vector < unsigned char > data ( ParseHex ( params [ 0 ] . get_str ( ) ) ) ;
CPubKey pubKey ( data . begin ( ) , data . end ( ) ) ;
if ( ! pubKey . IsFullyValid ( ) )
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Pubkey is not a valid public key " ) ;
{
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
for ( const auto & dest : GetAllDestinationsForKey ( pubKey ) ) {
ImportAddress ( pwallet , dest , strLabel ) ;
}
//ImportScript(pwallet, GetScriptForRawPubKey(pubKey), strLabel, false);
//pwallet->LearnAllRelatedScripts(pubKey);
}
if ( fRescan )
{
pwallet - > RescanFromTime ( TIMESTAMP_MIN , reserver , true /* update */ ) ;
pwallet - > ReacceptWalletTransactions ( ) ;
}
return NullUniValue ;
}
UniValue getspentinfo ( const UniValue & params , bool fHelp )