// Copyright 2018-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see .
use super::*;
use codec::Encode;
use futures::executor::block_on;
use sc_transaction_graph::{self, Pool};
use substrate_test_runtime_client::{runtime::{AccountId, Block, Hash, Index, Extrinsic, Transfer}, AccountKeyring::{self, *}};
use sp_runtime::{
generic::{self, BlockId},
traits::{Hash as HashT, BlakeTwo256},
transaction_validity::{TransactionValidity, ValidTransaction},
};
struct TestApi {
pub modifier: Box,
}
impl TestApi {
fn default() -> Self {
TestApi {
modifier: Box::new(|_| {}),
}
}
}
impl sc_transaction_graph::ChainApi for TestApi {
type Block = Block;
type Hash = Hash;
type Error = error::Error;
type ValidationFuture = futures::future::Ready>;
fn validate_transaction(
&self,
at: &BlockId,
uxt: sc_transaction_graph::ExtrinsicFor,
) -> Self::ValidationFuture {
let expected = index(at);
let requires = if expected == uxt.transfer().nonce {
vec![]
} else {
vec![vec![uxt.transfer().nonce as u8 - 1]]
};
let provides = vec![vec![uxt.transfer().nonce as u8]];
let mut validity = ValidTransaction {
priority: 1,
requires,
provides,
longevity: 64,
propagate: true,
};
(self.modifier)(&mut validity);
futures::future::ready(Ok(
Ok(validity)
))
}
fn block_id_to_number(&self, at: &BlockId) -> error::Result