mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
pallet-mmr: RPC API and Runtime API work with block numbers (#12345)
* pallet-mmr: RPC API works with block_numbers * fixes * update rpc * fmt * final touches in the rpc * temporary fix * fix * fmt * docs * Update lib.rs * use NumberFor * validate input * update runtime * convert block_number to u64 * small edit * update runtime api * test fix * runtime fix * update test function * fmt * fix nits * remove block_num_to_leaf_index from runtime api * Update frame/merkle-mountain-range/src/lib.rs Co-authored-by: Robert Hambrock <roberthambrock@gmail.com> * fix tests * get the code to compile after merge * get the tests to compile * fix in tests? * fix test * Update frame/merkle-mountain-range/src/tests.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update frame/merkle-mountain-range/src/lib.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update primitives/merkle-mountain-range/src/lib.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * fix errors & nits * change block_num_to_leaf_index * don't make any assumptions * Update frame/merkle-mountain-range/src/tests.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update frame/merkle-mountain-range/src/tests.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update frame/merkle-mountain-range/src/tests.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * fix * small fix * use best_known_block_number * best_known_block_number instead of leaves_count * more readable? * remove warning * Update frame/merkle-mountain-range/src/lib.rs Co-authored-by: Robert Hambrock <roberthambrock@gmail.com> * simplify * update docs * nits * fmt & fix * merge fixes * fix * small fix * docs & nit fixes * Nit fixes * remove leaf_indices_to_block_numbers() * fmt Co-authored-by: Robert Hambrock <roberthambrock@gmail.com> Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
@@ -2016,11 +2016,15 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_mmr::primitives::MmrApi<Block, mmr::Hash> for Runtime {
|
||||
fn generate_proof(leaf_index: pallet_mmr::primitives::LeafIndex)
|
||||
impl pallet_mmr::primitives::MmrApi<
|
||||
Block,
|
||||
mmr::Hash,
|
||||
BlockNumber,
|
||||
> for Runtime {
|
||||
fn generate_proof(block_number: BlockNumber)
|
||||
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<mmr::Hash>), mmr::Error>
|
||||
{
|
||||
Mmr::generate_batch_proof(vec![leaf_index]).and_then(|(leaves, proof)|
|
||||
Mmr::generate_batch_proof(vec![block_number]).and_then(|(leaves, proof)|
|
||||
Ok((
|
||||
mmr::EncodableOpaqueLeaf::from_leaf(&leaves[0]),
|
||||
mmr::BatchProof::into_single_leaf_proof(proof)?
|
||||
@@ -2052,9 +2056,9 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
fn generate_batch_proof(
|
||||
leaf_indices: Vec<pallet_mmr::primitives::LeafIndex>,
|
||||
block_numbers: Vec<BlockNumber>,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<mmr::Hash>), mmr::Error> {
|
||||
Mmr::generate_batch_proof(leaf_indices).map(|(leaves, proof)| {
|
||||
Mmr::generate_batch_proof(block_numbers).map(|(leaves, proof)| {
|
||||
(
|
||||
leaves
|
||||
.into_iter()
|
||||
@@ -2066,10 +2070,10 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
fn generate_historical_batch_proof(
|
||||
leaf_indices: Vec<pallet_mmr::primitives::LeafIndex>,
|
||||
leaves_count: pallet_mmr::primitives::LeafIndex,
|
||||
block_numbers: Vec<BlockNumber>,
|
||||
best_known_block_number: BlockNumber,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<mmr::Hash>), mmr::Error> {
|
||||
Mmr::generate_historical_batch_proof(leaf_indices, leaves_count).map(
|
||||
Mmr::generate_historical_batch_proof(block_numbers, best_known_block_number).map(
|
||||
|(leaves, proof)| {
|
||||
(
|
||||
leaves
|
||||
|
||||
Reference in New Issue
Block a user