feat: initialize Kurdistan SDK - independent fork of Polkadot SDK

This commit is contained in:
2025-12-13 15:44:15 +03:00
commit 286de54384
6841 changed files with 1848356 additions and 0 deletions
@@ -0,0 +1,80 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::BlockBuilder;
use sp_inherents::{InherentData, InherentDataProvider, InherentIdentifier};
use sp_runtime::traits::Block as BlockT;
/// Errors that occur when creating and checking on the client side.
#[derive(Debug)]
pub enum CheckInherentsError {
/// Create inherents error.
CreateInherentData(sp_inherents::Error),
/// Client Error
Client(sp_api::ApiError),
/// Check inherents error
CheckInherents(sp_inherents::Error),
/// Unknown inherent error for identifier
CheckInherentsUnknownError(InherentIdentifier),
}
/// Create inherent data and check that the inherents are valid.
pub async fn check_inherents<Block: BlockT, Client: sp_api::ProvideRuntimeApi<Block>>(
client: std::sync::Arc<Client>,
at_hash: Block::Hash,
block: Block,
inherent_data_providers: &impl InherentDataProvider,
) -> Result<(), CheckInherentsError>
where
Client::Api: BlockBuilder<Block>,
{
let inherent_data = inherent_data_providers
.create_inherent_data()
.await
.map_err(CheckInherentsError::CreateInherentData)?;
check_inherents_with_data(client, at_hash, block, inherent_data_providers, inherent_data).await
}
/// Check that the inherents are valid.
pub async fn check_inherents_with_data<Block: BlockT, Client: sp_api::ProvideRuntimeApi<Block>>(
client: std::sync::Arc<Client>,
at_hash: Block::Hash,
block: Block,
inherent_data_provider: &impl InherentDataProvider,
inherent_data: InherentData,
) -> Result<(), CheckInherentsError>
where
Client::Api: BlockBuilder<Block>,
{
let res = client
.runtime_api()
.check_inherents(at_hash, block.into(), inherent_data)
.map_err(CheckInherentsError::Client)?;
if !res.ok() {
for (id, error) in res.into_errors() {
match inherent_data_provider.try_handle_error(&id, &error).await {
Some(res) => res.map_err(CheckInherentsError::CheckInherents)?,
None => return Err(CheckInherentsError::CheckInherentsUnknownError(id)),
}
}
}
Ok(())
}
@@ -0,0 +1,60 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The block builder runtime api.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
#[cfg(feature = "std")]
mod client_side;
#[cfg(feature = "std")]
pub use client_side::*;
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_runtime::{traits::Block as BlockT, ApplyExtrinsicResult};
sp_api::decl_runtime_apis! {
/// The `BlockBuilder` api trait that provides the required functionality for building a block.
#[api_version(6)]
pub trait BlockBuilder {
/// Apply the given extrinsic.
///
/// Returns an inclusion outcome which specifies if this extrinsic is included in
/// this block or not.
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult;
#[changed_in(6)]
fn apply_extrinsic(
extrinsic: <Block as BlockT>::Extrinsic,
) -> sp_runtime::legacy::byte_sized_error::ApplyExtrinsicResult;
/// Finish the current block.
#[renamed("finalise_block", 3)]
fn finalize_block() -> <Block as BlockT>::Header;
/// Generate inherent extrinsics. The inherent data will vary from chain to chain.
fn inherent_extrinsics(
inherent: InherentData,
) -> alloc::vec::Vec<<Block as BlockT>::Extrinsic>;
/// Check that the inherents are valid. The inherent data will vary from chain to chain.
fn check_inherents(block: <Block as BlockT>::LazyBlock, data: InherentData) -> CheckInherentsResult;
}
}