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 envelope —
JsonRpcRequest,JsonRpcResponse,JsonRpcError,RequestId,Version. - A stable error-code enum with explicit numeric wire values.
- Shared domain types —
HashHex,PubkeyHex,SignatureHex,Amount,BlockSummary,ValidatorSummary,ValidatorStatus. - The fullnode method catalogue — one
{Method}Request+{Method}Responsepair 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
clientfeature), 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
- Every enum is
#[non_exhaustive]— adding variants is additive, not breaking. ErrorCodenumeric values never change once assigned. New variants take the next unused integer.- Method names are snake_case and stable.
- Hex-encoded fields emit
0x+ lowercase; accept case-insensitive with optional0xprefix on parse. - Response envelopes are valid JSON-RPC 2.0 — exactly one of
resultorerrorper response, never both, never neither. SCHEMA_VERSIONis 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
| Flag | Default | Effect |
|---|---|---|
client | off | Ships a thin blocking reqwest-backed client for CLI tools |
schema-export | off | Generates 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-rpcservers in response headers / extensions.