feat: add CLI commands for creating posts, aggregates, and forget messages#82
Conversation
foxpatch-aleph
left a comment
There was a problem hiding this comment.
This PR adds useful CLI commands for creating posts, aggregates, and forget messages. The overall structure is clean and the code is well-organized. However, there are several issues that need to be addressed: (1) Using .unwrap() on hash parsing in the From implementations can cause panics instead of proper errors, (2) Private keys passed via CLI arguments can be exposed in process listings and shell history, and (3) no tests are added for the new functionality.
crates/aleph-cli/src/cli.rs (line 350): Using .unwrap() here will panic on invalid hash input rather than returning a proper error. The From<MessageFilterCli> implementation should handle parsing errors gracefully. Consider using map(|s| s.parse().unwrap()) with proper error handling, or changing the field type to store strings and parse later in the SDK layer.
crates/aleph-cli/src/cli.rs (line 357): Same issue as line 350 - .unwrap() on hash parsing will panic on invalid input.
crates/aleph-cli/src/cli.rs (line 258): Security concern: Allowing private keys via --private-key CLI argument exposes them in process listings (ps aux), shell history, and logs. Consider removing this option entirely and requiring the ALEPH_PRIVATE_KEY environment variable only, or at minimum add a prominent warning in the help text.
crates/aleph-cli/src/account.rs (line 47): Consider validating the private key length before passing to account constructors. EVM keys should be 32 bytes and Solana keys should be 64 bytes. This provides clearer error messages than letting the account constructor fail.
crates/aleph-cli/src/main.rs (line 140): The post_message call passes true for the sync flag, which blocks until the message is processed. This is reasonable for a CLI but consider adding a --async or --no-wait flag for users who want non-blocking behavior.
crates/aleph-cli/src/ (line None): No tests are added for the new functionality. At minimum, add unit tests for: (1) load_account with valid/invalid keys, (2) read_content with stdin and flag input, (3) the CLI argument parsing for the new commands. Consider integration tests that verify the CLI commands produce the expected message envelopes.
crates/aleph-cli/src/cli.rs (line 446): Minor: The #[arg(long = "type")] annotation is correct but note that type is a reserved keyword in some contexts. The current usage is fine with clap, but be aware this might cause confusion in shell completion scripts.
30b1fb8 to
43a124f
Compare
…sages Add four new commands matching the Python aleph-client CLI: - `aleph post create --type <type> --content <json>` - `aleph post amend --ref <hash> --content <json>` - `aleph aggregate create --key <key> --content <json>` - `aleph message forget <hashes...> [--reason <text>]` All write commands share --private-key (or ALEPH_PRIVATE_KEY env var) and --chain flags (27 EVM+SVM chains, default ETH). Content can be passed via --content flag or piped from stdin. Output modes: - Default: human-readable summary (item hash, sender, explorer link) - --json: structured JSON for scripting/tooling - --dry-run: build and sign but don't submit (prints full message) Supporting changes: - CliAccount enum wrapping EvmAccount/SolanaAccount for generic builders - ChainCli enum exposing only signable chains - --ccn-url promoted to global CLI flag (was hardcoded) - Derive Serialize on PostMessageResponse for JSON output - Fix EIP-55 checksum encoding for EVM addresses (was lowercase) - API errors now show the response body with extracted error message Tests: 20 new tests covering load_account (EVM/SOL/errors/0x prefix), read_content, format_api_error, and envelope construction shapes.
43a124f to
bf97ddf
Compare
Add four new commands matching the Python aleph-client CLI:
aleph post create --type <type> --content <json>aleph post amend --ref <hash> --content <json>aleph aggregate create --key <key> --content <json>aleph message forget <hashes...> [--reason <text>]All write commands share --private-key (or ALEPH_PRIVATE_KEY env var) and --chain flags (27 EVM+SVM chains, default ETH). Content can be passed via --content flag or piped from stdin.
Supporting changes: