| 114 | } |
| 115 | |
| 116 | bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) |
| 117 | { |
| 118 | if (args.IsArgSet("-format") && command != "createfromdump") { |
| 119 | tfm::format(std::cerr, "The -format option can only be used with the \"createfromdump\" command.\n"); |
| 120 | return false; |
| 121 | } |
| 122 | if (args.IsArgSet("-dumpfile") && command != "dump" && command != "createfromdump") { |
| 123 | tfm::format(std::cerr, "The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n"); |
| 124 | return false; |
| 125 | } |
| 126 | if (args.IsArgSet("-descriptors") && command != "create") { |
| 127 | tfm::format(std::cerr, "The -descriptors option can only be used with the 'create' command.\n"); |
| 128 | return false; |
| 129 | } |
| 130 | if (args.IsArgSet("-legacy") && command != "create") { |
| 131 | tfm::format(std::cerr, "The -legacy option can only be used with the 'create' command.\n"); |
| 132 | return false; |
| 133 | } |
| 134 | if (command == "create" && !args.IsArgSet("-wallet")) { |
| 135 | tfm::format(std::cerr, "Wallet name must be provided when creating a new wallet.\n"); |
| 136 | return false; |
| 137 | } |
| 138 | const std::string name = args.GetArg("-wallet", ""); |
| 139 | const fs::path path = fsbridge::AbsPathJoin(GetWalletDir(), fs::PathFromString(name)); |
| 140 | |
| 141 | if (command == "create") { |
| 142 | DatabaseOptions options; |
| 143 | options.require_create = true; |
| 144 | // If -legacy is set, use it. Otherwise default to false. |
| 145 | bool make_legacy = args.GetBoolArg("-legacy", false); |
| 146 | // If neither -legacy nor -descriptors is set, default to true. If -descriptors is set, use its value. |
| 147 | bool make_descriptors = (!args.IsArgSet("-descriptors") && !args.IsArgSet("-legacy")) || (args.IsArgSet("-descriptors") && args.GetBoolArg("-descriptors", true)); |
| 148 | if (make_legacy && make_descriptors) { |
| 149 | tfm::format(std::cerr, "Only one of -legacy or -descriptors can be set to true, not both\n"); |
| 150 | return false; |
| 151 | } |
| 152 | if (!make_legacy && !make_descriptors) { |
| 153 | tfm::format(std::cerr, "One of -legacy or -descriptors must be set to true (or omitted)\n"); |
| 154 | return false; |
| 155 | } |
| 156 | if (make_descriptors) { |
| 157 | options.create_flags |= WALLET_FLAG_DESCRIPTORS; |
| 158 | options.require_format = DatabaseFormat::SQLITE; |
| 159 | } |
| 160 | |
| 161 | const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, args, options); |
| 162 | if (wallet_instance) { |
| 163 | WalletShowInfo(wallet_instance.get()); |
| 164 | wallet_instance->Close(); |
| 165 | } |
| 166 | } else if (command == "info") { |
| 167 | DatabaseOptions options; |
| 168 | options.require_existing = true; |
| 169 | const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, args, options); |
| 170 | if (!wallet_instance) return false; |
| 171 | WalletShowInfo(wallet_instance.get()); |
| 172 | wallet_instance->Close(); |
| 173 | } else if (command == "salvage") { |
no test coverage detected