Skip to content

Commit c9498ba

Browse files
committed
all the new types
1 parent 66b9ea5 commit c9498ba

File tree

14 files changed

+3632
-0
lines changed

14 files changed

+3632
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Cardano.Db.Schema.Core
2+
( module Cardano.Db.Schema.Core.Base
3+
, module Cardano.Db.Schema.Core.EpochAndProtocol
4+
, module Cardano.Db.Schema.Core.GovernanceAndVoting
5+
, module Cardano.Db.Schema.Core.MultiAsset
6+
, module Cardano.Db.Schema.Core.OffChain
7+
, module Cardano.Db.Schema.Core.Pool
8+
, module Cardano.Db.Schema.Core.StakeDeligation
9+
) where
10+
11+
import Cardano.Db.Schema.Core.Base
12+
import Cardano.Db.Schema.Core.EpochAndProtocol
13+
import Cardano.Db.Schema.Core.GovernanceAndVoting
14+
import Cardano.Db.Schema.Core.MultiAsset
15+
import Cardano.Db.Schema.Core.OffChain
16+
import Cardano.Db.Schema.Core.Pool
17+
import Cardano.Db.Schema.Core.StakeDeligation

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

Lines changed: 640 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 514 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 741 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{-# LANGUAGE ConstraintKinds #-}
2+
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE DeriveGeneric #-}
4+
{-# LANGUAGE DerivingStrategies #-}
5+
{-# LANGUAGE FlexibleContexts #-}
6+
{-# LANGUAGE FlexibleInstances #-}
7+
{-# LANGUAGE GADTs #-}
8+
{-# LANGUAGE MultiParamTypeClasses #-}
9+
{-# LANGUAGE TypeFamilies #-}
10+
{-# LANGUAGE UndecidableInstances #-}
11+
12+
module Cardano.Db.Schema.Core.MultiAsset where
13+
14+
import Cardano.Db.Schema.Ids
15+
import Data.ByteString.Char8 (ByteString)
16+
import Data.Text (Text)
17+
-- import Database.Persist.Class (Unique)
18+
-- import Database.Persist.Documentation (deriveShowFields, document, (#), (--^))
19+
-- import Database.Persist.EntityDef.Internal (EntityDef (..))
20+
import GHC.Generics (Generic)
21+
22+
import Hasql.Decoders as D
23+
import Hasql.Encoders as E
24+
import Cardano.Db.Types (DbInt65, dbInt65Decoder, dbInt65Encoder)
25+
import Data.Functor.Contravariant ((>$<))
26+
27+
-----------------------------------------------------------------------------------------------------------------------------------
28+
-- MULTI ASSETS
29+
-- These tables manage governance-related data, including DReps, committees, and voting procedures.
30+
-----------------------------------------------------------------------------------------------------------------------------------
31+
32+
{-|
33+
Table Name: multi_asset
34+
Description: Contains information about multi-assets, including the policy and name of the asset.
35+
-}
36+
data MultiAsset = MultiAsset
37+
{ multiAssetId :: !MultiAssetId
38+
, multiAssetPolicy :: !ByteString -- sqltype=hash28type
39+
, multiAssetName :: !ByteString -- sqltype=asset32type
40+
, multiAssetFingerprint :: !Text
41+
} deriving (Eq, Show, Generic)
42+
-- UniqueMultiAsset policy name
43+
44+
multiAssetDecoder :: D.Row MultiAsset
45+
multiAssetDecoder =
46+
MultiAsset
47+
<$> idDecoder MultiAssetId -- multiAssetId
48+
<*> D.column (D.nonNullable D.bytea) -- multiAssetPolicy
49+
<*> D.column (D.nonNullable D.bytea) -- multiAssetName
50+
<*> D.column (D.nonNullable D.text) -- multiAssetFingerprint
51+
52+
multiAssetEncoder :: E.Params MultiAsset
53+
multiAssetEncoder =
54+
mconcat
55+
[ multiAssetId >$< idEncoder getMultiAssetId
56+
, multiAssetPolicy >$< E.param (E.nonNullable E.bytea)
57+
, multiAssetName >$< E.param (E.nonNullable E.bytea)
58+
, multiAssetFingerprint >$< E.param (E.nonNullable E.text)
59+
]
60+
61+
multiAssetInsertEncoder :: E.Params MultiAsset
62+
multiAssetInsertEncoder =
63+
mconcat
64+
[ multiAssetPolicy >$< E.param (E.nonNullable E.bytea)
65+
, multiAssetName >$< E.param (E.nonNullable E.bytea)
66+
, multiAssetFingerprint >$< E.param (E.nonNullable E.text)
67+
]
68+
69+
70+
-----------------------------------------------------------------------------------------------------------------------------------
71+
{-|
72+
Table Name: ma_tx_mint
73+
Description: Contains information about the minting of multi-assets, including the quantity of the asset and the transaction in which it was minted.
74+
-}
75+
data MaTxMint = MaTxMint
76+
{ maTxMintId :: !MaTxMintId
77+
, maTxMintIdent :: !MultiAssetId -- noreference
78+
, maTxMintQuantity :: !DbInt65 -- sqltype=int65type
79+
, maTxMintTxId :: !TxId -- noreference
80+
} deriving (Eq, Show, Generic)
81+
82+
maTxMintDecoder :: D.Row MaTxMint
83+
maTxMintDecoder =
84+
MaTxMint
85+
<$> idDecoder MaTxMintId
86+
<*> idDecoder MultiAssetId
87+
<*> D.column (D.nonNullable dbInt65Decoder)
88+
<*> idDecoder TxId
89+
90+
maTxMintEncoder :: E.Params MaTxMint
91+
maTxMintEncoder =
92+
mconcat
93+
[ maTxMintId >$< idEncoder getMaTxMintId
94+
, maTxMintIdent >$< idEncoder getMultiAssetId
95+
, maTxMintQuantity >$< E.param (E.nonNullable dbInt65Encoder)
96+
, maTxMintTxId >$< idEncoder getTxId
97+
]

0 commit comments

Comments
 (0)