Skip to content

Commit 9395f55

Browse files
committed
Add new tables for CIP-108 and CIP-119
1 parent f74e8d8 commit 9395f55

File tree

5 files changed

+79
-15
lines changed

5 files changed

+79
-15
lines changed

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ insertOffChainVoteResults trce resultQueue = do
143143
OffChainVoteResultMetadata md accessors -> do
144144
mocvdId <- DB.insertOffChainVoteData md
145145
whenJust mocvdId $ \ocvdId -> do
146+
whenJust (offChainVoteGovAction accessors ocvdId) $ \ocvga ->
147+
void $ DB.insertOffChainVoteGovActionData ocvga
148+
whenJust (offChainVoteDrep accessors ocvdId) $ \ocvdr ->
149+
void $ DB.insertOffChainVoteDrepData ocvdr
146150
DB.insertOffChainVoteAuthors $ offChainVoteAuthors accessors ocvdId
147151
DB.insertOffChainVoteReference $ offChainVoteReferences accessors ocvdId
148152
DB.insertOffChainVoteExternalUpdate $ offChainVoteExternalUpdates accessors ocvdId
@@ -275,22 +279,20 @@ fetchOffChainVoteData _tracer manager time oVoteWorkQ =
275279
DB.OffChainVoteData
276280
{ DB.offChainVoteDataLanguage = Vote.getLanguage offChainData
277281
, DB.offChainVoteDataComment = Vote.textValue <$> Vote.comment minimalBody
278-
, DB.offChainVoteDataTitle = Vote.getTitle offChainData
279-
, DB.offChainVoteDataAbstract = Vote.getAbstract offChainData
280-
, DB.offChainVoteDataMotivation = Vote.getMotivation offChainData
281-
, DB.offChainVoteDataRationale = Vote.getRationale offChainData
282282
, DB.offChainVoteDataBytes = sovaBytes sVoteData
283283
, DB.offChainVoteDataHash = sovaHash sVoteData
284284
, DB.offChainVoteDataJson = sovaJson sVoteData
285285
, DB.offChainVoteDataVotingAnchorId = oVoteWqReferenceId oVoteWorkQ
286286
, DB.offChainVoteDataWarning = sovaWarning sVoteData
287287
, DB.offChainVoteDataIsValid = Nothing
288288
}
289+
gaF ocvdId = mkGovAction ocvdId offChainData
290+
drepF ocvdId = mkDrep ocvdId offChainData
289291
authorsF ocvdId = map (mkAuthor ocvdId) $ Vote.getAuthors offChainData
290292
referencesF ocvdId = map (mkReference ocvdId) $ mListToList $ Vote.references minimalBody
291293
externalUpdatesF ocvdId = map (mkexternalUpdates ocvdId) $ mListToList $ Vote.externalUpdates minimalBody
292294
in
293-
OffChainVoteResultMetadata vdt (OffChainVoteAccessors authorsF referencesF externalUpdatesF)
295+
OffChainVoteResultMetadata vdt (OffChainVoteAccessors gaF drepF authorsF referencesF externalUpdatesF)
294296
Left err ->
295297
OffChainVoteResultError $
296298
DB.OffChainVoteFetchError
@@ -299,6 +301,31 @@ fetchOffChainVoteData _tracer manager time oVoteWorkQ =
299301
, DB.offChainVoteFetchErrorFetchTime = Time.posixSecondsToUTCTime time
300302
, DB.offChainVoteFetchErrorRetryCount = retryCount (oVoteWqRetry oVoteWorkQ)
301303
}
304+
mkGovAction ocvdId = \case
305+
Vote.OffChainVoteDataGa dt ->
306+
Just $
307+
DB.OffChainVoteGovActionData
308+
{ DB.offChainVoteGovActionDataOffChainVoteDataId = ocvdId
309+
, DB.offChainVoteGovActionDataTitle = Vote.textValue $ Vote.title $ Vote.body dt
310+
, DB.offChainVoteGovActionDataAbstract = Vote.textValue $ Vote.abstract $ Vote.body dt
311+
, DB.offChainVoteGovActionDataMotivation = Vote.textValue $ Vote.motivation $ Vote.body dt
312+
, DB.offChainVoteGovActionDataRationale = Vote.textValue $ Vote.rationale $ Vote.body dt
313+
}
314+
_ -> Nothing
315+
316+
mkDrep ocvdId = \case
317+
Vote.OffChainVoteDataDr dt ->
318+
Just $
319+
DB.OffChainVoteDrepData
320+
{ DB.offChainVoteDrepDataOffChainVoteDataId = ocvdId
321+
, DB.offChainVoteDrepDataPaymentAddress = Vote.textValue <$> Vote.paymentAddress (Vote.body dt)
322+
, DB.offChainVoteDrepDataGivenName = Vote.textValue $ Vote.givenName $ Vote.body dt
323+
, DB.offChainVoteDrepDataObjectives = Vote.textValue <$> Vote.objectives (Vote.body dt)
324+
, DB.offChainVoteDrepDataMotivations = Vote.textValue <$> Vote.motivations (Vote.body dt)
325+
, DB.offChainVoteDrepDataQualifications = Vote.textValue <$> Vote.qualifications (Vote.body dt)
326+
}
327+
_ -> Nothing
328+
302329
mkAuthor ocvdId au =
303330
DB.OffChainVoteAuthor
304331
{ DB.offChainVoteAuthorOffChainVoteDataId = ocvdId

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ data DrepBody = DrepBody
157157
}
158158
deriving (Show, Generic)
159159

160-
data Image = Image TextValue
160+
data Image = Image
161+
{ contentUrl :: Text
162+
, sha256 :: Text
163+
}
161164
deriving (Show, Generic, FromJSON)
162165

163166
data Reference tp = Reference

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ data OffChainVoteResult
153153
| OffChainVoteResultError !OffChainVoteFetchError
154154

155155
data OffChainVoteAccessors = OffChainVoteAccessors
156-
{ offChainVoteAuthors :: DB.OffChainVoteDataId -> [OffChainVoteAuthor]
156+
{ offChainVoteGovAction :: DB.OffChainVoteDataId -> Maybe DB.OffChainVoteGovActionData
157+
, offChainVoteDrep :: DB.OffChainVoteDataId -> Maybe DB.OffChainVoteDrepData
158+
, offChainVoteAuthors :: DB.OffChainVoteDataId -> [OffChainVoteAuthor]
157159
, offChainVoteReferences :: DB.OffChainVoteDataId -> [OffChainVoteReference]
158160
, offChainVoteExternalUpdates :: DB.OffChainVoteDataId -> [OffChainVoteExternalUpdate]
159161
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ module Cardano.Db.Insert (
5656
insertCheckOffChainPoolData,
5757
insertCheckOffChainPoolFetchError,
5858
insertOffChainVoteData,
59+
insertOffChainVoteGovActionData,
60+
insertOffChainVoteDrepData,
5961
insertOffChainVoteAuthors,
6062
insertOffChainVoteReference,
6163
insertOffChainVoteExternalUpdate,
@@ -343,6 +345,12 @@ insertOffChainVoteData ocvd = do
343345
then Just <$> insertCheckUnique "OffChainVoteData" ocvd
344346
else pure Nothing
345347

348+
insertOffChainVoteGovActionData :: (MonadBaseControl IO m, MonadIO m) => OffChainVoteGovActionData -> ReaderT SqlBackend m OffChainVoteGovActionDataId
349+
insertOffChainVoteGovActionData = insertUnchecked "OffChainVoteGovActionData"
350+
351+
insertOffChainVoteDrepData :: (MonadBaseControl IO m, MonadIO m) => OffChainVoteDrepData -> ReaderT SqlBackend m OffChainVoteDrepDataId
352+
insertOffChainVoteDrepData = insertUnchecked "OffChainVoteDrepData"
353+
346354
insertOffChainVoteAuthors :: (MonadBaseControl IO m, MonadIO m) => [OffChainVoteAuthor] -> ReaderT SqlBackend m ()
347355
insertOffChainVoteAuthors = void . insertMany' "OffChainVoteAuthor"
348356

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,17 +690,28 @@ share
690690
hash ByteString
691691
language Text
692692
comment Text Maybe
693-
title Text Maybe
694-
abstract Text Maybe
695-
motivation Text Maybe
696-
rationale Text Maybe
697693
json Text sqltype=jsonb
698694
bytes ByteString sqltype=bytea
699695
warning Text Maybe
700696
isValid Bool Maybe
701697
UniqueOffChainVoteData votingAnchorId hash
702698
deriving Show
703699

700+
OffChainVoteGovActionData
701+
offChainVoteDataId OffChainVoteDataId noreference
702+
title Text
703+
abstract Text
704+
motivation Text
705+
rationale Text
706+
707+
OffChainVoteDrepData
708+
offChainVoteDataId OffChainVoteDataId noreference
709+
paymentAddress Text Maybe
710+
givenName Text
711+
objectives Text Maybe
712+
motivations Text Maybe
713+
qualifications Text Maybe
714+
704715
OffChainVoteAuthor
705716
offChainVoteDataId OffChainVoteDataId noreference
706717
name Text Maybe
@@ -1340,10 +1351,6 @@ schemaDocs =
13401351
OffChainVoteDataVotingAnchorId # "The VotingAnchor table index this offchain data refers."
13411352
OffChainVoteDataHash # "The hash of the offchain data."
13421353
OffChainVoteDataLanguage # "The langauge described in the context of the metadata. Described in CIP-100. New in 13.3-Conway."
1343-
OffChainVoteDataComment # "The title of the metadata. Described in CIP-108. New in 13.3-Conway."
1344-
OffChainVoteDataAbstract # "The abstract of the metadata. Described in CIP-108. New in 13.3-Conway."
1345-
OffChainVoteDataMotivation # "The motivation of the metadata. Described in CIP-108. New in 13.3-Conway."
1346-
OffChainVoteDataRationale # "The rationale of the metadata. Described in CIP-108. New in 13.3-Conway."
13471354
OffChainVoteDataJson # "The payload as JSON."
13481355
OffChainVoteDataBytes # "The raw bytes of the payload."
13491356
OffChainVoteDataWarning # "A warning that occured while validating the metadata."
@@ -1352,6 +1359,23 @@ schemaDocs =
13521359
\since it normally populates off_chain_vote_fetch_error for invalid data. \
13531360
\It can be used manually to mark some metadata invalid by clients."
13541361

1362+
OffChainVoteGovActionData --^ do
1363+
"The table with offchain metadata for Governance Actions. Implementes CIP-108. New in 13.3-Conway."
1364+
OffChainVoteGovActionDataOffChainVoteDataId # "The vote metadata table index this offchain data belongs to."
1365+
OffChainVoteGovActionDataTitle # "The title"
1366+
OffChainVoteGovActionDataAbstract # "The abstract"
1367+
OffChainVoteGovActionDataMotivation # "The motivation"
1368+
OffChainVoteGovActionDataRationale # "The rationale"
1369+
1370+
OffChainVoteDrepData --^ do
1371+
"The table with offchain metadata for Drep Registrations. Implementes CIP-108. New in 13.3-Conway."
1372+
OffChainVoteDrepDataOffChainVoteDataId # "The vote metadata table index this offchain data belongs to."
1373+
OffChainVoteDrepDataPaymentAddress # "The payment address"
1374+
OffChainVoteDrepDataGivenName # "The name. This is the only mandatory field"
1375+
OffChainVoteDrepDataObjectives # "The objectives"
1376+
OffChainVoteDrepDataMotivations # "The motivations"
1377+
OffChainVoteDrepDataQualifications # "The qualifications"
1378+
13551379
OffChainVoteAuthor --^ do
13561380
"The table with offchain metadata authors, as decribed in CIP-100. New in 13.3-Conway."
13571381
OffChainVoteAuthorOffChainVoteDataId # "The OffChainVoteData table index this offchain data refers."

0 commit comments

Comments
 (0)