mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
SegWit wallet support
This introduces two command line flags (-addresstype and -changetype) which control the type of addresses/outputs created by the GUI and RPCs. Certain RPCs allow overriding these (`getnewaddress` and `getrawchangeaddress`). Supported types are "legacy" (P2PKH and P2SH-multisig), "p2sh-segwit" (P2SH-P2WPKH and P2SH-P2WSH-multisig), and "bech32" (P2WPKH and P2WSH-multisig). A few utility functions are added to the wallet to construct different address type and to add the necessary entries to the wallet file to be compatible with earlier versions (see `CWallet::LearnRelatedScripts`, `GetDestinationForKey`, `GetAllDestinationsForKey`, `CWallet::AddAndGetDestinationForScript`).
This commit is contained in:
@@ -131,7 +131,11 @@ UniValue importprivkey(const JSONRPCRequest& request)
|
||||
CKeyID vchAddress = pubkey.GetID();
|
||||
{
|
||||
pwallet->MarkDirty();
|
||||
pwallet->SetAddressBook(vchAddress, strLabel, "receive");
|
||||
|
||||
// We don't know which corresponding address will be used; label them all
|
||||
for (const auto& dest : GetAllDestinationsForKey(pubkey)) {
|
||||
pwallet->SetAddressBook(dest, strLabel, "receive");
|
||||
}
|
||||
|
||||
// Don't throw error in case a key is already there
|
||||
if (pwallet->HaveKey(vchAddress)) {
|
||||
@@ -143,6 +147,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
|
||||
if (!pwallet->AddKeyPubKey(key, pubkey)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
|
||||
}
|
||||
pwallet->LearnAllRelatedScripts(pubkey);
|
||||
|
||||
// whenever a key is imported, we need to scan the whole chain
|
||||
pwallet->UpdateTimeFirstKey(1);
|
||||
@@ -433,8 +438,11 @@ UniValue importpubkey(const JSONRPCRequest& request)
|
||||
|
||||
LOCK2(cs_main, pwallet->cs_wallet);
|
||||
|
||||
ImportAddress(pwallet, pubKey.GetID(), strLabel);
|
||||
for (const auto& dest : GetAllDestinationsForKey(pubKey)) {
|
||||
ImportAddress(pwallet, dest, strLabel);
|
||||
}
|
||||
ImportScript(pwallet, GetScriptForRawPubKey(pubKey), strLabel, false);
|
||||
pwallet->LearnAllRelatedScripts(pubKey);
|
||||
|
||||
if (fRescan)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user