platform icon indicating copy to clipboard operation
platform copied to clipboard

test(dapi): dapi-cli example in dapi-grpc

Open lklimek opened this issue 3 months ago • 1 comments

Issue being fixed or feature implemented

For testing of DAPI, we need some tool

What was done?

Created dapi-grpc/examples/dap-cli

How Has This Been Tested?

On local devnet

Breaking Changes

None

Checklist:

  • [x] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have added or updated relevant unit/integration/functional/e2e tests
  • [ ] I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • [ ] I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • [ ] I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Adds a dapi-cli tool for interacting with DAPI over gRPC.
    • Core: fetch block hash by height, stream transactions (optionally hashes-only), subscribe to chain locks, monitor masternode updates, view masternode status.
    • Platform: get identity by public-key-hash (with proofs), get status, view protocol upgrade/state and vote status, broadcast & wait for state transitions, monitor transitions.
    • Configurable verbosity via CLI flag.
  • Chores

    • Adds CLI example to project config and updates package metadata and dev-dependencies.

lklimek avatar Oct 06 '25 13:10 lklimek

Walkthrough

Adds a new dapi-cli example under packages/dapi-grpc with a Clap/Tokio-based CLI for Core and Platform gRPC endpoints, many subcommands (core: block hash, transactions, masternode, chain locks; platform: identity, protocol, state transitions), centralized error types, and dev-dependency/Cargo metadata updates.

Changes

Cohort / File(s) Summary of Changes
Cargo metadata
packages/dapi-grpc/Cargo.toml
Adds [[example]] name = "dapi-cli" (path examples/dapi-cli/main.rs); adds a [dev-dependencies] block for many crates (dashcore, serde, tokio, ciborium, clap, tracing, etc.); updates package.metadata.cargo-machete.ignored to ["platform-version","futures-core","getrandom","tonic-prost-build"].
CLI entrypoint & errors
packages/dapi-grpc/examples/dapi-cli/main.rs, packages/dapi-grpc/examples/dapi-cli/error.rs
New async binary with global URL and verbosity options, tracing init, Clap routing; introduces CliResult and CliError enum with conversions and mapped error kinds.
Core command router
packages/dapi-grpc/examples/dapi-cli/core/mod.rs
Adds CoreCommand enum and dispatcher; exposes core submodules.
Core subcommands
packages/dapi-grpc/examples/dapi-cli/core/block_hash.rs, .../transactions.rs, .../masternode.rs, .../masternode_status.rs, .../chainlocks.rs
New command modules implementing gRPC flows: GetBlock (block hash + pretty JSON), streaming TransactionsWithProofs, Masternode list stream decoding, Masternode status lookup, and ChainLocks header subscription — each with a public Command struct and run async function.
Platform router
packages/dapi-grpc/examples/dapi-cli/platform/mod.rs
Adds PlatformCommand enum and dispatcher; exposes identity, protocol, and state_transition submodules.
Platform identity
packages/dapi-grpc/examples/dapi-cli/platform/identity.rs
Adds identity-by-public-key-hash command with optional proof, request/response handling, metadata and proof printing.
Platform protocol
packages/dapi-grpc/examples/dapi-cli/platform/protocol.rs
Adds commands for protocol upgrade state, upgrade vote status, and get_status; builds versioned requests, decodes optional hex inputs, prints metadata/entries/proofs.
State transition router
packages/dapi-grpc/examples/dapi-cli/platform/state_transition/mod.rs
Adds StateTransitionCommand enum (Monitor, Workflow) and dispatcher.
State transition monitor
packages/dapi-grpc/examples/dapi-cli/platform/state_transition/monitor.rs
Implements waiting for a state transition result by hash with optional proof; prints metadata, proof, or error information; exposes printer helpers.
State transition workflow
packages/dapi-grpc/examples/dapi-cli/platform/state_transition/workflow.rs
Implements broadcast of hex-encoded state transition, computes SHA-256 hash, broadcasts, waits for result with timeout and optional proof, and prints outcomes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant CLI as dapi-cli
  participant Core as CoreClient (gRPC)
  participant Plat as PlatformClient (gRPC)
  Note over CLI: parse args, init tracing
  U->>CLI: run --url <addr> <Core|Platform> <subcommand>
  alt Core subcommand
    CLI->>Core: unary or streaming request (GetBlock/Transactions...)
    Core-->>CLI: response / stream
    CLI-->>U: formatted output / logs
  else Platform subcommand
    CLI->>Plat: unary or streaming request (GetStatus/Identity/StateTransition...)
    Plat-->>CLI: response / stream
    CLI-->>U: formatted output / proofs / logs
  end
sequenceDiagram
  autonumber
  actor U as User
  participant CLI as dapi-cli (workflow)
  participant Plat as PlatformClient
  rect rgba(230,245,255,0.6)
  Note over CLI: Broadcast + Await Result (Workflow)
  U->>CLI: workflow --state-transition <HEX> --prove --timeout <s>
  CLI->>CLI: decode hex -> sha256(hash)
  CLI->>Plat: broadcastStateTransition(data)
  Plat-->>CLI: ack
  CLI->>Plat: waitForStateTransitionResult(hash, prove)
  alt Result::Proof
    Plat-->>CLI: Result(V0.Proof)
    CLI-->>U: print metadata + proof
  else Result::Error
    Plat-->>CLI: Result(V0.Error)
    CLI-->>U: print metadata + error
  else Result::None
    Plat-->>CLI: Result(V0.None)
    CLI-->>U: log no-result
  end
  end

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

Thump-thump, I hop to greet the new CLI,
Streams and proofs and hashes leap high.
I nibble logs, decode a hex delight,
Broadcast, await — then thump in the night.
A carrot for every clean, printed line 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "test(dapi): dapi-cli example in dapi-grpc" directly and accurately describes the primary change in the changeset. The title clearly identifies that a new dapi-cli example tool is being added to the dapi-grpc package, which aligns with the PR objectives to provide a testing tool for DAPI. The title is concise, specific, and avoids vague terminology or noise. While the title doesn't enumerate all the individual CLI subcommands (Core, Platform, StateTransition workflows, etc.), it appropriately summarizes the main deliverable at a high level, which is the addition of the example tool itself.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch test/dapi-cli

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 06 '25 13:10 coderabbitai[bot]