mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 05:37:58 +00:00
Simplify runtime api error handling (#8114)
* Ahh * Work work work * Fix all the compilation errors * Fix test * More fixes...
This commit is contained in:
@@ -273,6 +273,8 @@ pub enum Error<B: BlockT> {
|
||||
CheckInherents(String),
|
||||
/// Client error
|
||||
Client(sp_blockchain::Error),
|
||||
/// Runtime Api error.
|
||||
RuntimeApi(sp_api::ApiError),
|
||||
/// Runtime error
|
||||
Runtime(sp_inherents::Error),
|
||||
/// Fork tree error
|
||||
@@ -310,14 +312,14 @@ impl Config {
|
||||
/// Either fetch the slot duration from disk or compute it from the genesis
|
||||
/// state.
|
||||
pub fn get_or_compute<B: BlockT, C>(client: &C) -> ClientResult<Self> where
|
||||
C: AuxStore + ProvideRuntimeApi<B>, C::Api: BabeApi<B, Error = sp_blockchain::Error>,
|
||||
C: AuxStore + ProvideRuntimeApi<B>, C::Api: BabeApi<B>,
|
||||
{
|
||||
trace!(target: "babe", "Getting slot duration");
|
||||
match sc_consensus_slots::SlotDuration::get_or_compute(client, |a, b| {
|
||||
let has_api_v1 = a.has_api_with::<dyn BabeApi<B, Error = sp_blockchain::Error>, _>(
|
||||
let has_api_v1 = a.has_api_with::<dyn BabeApi<B>, _>(
|
||||
&b, |v| v == 1,
|
||||
)?;
|
||||
let has_api_v2 = a.has_api_with::<dyn BabeApi<B, Error = sp_blockchain::Error>, _>(
|
||||
let has_api_v2 = a.has_api_with::<dyn BabeApi<B>, _>(
|
||||
&b, |v| v == 2,
|
||||
)?;
|
||||
|
||||
@@ -326,7 +328,7 @@ impl Config {
|
||||
Ok(a.configuration_before_version_2(b)?.into())
|
||||
}
|
||||
} else if has_api_v2 {
|
||||
a.configuration(b)
|
||||
a.configuration(b).map_err(Into::into)
|
||||
} else {
|
||||
Err(sp_blockchain::Error::VersionInvalid(
|
||||
"Unsupported or invalid BabeApi version".to_string()
|
||||
@@ -846,8 +848,7 @@ impl<Block, Client, SelectChain, CAW> BabeVerifier<Block, Client, SelectChain, C
|
||||
where
|
||||
Block: BlockT,
|
||||
Client: AuxStore + HeaderBackend<Block> + HeaderMetadata<Block> + ProvideRuntimeApi<Block>,
|
||||
Client::Api: BlockBuilderApi<Block, Error = sp_blockchain::Error>
|
||||
+ BabeApi<Block, Error = sp_blockchain::Error>,
|
||||
Client::Api: BlockBuilderApi<Block> + BabeApi<Block>,
|
||||
SelectChain: sp_consensus::SelectChain<Block>,
|
||||
CAW: CanAuthorWith<Block>,
|
||||
{
|
||||
@@ -871,7 +872,7 @@ where
|
||||
&block_id,
|
||||
block,
|
||||
inherent_data,
|
||||
).map_err(Error::Client)?;
|
||||
).map_err(Error::RuntimeApi)?;
|
||||
|
||||
if !inherent_res.ok() {
|
||||
inherent_res
|
||||
@@ -934,7 +935,7 @@ where
|
||||
self.client
|
||||
.runtime_api()
|
||||
.generate_key_ownership_proof(block_id, slot, equivocation_proof.offender.clone())
|
||||
.map_err(Error::Client)
|
||||
.map_err(Error::RuntimeApi)
|
||||
};
|
||||
|
||||
let parent_id = BlockId::Hash(*header.parent_hash());
|
||||
@@ -957,7 +958,7 @@ where
|
||||
equivocation_proof,
|
||||
key_owner_proof,
|
||||
)
|
||||
.map_err(Error::Client)?;
|
||||
.map_err(Error::RuntimeApi)?;
|
||||
|
||||
info!(target: "babe", "Submitted equivocation report for author {:?}", author);
|
||||
|
||||
@@ -971,7 +972,7 @@ where
|
||||
Block: BlockT,
|
||||
Client: HeaderMetadata<Block, Error = sp_blockchain::Error> + HeaderBackend<Block> + ProvideRuntimeApi<Block>
|
||||
+ Send + Sync + AuxStore + ProvideCache<Block>,
|
||||
Client::Api: BlockBuilderApi<Block, Error = sp_blockchain::Error> + BabeApi<Block, Error = sp_blockchain::Error>,
|
||||
Client::Api: BlockBuilderApi<Block> + BabeApi<Block>,
|
||||
SelectChain: sp_consensus::SelectChain<Block>,
|
||||
CAW: CanAuthorWith<Block> + Send + Sync,
|
||||
{
|
||||
@@ -1498,7 +1499,7 @@ pub fn import_queue<Block: BlockT, Client, SelectChain, Inner, CAW>(
|
||||
+ Send + Sync + 'static,
|
||||
Client: ProvideRuntimeApi<Block> + ProvideCache<Block> + Send + Sync + AuxStore + 'static,
|
||||
Client: HeaderBackend<Block> + HeaderMetadata<Block, Error = sp_blockchain::Error>,
|
||||
Client::Api: BlockBuilderApi<Block> + BabeApi<Block> + ApiExt<Block, Error = sp_blockchain::Error>,
|
||||
Client::Api: BlockBuilderApi<Block> + BabeApi<Block> + ApiExt<Block>,
|
||||
SelectChain: sp_consensus::SelectChain<Block> + 'static,
|
||||
CAW: CanAuthorWith<Block> + Send + Sync + 'static,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user