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::{WorkDigest, WorkExecResult},
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::{WorkDigestJson, WorkExecResultJson},
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///
29/// encoding (D.2)
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
31#[cfg_attr(feature = "json", derive(Json))]
32pub struct Privileges {
33    /// The index of the manager service (χM)
34    pub bless: ServiceId,
35
36    /// The assign service id (χA)
37    #[cfg_attr(feature = "json", json(Vec<ServiceId>))]
38    pub assign: [ServiceId; crate::CORES_COUNT],
39
40    /// The designate service id (χV)
41    pub designate: ServiceId,
42
43    /// ...then χR alone is able to create new service accounts with
44    /// indices in the protected range (χR)
45    pub register: ServiceId,
46
47    /// The always accumulate service ids (χZ)
48    pub always_acc: BTreeMap<ServiceId, Gas>,
49}
50
51impl Privileges {
52    /// Get the gas limit from the privileges
53    pub fn gas_limit(&self) -> Gas {
54        (crate::GAS_ACC * crate::CORES_COUNT as u64 + self.always_acc.values().sum::<u64>())
55            .max(crate::GAS_ALL_ACC)
56    }
57}
58
59/// The gas limits of the service account
60#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Default)]
61#[cfg_attr(feature = "json", derive(Json))]
62pub struct GasLimit {
63    /// The minimum gas in order to execute the accumulate
64    /// entry-point of the service code (g)
65    #[serde(alias = "min_memo_gas")]
66    pub accumulate: Gas,
67
68    /// The minimum required for the on transfer entry-point (m)
69    #[serde(alias = "min_item_gas")]
70    pub transfer: Gas,
71}