referrerpolicy=no-referrer-when-downgrade

cumulus_aura_authorizer_utils/
work_package.rs

1// This file is part of Cumulus.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use codec::Encode as ScaleEncode;
19use jam_types::{
20	Authorizer, BoundedVec, MaxWorkItems, RefineContext, ServiceId, WorkItem, WorkPackage,
21};
22use primitive_types::H256;
23
24use crate::{signing::SigningPayload, AuthToken};
25
26/// A work package awaiting its authorization token.
27#[derive(Clone, Debug)]
28pub struct WorkPackageBody {
29	/// Service hosting the authorizer code.
30	pub auth_code_host: ServiceId,
31
32	/// Authorizer code hash and configuration.
33	pub authorizer: Authorizer,
34
35	/// Refinement context.
36	pub context: RefineContext,
37
38	/// Work items in execution order.
39	pub items: BoundedVec<WorkItem, MaxWorkItems>,
40}
41
42impl WorkPackageBody {
43	/// Hash to be signed by the collator when constructing an AURA token.
44	pub fn signing_hash(&self) -> H256 {
45		SigningPayload::from(self).hash()
46	}
47
48	/// Attach an existing AURA token and return the complete work package.
49	pub fn with_authorization(self, token: &AuthToken) -> WorkPackage {
50		WorkPackage {
51			authorization: ScaleEncode::encode(token).into(),
52			auth_code_host: self.auth_code_host,
53			authorizer: self.authorizer,
54			context: self.context,
55			items: self.items,
56		}
57	}
58}