Skip to main content

Crate dig_rpc_types

Crate dig_rpc_types 

Source
Expand description

§dig-rpc-types

Pure serde-derived wire types for the DIG Network JSON-RPC surface. This crate is the single source of truth for the shape of every request and response exchanged between a DIG fullnode / validator and its clients.

§What lives here

  • The JSON-RPC 2.0 envelopeJsonRpcRequest, JsonRpcResponse, JsonRpcError, RequestId, Version.
  • A stable error-code enum with explicit numeric wire values.
  • Shared domain typesHashHex, PubkeyHex, SignatureHex, Amount, BlockSummary, ValidatorSummary, ValidatorStatus.
  • The fullnode method catalogue — one {Method}Request + {Method}Response pair per method.
  • The validator method catalogue — operator-facing RPC.

§What does NOT live here

  • No I/O. No tokio, no reqwest (except behind the optional client feature), no Axum. Consumers build their own clients / servers over these types.
  • No business logic. A method’s request/response is defined; what the server does with it lives in dig-rpc, apps/fullnode, etc.
  • No validation beyond serde. Length caps, range checks, and cross-field invariants are the server’s responsibility.

§Stability guarantees

  1. Every enum is #[non_exhaustive] — adding variants is additive, not breaking.
  2. ErrorCode numeric values never change once assigned. New variants take the next unused integer.
  3. Method names are snake_case and stable.
  4. Hex-encoded fields emit 0x + lowercase; accept case-insensitive with optional 0x prefix on parse.
  5. Response envelopes are valid JSON-RPC 2.0 — exactly one of result or error per response, never both, never neither.
  6. SCHEMA_VERSION is bumped on wire-breaking changes.

§Versioning policy

  • Additive changes (new methods, new optional fields, new enum variants): bump the minor version. Clients on an older minor continue to work.
  • Removing or reshaping a field: bump the major version. Servers MAY serve multiple majors behind URL prefixes (/v1/, /v2/).

§Feature flags

FlagDefaultEffect
clientoffShips a thin blocking reqwest-backed client for CLI tools
schema-exportoffGenerates JSON-Schema dumps for Go/TS codegen via schemars

§Example — decode a response envelope

use dig_rpc_types::{JsonRpcResponse, JsonRpcResponseBody};

let raw = r#"{"jsonrpc":"2.0","id":1,"result":{"ok":true}}"#;
let resp: JsonRpcResponse<serde_json::Value> = serde_json::from_str(raw).unwrap();
match resp.body {
    JsonRpcResponseBody::Success { result } => {
        assert_eq!(result["ok"], true);
    }
    JsonRpcResponseBody::Error { .. } => unreachable!(),
}

Re-exports§

pub use envelope::JsonRpcError;
pub use envelope::JsonRpcRequest;
pub use envelope::JsonRpcResponse;
pub use envelope::JsonRpcResponseBody;
pub use envelope::RequestId;
pub use envelope::Version;
pub use errors::ErrorCode;
pub use types::Amount;
pub use types::BlockSummary;
pub use types::HashHex;
pub use types::PubkeyHex;
pub use types::SignatureHex;
pub use types::ValidatorStatus;
pub use types::ValidatorSummary;

Modules§

envelope
JSON-RPC 2.0 envelope types.
errors
Stable JSON-RPC error codes.
fullnode
Fullnode RPC method catalogue.
types
Shared domain types used across multiple RPC methods.
validator
Validator RPC method catalogue.

Constants§

SCHEMA_VERSION
Wire-schema version exposed by dig-rpc servers in response headers / extensions.