Skip to content

Commit

Permalink
Merge pull request #2592 from IntersectMBO/main
Browse files Browse the repository at this point in the history
hotfix: fetching latest drep voting anchor
  • Loading branch information
MSzalowski authored Dec 31, 2024
2 parents 6e9a766 + 1b0d220 commit 214e583
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
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

0 comments on commit 214e583

Please sign in to comment.