Skip to content

Commit bb9426a

Browse files
random-zebraFuzzbawls
authored andcommitted
[RPC] Add coldstaking address support in importaddress
Github-Pull: #1242 Rebased-From: 3bd5579
1 parent 3084143 commit bb9426a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/wallet/rpcdump.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
9999
"\nAs a JSON-RPC call\n" +
100100
HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false"));
101101

102-
LOCK2(cs_main, pwalletMain->cs_wallet);
103-
104-
EnsureWalletIsUnlocked();
105-
106102
const std::string strSecret = params[0].get_str();
107103
const std::string strLabel = (params.size() > 1 ? params[1].get_str() : "");
108104
const bool fRescan = (params.size() > 2 ? params[2].get_bool() : true);
@@ -120,6 +116,9 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
120116
assert(key.VerifyPubKey(pubkey));
121117
CKeyID vchAddress = pubkey.GetID();
122118
{
119+
LOCK2(cs_main, pwalletMain->cs_wallet);
120+
EnsureWalletIsUnlocked();
121+
123122
pwalletMain->MarkDirty();
124123
pwalletMain->SetAddressBook(vchAddress, strLabel, (
125124
fStakingAddress ?
@@ -201,8 +200,12 @@ UniValue importaddress(const UniValue& params, bool fHelp)
201200
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
202201

203202
// add to address book or update label
204-
if (address.IsValid())
205-
pwalletMain->SetAddressBook(address.Get(), strLabel, AddressBook::AddressBookPurpose::RECEIVE);
203+
if (address.IsValid()) {
204+
pwalletMain->SetAddressBook(address.Get(), strLabel,
205+
(address.IsStakingAddress() ?
206+
AddressBook::AddressBookPurpose::COLD_STAKING :
207+
AddressBook::AddressBookPurpose::RECEIVE));
208+
}
206209

207210
// Don't throw error in case an address is already there
208211
if (pwalletMain->HaveWatchOnly(script))

0 commit comments

Comments
 (0)