Skip to content

Commit c3e8886

Browse files
authored
Merge pull request #2593 from IntersectMBO/staging
hotfix: fetching latest drep voting anchor
2 parents 36b629e + 214e583 commit c3e8886

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ changes.
3939
- Revert to drep_distr for providing active voting power
4040
- Add rewards amount in the ada holder voting power
4141
- Fix nested @value in jsonld metadatas [Issue 2509](https://github.com/IntersectMBO/govtool/issues/2509)
42+
- Fix fetching latest voting anchor after DRep updates
4243

4344
### Changed
4445

govtool/backend/sql/list-dreps.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ DRepActivity AS (
1818
epoch_no DESC
1919
LIMIT 1
2020
)
21-
SELECT
21+
SELECT DISTINCT ON (dh.raw)
2222
encode(dh.raw, 'hex'),
2323
dh.view,
2424
dh.has_script,
2525
va.url,
2626
encode(va.data_hash, 'hex'),
2727
dr_deposit.deposit,
2828
DRepDistr.amount,
29-
(DRepActivity.epoch_no - COALESCE(block.epoch_no, block_first_register.epoch_no)) <= DRepActivity.drep_activity AS active,
29+
(DRepActivity.epoch_no - newestRegister.epoch_no) <= DRepActivity.drep_activity AS active,
3030
encode(dr_voting_anchor.tx_hash, 'hex') AS tx_hash,
3131
newestRegister.time AS last_register_time,
3232
COALESCE(latestDeposit.deposit, 0),
@@ -72,7 +72,7 @@ FROM
7272
drep_registration dr
7373
JOIN tx ON tx.id = dr.tx_id
7474
WHERE
75-
dr.deposit IS NOT NULL AND dr.deposit >= 0
75+
COALESCE(dr.deposit, 0) >= 0
7676
) AS dr_voting_anchor ON dr_voting_anchor.drep_hash_id = dh.id AND dr_voting_anchor.rn = 1
7777
LEFT JOIN (
7878
SELECT
@@ -122,6 +122,7 @@ FROM
122122
LEFT JOIN block ON block.id = tx.block_id
123123
LEFT JOIN (
124124
SELECT
125+
block.epoch_no,
125126
block.time,
126127
dr.drep_hash_id,
127128
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
@@ -130,7 +131,7 @@ FROM
130131
JOIN tx ON tx.id = dr.tx_id
131132
JOIN block ON block.id = tx.block_id
132133
WHERE
133-
NOT (dr.deposit < 0)
134+
COALESCE(dr.deposit, 0) >= 0
134135
) AS newestRegister ON newestRegister.drep_hash_id = dh.id AND newestRegister.rn = 1
135136
LEFT JOIN (
136137
SELECT
@@ -164,6 +165,7 @@ GROUP BY
164165
DRepActivity.drep_activity,
165166
dr_voting_anchor.tx_hash,
166167
newestRegister.time,
168+
newestRegister.epoch_no,
167169
latestDeposit.deposit,
168170
non_deregister_voting_anchor.url,
169171
fetch_error.message,

govtool/frontend/src/services/requests/getDRepList.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { bech32 } from "bech32";
2-
32
import {
43
type Infinite,
54
type DRepStatus,
@@ -33,29 +32,35 @@ export const getDRepList = async ({
3332
}: GetDRepListArguments): Promise<Infinite<DRepData>> => {
3433
// DBSync contains wrong representation of DRep view for script based DReps,
3534
// but it's still used by BE
36-
const searchPhrase = (() => {
37-
if (rawSearchPhrase.startsWith("drep_script")) {
38-
const { words } = bech32.decode(rawSearchPhrase);
39-
return bech32.encode("drep", words);
40-
}
41-
if (rawSearchPhrase.startsWith("drep")) {
42-
const decodedIdentifier = decodeCIP129Identifier(rawSearchPhrase);
43-
if (decodedIdentifier) {
44-
const isCIP129Identifier = decodedIdentifier.txID.startsWith("22");
45-
if (isCIP129Identifier) {
35+
const searchPhraseProcessor = async () => {
36+
try {
37+
if (rawSearchPhrase.startsWith("drep_script")) {
38+
const { words } = bech32.decode(rawSearchPhrase);
39+
return bech32.encode("drep", words);
40+
}
41+
if (rawSearchPhrase.startsWith("drep")) {
42+
const decodedIdentifier = decodeCIP129Identifier(rawSearchPhrase);
43+
if (decodedIdentifier) {
44+
const isCIP129Identifier = decodedIdentifier.txID.startsWith("22");
45+
if (isCIP129Identifier) {
46+
return encodeCIP129Identifier({
47+
txID: decodedIdentifier.txID.slice(2),
48+
bech32Prefix: "drep",
49+
});
50+
}
4651
return encodeCIP129Identifier({
47-
txID: decodedIdentifier.txID.slice(2),
52+
txID: decodedIdentifier.txID,
4853
bech32Prefix: "drep",
4954
});
5055
}
51-
return encodeCIP129Identifier({
52-
txID: decodedIdentifier.txID,
53-
bech32Prefix: "drep",
54-
});
5556
}
57+
return rawSearchPhrase;
58+
} catch (e) {
59+
return rawSearchPhrase;
5660
}
57-
return rawSearchPhrase;
58-
})();
61+
};
62+
63+
const searchPhrase = await searchPhraseProcessor();
5964

6065
const response = await API.get<Infinite<DrepDataDTO>>("/drep/list", {
6166
params: {

0 commit comments

Comments
 (0)