cfx_rpc_cfx_api/
test.rs

1// Copyright 2019 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5use cfx_rpc_cfx_types::{pos::Block as PosBlock, BlameInfo, Block, Bytes};
6use cfx_types::{H256, U256, U64};
7use diem_types::{
8    account_address::AccountAddress, transaction::TransactionPayload,
9};
10use jsonrpsee::{core::RpcResult, proc_macros::rpc};
11use network::{node_table::NodeId, PeerInfo};
12use std::net::SocketAddr;
13
14#[rpc(server, namespace = "test")]
15pub trait TestRpc {
16    #[method(name = "sayHello")]
17    fn say_hello(&self) -> RpcResult<String>;
18
19    #[method(name = "getBlockCount")]
20    fn get_block_count(&self) -> RpcResult<u64>;
21
22    #[method(name = "getGoodPut")]
23    fn get_goodput(&self) -> RpcResult<String>;
24
25    #[method(name = "generateEmptyBlocks")]
26    fn generate_empty_blocks(&self, num_blocks: usize) -> RpcResult<Vec<H256>>;
27
28    #[method(name = "generateFixedBlock")]
29    fn generate_fixed_block(
30        &self, parent_hash: H256, referee: Vec<H256>, num_txs: usize,
31        adaptive: bool, difficulty: Option<u64>, pos_reference: Option<H256>,
32    ) -> RpcResult<H256>;
33
34    #[method(name = "addNode")]
35    fn add_peer(&self, id: NodeId, addr: SocketAddr) -> RpcResult<()>;
36
37    #[method(name = "removeNode")]
38    fn drop_peer(&self, id: NodeId, addr: SocketAddr) -> RpcResult<()>;
39
40    #[method(name = "getPeerInfo")]
41    fn get_peer_info(&self) -> RpcResult<Vec<PeerInfo>>;
42
43    /// Returns the JSON of whole chain
44    #[method(name = "getChain")]
45    fn chain(&self) -> RpcResult<Vec<Block>>;
46
47    #[method(name = "stop")]
48    fn stop(&self) -> RpcResult<()>;
49
50    #[method(name = "getNodeId")]
51    fn get_nodeid(&self, challenge: Vec<u8>) -> RpcResult<Vec<u8>>;
52
53    #[method(name = "addLatency")]
54    fn add_latency(&self, id: NodeId, latency_ms: f64) -> RpcResult<()>;
55
56    #[method(name = "generateOneBlock")]
57    fn generate_one_block(
58        &self, num_txs: usize, block_size_limit: usize,
59    ) -> RpcResult<H256>;
60
61    #[method(name = "generateOneBlockWithDirectTxGen")]
62    fn generate_one_block_with_direct_txgen(
63        &self, num_txs: usize, block_size_limit: usize, num_txs_simple: usize,
64        num_txs_erc20: usize,
65    ) -> RpcResult<H256>;
66
67    #[method(name = "generateCustomBlock")]
68    fn generate_custom_block(
69        &self, parent: H256, referees: Vec<H256>, raw: Bytes,
70        adaptive: Option<bool>, custom: Option<Vec<Bytes>>,
71    ) -> RpcResult<H256>;
72
73    #[method(name = "generateBlockWithFakeTxs")]
74    fn generate_block_with_fake_txs(
75        &self, raw: Bytes, adaptive: Option<bool>, tx_data_len: Option<usize>,
76    ) -> RpcResult<H256>;
77
78    #[method(name = "generateBlockWithBlameInfo")]
79    fn generate_block_with_blame_info(
80        &self, num_txs: usize, block_size_limit: usize, blame_info: BlameInfo,
81    ) -> RpcResult<H256>;
82
83    #[method(name = "generateBlockWithNonceAndTimestamp")]
84    fn generate_block_with_nonce_and_timestamp(
85        &self, parent: H256, referees: Vec<H256>, raw: Bytes, nonce: U256,
86        timestamp: u64, adaptive: bool,
87    ) -> RpcResult<H256>;
88
89    #[method(name = "getBlockStatus")]
90    fn get_block_status(&self, block_hash: H256) -> RpcResult<(u8, bool)>;
91
92    #[method(name = "expireBlockGc")]
93    fn expire_block_gc(&self, timeout: u64) -> RpcResult<()>;
94
95    #[method(name = "getPivotChainAndWeight")]
96    fn get_pivot_chain_and_weight(
97        &self, height_range: Option<(u64, u64)>,
98    ) -> RpcResult<Vec<(H256, U256)>>;
99
100    #[method(name = "getExecutedInfo")]
101    fn get_executed_info(&self, block_hash: H256) -> RpcResult<(H256, H256)>;
102
103    #[method(name = "sendUsableGenesisAccounts")]
104    fn send_usable_genesis_accounts(
105        &self, account_start_index: usize,
106    ) -> RpcResult<Bytes>;
107
108    #[method(name = "setDbCrash")]
109    fn set_db_crash(
110        &self, crash_probability: f64, crash_exit_code: i32,
111    ) -> RpcResult<()>;
112
113    #[method(name = "saveNodeDb")]
114    fn save_node_db(&self) -> RpcResult<()>;
115
116    #[method(name = "posRegister")]
117    fn pos_register(
118        &self, voting_power: U64, version: Option<u8>,
119    ) -> RpcResult<(Bytes, AccountAddress)>;
120
121    #[method(name = "posUpdateVotingPower")]
122    fn pos_update_voting_power(
123        &self, pos_account: AccountAddress, increased_voting_power: U64,
124    ) -> RpcResult<()>;
125
126    #[method(name = "posStopElection")]
127    fn pos_stop_election(&self) -> RpcResult<Option<u64>>;
128
129    #[method(name = "posStartVoting")]
130    fn pos_start_voting(&self, initialize: bool) -> RpcResult<()>;
131
132    #[method(name = "posStopVoting")]
133    fn pos_stop_voting(&self) -> RpcResult<()>;
134
135    #[method(name = "posVotingStatus")]
136    fn pos_voting_status(&self) -> RpcResult<bool>;
137
138    #[method(name = "posStart")]
139    fn pos_start(&self) -> RpcResult<()>;
140
141    #[method(name = "posForceVoteProposal")]
142    fn pos_force_vote_proposal(&self, block_id: H256) -> RpcResult<()>;
143
144    #[method(name = "posForcePropose")]
145    fn pos_force_propose(
146        &self, round: U64, parent_block_id: H256,
147        payload: Vec<TransactionPayload>,
148    ) -> RpcResult<()>;
149
150    #[method(name = "posTriggerTimeout")]
151    fn pos_trigger_timeout(&self, timeout_type: String) -> RpcResult<()>;
152
153    #[method(name = "posForceSignPivotDecision")]
154    fn pos_force_sign_pivot_decision(
155        &self, block_hash: H256, height: U64,
156    ) -> RpcResult<()>;
157
158    #[method(name = "posGetChosenProposal")]
159    fn pos_get_chosen_proposal(&self) -> RpcResult<Option<PosBlock>>;
160}