utils.rs 1.75 KB
Newer Older
Gav Wood's avatar
Gav Wood committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot 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.

// Polkadot 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 Polkadot.  If not, see <http://www.gnu.org/licenses/>.

//! Utils for block interaction.

use rstd::prelude::*;
Gav's avatar
Gav committed
20
use super::{Call, UncheckedExtrinsic, Extrinsic, Balances};
Gav Wood's avatar
Gav Wood committed
21
22
23
use runtime_primitives::traits::{Checkable, AuxLookup};
use timestamp::Call as TimestampCall;
use parachains::Call as ParachainsCall;
Gav's avatar
Gav committed
24
use consensus::Call as ConsensusCall;
Gav Wood's avatar
Gav Wood committed
25
26

/// Produces the list of inherent extrinsics.
27
pub fn inherent_extrinsics(data: ::primitives::InherentData) -> Vec<UncheckedExtrinsic> {
Gav's avatar
Gav committed
28
	let make_inherent = |function| UncheckedExtrinsic::new(
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
		Extrinsic {
			signed: Default::default(),
			function,
			index: 0,
		},
		Default::default(),
	);

	let mut inherent = vec![
		make_inherent(Call::Timestamp(TimestampCall::set(data.timestamp))),
		make_inherent(Call::Parachains(ParachainsCall::set_heads(data.parachain_heads))),
	];

	if !data.offline_indices.is_empty() {
		inherent.push(make_inherent(
Gav's avatar
Gav committed
44
			Call::Consensus(ConsensusCall::note_offline(data.offline_indices))
45
46
47
48
		));
	}

	inherent
Gav Wood's avatar
Gav Wood committed
49
50
51
52
}

/// Checks an unchecked extrinsic for validity.
pub fn check_extrinsic(xt: UncheckedExtrinsic) -> bool {
Gav's avatar
Gav committed
53
	xt.check_with(Balances::lookup).is_ok()
Gav Wood's avatar
Gav Wood committed
54
}