#json-rpc #json-rpc-server #axum #abstraction #prople #tokio #run-rpc

prople-jsonrpc-axum

该库提供了处理 JSON-RPC 的核心抽象

2 个版本

新版本 0.1.1 2024 年 8 月 26 日
0.1.0 2024 年 6 月 24 日

5#prople 中排名

Download history 137/week @ 2024-06-24

每月 95 次下载

GPL-3.0-only

50KB
752

prople/jsonrpc/axum

使用 JSON-RPC 服务器实现的 Tokio Axum

用法

use tokio;
use prople_jsonrpc_axum::{Config, RpcState, run_rpc, build_canceller};

#[tokio:main]
async fn main() {
    let cfg = Config { ... };
    let state = RpcState { ... };
    let (_, rx) = build_canceller(0);

    run_rpc(cfg, state, rx).await;
}

示例

fn build_rpc_processor(args: AnaArgs) -> RpcState {
    let mut cf_names: Vec<String> = Vec::new();
    cf_names.push(types::STORAGE_COLUMN_DID.to_string());
    cf_names.push(types::STORAGE_COLUMN_DID_DOC.to_string());
    cf_names.push(types::STORAGE_COLUMN_DID_KEY_SECURES.to_string());

    let mut rocksdb_opts = RocksDBOptions::default();
    rocksdb_opts.max_write_buffer_number = 6;

    let storage_path = args.db_path;
    let storage = RocksDB::new(&storage_path, cf_names, rocksdb_opts)
        .expect("Failed to initiate RocksDB instance");
    let storage_did = StorageDID::new(storage);
    let handler_did = IdentityRPCHandler::new(Box::new(storage_did));

    let mut processor = RpcProcessorObject::build();
    processor.register_handler(
        String::from("prople.agent.controller.setup"),
        Box::new(handler_did),
    );

    RpcState {
        processor: Arc::new(processor),
    }
}

依赖项

~16–29MB
~439K SLoC