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