Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: fetching latest drep voting anchor #2594

Merged
merged 10 commits into from
Dec 31, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ changes.
- Revert to drep_distr for providing active voting power
- Add rewards amount in the ada holder voting power
- Fix nested @value in jsonld metadatas [Issue 2509](https://github.com/IntersectMBO/govtool/issues/2509)
- Fix fetching latest voting anchor after DRep updates

### Changed

Expand Down
10 changes: 6 additions & 4 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ DRepActivity AS (
epoch_no DESC
LIMIT 1
)
SELECT
SELECT DISTINCT ON (dh.raw)
encode(dh.raw, 'hex'),
dh.view,
dh.has_script,
va.url,
encode(va.data_hash, 'hex'),
dr_deposit.deposit,
DRepDistr.amount,
(DRepActivity.epoch_no - COALESCE(block.epoch_no, block_first_register.epoch_no)) <= DRepActivity.drep_activity AS active,
(DRepActivity.epoch_no - newestRegister.epoch_no) <= DRepActivity.drep_activity AS active,
encode(dr_voting_anchor.tx_hash, 'hex') AS tx_hash,
newestRegister.time AS last_register_time,
COALESCE(latestDeposit.deposit, 0),
Expand Down Expand Up @@ -72,7 +72,7 @@ FROM
drep_registration dr
JOIN tx ON tx.id = dr.tx_id
WHERE
dr.deposit IS NOT NULL AND dr.deposit >= 0
COALESCE(dr.deposit, 0) >= 0
) AS dr_voting_anchor ON dr_voting_anchor.drep_hash_id = dh.id AND dr_voting_anchor.rn = 1
LEFT JOIN (
SELECT
Expand Down Expand Up @@ -122,6 +122,7 @@ FROM
LEFT JOIN block ON block.id = tx.block_id
LEFT JOIN (
SELECT
block.epoch_no,
block.time,
dr.drep_hash_id,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
Expand All @@ -130,7 +131,7 @@ FROM
JOIN tx ON tx.id = dr.tx_id
JOIN block ON block.id = tx.block_id
WHERE
NOT (dr.deposit < 0)
COALESCE(dr.deposit, 0) >= 0
) AS newestRegister ON newestRegister.drep_hash_id = dh.id AND newestRegister.rn = 1
LEFT JOIN (
SELECT
Expand Down Expand Up @@ -164,6 +165,7 @@ GROUP BY
DRepActivity.drep_activity,
dr_voting_anchor.tx_hash,
newestRegister.time,
newestRegister.epoch_no,
latestDeposit.deposit,
non_deregister_voting_anchor.url,
fetch_error.message,
Expand Down
41 changes: 23 additions & 18 deletions govtool/frontend/src/services/requests/getDRepList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { bech32 } from "bech32";

import {
type Infinite,
type DRepStatus,
Expand Down Expand Up @@ -33,29 +32,35 @@ export const getDRepList = async ({
}: GetDRepListArguments): Promise<Infinite<DRepData>> => {
// DBSync contains wrong representation of DRep view for script based DReps,
// but it's still used by BE
const searchPhrase = (() => {
if (rawSearchPhrase.startsWith("drep_script")) {
const { words } = bech32.decode(rawSearchPhrase);
return bech32.encode("drep", words);
}
if (rawSearchPhrase.startsWith("drep")) {
const decodedIdentifier = decodeCIP129Identifier(rawSearchPhrase);
if (decodedIdentifier) {
const isCIP129Identifier = decodedIdentifier.txID.startsWith("22");
if (isCIP129Identifier) {
const searchPhraseProcessor = async () => {
try {
if (rawSearchPhrase.startsWith("drep_script")) {
const { words } = bech32.decode(rawSearchPhrase);
return bech32.encode("drep", words);
}
if (rawSearchPhrase.startsWith("drep")) {
const decodedIdentifier = decodeCIP129Identifier(rawSearchPhrase);
if (decodedIdentifier) {
const isCIP129Identifier = decodedIdentifier.txID.startsWith("22");
if (isCIP129Identifier) {
return encodeCIP129Identifier({
txID: decodedIdentifier.txID.slice(2),
bech32Prefix: "drep",
});
}
return encodeCIP129Identifier({
txID: decodedIdentifier.txID.slice(2),
txID: decodedIdentifier.txID,
bech32Prefix: "drep",
});
}
return encodeCIP129Identifier({
txID: decodedIdentifier.txID,
bech32Prefix: "drep",
});
}
return rawSearchPhrase;
} catch (e) {
return rawSearchPhrase;
}
return rawSearchPhrase;
})();
};

const searchPhrase = await searchPhraseProcessor();

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