spacejam_service/service/
mod.rs

1//! Service types of SpaceJam
2
3use crate::{BTreeMap, Gas, ServiceId};
4use serde::{Deserialize, Serialize};
5pub use {
6    account::ServiceAccount,
7    refine::{RefineContext, RefineLoad},
8    result::{WorkExecResult, WorkResult},
9    work::{ExtrinsicSpec, ImportSpec, WorkItem, WorkPackage, WorkPackageSpec},
10};
11
12#[cfg(feature = "json")]
13use {crate::Vec, spacejson::Json};
14
15#[cfg(feature = "json")]
16pub use {
17    refine::{RefineContextJson, RefineLoadJson},
18    result::{WorkExecResultJson, WorkResultJson},
19    work::{ExtrinsicSpecJson, ImportSpecJson, WorkPackageSpecJson},
20};
21
22pub mod account;
23pub mod refine;
24pub mod result;
25pub mod work;
26
27/// The privileged service indices (χ)
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
29#[cfg_attr(feature = "json", derive(Json))]
30pub struct Privileges {
31    /// The bless service id (χm)
32    pub bless: ServiceId,
33
34    /// The assign service id (χa)
35    #[cfg_attr(feature = "json", json(Vec<ServiceId>))]
36    pub assign: [ServiceId; crate::CORES_COUNT],
37
38    /// The designate service id (χv)
39    pub designate: ServiceId,
40
41    /// The always accumulate service ids (χg)
42    pub always_acc: BTreeMap<ServiceId, Gas>,
43}
44
45impl Privileges {
46    /// Get the gas limit from the privileges
47    pub fn gas_limit(&self) -> Gas {
48        (crate::GAS_ACC * crate::CORES_COUNT as u64 + self.always_acc.values().sum::<u64>())
49            .max(crate::GAS_ALL_ACC)
50    }
51}
52
53/// The gas limits of the service account
54#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Default)]
55#[cfg_attr(feature = "json", derive(Json))]
56pub struct GasLimit {
57    /// The minimum gas in order to execute the accumulate
58    /// entry-point of the service code (g)
59    #[serde(alias = "min_memo_gas")]
60    pub accumulate: Gas,
61
62    /// The minimum required for the on transfer entry-point (m)
63    #[serde(alias = "min_item_gas")]
64    pub transfer: Gas,
65}