// Copyright 2018-2019 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 txpool::{self, Pool};
use test_client::{runtime::{AccountId, Block, Hash, Index, Extrinsic, Transfer}, AccountKeyring::{self, *}};
use sr_primitives::{
generic::{self, BlockId},
traits::{Hash as HashT, BlakeTwo256},
transaction_validity::{TransactionValidity, ValidTransaction},
};
struct TestApi;
impl TestApi {
fn default() -> Self {
TestApi
}
}
impl txpool::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: txpool::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]];
futures::future::ready(Ok(
Ok(ValidTransaction {
priority: 1,
requires,
provides,
longevity: 64,
propagate: true,
})
))
}
fn block_id_to_number(&self, at: &BlockId) -> error::Result