linera_sdk/abis/
controller.rs1use async_graphql::{scalar, Request, Response, SimpleObject};
5use linera_sdk_derive::GraphQLMutationRootInCrate;
6use serde::{Deserialize, Serialize};
7
8use crate::linera_base_types::{
9 AccountOwner, ApplicationId, ChainId, ContractAbi, DataBlobHash, ServiceAbi,
10};
11
12pub struct ControllerAbi;
13
14impl ContractAbi for ControllerAbi {
15 type Operation = Operation;
16 type Response = ();
17}
18
19impl ServiceAbi for ControllerAbi {
20 type Query = Request;
21 type QueryResponse = Response;
22}
23
24pub type ManagedServiceId = DataBlobHash;
26
27#[derive(Debug, Deserialize, Serialize, GraphQLMutationRootInCrate)]
28pub enum Operation {
29 ExecuteWorkerCommand {
31 owner: AccountOwner,
32 command: WorkerCommand,
33 },
34 ExecuteControllerCommand {
36 admin: AccountOwner,
37 command: ControllerCommand,
38 },
39}
40
41#[derive(Clone, Debug, Deserialize, Serialize)]
43pub enum WorkerCommand {
44 RegisterWorker { capabilities: Vec<String> },
46 DeregisterWorker,
48}
49
50scalar!(WorkerCommand);
51
52#[derive(Clone, Debug, Deserialize, Serialize)]
54pub enum ControllerCommand {
55 SetAdmins { admins: Option<Vec<AccountOwner>> },
57 RemoveWorker { worker_id: ChainId },
60 UpdateService {
62 service_id: ManagedServiceId,
63 workers: Vec<ChainId>,
64 },
65 RemoveService { service_id: ManagedServiceId },
67 UpdateAllServices {
69 services: Vec<(ManagedServiceId, Vec<ChainId>)>,
70 },
71}
72
73scalar!(ControllerCommand);
74
75#[derive(Clone, Debug, Serialize, Deserialize, SimpleObject)]
77pub struct Worker {
78 pub owner: AccountOwner,
80 pub capabilities: Vec<String>,
83}
84
85#[derive(Clone, Debug, Serialize, Deserialize)]
87pub struct ManagedService {
88 pub application_id: ApplicationId,
90 pub name: String,
93 pub chain_id: ChainId,
97 pub requirements: Vec<String>,
100}
101
102scalar!(ManagedService);
103
104#[derive(Clone, Debug, Deserialize, Serialize)]
107pub struct LocalWorkerState {
108 pub local_worker: Option<Worker>,
110 pub local_services: Vec<ManagedService>,
112 pub local_chains: Vec<ChainId>,
115}
116
117scalar!(LocalWorkerState);