NAC_Blockchain/archive/nac-cli-backup/src/cli.rs

326 lines
5.7 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<String>,
}
#[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<String>,
},
/// 列出所有账户
List,
/// 查看账户详情
Show {
/// 账户地址
address: String,
},
/// 导入账户
Import {
/// 私钥(十六进制)
#[arg(long)]
private_key: String,
/// 账户密码
#[arg(long)]
password: Option<String>,
},
/// 导出账户私钥
Export {
/// 账户地址
address: String,
/// 账户密码
#[arg(long)]
password: Option<String>,
},
/// 查询账户余额
Balance {
/// 账户地址
address: String,
},
}
#[derive(Subcommand, Clone)]
pub enum TransactionCommands {
/// 发送交易
Send {
/// 发送方地址
from: String,
/// 接收方地址
to: String,
/// 金额
amount: String,
/// Gas限制
#[arg(long)]
gas_limit: Option<u64>,
/// Gas价格
#[arg(long)]
gas_price: Option<u64>,
},
/// 查看交易详情
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<String>,
},
/// 调用合约方法
Call {
/// 合约地址
address: String,
/// 方法名
method: String,
/// 参数JSON数组
#[arg(long)]
args: Option<String>,
/// 调用者地址
#[arg(long)]
from: String,
},
/// 查询合约状态
Query {
/// 合约地址
address: String,
/// 方法名
method: String,
/// 参数JSON数组
#[arg(long)]
args: Option<String>,
},
/// 查看合约代码
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<u64>,
/// 限制数量
#[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,
},
}