|
| 1 | +{-# LANGUAGE ConstraintKinds #-} |
| 2 | +{-# LANGUAGE DataKinds #-} |
| 3 | +{-# LANGUAGE DeriveDataTypeable #-} |
| 4 | +{-# LANGUAGE DeriveGeneric #-} |
| 5 | +{-# LANGUAGE DerivingStrategies #-} |
| 6 | +{-# LANGUAGE FlexibleContexts #-} |
| 7 | +{-# LANGUAGE FlexibleInstances #-} |
| 8 | +{-# LANGUAGE GADTs #-} |
| 9 | +{-# LANGUAGE GeneralizedNewtypeDeriving #-} |
| 10 | +{-# LANGUAGE MultiParamTypeClasses #-} |
| 11 | +{-# LANGUAGE OverloadedStrings #-} |
| 12 | +{-# LANGUAGE QuasiQuotes #-} |
| 13 | +{-# LANGUAGE StandaloneDeriving #-} |
| 14 | +{-# LANGUAGE TemplateHaskell #-} |
| 15 | +{-# LANGUAGE TypeFamilies #-} |
| 16 | +{-# LANGUAGE TypeOperators #-} |
| 17 | +{-# LANGUAGE UndecidableInstances #-} |
| 18 | + |
| 19 | +module Cardano.Db.Schema.Core.TxOut where |
| 20 | + |
| 21 | +import Cardano.Db.Schema.BaseSchema (DatumId, MultiAssetId, ScriptId, StakeAddressId, TxId) |
| 22 | +import Cardano.Db.Types (DbLovelace, DbWord64) |
| 23 | +import Data.ByteString.Char8 (ByteString) |
| 24 | +import Data.Text (Text) |
| 25 | +import Data.Word (Word64) |
| 26 | +import Database.Persist.Documentation (deriveShowFields, document, (#), (--^)) |
| 27 | +import Database.Persist.EntityDef.Internal (EntityDef (..)) |
| 28 | +import Database.Persist.TH |
| 29 | +import GHC.Generics (Generic) |
| 30 | + |
| 31 | +----------------------------------------------------------------------------------------------- |
| 32 | +-- TxOut |
| 33 | +----------------------------------------------------------------------------------------------- |
| 34 | +data TxOut = TxOut |
| 35 | + { txOutId :: !TxOutId |
| 36 | + , txOutAddress :: !Text |
| 37 | + , txOutAddressHasScript :: !Bool |
| 38 | + , txOutDataHash :: !(Maybe ByteString) |
| 39 | + , txOutConsumedByTxId :: !(Maybe TxId) |
| 40 | + , txOutIndex :: !Word64 |
| 41 | + , txOutInlineDatumId :: !(Maybe DatumId) |
| 42 | + , txOutPaymentCred :: !(Maybe ByteString) |
| 43 | + , txOutReferenceScriptId :: !(Maybe ScriptId) |
| 44 | + , txOutStakeAddressId :: !(Maybe StakeAddressId) |
| 45 | + , txOutTxId :: !TxId |
| 46 | + , txOutValue :: !DbLovelace |
| 47 | + } |
| 48 | + deriving (Eq, Show, Generic) |
| 49 | + |
| 50 | +newtype TxOutId = TxOutId { unTxOutId :: Word64 } |
| 51 | + deriving newtype (Eq, Ord, Show) |
| 52 | + |
| 53 | +----------------------------------------------------------------------------------------------- |
| 54 | +-- CollateralTxOut |
| 55 | +----------------------------------------------------------------------------------------------- |
| 56 | +data CollateralTxOut = CollateralTxOut |
| 57 | + { colateralTxOutId :: !TxOutId |
| 58 | + , collateralTxOutTxId :: !TxId |
| 59 | + , collateralTxOutIndex :: !Word64 |
| 60 | + , collateralTxOutAddress :: !Text |
| 61 | + , collateralTxOutAddressHasScript :: !Bool |
| 62 | + , collateralTxOutPaymentCred :: !(Maybe ByteString) |
| 63 | + , collateralTxOutStakeAddressId :: !(Maybe StakeAddressId) |
| 64 | + , collateralTxOutValue :: !DbLovelace |
| 65 | + , collateralTxOutDataHash :: !(Maybe ByteString) |
| 66 | + , collateralTxOutMultiAssetsDescr :: !Text |
| 67 | + , collateralTxOutInlineDatumId :: !(Maybe DatumId) |
| 68 | + , collateralTxOutReferenceScriptId :: !(Maybe ScriptId) |
| 69 | + } |
| 70 | + deriving (Eq, Show, Generic) |
| 71 | + |
| 72 | +newtype CollateralTxOutId = CollateralTxOutId { unCollateralTxOutId :: Word64 } |
| 73 | + deriving newtype (Eq, Ord, Show) |
| 74 | + |
| 75 | +----------------------------------------------------------------------------------------------- |
| 76 | +-- MultiAssetTxOut |
| 77 | +----------------------------------------------------------------------------------------------- |
| 78 | +data MaTxOut = MaTxOut |
| 79 | + { maTxOutId :: !MaTxOutId |
| 80 | + , maTxOutIdent :: !MultiAssetId |
| 81 | + , maTxOutQuantity :: !DbWord64 |
| 82 | + , maTxOutTxOutId :: !TxOutId |
| 83 | + } |
| 84 | + deriving (Eq, Show, Generic) |
| 85 | + |
| 86 | +newtype MaTxOutId = MaTxOutId { unMaTxOutId :: Word64 } |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +-- share |
| 93 | +-- [ mkPersist sqlSettings |
| 94 | +-- , mkMigrate "migrateCoreTxOutCardanoDb" |
| 95 | +-- , mkEntityDefList "entityDefsTxOutCore" |
| 96 | +-- , deriveShowFields |
| 97 | +-- ] |
| 98 | +-- [persistLowerCase| |
| 99 | +-- ---------------------------------------------- |
| 100 | +-- -- Core TxOut |
| 101 | +-- ---------------------------------------------- |
| 102 | +-- TxOut |
| 103 | +-- address Text |
| 104 | +-- addressHasScript Bool |
| 105 | +-- dataHash ByteString Maybe sqltype=hash32type |
| 106 | +-- consumedByTxId TxId Maybe noreference |
| 107 | +-- index Word64 sqltype=txindex |
| 108 | +-- inlineDatumId DatumId Maybe noreference |
| 109 | +-- paymentCred ByteString Maybe sqltype=hash28type |
| 110 | +-- referenceScriptId ScriptId Maybe noreference |
| 111 | +-- stakeAddressId StakeAddressId Maybe noreference |
| 112 | +-- txId TxId noreference |
| 113 | +-- value DbLovelace sqltype=lovelace |
| 114 | +-- UniqueTxout txId index -- The (tx_id, index) pair must be unique. |
| 115 | + |
| 116 | +-- ---------------------------------------------- |
| 117 | +-- -- Core CollateralTxOut |
| 118 | +-- ---------------------------------------------- |
| 119 | +-- CollateralTxOut |
| 120 | +-- txId TxId noreference -- This type is the primary key for the 'tx' table. |
| 121 | +-- index Word64 sqltype=txindex |
| 122 | +-- address Text |
| 123 | +-- addressHasScript Bool |
| 124 | +-- paymentCred ByteString Maybe sqltype=hash28type |
| 125 | +-- stakeAddressId StakeAddressId Maybe noreference |
| 126 | +-- value DbLovelace sqltype=lovelace |
| 127 | +-- dataHash ByteString Maybe sqltype=hash32type |
| 128 | +-- multiAssetsDescr Text |
| 129 | +-- inlineDatumId DatumId Maybe noreference |
| 130 | +-- referenceScriptId ScriptId Maybe noreference |
| 131 | +-- deriving Show |
| 132 | + |
| 133 | +-- ---------------------------------------------- |
| 134 | +-- -- MultiAsset |
| 135 | +-- ---------------------------------------------- |
| 136 | +-- MaTxOut |
| 137 | +-- ident MultiAssetId noreference |
| 138 | +-- quantity DbWord64 sqltype=word64type |
| 139 | +-- txOutId TxOutId noreference |
| 140 | +-- deriving Show |
| 141 | + |
| 142 | +-- |] |
| 143 | + |
| 144 | +-- schemaDocsTxOutCore :: [EntityDef] |
| 145 | +-- schemaDocsTxOutCore = |
| 146 | +-- document entityDefsTxOutCore $ do |
| 147 | +-- TxOut --^ do |
| 148 | +-- "A table for transaction outputs." |
| 149 | +-- TxOutAddress # "The human readable encoding of the output address. Will be Base58 for Byron era addresses and Bech32 for Shelley era." |
| 150 | +-- TxOutAddressHasScript # "Flag which shows if this address is locked by a script." |
| 151 | +-- TxOutConsumedByTxId # "The Tx table index of the transaction that consumes this transaction output. Not populated by default, can be activated via tx-out configs." |
| 152 | +-- TxOutDataHash # "The hash of the transaction output datum. (NULL for Txs without scripts)." |
| 153 | +-- TxOutIndex # "The index of this transaction output with the transaction." |
| 154 | +-- TxOutInlineDatumId # "The inline datum of the output, if it has one. New in v13." |
| 155 | +-- TxOutPaymentCred # "The payment credential part of the Shelley address. (NULL for Byron addresses). For a script-locked address, this is the script hash." |
| 156 | +-- TxOutReferenceScriptId # "The reference script of the output, if it has one. New in v13." |
| 157 | +-- TxOutStakeAddressId # "The StakeAddress table index for the stake address part of the Shelley address. (NULL for Byron addresses)." |
| 158 | +-- TxOutValue # "The output value (in Lovelace) of the transaction output." |
| 159 | + |
| 160 | +-- TxOutTxId # "The Tx table index of the transaction that contains this transaction output." |
| 161 | + |
| 162 | +-- CollateralTxOut --^ do |
| 163 | +-- "A table for transaction collateral outputs. New in v13." |
| 164 | +-- CollateralTxOutTxId # "The Tx table index of the transaction that contains this transaction output." |
| 165 | +-- CollateralTxOutIndex # "The index of this transaction output with the transaction." |
| 166 | +-- CollateralTxOutAddress # "The human readable encoding of the output address. Will be Base58 for Byron era addresses and Bech32 for Shelley era." |
| 167 | +-- CollateralTxOutAddressHasScript # "Flag which shows if this address is locked by a script." |
| 168 | +-- CollateralTxOutPaymentCred # "The payment credential part of the Shelley address. (NULL for Byron addresses). For a script-locked address, this is the script hash." |
| 169 | +-- CollateralTxOutStakeAddressId # "The StakeAddress table index for the stake address part of the Shelley address. (NULL for Byron addresses)." |
| 170 | +-- CollateralTxOutValue # "The output value (in Lovelace) of the transaction output." |
| 171 | +-- CollateralTxOutDataHash # "The hash of the transaction output datum. (NULL for Txs without scripts)." |
| 172 | +-- CollateralTxOutMultiAssetsDescr # "This is a description of the multiassets in collateral output. Since the output is not really created, we don't need to add them in separate tables." |
| 173 | +-- CollateralTxOutInlineDatumId # "The inline datum of the output, if it has one. New in v13." |
| 174 | +-- CollateralTxOutReferenceScriptId # "The reference script of the output, if it has one. New in v13." |
| 175 | + |
| 176 | +-- MaTxOut --^ do |
| 177 | +-- "A table containing Multi-Asset transaction outputs." |
| 178 | +-- MaTxOutIdent # "The MultiAsset table index specifying the asset." |
| 179 | +-- MaTxOutQuantity # "The Multi Asset transaction output amount (denominated in the Multi Asset)." |
| 180 | +-- MaTxOutTxOutId # "The TxOut table index for the transaction that this Multi Asset transaction output." |
0 commit comments