mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 11:38:01 +00:00
Client::info() no longer returns a Result (#2776)
This commit is contained in:
committed by
Bastian Köcher
parent
53e8ad8728
commit
5df89a8a6f
@@ -44,9 +44,7 @@ where
|
||||
/// Create a new instance of builder from the given client, building on the
|
||||
/// latest block.
|
||||
pub fn new(api: &'a A, inherent_digests: DigestFor<Block>) -> error::Result<Self> {
|
||||
api.info().and_then(|i|
|
||||
Self::at_block(&BlockId::Hash(i.best_hash), api, false, inherent_digests)
|
||||
)
|
||||
Self::at_block(&BlockId::Hash(api.info().best_hash), api, false, inherent_digests)
|
||||
}
|
||||
|
||||
/// Create a new instance of builder from the given client using a
|
||||
|
||||
@@ -30,7 +30,7 @@ pub trait HeaderBackend<Block: BlockT>: Send + Sync {
|
||||
/// Get block header. Returns `None` if block is not found.
|
||||
fn header(&self, id: BlockId<Block>) -> Result<Option<Block::Header>>;
|
||||
/// Get blockchain info.
|
||||
fn info(&self) -> Result<Info<Block>>;
|
||||
fn info(&self) -> Info<Block>;
|
||||
/// Get block status.
|
||||
fn status(&self, id: BlockId<Block>) -> Result<BlockStatus>;
|
||||
/// Get block number by hash. Returns `None` if the header is not in the chain.
|
||||
|
||||
@@ -497,7 +497,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
if first > last_num {
|
||||
return Err(error::Error::ChangesTrieAccessFailed("Invalid changes trie range".into()));
|
||||
}
|
||||
let finalized_number = self.backend.blockchain().info()?.finalized_number;
|
||||
let finalized_number = self.backend.blockchain().info().finalized_number;
|
||||
let oldest = storage.oldest_changes_trie_block(&config, finalized_number);
|
||||
let first = ::std::cmp::max(first, oldest);
|
||||
Ok(Some((first, last)))
|
||||
@@ -523,7 +523,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
hash: convert_hash(&last_hash),
|
||||
number: last_number,
|
||||
},
|
||||
self.backend.blockchain().info()?.best_number,
|
||||
self.backend.blockchain().info().best_number,
|
||||
&key.0)
|
||||
.and_then(|r| r.map(|r| r.map(|(block, tx)| (block, tx))).collect::<Result<_, _>>())
|
||||
.map_err(|err| error::Error::ChangesTrieAccessFailed(err))
|
||||
@@ -608,7 +608,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
};
|
||||
|
||||
let max_number = ::std::cmp::min(
|
||||
self.backend.blockchain().info()?.best_number,
|
||||
self.backend.blockchain().info().best_number,
|
||||
self.backend.blockchain().expect_block_number_from_id(&BlockId::Hash(max))?,
|
||||
);
|
||||
|
||||
@@ -879,7 +879,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
}
|
||||
|
||||
let (last_best, last_best_number) = {
|
||||
let info = self.backend.blockchain().info()?;
|
||||
let info = self.backend.blockchain().info();
|
||||
(info.best_hash, info.best_number)
|
||||
};
|
||||
|
||||
@@ -1152,7 +1152,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
justification: Option<Justification>,
|
||||
notify: bool,
|
||||
) -> error::Result<()> {
|
||||
let last_best = self.backend.blockchain().info()?.best_hash;
|
||||
let last_best = self.backend.blockchain().info().best_hash;
|
||||
let to_finalize_hash = self.backend.blockchain().expect_block_hash_from_id(&id)?;
|
||||
self.apply_finality_with_block_hash(operation, to_finalize_hash, justification, last_best, notify)
|
||||
}
|
||||
@@ -1165,7 +1165,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
/// while performing major synchronization work.
|
||||
pub fn finalize_block(&self, id: BlockId<Block>, justification: Option<Justification>, notify: bool) -> error::Result<()> {
|
||||
self.lock_import_and_run(|operation| {
|
||||
let last_best = self.backend.blockchain().info()?.best_hash;
|
||||
let last_best = self.backend.blockchain().info().best_hash;
|
||||
let to_finalize_hash = self.backend.blockchain().expect_block_hash_from_id(&id)?;
|
||||
self.apply_finality_with_block_hash(operation, to_finalize_hash, justification, last_best, notify)
|
||||
})
|
||||
@@ -1178,13 +1178,13 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
}
|
||||
|
||||
/// Get blockchain info.
|
||||
pub fn info(&self) -> error::Result<ClientInfo<Block>> {
|
||||
let info = self.backend.blockchain().info().map_err(|e| error::Error::from_blockchain(Box::new(e)))?;
|
||||
Ok(ClientInfo {
|
||||
pub fn info(&self) -> ClientInfo<Block> {
|
||||
let info = self.backend.blockchain().info();
|
||||
ClientInfo {
|
||||
chain: info,
|
||||
best_queued_hash: None,
|
||||
best_queued_number: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Get block status.
|
||||
@@ -1246,7 +1246,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
}
|
||||
};
|
||||
|
||||
let genesis_hash = self.backend.blockchain().info()?.genesis_hash;
|
||||
let genesis_hash = self.backend.blockchain().info().genesis_hash;
|
||||
if genesis_hash == target_hash { return Ok(Vec::new()); }
|
||||
|
||||
let mut current_hash = target_hash;
|
||||
@@ -1269,7 +1269,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
}
|
||||
|
||||
fn changes_trie_config(&self) -> Result<Option<ChangesTrieConfiguration>, Error> {
|
||||
Ok(self.backend.state_at(BlockId::Number(self.backend.blockchain().info()?.best_number))?
|
||||
Ok(self.backend.state_at(BlockId::Number(self.backend.blockchain().info().best_number))?
|
||||
.storage(well_known_keys::CHANGES_TRIE_CONFIG)
|
||||
.map_err(|e| error::Error::from_state(Box::new(e)))?
|
||||
.and_then(|c| Decode::decode(&mut &*c)))
|
||||
@@ -1298,7 +1298,7 @@ impl<B, E, Block, RA> ChainHeaderBackend<Block> for Client<B, E, Block, RA> wher
|
||||
self.backend.blockchain().header(id)
|
||||
}
|
||||
|
||||
fn info(&self) -> error::Result<blockchain::Info<Block>> {
|
||||
fn info(&self) -> blockchain::Info<Block> {
|
||||
self.backend.blockchain().info()
|
||||
}
|
||||
|
||||
@@ -1448,7 +1448,7 @@ impl<B, E, Block, RA> CurrentHeight for Client<B, E, Block, RA> where
|
||||
{
|
||||
type BlockNumber = <Block::Header as HeaderT>::Number;
|
||||
fn current_height(&self) -> Self::BlockNumber {
|
||||
self.backend.blockchain().info().map(|i| i.best_number).unwrap_or_else(|_| Zero::zero())
|
||||
self.backend.blockchain().info().best_number
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1524,10 +1524,7 @@ where
|
||||
}
|
||||
|
||||
fn best_block_header(&self) -> error::Result<<Block as BlockT>::Header> {
|
||||
let info : ChainInfo<Block> = match self.backend.blockchain().info() {
|
||||
Ok(i) => i,
|
||||
Err(e) => return Err(error::Error::from_blockchain(Box::new(e)))
|
||||
};
|
||||
let info : ChainInfo<Block> = self.backend.blockchain().info();
|
||||
Ok(self.backend.blockchain().header(BlockId::Hash(info.best_hash))?
|
||||
.expect("Best block header must always exist"))
|
||||
}
|
||||
@@ -1569,7 +1566,7 @@ where
|
||||
// we depend on the canonical chain staying the same during this code block.
|
||||
let _import_lock = self.import_lock.lock();
|
||||
|
||||
let info = self.backend.blockchain().info()?;
|
||||
let info = self.backend.blockchain().info();
|
||||
|
||||
let canon_hash = self.backend.blockchain().hash(*target_header.number())?
|
||||
.ok_or_else(|| error::Error::from(format!("failed to get hash for block number {}", target_header.number())))?;
|
||||
@@ -1816,14 +1813,14 @@ pub(crate) mod tests {
|
||||
|
||||
assert_eq!(
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::Number(client.info().unwrap().chain.best_number),
|
||||
&BlockId::Number(client.info().chain.best_number),
|
||||
AccountKeyring::Alice.into()
|
||||
).unwrap(),
|
||||
1000
|
||||
);
|
||||
assert_eq!(
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::Number(client.info().unwrap().chain.best_number),
|
||||
&BlockId::Number(client.info().chain.best_number),
|
||||
AccountKeyring::Ferdie.into()
|
||||
).unwrap(),
|
||||
0
|
||||
@@ -1838,7 +1835,7 @@ pub(crate) mod tests {
|
||||
|
||||
client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap();
|
||||
|
||||
assert_eq!(client.info().unwrap().chain.best_number, 1);
|
||||
assert_eq!(client.info().chain.best_number, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1856,18 +1853,18 @@ pub(crate) mod tests {
|
||||
|
||||
client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap();
|
||||
|
||||
assert_eq!(client.info().unwrap().chain.best_number, 1);
|
||||
assert_eq!(client.info().chain.best_number, 1);
|
||||
assert!(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().unwrap().chain.best_number),
|
||||
&BlockId::Number(client.info().chain.best_number),
|
||||
AccountKeyring::Alice.into()
|
||||
).unwrap(),
|
||||
958
|
||||
);
|
||||
assert_eq!(
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::Number(client.info().unwrap().chain.best_number),
|
||||
&BlockId::Number(client.info().chain.best_number),
|
||||
AccountKeyring::Ferdie.into()
|
||||
).unwrap(),
|
||||
42
|
||||
@@ -1896,7 +1893,7 @@ pub(crate) mod tests {
|
||||
|
||||
client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap();
|
||||
|
||||
assert_eq!(client.info().unwrap().chain.best_number, 1);
|
||||
assert_eq!(client.info().chain.best_number, 1);
|
||||
assert!(client.state_at(&BlockId::Number(1)).unwrap().pairs() != client.state_at(&BlockId::Number(0)).unwrap().pairs());
|
||||
assert_eq!(client.body(&BlockId::Number(1)).unwrap().unwrap().len(), 1)
|
||||
}
|
||||
@@ -1908,7 +1905,7 @@ pub(crate) mod tests {
|
||||
|
||||
let client = test_client::new();
|
||||
|
||||
let genesis_hash = client.info().unwrap().chain.genesis_hash;
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
#[allow(deprecated)]
|
||||
let longest_chain_select = test_client::client::LongestChain::new(
|
||||
client.backend().clone(),
|
||||
@@ -2029,7 +2026,7 @@ pub(crate) mod tests {
|
||||
let d2 = builder.bake().unwrap();
|
||||
client.import(BlockOrigin::Own, d2.clone()).unwrap();
|
||||
|
||||
let genesis_hash = client.info().unwrap().chain.genesis_hash;
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
|
||||
let uncles1 = client.uncles(a4.hash(), 10).unwrap();
|
||||
assert_eq!(vec![b2.hash(), d2.hash()], uncles1);
|
||||
@@ -2065,7 +2062,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().unwrap().chain.genesis_hash;
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
#[allow(deprecated)]
|
||||
let longest_chain_select = test_client::client::LongestChain::new(
|
||||
Arc::new(client.backend().as_in_memory()),
|
||||
@@ -2152,9 +2149,9 @@ pub(crate) mod tests {
|
||||
let d2 = builder.bake().unwrap();
|
||||
client.import(BlockOrigin::Own, d2.clone()).unwrap();
|
||||
|
||||
assert_eq!(client.info().unwrap().chain.best_hash, a5.hash());
|
||||
assert_eq!(client.info().chain.best_hash, a5.hash());
|
||||
|
||||
let genesis_hash = client.info().unwrap().chain.genesis_hash;
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
#[allow(deprecated)]
|
||||
let longest_chain_select = test_client::client::LongestChain::new(
|
||||
Arc::new(client.backend().as_in_memory()),
|
||||
@@ -2385,7 +2382,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().unwrap().chain.genesis_hash;
|
||||
let genesis_hash = client.info().chain.genesis_hash;
|
||||
#[allow(deprecated)]
|
||||
let longest_chain_select = test_client::client::LongestChain::new(
|
||||
Arc::new(client.backend().as_in_memory()),
|
||||
|
||||
@@ -297,15 +297,15 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn info(&self) -> error::Result<blockchain::Info<Block>> {
|
||||
fn info(&self) -> blockchain::Info<Block> {
|
||||
let storage = self.storage.read();
|
||||
Ok(blockchain::Info {
|
||||
blockchain::Info {
|
||||
best_hash: storage.best_hash,
|
||||
best_number: storage.best_number,
|
||||
genesis_hash: storage.genesis_hash,
|
||||
finalized_hash: storage.finalized_hash,
|
||||
finalized_number: storage.finalized_number,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn status(&self, id: BlockId<Block>) -> error::Result<BlockStatus> {
|
||||
|
||||
@@ -134,7 +134,7 @@ impl<S, F, Block> BlockchainHeaderBackend<Block> for Blockchain<S, F> where Bloc
|
||||
}
|
||||
}
|
||||
|
||||
fn info(&self) -> ClientResult<BlockchainInfo<Block>> {
|
||||
fn info(&self) -> BlockchainInfo<Block> {
|
||||
self.storage.info()
|
||||
}
|
||||
|
||||
@@ -223,8 +223,8 @@ pub mod tests {
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
|
||||
fn info(&self) -> ClientResult<Info<Block>> {
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
fn info(&self) -> Info<Block> {
|
||||
panic!("Test error")
|
||||
}
|
||||
|
||||
fn status(&self, _id: BlockId<Block>) -> ClientResult<BlockStatus> {
|
||||
|
||||
@@ -668,8 +668,8 @@ pub mod tests {
|
||||
test_client::LocalExecutor::new(None)
|
||||
);
|
||||
let local_checker = &local_checker as &FetchChecker<Block>;
|
||||
let max = remote_client.info().unwrap().chain.best_number;
|
||||
let max_hash = remote_client.info().unwrap().chain.best_hash;
|
||||
let max = remote_client.info().chain.best_number;
|
||||
let max_hash = remote_client.info().chain.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();
|
||||
@@ -764,8 +764,8 @@ pub mod tests {
|
||||
test_client::LocalExecutor::new(None)
|
||||
);
|
||||
let local_checker = &local_checker as &FetchChecker<Block>;
|
||||
let max = remote_client.info().unwrap().chain.best_number;
|
||||
let max_hash = remote_client.info().unwrap().chain.best_hash;
|
||||
let max = remote_client.info().chain.best_number;
|
||||
let max_hash = remote_client.info().chain.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