Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add definitions for ImportAddress, uncomment in kmd_validation015.h #17

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/komodo_validation015.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ int32_t komodo_importaddress(std::string addr)
else
{
printf("komodo_importaddress %s\n",EncodeDestination(address).c_str());
//ImportAddress(pwallet, address, addr);
ImportAddress(pwallet, address, addr);
return(1);
}
}
Expand Down
37 changes: 37 additions & 0 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,43 @@ RPCHelpMan abortrescan()
};
}

void ImportAddress(CWallet*, const CTxDestination& dest, const std::string& strLabel);
void ImportScript(CWallet* const pwallet, const CScript& script, const std::string& strLabel, bool isRedeemScript)
{
if (!isRedeemScript && pwallet->IsMine(script) == ISMINE_SPENDABLE) {
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
}

pwallet->MarkDirty();

auto spk_man = pwallet->GetLegacyScriptPubKeyMan();

if (!spk_man->HaveWatchOnly(script) && !spk_man->AddWatchOnly(script, 0 /* nCreateTime */)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
}

if (isRedeemScript) {
if (!spk_man->HaveCScript(CScriptID(script)) && !spk_man->AddCScript(script)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding p2sh redeemScript to wallet");
}
ImportAddress(pwallet, ScriptHash(script), strLabel);
} else {
CTxDestination destination;
if (ExtractDestination(script, destination)) {
pwallet->SetAddressBook(destination, strLabel, "receive");
}
}
}

void ImportAddress(CWallet* const pwallet, const CTxDestination& dest, const std::string& strLabel)
{
CScript script = GetScriptForDestination(dest);
ImportScript(pwallet, script, strLabel, false);
// add to address book or update label
if (IsValidDestination(dest))
pwallet->SetAddressBook(dest, strLabel, "receive");
}

RPCHelpMan importaddress()
{
return RPCHelpMan{"importaddress",
Expand Down