Skip to content

Commit 1c221e5

Browse files
authored
Merge pull request #272 from input-output-hk/whankinsiv/historical-accounts-cert-processing
Historical accounts state certificate processing
2 parents 0224c04 + 0f76582 commit 1c221e5

File tree

19 files changed

+913
-671
lines changed

19 files changed

+913
-671
lines changed

codec/src/map_parameters.rs

Lines changed: 228 additions & 195 deletions
Large diffs are not rendered by default.

common/src/messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct AssetDeltasMessage {
9191
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
9292
pub struct TxCertificatesMessage {
9393
/// Ordered set of certificates
94-
pub certificates: Vec<TxCertificate>,
94+
pub certificates: Vec<TxCertificateWithPos>,
9595
}
9696

9797
/// Address deltas message

common/src/queries/accounts.rs

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use crate::{DRepChoice, KeyHash, PoolLiveStakeInfo, StakeAddress};
3+
use crate::{DRepChoice, KeyHash, PoolId, PoolLiveStakeInfo, StakeAddress, TxIdentifier};
44

55
pub const DEFAULT_ACCOUNTS_QUERY_TOPIC: (&str, &str) =
66
("accounts-state-query-topic", "cardano.query.accounts");
@@ -15,10 +15,10 @@ pub enum AccountsStateQuery {
1515
GetAccountInfo { stake_address: StakeAddress },
1616
GetAccountRewardHistory { stake_key: Vec<u8> },
1717
GetAccountHistory { stake_key: Vec<u8> },
18-
GetAccountDelegationHistory { stake_key: Vec<u8> },
19-
GetAccountRegistrationHistory { stake_key: Vec<u8> },
18+
GetAccountRegistrationHistory { account: StakeAddress },
19+
GetAccountDelegationHistory { account: StakeAddress },
20+
GetAccountMIRHistory { account: StakeAddress },
2021
GetAccountWithdrawalHistory { stake_key: Vec<u8> },
21-
GetAccountMIRHistory { stake_key: Vec<u8> },
2222
GetAccountAssociatedAddresses { stake_key: Vec<u8> },
2323
GetAccountAssets { stake_key: Vec<u8> },
2424
GetAccountAssetsTotals { stake_key: Vec<u8> },
@@ -49,10 +49,10 @@ pub enum AccountsStateQueryResponse {
4949
AccountInfo(AccountInfo),
5050
AccountRewardHistory(AccountRewardHistory),
5151
AccountHistory(AccountHistory),
52-
AccountDelegationHistory(AccountDelegationHistory),
53-
AccountRegistrationHistory(AccountRegistrationHistory),
52+
AccountRegistrationHistory(Vec<RegistrationUpdate>),
53+
AccountDelegationHistory(Vec<DelegationUpdate>),
54+
AccountMIRHistory(Vec<AccountWithdrawal>),
5455
AccountWithdrawalHistory(AccountWithdrawalHistory),
55-
AccountMIRHistory(AccountMIRHistory),
5656
AccountAssociatedAddresses(AccountAssociatedAddresses),
5757
AccountAssets(AccountAssets),
5858
AccountAssetsTotals(AccountAssetsTotals),
@@ -97,17 +97,52 @@ pub struct AccountRewardHistory {}
9797
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
9898
pub struct AccountHistory {}
9999

100-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
101-
pub struct AccountDelegationHistory {}
100+
#[derive(
101+
Debug, Clone, serde::Serialize, serde::Deserialize, minicbor::Decode, minicbor::Encode,
102+
)]
103+
pub struct DelegationUpdate {
104+
#[n(0)]
105+
pub active_epoch: u32,
106+
#[n(1)]
107+
pub tx_identifier: TxIdentifier,
108+
#[n(2)]
109+
pub amount: u64,
110+
#[n(3)]
111+
pub pool: PoolId,
112+
}
102113

103-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
104-
pub struct AccountRegistrationHistory {}
114+
#[derive(
115+
Debug, Clone, serde::Serialize, serde::Deserialize, minicbor::Decode, minicbor::Encode,
116+
)]
117+
pub struct RegistrationUpdate {
118+
#[n(0)]
119+
pub tx_identifier: TxIdentifier,
120+
#[n(1)]
121+
pub status: RegistrationStatus,
122+
}
105123

106-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
107-
pub struct AccountWithdrawalHistory {}
124+
#[derive(
125+
Debug, Clone, serde::Serialize, serde::Deserialize, minicbor::Decode, minicbor::Encode,
126+
)]
127+
pub enum RegistrationStatus {
128+
#[n(0)]
129+
Registered,
130+
#[n(1)]
131+
Deregistered,
132+
}
133+
134+
#[derive(
135+
Debug, Clone, serde::Serialize, serde::Deserialize, minicbor::Decode, minicbor::Encode,
136+
)]
137+
pub struct AccountWithdrawal {
138+
#[n(0)]
139+
pub tx_identifier: TxIdentifier,
140+
#[n(1)]
141+
pub amount: u64,
142+
}
108143

109144
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
110-
pub struct AccountMIRHistory {}
145+
pub struct AccountWithdrawalHistory {}
111146

112147
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
113148
pub struct AccountAssociatedAddresses {}

common/src/queries/governance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::HashMap;
22

33
use crate::{
4-
Anchor, DRepCredential, GovActionId, Lovelace, ProposalProcedure, StakeAddress, TxHash, Vote,
5-
Voter, VotingProcedure,
4+
Anchor, DRepCredential, GovActionId, Lovelace, ProposalProcedure, StakeAddress, TxHash,
5+
TxIdentifier, Vote, Voter, VotingProcedure,
66
};
77

88
pub const DEFAULT_DREPS_QUERY_TOPIC: (&str, &str) =
@@ -77,7 +77,7 @@ pub struct DRepUpdates {
7777

7878
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
7979
pub struct DRepUpdateEvent {
80-
pub tx_hash: TxHash,
80+
pub tx_identifier: TxIdentifier,
8181
pub cert_index: u64,
8282
pub action: DRepActionUpdate,
8383
}

common/src/types.rs

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -808,14 +808,6 @@ pub struct PoolMetadata {
808808
pub hash: DataHash,
809809
}
810810

811-
/// Pool registration with position
812-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
813-
pub struct PoolRegistrationWithPos {
814-
pub reg: PoolRegistration,
815-
pub tx_hash: TxHash,
816-
pub cert_index: u64,
817-
}
818-
819811
/// Pool registration data
820812
#[serde_as]
821813
#[derive(
@@ -869,14 +861,6 @@ pub struct PoolRegistration {
869861
pub pool_metadata: Option<PoolMetadata>,
870862
}
871863

872-
// Pool Retirment with position
873-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
874-
pub struct PoolRetirementWithPos {
875-
pub ret: PoolRetirement,
876-
pub tx_hash: TxHash,
877-
pub cert_index: u64,
878-
}
879-
880864
/// Pool retirement data
881865
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
882866
pub struct PoolRetirement {
@@ -897,23 +881,23 @@ pub enum PoolUpdateAction {
897881
/// Pool Update Event
898882
#[derive(Debug, Clone, Serialize, Deserialize)]
899883
pub struct PoolUpdateEvent {
900-
pub tx_hash: TxHash,
884+
pub tx_identifier: TxIdentifier,
901885
pub cert_index: u64,
902886
pub action: PoolUpdateAction,
903887
}
904888

905889
impl PoolUpdateEvent {
906-
pub fn register_event(tx_hash: TxHash, cert_index: u64) -> Self {
890+
pub fn register_event(tx_identifier: TxIdentifier, cert_index: u64) -> Self {
907891
Self {
908-
tx_hash,
892+
tx_identifier,
909893
cert_index,
910894
action: PoolUpdateAction::Registered,
911895
}
912896
}
913897

914-
pub fn retire_event(tx_hash: TxHash, cert_index: u64) -> Self {
898+
pub fn retire_event(tx_identifier: TxIdentifier, cert_index: u64) -> Self {
915899
Self {
916-
tx_hash,
900+
tx_identifier,
917901
cert_index,
918902
action: PoolUpdateAction::Deregistered,
919903
}
@@ -1140,13 +1124,6 @@ pub struct DRepRegistration {
11401124
pub anchor: Option<Anchor>,
11411125
}
11421126

1143-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
1144-
pub struct DRepRegistrationWithPos {
1145-
pub reg: DRepRegistration,
1146-
pub tx_hash: TxHash,
1147-
pub cert_index: u64,
1148-
}
1149-
11501127
/// DRep Deregistration = unreg_drep_cert
11511128
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
11521129
pub struct DRepDeregistration {
@@ -1157,13 +1134,6 @@ pub struct DRepDeregistration {
11571134
pub refund: Lovelace,
11581135
}
11591136

1160-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
1161-
pub struct DRepDeregistrationWithPos {
1162-
pub reg: DRepDeregistration,
1163-
pub tx_hash: TxHash,
1164-
pub cert_index: u64,
1165-
}
1166-
11671137
/// DRep Update = update_drep_cert
11681138
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
11691139
pub struct DRepUpdate {
@@ -1174,13 +1144,6 @@ pub struct DRepUpdate {
11741144
pub anchor: Option<Anchor>,
11751145
}
11761146

1177-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
1178-
pub struct DRepUpdateWithPos {
1179-
pub reg: DRepUpdate,
1180-
pub tx_hash: TxHash,
1181-
pub cert_index: u64,
1182-
}
1183-
11841147
pub type CommitteeCredential = Credential;
11851148

11861149
/// Authorise a committee hot credential
@@ -1794,21 +1757,14 @@ pub struct GovernanceOutcome {
17941757
pub action_to_perform: GovernanceOutcomeVariant,
17951758
}
17961759

1797-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
1798-
pub struct StakeAddressWithPos {
1799-
pub stake_address: StakeAddress,
1800-
pub tx_index: u64,
1801-
pub cert_index: u64,
1802-
}
1803-
18041760
/// Certificate in a transaction
18051761
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
18061762
pub enum TxCertificate {
18071763
/// Default
18081764
None(()),
18091765

18101766
/// Stake registration
1811-
StakeRegistration(StakeAddressWithPos),
1767+
StakeRegistration(StakeAddress),
18121768

18131769
/// Stake de-registration
18141770
StakeDeregistration(StakeAddress),
@@ -1817,10 +1773,10 @@ pub enum TxCertificate {
18171773
StakeDelegation(StakeDelegation),
18181774

18191775
/// Pool registration
1820-
PoolRegistrationWithPos(PoolRegistrationWithPos),
1776+
PoolRegistration(PoolRegistration),
18211777

18221778
/// Pool retirement
1823-
PoolRetirementWithPos(PoolRetirementWithPos),
1779+
PoolRetirement(PoolRetirement),
18241780

18251781
/// Genesis key delegation
18261782
GenesisKeyDelegation(GenesisKeyDelegation),
@@ -1856,13 +1812,20 @@ pub enum TxCertificate {
18561812
ResignCommitteeCold(ResignCommitteeCold),
18571813

18581814
/// DRep registration
1859-
DRepRegistration(DRepRegistrationWithPos),
1815+
DRepRegistration(DRepRegistration),
18601816

18611817
/// DRep deregistration
1862-
DRepDeregistration(DRepDeregistrationWithPos),
1818+
DRepDeregistration(DRepDeregistration),
18631819

18641820
/// DRep update
1865-
DRepUpdate(DRepUpdateWithPos),
1821+
DRepUpdate(DRepUpdate),
1822+
}
1823+
1824+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
1825+
pub struct TxCertificateWithPos {
1826+
pub cert: TxCertificate,
1827+
pub tx_identifier: TxIdentifier,
1828+
pub cert_index: u64,
18661829
}
18671830

18681831
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]

0 commit comments

Comments
 (0)