@@ -701,6 +701,59 @@ RPCHelpMan simulaterawtransaction()
701
701
};
702
702
}
703
703
704
+ static RPCHelpMan migratewallet ()
705
+ {
706
+ return RPCHelpMan{" migratewallet" ,
707
+ " EXPERIMENTAL warning: This call may not work as expected and may be changed in future releases\n "
708
+ " \n Migrate the wallet to a descriptor wallet.\n "
709
+ " A new wallet backup will need to be made.\n "
710
+ " \n The migration process will create a backup of the wallet before migrating. This backup\n "
711
+ " file will be named <wallet name>-<timestamp>.legacy.bak and can be found in the directory\n "
712
+ " for this wallet. In the event of an incorrect migration, the backup can be restored using restorewallet." +
713
+ HELP_REQUIRING_PASSPHRASE,
714
+ {},
715
+ RPCResult{
716
+ RPCResult::Type::OBJ, " " , " " ,
717
+ {
718
+ {RPCResult::Type::STR, " wallet_name" , " The name of the primary migrated wallet" },
719
+ {RPCResult::Type::STR, " watchonly_name" , /* optional=*/ true , " The name of the migrated wallet containing the watchonly scripts" },
720
+ {RPCResult::Type::STR, " solvables_name" , /* optional=*/ true , " The name of the migrated wallet containing solvable but not watched scripts" },
721
+ {RPCResult::Type::STR, " backup_path" , " The location of the backup of the original wallet" },
722
+ }
723
+ },
724
+ RPCExamples{
725
+ HelpExampleCli (" migratewallet" , " " )
726
+ + HelpExampleRpc (" migratewallet" , " " )
727
+ },
728
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
729
+ {
730
+ std::shared_ptr<CWallet> wallet = GetWalletForJSONRPCRequest (request);
731
+ if (!wallet) return NullUniValue;
732
+
733
+ EnsureWalletIsUnlocked (*wallet);
734
+
735
+ WalletContext& context = EnsureWalletContext (request.context );
736
+
737
+ util::Result<MigrationResult> res = MigrateLegacyToDescriptor (std::move (wallet), context);
738
+ if (!res) {
739
+ throw JSONRPCError (RPC_WALLET_ERROR, util::ErrorString (res).original );
740
+ }
741
+
742
+ UniValue r{UniValue::VOBJ};
743
+ r.pushKV (" wallet_name" , res->wallet_name );
744
+ if (res->watchonly_wallet ) {
745
+ r.pushKV (" watchonly_name" , res->watchonly_wallet ->GetName ());
746
+ }
747
+ if (res->solvables_wallet ) {
748
+ r.pushKV (" solvables_name" , res->solvables_wallet ->GetName ());
749
+ }
750
+ r.pushKV (" backup_path" , res->backup_path .u8string ());
751
+
752
+ return r;
753
+ },
754
+ };
755
+ }
756
+
704
757
// addresses
705
758
RPCHelpMan getaddressinfo ();
706
759
RPCHelpMan getnewaddress ();
@@ -820,6 +873,7 @@ Span<const CRPCCommand> GetWalletRPCCommands()
820
873
{" wallet" , &listwallets},
821
874
{" wallet" , &loadwallet},
822
875
{" wallet" , &lockunspent},
876
+ {" wallet" , &migratewallet},
823
877
{" wallet" , &newkeypool},
824
878
{" wallet" , &removeprunedfunds},
825
879
{" wallet" , &rescanblockchain},
0 commit comments