mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Refactor to use only chain info (#4516)
This commit is contained in:
committed by
Bastian Köcher
parent
8ecc450fd9
commit
6d06a19f41
@@ -655,11 +655,11 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
Self: ProvideRuntimeApi,
|
||||
<Self as ProvideRuntimeApi>::Api: BlockBuilderApi<Block, Error = Error>
|
||||
{
|
||||
let info = self.info();
|
||||
let info = self.chain_info();
|
||||
sc_block_builder::BlockBuilder::new(
|
||||
self,
|
||||
info.chain.best_hash,
|
||||
info.chain.best_number,
|
||||
info.best_hash,
|
||||
info.best_number,
|
||||
false,
|
||||
inherent_digests,
|
||||
)
|
||||
@@ -1148,15 +1148,19 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
Ok(self.backend.revert(n)?)
|
||||
}
|
||||
|
||||
/// Get blockchain info.
|
||||
pub fn info(&self) -> ClientInfo<Block> {
|
||||
let info = self.backend.blockchain().info();
|
||||
/// Get usage info about current client.
|
||||
pub fn usage_info(&self) -> ClientInfo<Block> {
|
||||
ClientInfo {
|
||||
chain: info,
|
||||
chain: self.chain_info(),
|
||||
used_state_cache_size: self.backend.used_state_cache_size(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get blockchain info.
|
||||
pub fn chain_info(&self) -> blockchain::Info<Block> {
|
||||
self.backend.blockchain().info()
|
||||
}
|
||||
|
||||
/// Get block status.
|
||||
pub fn block_status(&self, id: &BlockId<Block>) -> sp_blockchain::Result<BlockStatus> {
|
||||
// this can probably be implemented more efficiently
|
||||
@@ -1862,14 +1866,14 @@ pub(crate) mod tests {
|
||||
|
||||
assert_eq!(
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::Number(client.info().chain.best_number),
|
||||
&BlockId::Number(client.chain_info().best_number),
|
||||
AccountKeyring::Alice.into()
|
||||
).unwrap(),
|
||||
1000
|
||||
);
|
||||
assert_eq!(
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::Number(client.info().chain.best_number),
|
||||
&BlockId::Number(client.chain_info().best_number),
|
||||
AccountKeyring::Ferdie.into()
|
||||
).unwrap(),
|
||||
0
|
||||
@@ -1884,7 +1888,7 @@ pub(crate) mod tests {
|
||||
|
||||
client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap();
|
||||
|
||||
assert_eq!(client.info().chain.best_number, 1);
|
||||
assert_eq!(client.chain_info().best_number, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1902,21 +1906,21 @@ pub(crate) mod tests {
|
||||
|
||||
client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap();
|
||||
|
||||
assert_eq!(client.info().chain.best_number, 1);
|
||||
assert_eq!(client.chain_info().best_number, 1);
|
||||
assert_ne!(
|
||||
client.state_at(&BlockId::Number(1)).unwrap().pairs(),
|
||||
client.state_at(&BlockId::Number(0)).unwrap().pairs()
|
||||
);
|
||||
assert_eq!(
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::Number(client.info().chain.best_number),
|
||||
&BlockId::Number(client.chain_info().best_number),
|
||||
AccountKeyring::Alice.into()
|
||||
).unwrap(),
|
||||
958
|
||||
);
|
||||
assert_eq!(
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::Number(client.info().chain.best_number),
|
||||
&BlockId::Number(client.chain_info().best_number),
|
||||
AccountKeyring::Ferdie.into()
|
||||
).unwrap(),
|
||||
42
|
||||
@@ -1945,7 +1949,7 @@ pub(crate) mod tests {
|
||||
|
||||
client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap();
|
||||
|
||||
assert_eq!(client.info().chain.best_number, 1);
|
||||
assert_eq!(client.chain_info().best_number, 1);
|
||||
assert_ne!(
|
||||
client.state_at(&BlockId::Number(1)).unwrap().pairs(),
|
||||
client.state_at(&BlockId::Number(0)).unwrap().pairs()
|
||||
@@ -1960,7 +1964,7 @@ pub(crate) mod tests {
|
||||
|
||||
let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain();
|
||||
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
let genesis_hash = client.chain_info().genesis_hash;
|
||||
|
||||
assert_eq!(
|
||||
genesis_hash.clone(),
|
||||
@@ -2073,7 +2077,7 @@ pub(crate) mod tests {
|
||||
let d2 = builder.bake().unwrap();
|
||||
client.import(BlockOrigin::Own, d2.clone()).unwrap();
|
||||
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
let genesis_hash = client.chain_info().genesis_hash;
|
||||
|
||||
let uncles1 = client.uncles(a4.hash(), 10).unwrap();
|
||||
assert_eq!(vec![b2.hash(), d2.hash()], uncles1);
|
||||
@@ -2109,7 +2113,7 @@ pub(crate) mod tests {
|
||||
let a2 = client.new_block(Default::default()).unwrap().bake().unwrap();
|
||||
client.import(BlockOrigin::Own, a2.clone()).unwrap();
|
||||
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
let genesis_hash = client.chain_info().genesis_hash;
|
||||
|
||||
assert_eq!(a2.hash(), longest_chain_select.finality_target(genesis_hash, None).unwrap().unwrap());
|
||||
assert_eq!(a2.hash(), longest_chain_select.finality_target(a1.hash(), None).unwrap().unwrap());
|
||||
@@ -2189,9 +2193,9 @@ pub(crate) mod tests {
|
||||
let d2 = builder.bake().unwrap();
|
||||
client.import(BlockOrigin::Own, d2.clone()).unwrap();
|
||||
|
||||
assert_eq!(client.info().chain.best_hash, a5.hash());
|
||||
assert_eq!(client.chain_info().best_hash, a5.hash());
|
||||
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
let genesis_hash = client.chain_info().genesis_hash;
|
||||
let leaves = longest_chain_select.leaves().unwrap();
|
||||
|
||||
assert!(leaves.contains(&a5.hash()));
|
||||
@@ -2417,7 +2421,7 @@ pub(crate) mod tests {
|
||||
let a2 = client.new_block(Default::default()).unwrap().bake().unwrap();
|
||||
client.import(BlockOrigin::Own, a2.clone()).unwrap();
|
||||
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
let genesis_hash = client.chain_info().genesis_hash;
|
||||
|
||||
assert_eq!(a2.hash(), longest_chain_select.finality_target(genesis_hash, Some(10)).unwrap().unwrap());
|
||||
}
|
||||
@@ -2460,7 +2464,7 @@ pub(crate) mod tests {
|
||||
client.import_justified(BlockOrigin::Own, a3.clone(), justification.clone()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
client.info().chain.finalized_hash,
|
||||
client.chain_info().finalized_hash,
|
||||
a3.hash(),
|
||||
);
|
||||
|
||||
@@ -2507,7 +2511,7 @@ pub(crate) mod tests {
|
||||
|
||||
// A2 is the current best since it's the longest chain
|
||||
assert_eq!(
|
||||
client.info().chain.best_hash,
|
||||
client.chain_info().best_hash,
|
||||
a2.hash(),
|
||||
);
|
||||
|
||||
@@ -2516,12 +2520,12 @@ pub(crate) mod tests {
|
||||
client.import_justified(BlockOrigin::Own, b1.clone(), justification).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
client.info().chain.best_hash,
|
||||
client.chain_info().best_hash,
|
||||
b1.hash(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
client.info().chain.finalized_hash,
|
||||
client.chain_info().finalized_hash,
|
||||
b1.hash(),
|
||||
);
|
||||
}
|
||||
@@ -2556,7 +2560,7 @@ pub(crate) mod tests {
|
||||
|
||||
// A2 is the current best since it's the longest chain
|
||||
assert_eq!(
|
||||
client.info().chain.best_hash,
|
||||
client.chain_info().best_hash,
|
||||
a2.hash(),
|
||||
);
|
||||
|
||||
@@ -2566,14 +2570,14 @@ pub(crate) mod tests {
|
||||
|
||||
// B1 should now be the latest finalized
|
||||
assert_eq!(
|
||||
client.info().chain.finalized_hash,
|
||||
client.chain_info().finalized_hash,
|
||||
b1.hash(),
|
||||
);
|
||||
|
||||
// and B1 should be the new best block (`finalize_block` as no way of
|
||||
// knowing about B2)
|
||||
assert_eq!(
|
||||
client.info().chain.best_hash,
|
||||
client.chain_info().best_hash,
|
||||
b1.hash(),
|
||||
);
|
||||
|
||||
@@ -2592,7 +2596,7 @@ pub(crate) mod tests {
|
||||
client.import(BlockOrigin::Own, b3.clone()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
client.info().chain.best_hash,
|
||||
client.chain_info().best_hash,
|
||||
b3.hash(),
|
||||
);
|
||||
}
|
||||
@@ -2614,7 +2618,7 @@ pub(crate) mod tests {
|
||||
|
||||
let current_balance = ||
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::number(client.info().chain.best_number), AccountKeyring::Alice.into()
|
||||
&BlockId::number(client.chain_info().best_number), AccountKeyring::Alice.into()
|
||||
).unwrap();
|
||||
|
||||
// G -> A1 -> A2
|
||||
|
||||
@@ -550,8 +550,8 @@ pub mod tests {
|
||||
local_executor(),
|
||||
);
|
||||
let local_checker = &local_checker as &dyn FetchChecker<Block>;
|
||||
let max = remote_client.info().chain.best_number;
|
||||
let max_hash = remote_client.info().chain.best_hash;
|
||||
let max = remote_client.chain_info().best_number;
|
||||
let max_hash = remote_client.chain_info().best_hash;
|
||||
|
||||
for (index, (begin, end, key, expected_result)) in test_cases.into_iter().enumerate() {
|
||||
let begin_hash = remote_client.block_hash(begin).unwrap().unwrap();
|
||||
@@ -648,8 +648,8 @@ pub mod tests {
|
||||
local_executor(),
|
||||
);
|
||||
let local_checker = &local_checker as &dyn FetchChecker<Block>;
|
||||
let max = remote_client.info().chain.best_number;
|
||||
let max_hash = remote_client.info().chain.best_hash;
|
||||
let max = remote_client.chain_info().best_number;
|
||||
let max_hash = remote_client.chain_info().best_hash;
|
||||
|
||||
let (begin, end, key, _) = test_cases[0].clone();
|
||||
let begin_hash = remote_client.block_hash(begin).unwrap().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user