mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 15:51:04 +00:00
This reverts commit c0a1926704.
This commit is contained in:
@@ -39,7 +39,7 @@ use codec::Decode;
|
||||
use sr_primitives::traits::{ApiRef, ProvideRuntimeApi, Header as HeaderT};
|
||||
use sr_primitives::generic::{BlockId, DigestItem};
|
||||
use primitives::{NativeOrEncoded, ExecutionContext, crypto::Public};
|
||||
use fg_primitives::{GRANDPA_ENGINE_ID, AuthorityList};
|
||||
use fg_primitives::{GRANDPA_ENGINE_ID, AuthorityId};
|
||||
use state_machine::{backend::InMemory, prove_read, read_proof_check};
|
||||
|
||||
use authorities::AuthoritySet;
|
||||
@@ -137,8 +137,8 @@ impl TestNetFactory for GrandpaTestNet {
|
||||
let import = light_block_import_without_justifications(
|
||||
client.clone(),
|
||||
backend.clone(),
|
||||
&self.test_config,
|
||||
authorities_provider,
|
||||
Arc::new(self.test_config.clone())
|
||||
).expect("Could not create block import for fresh peer.");
|
||||
let finality_proof_req_builder = import.0.create_finality_proof_request_builder();
|
||||
let proof_import = Box::new(import.clone());
|
||||
@@ -188,24 +188,26 @@ impl Future for Exit {
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub(crate) struct TestApi {
|
||||
genesis_authorities: AuthorityList,
|
||||
genesis_authorities: Vec<(AuthorityId, u64)>,
|
||||
}
|
||||
|
||||
impl TestApi {
|
||||
pub fn new(genesis_authorities: AuthorityList) -> Self {
|
||||
pub fn new(genesis_authorities: Vec<(AuthorityId, u64)>) -> Self {
|
||||
TestApi {
|
||||
genesis_authorities,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct RuntimeApi;
|
||||
pub(crate) struct RuntimeApi {
|
||||
inner: TestApi,
|
||||
}
|
||||
|
||||
impl ProvideRuntimeApi for TestApi {
|
||||
type Api = RuntimeApi;
|
||||
|
||||
fn runtime_api<'a>(&'a self) -> ApiRef<'a, Self::Api> {
|
||||
RuntimeApi.into()
|
||||
RuntimeApi { inner: self.clone() }.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,15 +264,26 @@ impl ApiExt<Block> for RuntimeApi {
|
||||
}
|
||||
}
|
||||
|
||||
impl GenesisAuthoritySetProvider<Block> for TestApi {
|
||||
fn get(&self) -> Result<AuthorityList> {
|
||||
Ok(self.genesis_authorities.clone())
|
||||
impl GrandpaApi<Block> for RuntimeApi {
|
||||
fn GrandpaApi_grandpa_authorities_runtime_api_impl(
|
||||
&self,
|
||||
_: &BlockId<Block>,
|
||||
_: ExecutionContext,
|
||||
_: Option<()>,
|
||||
_: Vec<u8>,
|
||||
) -> Result<NativeOrEncoded<Vec<(AuthorityId, u64)>>> {
|
||||
Ok(self.inner.genesis_authorities.clone()).map(NativeOrEncoded::Native)
|
||||
}
|
||||
}
|
||||
|
||||
impl AuthoritySetForFinalityProver<Block> for TestApi {
|
||||
fn authorities(&self, _block: &BlockId<Block>) -> Result<AuthorityList> {
|
||||
Ok(self.genesis_authorities.clone())
|
||||
fn authorities(&self, block: &BlockId<Block>) -> Result<Vec<(AuthorityId, u64)>> {
|
||||
let runtime_api = RuntimeApi { inner: self.clone() };
|
||||
runtime_api.GrandpaApi_grandpa_authorities_runtime_api_impl(block, ExecutionContext::Syncing, None, Vec::new())
|
||||
.map(|v| match v {
|
||||
NativeOrEncoded::Native(value) => value,
|
||||
_ => unreachable!("only providing native values"),
|
||||
})
|
||||
}
|
||||
|
||||
fn prove_authorities(&self, block: &BlockId<Block>) -> Result<StorageProof> {
|
||||
@@ -290,7 +303,7 @@ impl AuthoritySetForFinalityChecker<Block> for TestApi {
|
||||
_hash: <Block as BlockT>::Hash,
|
||||
header: <Block as BlockT>::Header,
|
||||
proof: StorageProof,
|
||||
) -> Result<AuthorityList> {
|
||||
) -> Result<Vec<(AuthorityId, u64)>> {
|
||||
let results = read_proof_check::<Blake2Hasher, _>(
|
||||
*header.state_root(), proof, vec![b"authorities"]
|
||||
)
|
||||
@@ -307,7 +320,7 @@ impl AuthoritySetForFinalityChecker<Block> for TestApi {
|
||||
|
||||
const TEST_GOSSIP_DURATION: Duration = Duration::from_millis(500);
|
||||
|
||||
fn make_ids(keys: &[Ed25519Keyring]) -> AuthorityList {
|
||||
fn make_ids(keys: &[Ed25519Keyring]) -> Vec<(AuthorityId, u64)> {
|
||||
keys.iter().map(|key| key.clone().public().into()).map(|id| (id, 1)).collect()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user