sdk: build CLI clients directly from CliContext (from_context)#3805
Open
juan-malbeclabs wants to merge 1 commit into
Open
sdk: build CLI clients directly from CliContext (from_context)#3805juan-malbeclabs wants to merge 1 commit into
juan-malbeclabs wants to merge 1 commit into
Conversation
Build the serviceability and geolocation SDK clients directly from a resolved RFC-20 CliContext instead of round-tripping its values back through DZClient::new's config-file re-resolution and moniker conversion. - Add DZClient::from_context and GeoClient::from_context, gated behind a new `cli-context` cargo feature so non-CLI SDK consumers keep a dependency-light default build. - Preserve keypair precedence (CLI flag > DOUBLEZERO_KEYPAIR > stdin > context keypair path > default); the context path is only the low-precedence fallback so the env var still wins. - Wire the doublezero binary to from_context, removing the legacy bridge.
ben-dz
reviewed
May 29, 2026
| - Migrate all eight `tenant` verbs (`create`, `update`, `list`, `get`, `delete`, `administrator add`, `administrator remove`, `update-payment-status`) and all six `permission` verbs (`set`, `suspend`, `resume`, `delete`, `get`, `list`) to the RFC-20 conforming shape on top of the shared CLI helpers. Every verb is now `pub async fn execute(self, ctx: &CliContext, client: &C, out: &mut W) -> eyre::Result<()>`, consumes the helpers (`require!`, `render_collection`, `render_record`, `print_signature`), and tenant verbs that accept a pubkey-or-code identifier (`update`, `delete`, `add-administrator`, `remove-administrator`, `update-payment-status`) route through a new `resolve_tenant_pk` helper in `smartcontract/cli/src/helpers.rs`. The duplicate-code precondition in `tenant create` is preserved, as is the `administrator = "me"` short-circuit. `tenant delete`'s bespoke two-line output ("✓ Tenant 'X' deleted successfully\n Signature: ..."), its cascade-delete progress spinners, and its reference-count polling loop are preserved with manual `writeln!` calls and an explanatory comment. `permission set`'s bespoke two-line aligned output ("Signature: ..." + "Permissions: ...") is preserved the same way. Permission verbs derive the on-chain PDA from `user_payer` rather than going through a pubkey-or-code resolver. `controlplane/doublezero-admin`, the unified `doublezero` binary, and the serviceability dispatcher all forward `&ctx` and await every tenant and permission arm. Behavior is byte-identical: table layout, JSON schema, `Signature:` line shape, and `--json` / `--json-compact` semantics match pre-refactor output exactly; all 18 tenant and 18 permission unit tests pass without assertion changes. | ||
| - SDK (Rust) | ||
| - Add `DZClient::from_context` and `GeoClient::from_context`, which build clients directly from a resolved RFC-20 `CliContext` instead of re-reading `~/.config/doublezero/cli/config.yml` and re-applying moniker conversion. The context already carries the fully resolved ledger RPC/WS URLs and program IDs, so these constructors consume them verbatim, making the context the single source of truth and removing the double-resolution the binary previously incurred. Keypair precedence is preserved exactly (CLI flag > `DOUBLEZERO_KEYPAIR` > stdin > context keypair path > default): the raw `--keypair` flag is passed as the highest-precedence source and the context keypair path is used only as the low-precedence fallback, so the env var still wins. The new constructors and their `doublezero-cli-core` dependency are gated behind a `cli-context` cargo feature so non-CLI SDK consumers (controlplane, telemetry, e2e) keep a dependency-light default build. `DZClient::new` / `GeoClient::new` are unchanged for callers that do not build a `CliContext` (e.g. `controlplane/doublezero-admin`). | ||
| - CLI |
Contributor
There was a problem hiding this comment.
There are already CLI and SDK sections. Fold the changelog entries into them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
DZClient::from_contextandGeoClient::from_contextto the Rust SDK, building clients directly from a resolved RFC-20CliContextinstead of re-readingconfig.ymland re-applying moniker conversion. The context already carries fully resolved ledger RPC/WS URLs and program IDs, so the context becomes the single source of truth and the binary's previous double-resolution is removed.DOUBLEZERO_KEYPAIR> stdin > context keypair path > default): the raw--keypairflag is the highest-precedence source and the context keypair path is only the low-precedence fallback, so the env var still wins.doublezero-cli-coredependency behind acli-contextcargo feature so non-CLI SDK consumers (controlplane, telemetry, e2e) keep a dependency-light default build.doublezerobinary tofrom_context, removing the legacyDZClient::new(Option<String>, ...)bridge.DZClient::new/GeoClient::neware unchanged for callers that build noCliContext(e.g.controlplane/doublezero-admin).Related RFC:
rfcs/rfc20-cli-standardization.mdDiff Breakdown
Small, focused change: two new SDK constructors plus binary wiring, with the bulk of additions being the constructors and their tests.
Key files (click to expand)
smartcontract/sdk/rs/src/client.rs— addDZClient::from_context(no config re-read / moniker conversion) plus feature-gated unit tests for resolved-value consumption and keypair env-var precedencesmartcontract/sdk/rs/src/geolocation/client.rs— addGeoClient::from_contextusing the context's ledger RPC URL and geolocation program IDclient/doublezero/src/main.rs— construct both clients viafrom_context, drop the legacy bridge localssmartcontract/sdk/rs/Cargo.toml— optionaldoublezero-cli-coredep behind a newcli-contextfeaturesmartcontract/sdk/rs/src/config.rs— makedefault_keypair_pathpub(crate)for the fallback pathTesting Verification
cargo test -p doublezero_sdk --features cli-context): one assertsfrom_contextconsumes the context's RPC/WS/program-ID verbatim with noconfig.ymlpresent, and one assertsDOUBLEZERO_KEYPAIRstill wins over a (bogus) context keypair path, guarding the masking hazard.doublezero location list(exercisesDZClient::from_context) anddoublezero geolocation probe list(exercisesGeoClient::from_context) both returned live data.cli-contextfeature) still compiles, so non-CLI consumers are unaffected.