Skip to content

Commit 208e4a3

Browse files
committed
more core space rpc types from client crate to cfx-rpc-types crate
1 parent 6075890 commit 208e4a3

37 files changed

+733
-307
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/client/src/rpc/helpers/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ pub use cfx_rpc::helpers::{
1313
poll_manager::PollManager,
1414
EpochQueue, MAX_FEE_HISTORY_CACHE_BLOCK_COUNT,
1515
};
16-
pub use cfx_rpc_primitives::{maybe_vec_into, VariadicValue};
1716
pub use subscribers::{Id as SubscriberId, Subscribers};

crates/client/src/rpc/impls/cfx/cfx_handler.rs

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ use crate::{
8787
pos::Block as PosBlock, Account as RpcAccount, AccountPendingInfo,
8888
AccountPendingTransactions, BlameInfo, Block as RpcBlock,
8989
BlockHashOrEpochNumber, Bytes, CfxRpcLogFilter,
90-
CheckBalanceAgainstTransactionResponse, ConsensusGraphStates,
91-
EpochNumber, EstimateGasAndCollateralResponse, Log as RpcLog,
92-
PackedOrExecuted, Receipt as RpcReceipt,
93-
RewardInfo as RpcRewardInfo, Status as RpcStatus,
94-
StorageCollateralInfo, SyncGraphStates,
95-
Transaction as RpcTransaction, TransactionRequest,
90+
CheckBalanceAgainstTransactionResponse,
91+
ConsensusGraphBlockExecutionState, ConsensusGraphBlockState,
92+
ConsensusGraphStates, EpochNumber,
93+
EstimateGasAndCollateralResponse, Log as RpcLog, PackedOrExecuted,
94+
Receipt as RpcReceipt, RewardInfo as RpcRewardInfo,
95+
Status as RpcStatus, StorageCollateralInfo, SyncGraphBlockState,
96+
SyncGraphStates, Transaction as RpcTransaction, TransactionRequest,
9697
},
9798
CoreResult,
9899
},
@@ -633,6 +634,7 @@ impl RpcImpl {
633634
password,
634635
self.accounts.clone(),
635636
)
637+
.map_err(Into::into)
636638
}
637639

638640
fn send_transaction(
@@ -1249,7 +1251,13 @@ impl RpcImpl {
12491251
*self.sync.network.get_network_type(),
12501252
)?;
12511253

1252-
ret.push(RpcRewardInfo::new(b, author, reward_result));
1254+
ret.push(RpcRewardInfo {
1255+
block_hash: b.into(),
1256+
author,
1257+
total_reward: reward_result.total_reward.into(),
1258+
base_reward: reward_result.base_reward.into(),
1259+
tx_fee: reward_result.tx_fee.into(),
1260+
})
12531261
}
12541262
}
12551263
}
@@ -1532,12 +1540,55 @@ impl RpcImpl {
15321540
pub fn consensus_graph_state(&self) -> CoreResult<ConsensusGraphStates> {
15331541
let consensus_graph_states =
15341542
STATE_EXPOSER.consensus_graph.lock().retrieve();
1535-
Ok(ConsensusGraphStates::new(consensus_graph_states))
1543+
// Ok(ConsensusGraphStates::new(consensus_graph_states))
1544+
let mut block_state_vec = Vec::new();
1545+
let mut block_execution_state_vec = Vec::new();
1546+
1547+
for block_state in &consensus_graph_states.block_state_vec {
1548+
block_state_vec.push(ConsensusGraphBlockState {
1549+
block_hash: block_state.block_hash.into(),
1550+
best_block_hash: block_state.best_block_hash.into(),
1551+
block_status: (block_state.block_status as u8).into(),
1552+
era_block_hash: block_state.era_block_hash.into(),
1553+
adaptive: block_state.adaptive,
1554+
})
1555+
}
1556+
for exec_state in &consensus_graph_states.block_execution_state_vec {
1557+
block_execution_state_vec.push(ConsensusGraphBlockExecutionState {
1558+
block_hash: exec_state.block_hash.into(),
1559+
deferred_state_root: exec_state.deferred_state_root.into(),
1560+
deferred_receipt_root: exec_state.deferred_receipt_root.into(),
1561+
deferred_logs_bloom_hash: exec_state
1562+
.deferred_logs_bloom_hash
1563+
.into(),
1564+
state_valid: exec_state.state_valid,
1565+
})
1566+
}
1567+
1568+
Ok(ConsensusGraphStates {
1569+
block_state_vec,
1570+
block_execution_state_vec,
1571+
})
15361572
}
15371573

15381574
pub fn sync_graph_state(&self) -> CoreResult<SyncGraphStates> {
15391575
let sync_graph_states = STATE_EXPOSER.sync_graph.lock().retrieve();
1540-
Ok(SyncGraphStates::new(sync_graph_states))
1576+
let mut ready_block_vec = Vec::new();
1577+
for block_state in sync_graph_states.ready_block_vec {
1578+
ready_block_vec.push(SyncGraphBlockState {
1579+
block_hash: block_state.block_hash.into(),
1580+
parent: block_state.parent.into(),
1581+
referees: block_state
1582+
.referees
1583+
.iter()
1584+
.map(|x| H256::from(*x))
1585+
.collect(),
1586+
nonce: block_state.nonce.into(),
1587+
timestamp: U64::from(block_state.timestamp),
1588+
adaptive: block_state.adaptive,
1589+
})
1590+
}
1591+
Ok(SyncGraphStates { ready_block_vec })
15411592
}
15421593

15431594
/// Return (block_info.status, state_valid)

crates/client/src/rpc/types/cfx.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub use cfx_rpc_cfx_types::{
2+
access_list::*,
3+
account::{self, Account},
4+
address,
5+
address::{
6+
check_rpc_address_network, check_two_rpc_address_network_match,
7+
RcpAddressNetworkInconsistent, RpcAddress, UnexpectedRpcAddressNetwork,
8+
},
9+
blame_info, block, consensus_graph_states, epoch_number, filter, log,
10+
pos_economics, pubsub, receipt, reward_info, sponsor_info,
11+
stat_on_gas_load, status, storage_collateral_info, sync_graph_states,
12+
token_supply_info, transaction, transaction_request, tx_pool,
13+
vote_params_info, CfxFeeHistory,
14+
};
15+
pub use sponsor_info::SponsorInfo;
16+
pub use tx_pool::*;

crates/client/src/rpc/types/cfx/consensus_graph_states.rs

Lines changed: 0 additions & 68 deletions
This file was deleted.

crates/client/src/rpc/types/cfx/mod.rs

Lines changed: 0 additions & 34 deletions
This file was deleted.

crates/client/src/rpc/types/cfx/reward_info.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

crates/client/src/rpc/types/cfx/sync_graph_states.rs

Lines changed: 0 additions & 47 deletions
This file was deleted.

crates/client/src/rpc/types/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44

55
pub mod cfx;
66
mod constants;
7-
mod provenance;
8-
pub use cfx_rpc_cfx_types::pos;
9-
10-
pub use cfx_rpc_primitives::{Bytes, Index, U64};
117

128
pub use self::{
139
cfx::{
14-
address,
15-
address::{check_two_rpc_address_network_match, RpcAddress},
10+
address::{self, check_two_rpc_address_network_match, RpcAddress},
1611
blame_info::BlameInfo,
1712
block::{Block, BlockTransactions, Header},
18-
consensus_graph_states::ConsensusGraphStates,
13+
consensus_graph_states::{
14+
ConsensusGraphBlockExecutionState, ConsensusGraphBlockState,
15+
ConsensusGraphStates,
16+
},
1917
epoch_number::{BlockHashOrEpochNumber, EpochNumber},
2018
filter::{CfxFilterChanges, CfxFilterLog, CfxRpcLogFilter, RevertTo},
2119
log::Log,
@@ -26,9 +24,9 @@ pub use self::{
2624
stat_on_gas_load::StatOnGasLoad,
2725
status::Status,
2826
storage_collateral_info::StorageCollateralInfo,
29-
sync_graph_states::SyncGraphStates,
27+
sync_graph_states::{SyncGraphBlockState, SyncGraphStates},
3028
token_supply_info::TokenSupplyInfo,
31-
transaction::{PackedOrExecuted, Transaction, WrapTransaction},
29+
transaction::{PackedOrExecuted, Transaction},
3230
transaction_request::{
3331
self, CheckBalanceAgainstTransactionResponse,
3432
EstimateGasAndCollateralResponse, TransactionRequest,
@@ -42,13 +40,15 @@ pub use self::{
4240
Account, CfxFeeHistory, SponsorInfo,
4341
},
4442
constants::MAX_GAS_CALL_REQUEST,
45-
provenance::Origin,
4643
};
4744
pub use cfx_rpc_cfx_types::{
45+
pos,
46+
provenance::Origin,
4847
trace::{
4948
Action, LocalizedBlockTrace, LocalizedTrace, LocalizedTransactionTrace,
5049
},
5150
trace_filter::TraceFilter,
5251
};
52+
pub use cfx_rpc_primitives::{Bytes, Index, U64};
5353

54-
pub use cfx_rpc_eth_types::FeeHistory;
54+
pub use cfx_rpc_eth_types::{FeeHistory, WrapTransaction};

crates/rpc/rpc-cfx-types/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ diem-types = { workspace = true }
3434
rustc-hex = { workspace = true }
3535
bls-signatures = { workspace = true }
3636
once_cell = { workspace = true }
37+
cfxkey = { workspace = true }
38+
cfx-rpc-utils = { workspace = true }
39+
cfxcore-accounts = { workspace = true }
3740

3841
[dev-dependencies]

0 commit comments

Comments
 (0)