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
use crate::database::Database;
use crate::model::fuel_block::FuelBlock;
use crate::schema::block::Block;
use crate::schema::scalars::U64;
use async_graphql::{Context, Object};
use fuel_storage::Storage;
use fuel_tx::Bytes32;
pub const DEFAULT_NAME: &str = "Fuel.testnet";
pub struct ChainInfo;
#[Object]
impl ChainInfo {
async fn name(&self) -> String {
DEFAULT_NAME.into()
}
async fn latest_block(&self, ctx: &Context<'_>) -> async_graphql::Result<Block> {
let db = ctx.data_unchecked::<Database>().clone();
let height = db.get_block_height()?.unwrap_or_default();
let id = db.get_block_id(height)?.unwrap_or_default();
let block = Storage::<Bytes32, FuelBlock>::get(&db, &id)?.unwrap_or_default();
Ok(Block(block.into_owned()))
}
async fn base_chain_height(&self) -> U64 {
0.into()
}
async fn peer_count(&self) -> u16 {
0
}
}
#[derive(Default)]
pub struct ChainQuery;
#[Object]
impl ChainQuery {
async fn chain(&self) -> ChainInfo {
ChainInfo
}
}