Currently restorewallet() logic is written in the RPC layer and it can´t be reused by GUI. So it moves this to the wallet section and then, GUI can access it. This is necessary to implement the "Restore Wallet" menu item in the GUI (which is already implemented in bitcoin-core/gui#471 ). This commit also simplifies error handling and adds a new behavior: if the restore fails, the invalid wallet folder is removed.
Backport of core#23721.
Includes the bugfixes from core#26005 and the required dependencies for this bugfix PR.
Backport of core#26005, core#25594 and core#25616.
Also include a bugfix from core#26747:
https://github.com/bitcoin/bitcoin/pull/26747/commits/8c7222bda3f7136f312a6e57b76d6a2d0a114f68
Note that the test has not been backported yet, so this is a partial backport of core#26747.
Note that we don't have the restore menu in the GUI yet.
Depends on D17952.