Skip to content

Commit 333d459

Browse files
committed
Fallback to Cip-100 for all metadata
Also ignore constitution metadata for now
1 parent 725fa4f commit 333d459

File tree

8 files changed

+60
-6
lines changed

8 files changed

+60
-6
lines changed

cardano-db-sync/app/http-get-json-metadata.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ main = do
5151
getVoteType ls
5252
| "ga" `List.elem` ls = Just GovAction
5353
| "drep" `List.elem` ls = Just DrepReg
54-
| "vote" `List.elem` ls = Just Other
54+
| "other" `List.elem` ls = Just Other
55+
| "vote" `List.elem` ls = Just Vote
56+
| "committee_dereg" `List.elem` ls = Just CommitteeDeReg
57+
| "const" `List.elem` ls = Just Constitution
5558
| otherwise = Nothing
5659
isItLink = List.elem "url"
5760

@@ -64,13 +67,22 @@ main = do
6467
_ ->
6568
runHttpGetPool (PoolUrl url) (PoolMetaHash <$> mhsh)
6669

67-
data OffChainVoteType = GovAction | DrepReg | Other
70+
data OffChainVoteType
71+
= GovAction
72+
| DrepReg
73+
| Other
74+
| Vote
75+
| CommitteeDeReg
76+
| Constitution
6877

6978
toDBOffChainVoteType :: OffChainVoteType -> DB.AnchorType
7079
toDBOffChainVoteType = \case
7180
GovAction -> DB.GovActionAnchor
7281
DrepReg -> DB.DrepAnchor
7382
Other -> DB.OtherAnchor
83+
Vote -> DB.VoteAnchor
84+
CommitteeDeReg -> DB.CommitteeDeRegAnchor
85+
Constitution -> DB.ConstitutionAnchor
7486

7587
-- -------------------------------------------------------------------------------------------------
7688

cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/Certificate.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ insertCommitteeDeRegistration ::
303303
Maybe (Anchor StandardCrypto) ->
304304
ReaderT SqlBackend m ()
305305
insertCommitteeDeRegistration blockId txId idx khCold mAnchor = do
306-
votingAnchorId <- whenMaybe mAnchor $ insertVotingAnchor blockId DB.OtherAnchor
306+
votingAnchorId <- whenMaybe mAnchor $ insertVotingAnchor blockId DB.CommitteeDeRegAnchor
307307
khColdId <- insertCommitteeHash khCold
308308
void
309309
. DB.insertCommitteeDeRegistration

cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/GovAction.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ insertParamProposal blkId txId pp = do
251251

252252
insertConstitution :: (MonadIO m, MonadBaseControl IO m) => DB.BlockId -> Maybe DB.GovActionProposalId -> Constitution StandardConway -> ReaderT SqlBackend m DB.ConstitutionId
253253
insertConstitution blockId mgapId constitution = do
254-
votingAnchorId <- insertVotingAnchor blockId DB.OtherAnchor $ constitutionAnchor constitution
254+
votingAnchorId <- insertVotingAnchor blockId DB.ConstitutionAnchor $ constitutionAnchor constitution
255255
DB.insertConstitution $
256256
DB.Constitution
257257
{ DB.constitutionGovActionProposalId = mgapId
@@ -284,7 +284,7 @@ insertVotingProcedure ::
284284
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
285285
insertVotingProcedure trce cache blkId txId voter (index, (gaId, vp)) = do
286286
govActionId <- resolveGovActionProposal cache gaId
287-
votingAnchorId <- whenMaybe (strictMaybeToMaybe $ vProcAnchor vp) $ lift . insertVotingAnchor blkId DB.OtherAnchor
287+
votingAnchorId <- whenMaybe (strictMaybeToMaybe $ vProcAnchor vp) $ lift . insertVotingAnchor blkId DB.VoteAnchor
288288
(mCommitteeVoterId, mDRepVoter, mStakePoolVoter) <- case voter of
289289
CommitteeVoter cred -> do
290290
khId <- lift $ insertCommitteeHash cred

cardano-db-sync/src/Cardano/DbSync/OffChain/Query.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Cardano.DbSync.OffChain.Query (
88
) where
99

1010
import Cardano.Db (
11-
AnchorType,
11+
AnchorType (..),
1212
EntityField (..),
1313
OffChainPoolData,
1414
OffChainPoolFetchError,
@@ -52,7 +52,9 @@ import Database.Esqueleto.Experimental (
5252
select,
5353
subList_select,
5454
table,
55+
val,
5556
where_,
57+
(!=.),
5658
(:&) ((:&)),
5759
(==.),
5860
(^.),
@@ -83,6 +85,7 @@ queryNewVoteWorkQueue now maxCount = do
8385
from (table @OffChainVoteData) >>= \ocvd ->
8486
where_ (ocvd ^. OffChainVoteDataVotingAnchorId ==. va ^. VotingAnchorId)
8587
)
88+
where_ (va ^. VotingAnchorType !=. val ConstitutionAnchor)
8689
where_
8790
( notExists $
8891
from (table @OffChainVoteFetchError) >>= \ocvfe ->
@@ -117,6 +120,7 @@ queryOffChainVoteWorkQueue _now maxCount = do
117120
`on` (\(va :& ocpfe) -> ocpfe ^. OffChainVoteFetchErrorVotingAnchorId ==. va ^. VotingAnchorId)
118121
orderBy [asc (ocpfe ^. OffChainVoteFetchErrorId)]
119122
where_ (just (ocpfe ^. OffChainVoteFetchErrorId) `in_` latestRefs)
123+
where_ (va ^. VotingAnchorType !=. val ConstitutionAnchor)
120124
limit $ fromIntegral maxCount
121125
pure
122126
( ocpfe ^. OffChainVoteFetchErrorFetchTime

cardano-db-sync/src/Cardano/DbSync/OffChain/Vote/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ eitherDecodeOffChainVoteData lbs = \case
6262
eitherDecodeAlternative (OffChainVoteDataGa <$> eitherDecode' lbs) (OffChainVoteDataOther <$> eitherDecode' lbs)
6363
DB.DrepAnchor ->
6464
eitherDecodeAlternative (OffChainVoteDataDr <$> eitherDecode' lbs) (OffChainVoteDataOther <$> eitherDecode' lbs)
65+
DB.VoteAnchor -> OffChainVoteDataOther <$> eitherDecode' lbs
66+
DB.CommitteeDeRegAnchor -> OffChainVoteDataOther <$> eitherDecode' lbs
67+
DB.ConstitutionAnchor -> Left "Unsupported Constitution metadata"
6568
DB.OtherAnchor -> OffChainVoteDataOther <$> eitherDecode' lbs
6669

6770
eitherDecodeAlternative :: Either String OffChainVoteData -> Either String OffChainVoteData -> Either String OffChainVoteData

cardano-db/src/Cardano/Db/Schema.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,7 @@ schemaDocs =
13281328
VotingAnchorBlockId # "The Block table index of the tx that includes this anchor. This only exists to facilitate rollbacks"
13291329
VotingAnchorDataHash # "A hash of the contents of the metadata URL"
13301330
VotingAnchorUrl # "A URL to a JSON payload of metadata"
1331+
VotingAnchorType # "The type of the anchor. It can be gov_action, drep, other, vote, committee_dereg, constitution"
13311332

13321333
GovActionProposal --^ do
13331334
"A table for proposed GovActionProposal, aka ProposalProcedure, GovAction or GovProposal.\

cardano-db/src/Cardano/Db/Types.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ data AnchorType
272272
= GovActionAnchor
273273
| DrepAnchor
274274
| OtherAnchor
275+
| VoteAnchor
276+
| CommitteeDeRegAnchor
277+
| ConstitutionAnchor
275278
deriving (Eq, Ord, Generic)
276279
deriving (Show) via (Quiet AnchorType)
277280

@@ -447,13 +450,19 @@ renderAnchorType gav =
447450
GovActionAnchor -> "gov_action"
448451
DrepAnchor -> "drep"
449452
OtherAnchor -> "other"
453+
VoteAnchor -> "vote"
454+
CommitteeDeRegAnchor -> "committee_dereg"
455+
ConstitutionAnchor -> "constitution"
450456

451457
readAnchorType :: String -> AnchorType
452458
readAnchorType str =
453459
case str of
454460
"gov_action" -> GovActionAnchor
455461
"drep" -> DrepAnchor
456462
"other" -> OtherAnchor
463+
"vote" -> VoteAnchor
464+
"committee_dereg" -> CommitteeDeRegAnchor
465+
"constitution" -> ConstitutionAnchor
457466
_other -> error $ "readAnchorType: Unknown AnchorType " ++ str
458467

459468
word64ToAda :: Word64 -> Ada

schema/migration-1-0015-20240724.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Hand written migration to create the custom types with 'DOMAIN' statements.
2+
3+
CREATE FUNCTION migrate() RETURNS void AS $$
4+
5+
DECLARE
6+
next_version int;
7+
8+
BEGIN
9+
SELECT stage_one + 1 INTO next_version FROM "schema_version";
10+
IF next_version = 15 THEN
11+
12+
ALTER TYPE anchorType ADD VALUE 'vote' AFTER 'other';
13+
ALTER TYPE anchorType ADD VALUE 'committee_dereg' AFTER 'vote';
14+
ALTER TYPE anchorType ADD VALUE 'constitution' AFTER 'committee_dereg';
15+
16+
UPDATE "schema_version" SET stage_one = next_version;
17+
RAISE NOTICE 'DB has been migrated to stage_one version %', next_version;
18+
END IF;
19+
END;
20+
21+
$$ LANGUAGE plpgsql;
22+
23+
SELECT migrate();
24+
25+
DROP FUNCTION migrate();

0 commit comments

Comments
 (0)