linera_execution/
graphql.rs

1// Copyright (c) Zefchain Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::collections::BTreeMap;
5
6use linera_base::{
7    data_types::{Amount, Timestamp},
8    doc_scalar,
9    identifiers::{ChainDescription, ChainId, Owner},
10    ownership::ChainOwnership,
11};
12use linera_views::{context::Context, map_view::MapView};
13
14use crate::{
15    committee::{Committee, Epoch, ValidatorName, ValidatorState},
16    system::{Recipient, UserData},
17    ChannelSubscription, ExecutionStateView, SystemExecutionStateView,
18};
19
20doc_scalar!(
21    Epoch,
22    "A number identifying the configuration of the chain (aka the committee)"
23);
24doc_scalar!(Recipient, "The recipient of a transfer");
25doc_scalar!(UserData, "Optional user message attached to a transfer");
26doc_scalar!(ValidatorName, "The identity of a validator");
27
28#[async_graphql::Object(cache_control(no_cache))]
29impl Committee {
30    #[graphql(derived(name = "validators"))]
31    async fn _validators(&self) -> &BTreeMap<ValidatorName, ValidatorState> {
32        self.validators()
33    }
34
35    #[graphql(derived(name = "total_votes"))]
36    async fn _total_votes(&self) -> u64 {
37        self.total_votes()
38    }
39
40    #[graphql(derived(name = "quorum_threshold"))]
41    async fn _quorum_threshold(&self) -> u64 {
42        self.quorum_threshold()
43    }
44
45    #[graphql(derived(name = "validity_threshold"))]
46    async fn _validity_threshold(&self) -> u64 {
47        self.validity_threshold()
48    }
49}
50
51#[async_graphql::Object(cache_control(no_cache))]
52impl<C: Send + Sync + Context> ExecutionStateView<C> {
53    #[graphql(derived(name = "system"))]
54    async fn _system(&self) -> &SystemExecutionStateView<C> {
55        &self.system
56    }
57}
58
59#[async_graphql::Object(cache_control(no_cache))]
60impl<C: Send + Sync + Context> SystemExecutionStateView<C> {
61    #[graphql(derived(name = "description"))]
62    async fn _description(&self) -> &Option<ChainDescription> {
63        self.description.get()
64    }
65
66    #[graphql(derived(name = "epoch"))]
67    async fn _epoch(&self) -> &Option<Epoch> {
68        self.epoch.get()
69    }
70
71    #[graphql(derived(name = "admin_id"))]
72    async fn _admin_id(&self) -> &Option<ChainId> {
73        self.admin_id.get()
74    }
75
76    #[graphql(derived(name = "subscription"))]
77    async fn _subscriptions(&self) -> Result<Vec<ChannelSubscription>, async_graphql::Error> {
78        Ok(self.subscriptions.indices().await?)
79    }
80
81    #[graphql(derived(name = "committees"))]
82    async fn _committees(&self) -> &BTreeMap<Epoch, Committee> {
83        self.committees.get()
84    }
85
86    #[graphql(derived(name = "ownership"))]
87    async fn _ownership(&self) -> &ChainOwnership {
88        self.ownership.get()
89    }
90
91    #[graphql(derived(name = "balance"))]
92    async fn _balance(&self) -> &Amount {
93        self.balance.get()
94    }
95
96    #[graphql(derived(name = "balances"))]
97    async fn _balances(&self) -> &MapView<C, Owner, Amount> {
98        &self.balances
99    }
100
101    #[graphql(derived(name = "timestamp"))]
102    async fn _timestamp(&self) -> &Timestamp {
103        self.timestamp.get()
104    }
105}