1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::collections::BTreeMap;

use linera_base::{
    crypto::ValidatorPublicKey,
    data_types::{Amount, Timestamp},
    doc_scalar,
    identifiers::{AccountOwner, ChainDescription, ChainId},
    ownership::ChainOwnership,
};
use linera_views::{context::Context, map_view::MapView};

use crate::{
    committee::{Committee, Epoch, ValidatorState},
    system::{Recipient, UserData},
    ChannelSubscription, ExecutionStateView, SystemExecutionStateView,
};

doc_scalar!(
    Epoch,
    "A number identifying the configuration of the chain (aka the committee)"
);
doc_scalar!(Recipient, "The recipient of a transfer");
doc_scalar!(UserData, "Optional user message attached to a transfer");

#[async_graphql::Object(cache_control(no_cache))]
impl Committee {
    #[graphql(derived(name = "validators"))]
    async fn _validators(&self) -> &BTreeMap<ValidatorPublicKey, ValidatorState> {
        self.validators()
    }

    #[graphql(derived(name = "total_votes"))]
    async fn _total_votes(&self) -> u64 {
        self.total_votes()
    }

    #[graphql(derived(name = "quorum_threshold"))]
    async fn _quorum_threshold(&self) -> u64 {
        self.quorum_threshold()
    }

    #[graphql(derived(name = "validity_threshold"))]
    async fn _validity_threshold(&self) -> u64 {
        self.validity_threshold()
    }
}

#[async_graphql::Object(cache_control(no_cache))]
impl<C: Send + Sync + Context> ExecutionStateView<C> {
    #[graphql(derived(name = "system"))]
    async fn _system(&self) -> &SystemExecutionStateView<C> {
        &self.system
    }
}

#[async_graphql::Object(cache_control(no_cache))]
impl<C: Send + Sync + Context> SystemExecutionStateView<C> {
    #[graphql(derived(name = "description"))]
    async fn _description(&self) -> &Option<ChainDescription> {
        self.description.get()
    }

    #[graphql(derived(name = "epoch"))]
    async fn _epoch(&self) -> &Option<Epoch> {
        self.epoch.get()
    }

    #[graphql(derived(name = "admin_id"))]
    async fn _admin_id(&self) -> &Option<ChainId> {
        self.admin_id.get()
    }

    #[graphql(derived(name = "subscription"))]
    async fn _subscriptions(&self) -> Result<Vec<ChannelSubscription>, async_graphql::Error> {
        Ok(self.subscriptions.indices().await?)
    }

    #[graphql(derived(name = "committees"))]
    async fn _committees(&self) -> &BTreeMap<Epoch, Committee> {
        self.committees.get()
    }

    #[graphql(derived(name = "ownership"))]
    async fn _ownership(&self) -> &ChainOwnership {
        self.ownership.get()
    }

    #[graphql(derived(name = "balance"))]
    async fn _balance(&self) -> &Amount {
        self.balance.get()
    }

    #[graphql(derived(name = "balances"))]
    async fn _balances(&self) -> &MapView<C, AccountOwner, Amount> {
        &self.balances
    }

    #[graphql(derived(name = "timestamp"))]
    async fn _timestamp(&self) -> &Timestamp {
        self.timestamp.get()
    }
}