| 10 | namespace quip { |
| 11 | |
| 12 | class CLI { |
| 13 | public: |
| 14 | CLI(const std::string &rpc_url, const std::string &contract_address = ""); |
| 15 | ~CLI(); |
| 16 | |
| 17 | // Parse and execute commands |
| 18 | bool execute(const std::vector<std::string> &args); |
| 19 | |
| 20 | // For testing: set a custom wallet factory |
| 21 | void setWalletFactory(std::function<std::unique_ptr<QuipWallet>( |
| 22 | const std::string &, const std::string &)> |
| 23 | factory) { |
| 24 | wallet_factory_ = std::move(factory); |
| 25 | } |
| 26 | |
| 27 | private: |
| 28 | // Command handlers |
| 29 | bool handleGenerateKeypair(const std::vector<std::string> &args); |
| 30 | bool handleRecoverKeypair(const std::vector<std::string> &args); |
| 31 | bool handleSign(const std::vector<std::string> &args); |
| 32 | bool handleGetPqOwner(const std::vector<std::string> &args); |
| 33 | bool handleChangePqOwner(const std::vector<std::string> &args); |
| 34 | bool handleGetBalance(const std::vector<std::string> &args); |
| 35 | bool handleTransfer(const std::vector<std::string> &args); |
| 36 | bool handleExecute(const std::vector<std::string> &args); |
| 37 | bool handleDeposit(const std::vector<std::string> &args); |
| 38 | bool handleGetVault(const std::vector<std::string> &args); |
| 39 | bool handleGetVaults(const std::vector<std::string> &args); |
| 40 | |
| 41 | // Helper functions |
| 42 | void printUsage() const; |
| 43 | std::string getContractAddress(const std::string &contract_name) const; |
| 44 | std::array<uint8_t, 32> parseVaultId(const std::string &vault_id) const; |
| 45 | Address parseAddress(const std::string &address) const; |
| 46 | Amount parseAmount(const std::string &amount) const; |
| 47 | std::vector<uint8_t> parseOpData(const std::string &opdata) const; |
| 48 | std::vector<uint8_t> parsePublicKey(const std::string &pubkey) const; |
| 49 | std::vector<uint8_t> parseSignature(const std::string &sig) const; |
| 50 | std::vector<uint8_t> parsePrivateKey(const std::string &key) const; |
| 51 | |
| 52 | // Create a wallet instance |
| 53 | std::unique_ptr<QuipWallet> createWallet(const std::string &address) { |
| 54 | if (wallet_factory_) { |
| 55 | return wallet_factory_(rpc_url_, address); |
| 56 | } |
| 57 | return std::make_unique<QuipWallet>(rpc_url_, address); |
| 58 | } |
| 59 | |
| 60 | std::string rpc_url_; |
| 61 | std::string contract_address_; |
| 62 | std::unique_ptr<QuipFactory> factory_; |
| 63 | std::function<std::unique_ptr<QuipWallet>(const std::string &, |
| 64 | const std::string &)> |
| 65 | wallet_factory_; |
| 66 | }; |
| 67 | |
| 68 | } // namespace quip |
nothing calls this directly
no outgoing calls
no test coverage detected