Skip to content

Commit 656efb7

Browse files
authored
Merge pull request #3812 from dusk-network/gql-block-label
rusk: add `status` to GQL block fields
2 parents f504a54 + 0e452ae commit 656efb7

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

node-data/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Add zeroize for secret info [#3687]
13+
- Add serde derive for Block Label
1314

1415
### Changed
1516

node-data/src/ledger/block.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//
55
// Copyright (c) DUSK NETWORK. All rights reserved.
66

7+
use serde::Serialize;
8+
79
use super::*;
810

911
pub type Hash = [u8; 32];
@@ -78,7 +80,7 @@ impl Block {
7880
}
7981
}
8082

81-
#[derive(Debug, Clone, Copy, PartialEq)]
83+
#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
8284
pub enum Label {
8385
Accepted(u64),
8486
Attested(u64),

rusk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Add support for `TransactionData::Blob`
1313
- Add `mempool_nonce` field to `/on/account/status` response
14+
- Add `status` to GQL block fields
1415

1516
### Changed
1617

rusk/src/lib/http/chain/graphql/data.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
use std::ops::Deref;
88

9-
use async_graphql::{FieldError, FieldResult, Object, SimpleObject};
9+
use async_graphql::{FieldError, FieldResult, Json, Object, SimpleObject};
1010
use node::database::{Ledger, LightBlock, DB};
11+
use node_data::ledger::Label;
1112
use serde::{Deserialize, Serialize};
1213

1314
/// Pair of (block height, block hash) of the last block and the last finalized
@@ -84,6 +85,23 @@ impl Block {
8485
Header(&self.header)
8586
}
8687

88+
pub async fn status(
89+
&self,
90+
ctx: &async_graphql::Context<'_>,
91+
) -> FieldResult<Json<Label>> {
92+
let db = ctx.data::<super::DBContext>()?.0.read().await;
93+
94+
Ok(async_graphql::Json(db.view(|t| {
95+
t.block_label_by_height(self.header.height)
96+
.map_err(|e| FieldError::new(e.to_string()))
97+
.and_then(|label| {
98+
label
99+
.map(|(_, label)| label)
100+
.ok_or_else(|| FieldError::new("Label not found"))
101+
})
102+
})?))
103+
}
104+
87105
pub async fn transactions(
88106
&self,
89107
ctx: &async_graphql::Context<'_>,

0 commit comments

Comments
 (0)