use clap::{Parser, Subcommand}; #[derive(Parser, Clone)] #[command(name = "nac")] #[command(version = "1.0.0")] #[command(about = "NAC区块链命令行工具", long_about = None)] #[command(author = "NAC Team")] pub struct Cli { #[command(subcommand)] pub command: Commands, /// 输出格式 (json, yaml, table) #[arg(long, short = 'o', default_value = "table", global = true)] pub output: String, /// 详细输出 #[arg(long, short = 'v', global = true)] pub verbose: bool, /// RPC节点地址 #[arg(long, global = true)] pub rpc_url: Option, } #[derive(Subcommand, Clone)] pub enum Commands { /// 账户管理 #[command(subcommand)] Account(AccountCommands), /// 交易管理 #[command(subcommand, alias = "tx")] Transaction(TransactionCommands), /// 合约管理 #[command(subcommand)] Contract(ContractCommands), /// 宪法查询 #[command(subcommand)] Constitution(ConstitutionCommands), /// 节点管理 #[command(subcommand)] Node(NodeCommands), /// 区块查询 #[command(subcommand)] Block(BlockCommands), /// 配置管理 #[command(subcommand)] Config(ConfigCommands), /// 工具功能 #[command(subcommand)] Utils(UtilsCommands), } #[derive(Subcommand, Clone)] pub enum AccountCommands { /// 创建新账户 Create { /// 账户密码 #[arg(long)] password: Option, }, /// 列出所有账户 List, /// 查看账户详情 Show { /// 账户地址 address: String, }, /// 导入账户 Import { /// 私钥(十六进制) #[arg(long)] private_key: String, /// 账户密码 #[arg(long)] password: Option, }, /// 导出账户私钥 Export { /// 账户地址 address: String, /// 账户密码 #[arg(long)] password: Option, }, /// 查询账户余额 Balance { /// 账户地址 address: String, }, } #[derive(Subcommand, Clone)] pub enum TransactionCommands { /// 发送交易 Send { /// 发送方地址 from: String, /// 接收方地址 to: String, /// 金额 amount: String, /// Gas限制 #[arg(long)] gas_limit: Option, /// Gas价格 #[arg(long)] gas_price: Option, }, /// 查看交易详情 Show { /// 交易哈希 tx_hash: String, }, /// 列出交易历史 List { /// 账户地址 address: String, /// 限制数量 #[arg(long, default_value = "10")] limit: usize, }, /// 签名交易 Sign { /// 交易文件路径 tx_file: String, /// 私钥 #[arg(long)] private_key: String, }, /// 广播已签名交易 Broadcast { /// 已签名交易(十六进制) signed_tx: String, }, } #[derive(Subcommand, Clone)] pub enum ContractCommands { /// 部署合约 Deploy { /// WASM文件路径 wasm_file: String, /// 部署者地址 #[arg(long)] from: String, /// 初始化参数(JSON) #[arg(long)] init_args: Option, }, /// 调用合约方法 Call { /// 合约地址 address: String, /// 方法名 method: String, /// 参数(JSON数组) #[arg(long)] args: Option, /// 调用者地址 #[arg(long)] from: String, }, /// 查询合约状态 Query { /// 合约地址 address: String, /// 方法名 method: String, /// 参数(JSON数组) #[arg(long)] args: Option, }, /// 查看合约代码 Code { /// 合约地址 address: String, }, } #[derive(Subcommand, Clone)] pub enum ConstitutionCommands { /// 列出所有宪法条款 List, /// 查看条款详情 Show { /// 条款ID clause_id: String, }, /// 验证条款状态 Verify { /// 条款ID clause_id: String, }, /// 查看条款参数 Params { /// 条款ID clause_id: String, }, } #[derive(Subcommand, Clone)] pub enum NodeCommands { /// 查看节点信息 Info, /// 查看节点状态 Status, /// 查看对等节点 Peers, /// 查看同步状态 Sync, } #[derive(Subcommand, Clone)] pub enum BlockCommands { /// 查看区块详情 Show { /// 区块高度或哈希 block_id: String, }, /// 查看最新区块 Latest, /// 列出区块 List { /// 起始高度 #[arg(default_value = "0")] start: u64, /// 结束高度(可选) end: Option, /// 限制数量 #[arg(long, default_value = "10")] limit: usize, }, } #[derive(Subcommand, Clone)] pub enum ConfigCommands { /// 初始化配置 Init, /// 显示当前配置 Show, /// 设置配置项 Set { /// 配置键 key: String, /// 配置值 value: String, }, /// 获取配置项 Get { /// 配置键 key: String, }, } #[derive(Subcommand, Clone)] pub enum UtilsCommands { /// 生成密钥对 Keygen, /// 计算哈希 Hash { /// 数据(十六进制或字符串) data: String, }, /// GNACS编码 Encode { /// 数据 data: String, }, /// GNACS解码 Decode { /// GNACS编码(48位二进制) gnacs: String, }, }