ckb_cli_plugin_protocol/
jsonrpc.rs1use ckb_types::{
2 packed::{CellInput, OutPoint},
3 prelude::Pack,
4 H256,
5};
6use serde_derive::{Deserialize, Serialize};
7
8pub const JSONRPC_VERSION: &str = "2.0";
9
10#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
12#[serde(deny_unknown_fields)]
13pub struct JsonrpcError {
14 pub code: i32,
16 pub message: String,
18 #[serde(skip_serializing_if = "Option::is_none")]
20 pub data: Option<serde_json::Value>,
21}
22
23#[derive(Serialize, Deserialize, Debug, Clone)]
25#[serde(deny_unknown_fields)]
26pub struct JsonrpcRequest {
27 pub jsonrpc: String,
29 pub id: serde_json::Value,
31 pub method: String,
33 pub params: Vec<serde_json::Value>,
35}
36
37#[derive(Serialize, Deserialize, Debug, Clone)]
39#[serde(deny_unknown_fields)]
40pub struct JsonrpcResponse {
41 pub jsonrpc: String,
43 pub id: serde_json::Value,
45 #[serde(skip_serializing_if = "Option::is_none")]
47 pub result: Option<serde_json::Value>,
48 #[serde(skip_serializing_if = "Option::is_none")]
50 pub error: Option<JsonrpcError>,
51}
52
53#[derive(Hash, Eq, PartialEq, Debug, Clone, Serialize, Deserialize)]
54pub struct LiveCellInfo {
55 pub tx_hash: H256,
56 pub output_index: u32,
57 pub data_bytes: u64,
58 pub lock_hash: H256,
59 pub type_hashes: Option<(H256, H256)>,
61 pub capacity: u64,
63 pub number: u64,
65 pub index: CellIndex,
67}
68
69impl LiveCellInfo {
70 pub fn out_point(&self) -> OutPoint {
71 OutPoint::new(self.tx_hash.pack(), self.output_index)
72 }
73 pub fn input(&self) -> CellInput {
74 CellInput::new(self.out_point(), 0)
75 }
76}
77
78#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
80pub struct CellIndex {
81 pub tx_index: u32,
83 pub output_index: u32,
85}