Skip to content

Commit a8020d0

Browse files
authored
Merge pull request #124 from input-output-hk/whankinsiv/drep-blockfrost-endpoints
feat: Add /governance/dreps/ endpoint handlers to rest_blockfrost
2 parents c6ce9dd + b93b2ff commit a8020d0

File tree

19 files changed

+1146
-174
lines changed

19 files changed

+1146
-174
lines changed

Cargo.lock

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub struct GovernanceProceduresMessage {
130130
pub proposal_procedures: Vec<ProposalProcedure>,
131131

132132
/// Voting
133-
pub voting_procedures: Vec<([u8; 32], VotingProcedures)>,
133+
pub voting_procedures: Vec<(TxHash, VotingProcedures)>,
134134

135135
/// Alonzo-compatible (from Shelley) and Babbage updates
136136
pub alonzo_babbage_updates: Vec<AlonzoBabbageUpdateProposal>,

common/src/queries/accounts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub enum AccountsStateQuery {
1818
GetAccountAssets { stake_key: Vec<u8> },
1919
GetAccountAssetsTotals { stake_key: Vec<u8> },
2020
GetAccountUTxOs { stake_key: Vec<u8> },
21+
GetAccountsBalancesMap { stake_keys: Vec<Vec<u8>> },
22+
GetAccountsBalancesSum { stake_keys: Vec<Vec<u8>> },
2123

2224
// Pools related queries
2325
GetPoolsLiveStakes { pools_operators: Vec<Vec<u8>> },
@@ -39,6 +41,8 @@ pub enum AccountsStateQueryResponse {
3941
AccountAssets(AccountAssets),
4042
AccountAssetsTotals(AccountAssetsTotals),
4143
AccountUTxOs(AccountUTxOs),
44+
AccountsBalancesMap(HashMap<Vec<u8>, u64>),
45+
AccountsBalancesSum(u64),
4246

4347
// Pools related responses
4448
PoolsLiveStakes(PoolsLiveStakes),

common/src/queries/governance.rs

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
use std::collections::HashMap;
22

33
use crate::{
4-
Anchor, DRepCredential, GovActionId, Lovelace, ProposalProcedure, Voter, VotingProcedure,
4+
Anchor, Credential, DRepCredential, GovActionId, Lovelace, ProposalProcedure, TxHash, Vote,
5+
Voter, VotingProcedure,
56
};
67

8+
pub const DEFAULT_DREPS_QUERY_TOPIC: (&str, &str) =
9+
("drep-state-query-topic", "cardano.query.dreps");
10+
pub const DEFAULT_GOVERNANCE_QUERY_TOPIC: (&str, &str) =
11+
("governance-state-query-topic", "cardano.query.governance");
12+
713
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
814
pub enum GovernanceStateQuery {
915
GetDRepsList,
10-
GetDRepInfo { drep_credential: DRepCredential },
16+
GetDRepInfoWithDelegators { drep_credential: DRepCredential },
1117
GetDRepDelegators { drep_credential: DRepCredential },
1218
GetDRepMetadata { drep_credential: DRepCredential },
1319
GetDRepUpdates { drep_credential: DRepCredential },
@@ -23,9 +29,9 @@ pub enum GovernanceStateQuery {
2329
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
2430
pub enum GovernanceStateQueryResponse {
2531
DRepsList(DRepsList),
26-
DRepInfo(DRepInfo),
32+
DRepInfoWithDelegators(DRepInfoWithDelegators),
2733
DRepDelegators(DRepDelegatorAddresses),
28-
DRepMetadata(DRepMetadata),
34+
DRepMetadata(Option<Option<Anchor>>),
2935
DRepUpdates(DRepUpdates),
3036
DRepVotes(DRepVotes),
3137
ProposalsList(ProposalsList),
@@ -46,20 +52,53 @@ pub struct DRepsList {
4652
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
4753
pub struct DRepInfo {
4854
pub deposit: Lovelace,
49-
pub anchor: Option<Anchor>,
55+
pub retired: bool,
56+
pub expired: bool,
57+
pub active_epoch: Option<u64>,
58+
pub last_active_epoch: u64,
5059
}
5160

5261
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
53-
pub struct DRepDelegatorAddresses {}
62+
pub struct DRepInfoWithDelegators {
63+
pub info: DRepInfo,
64+
pub delegators: Vec<Credential>,
65+
}
5466

5567
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
56-
pub struct DRepMetadata {}
68+
pub struct DRepDelegatorAddresses {
69+
pub addresses: Vec<Credential>,
70+
}
5771

5872
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
59-
pub struct DRepUpdates {}
73+
pub struct DRepUpdates {
74+
pub updates: Vec<DRepUpdateEvent>,
75+
}
6076

6177
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
62-
pub struct DRepVotes {}
78+
pub struct DRepUpdateEvent {
79+
pub tx_hash: TxHash,
80+
pub cert_index: u64,
81+
pub action: DRepActionUpdate,
82+
}
83+
84+
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
85+
pub enum DRepActionUpdate {
86+
Registered,
87+
Updated,
88+
Deregistered,
89+
}
90+
91+
#[derive(Clone, serde::Serialize, serde::Deserialize, Debug)]
92+
pub struct DRepVotes {
93+
pub votes: Vec<VoteRecord>,
94+
}
95+
96+
#[derive(Clone, serde::Serialize, serde::Deserialize, Debug)]
97+
pub struct VoteRecord {
98+
pub tx_hash: TxHash,
99+
pub vote_index: u32,
100+
pub vote: Vote,
101+
}
63102

64103
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
65104
pub struct ProposalsList {
@@ -79,8 +118,19 @@ pub struct ProposalWithdrawals {}
79118

80119
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
81120
pub struct ProposalVotes {
82-
pub votes: HashMap<Voter, (Vec<u8>, VotingProcedure)>,
121+
pub votes: HashMap<Voter, (TxHash, VotingProcedure)>,
83122
}
84123

85124
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
86125
pub struct ProposalMetadata {}
126+
127+
pub fn handle_governance_query_result<T>(
128+
result: anyhow::Result<Option<T>>,
129+
mapper: impl FnOnce(T) -> GovernanceStateQueryResponse,
130+
) -> GovernanceStateQueryResponse {
131+
match result {
132+
Ok(Some(val)) => mapper(val),
133+
Ok(None) => GovernanceStateQueryResponse::NotFound,
134+
Err(e) => GovernanceStateQueryResponse::Error(e.to_string()),
135+
}
136+
}

0 commit comments

Comments
 (0)