Skip to content

Commit 1aae034

Browse files
committed
experiment 2
1 parent 2ff63c2 commit 1aae034

File tree

28 files changed

+603
-229
lines changed

28 files changed

+603
-229
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Config.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ insertConfig = do
3434
, sioPoolStats = PoolStatsConfig False
3535
, sioJsonType = JsonTypeDisable
3636
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
37-
, sioAddressDetail = AddressDetailConfig False
37+
, sioAddress = AddressTypeConfig False
3838
}
3939

4040
dncInsertOptions cfg @?= expected

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Config/Parse.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ insertConfig = do
3434
, sioPoolStats = PoolStatsConfig False
3535
, sioJsonType = JsonTypeDisable
3636
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
37-
, sioAddressDetail = AddressDetailConfig False
37+
, sioAddress = AddressTypeConfig False
3838
}
3939

4040
dncInsertOptions cfg @?= expected

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ insertConfig = do
104104
, sioPoolStats = PoolStatsConfig False
105105
, sioJsonType = JsonTypeDisable
106106
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
107-
, sioAddressDetail = AddressDetailConfig False
107+
, sioAddress = AddressTypeConfig False
108108
}
109109

110110
dncInsertOptions cfg @?= expected

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ extractSyncOptions snp aop snc =
278278
, ioPoolStats = isPoolStatsEnabled (sioPoolStats (dncInsertOptions snc))
279279
, ioGov = useGovernance
280280
, ioRemoveJsonbFromSchema = isRemoveJsonbFromSchemaEnabled (sioRemoveJsonbFromSchema (dncInsertOptions snc))
281-
, ioAddressDetail = useAddressDetailTable (sioAddressDetail (dncInsertOptions snc))
281+
, ioAddress = unAddressTypeConfig (sioAddress (dncInsertOptions snc))
282282
}
283283

284284
useLedger = sioLedger (dncInsertOptions snc) == LedgerEnable

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ data InsertOptions = InsertOptions
8787
, ioPoolStats :: !Bool
8888
, ioGov :: !Bool
8989
, ioRemoveJsonbFromSchema :: !Bool
90-
, ioAddressDetail :: !Bool
90+
, ioAddress :: !DB.AddressType
9191
}
9292
deriving (Show)
9393

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Cardano.DbSync.Config.Types (
1919
GenesisHashAlonzo (..),
2020
GenesisHashConway (..),
2121
RemoveJsonbFromSchemaConfig (..),
22-
AddressDetailConfig (..),
22+
AddressTypeConfig (..),
2323
SyncNodeConfig (..),
2424
SyncPreConfig (..),
2525
SyncInsertConfig (..),
@@ -68,7 +68,7 @@ import qualified Cardano.BM.Data.Configuration as Logging
6868
import qualified Cardano.Chain.Update as Byron
6969
import Cardano.Crypto (RequiresNetworkMagic (..))
7070
import qualified Cardano.Crypto.Hash as Crypto
71-
import Cardano.Db (MigrationDir, PGPassSource (..))
71+
import Cardano.Db (MigrationDir, PGPassSource (..), AddressType(..))
7272
import Cardano.Prelude
7373
import Cardano.Slotting.Slot (SlotNo (..))
7474
import Control.Monad (fail)
@@ -184,7 +184,7 @@ data SyncInsertOptions = SyncInsertOptions
184184
, sioPoolStats :: PoolStatsConfig
185185
, sioJsonType :: JsonTypeConfig
186186
, sioRemoveJsonbFromSchema :: RemoveJsonbFromSchemaConfig
187-
, sioAddressDetail :: AddressDetailConfig
187+
, sioAddress :: AddressTypeConfig
188188
}
189189
deriving (Eq, Show)
190190

@@ -259,8 +259,8 @@ newtype RemoveJsonbFromSchemaConfig = RemoveJsonbFromSchemaConfig
259259
}
260260
deriving (Eq, Show)
261261

262-
newtype AddressDetailConfig = AddressDetailConfig
263-
{ useAddressDetailTable :: Bool
262+
newtype AddressTypeConfig = AddressTypeConfig
263+
{ unAddressTypeConfig :: AddressType
264264
}
265265
deriving (Eq, Show)
266266

@@ -446,7 +446,7 @@ parseOverrides obj baseOptions = do
446446
<*> obj .:? "pool_stats" .!= sioPoolStats baseOptions
447447
<*> obj .:? "json_type" .!= sioJsonType baseOptions
448448
<*> obj .:? "remove_jsonb_from_schema" .!= sioRemoveJsonbFromSchema baseOptions
449-
<*> obj .:? "use_address_table" .!= sioAddressDetail baseOptions
449+
<*> obj .:? "use_address_table" .!= sioAddress baseOptions
450450

451451
instance ToJSON SyncInsertConfig where
452452
toJSON (SyncInsertConfig preset options) =
@@ -489,7 +489,7 @@ instance FromJSON SyncInsertOptions where
489489
<*> obj .:? "pool_stat" .!= sioPoolStats def
490490
<*> obj .:? "json_type" .!= sioJsonType def
491491
<*> obj .:? "remove_jsonb_from_schema" .!= sioRemoveJsonbFromSchema def
492-
<*> obj .:? "use_address_table" .!= sioAddressDetail def
492+
<*> obj .:? "use_address_table" .!= sioAddress def
493493

494494
instance ToJSON SyncInsertOptions where
495495
toJSON SyncInsertOptions {..} =
@@ -680,14 +680,14 @@ instance FromJSON RemoveJsonbFromSchemaConfig where
680680
instance ToJSON RemoveJsonbFromSchemaConfig where
681681
toJSON = boolToEnableDisable . isRemoveJsonbFromSchemaEnabled
682682

683-
instance FromJSON AddressDetailConfig where
683+
instance FromJSON AddressTypeConfig where
684684
parseJSON = Aeson.withText "use_address_table" $ \v ->
685-
case enableDisableToBool v of
686-
Just g -> pure (AddressDetailConfig g)
685+
case enableDisableToAddressType v of
686+
Just g -> pure (AddressTypeConfig g)
687687
Nothing -> fail $ "unexpected use_address_table: " <> show v
688688

689-
instance ToJSON AddressDetailConfig where
690-
toJSON = boolToEnableDisable . useAddressDetailTable
689+
instance ToJSON AddressTypeConfig where
690+
toJSON = addressTypeToEnableDisable . unAddressTypeConfig
691691

692692
instance FromJSON OffchainPoolDataConfig where
693693
parseJSON = Aeson.withText "offchain_pool_data" $ \v ->
@@ -726,7 +726,7 @@ instance Default SyncInsertOptions where
726726
, sioPoolStats = PoolStatsConfig False
727727
, sioJsonType = JsonTypeText
728728
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
729-
, sioAddressDetail = AddressDetailConfig False
729+
, sioAddress = AddressTypeConfig False
730730
}
731731

732732
fullInsertOptions :: SyncInsertOptions
@@ -745,7 +745,7 @@ fullInsertOptions =
745745
, sioPoolStats = PoolStatsConfig True
746746
, sioJsonType = JsonTypeText
747747
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
748-
, sioAddressDetail = AddressDetailConfig False
748+
, sioAddress = AddressTypeConfig False
749749
}
750750

751751
onlyUTxOInsertOptions :: SyncInsertOptions
@@ -764,7 +764,7 @@ onlyUTxOInsertOptions =
764764
, sioPoolStats = PoolStatsConfig False
765765
, sioJsonType = JsonTypeText
766766
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
767-
, sioAddressDetail = AddressDetailConfig False
767+
, sioAddress = AddressTypeConfig False
768768
}
769769

770770
onlyGovInsertOptions :: SyncInsertOptions
@@ -791,9 +791,19 @@ disableAllInsertOptions =
791791
, sioGovernance = GovernanceConfig False
792792
, sioJsonType = JsonTypeText
793793
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
794-
, sioAddressDetail = AddressDetailConfig False
794+
, sioAddress = AddressTypeConfig False
795795
}
796796

797+
addressTypeToEnableDisable :: IsString s => AddressType -> s
798+
addressTypeToEnableDisable AddressExtended = "enable"
799+
addressTypeToEnableDisable AddressBasic = "disable"
800+
801+
enableDisableToAddressType :: (Eq s, IsString s) => s -> Maybe AddressType
802+
enableDisableToAddressType = \case
803+
"enable" -> Just AddressExtended
804+
"disable" -> Just AddressBasic
805+
_ -> Nothing
806+
797807
boolToEnableDisable :: IsString s => Bool -> s
798808
boolToEnableDisable True = "enable"
799809
boolToEnableDisable False = "disable"

cardano-db-sync/src/Cardano/DbSync/Era/Byron/Genesis.hs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import qualified Cardano.Chain.UTxO as Byron
1818
import qualified Cardano.Crypto as Crypto
1919
import qualified Cardano.Db as DB
2020
import Cardano.DbSync.Api
21-
import Cardano.DbSync.Api.Types (SyncEnv (..), SyncOptions (..), ioAddressDetail)
21+
import Cardano.DbSync.Api.Types (SyncEnv (..), SyncOptions (..), ioAddress)
2222
import Cardano.DbSync.Config.Types
2323
import qualified Cardano.DbSync.Era.Byron.Util as Byron
2424
import Cardano.DbSync.Era.Util (liftLookupFail)
@@ -205,9 +205,9 @@ insertTxOuts syncEnv hasConsumed disInOut blkId (address, value) = do
205205
, DB.txTreasuryDonation = DB.DbLovelace 0
206206
}
207207
-- Insert the address detail config is active
208-
if ioAddressDetail . soptInsertOptions $ envOptions syncEnv
209-
then do
210-
addrDetailId <- insertAddressDetail
208+
case ioAddress . soptInsertOptions $ envOptions syncEnv of
209+
DB.AddressExtended -> do
210+
addrDetailId <- insertAddress
211211
DB.insertTxOutPlex hasConsumed disInOut $
212212
DB.TxOut
213213
{ DB.txOutTxId = txId
@@ -220,9 +220,9 @@ insertTxOuts syncEnv hasConsumed disInOut blkId (address, value) = do
220220
, DB.txOutDataHash = Nothing
221221
, DB.txOutInlineDatumId = Nothing
222222
, DB.txOutReferenceScriptId = Nothing
223-
, DB.txOutAddressDetailId = Just addrDetailId
223+
, DB.txOutAddressId = Just addrDetailId
224224
}
225-
else
225+
DB.AddressBasic ->
226226
DB.insertTxOutPlex hasConsumed disInOut $
227227
DB.TxOut
228228
{ DB.txOutTxId = txId
@@ -235,24 +235,24 @@ insertTxOuts syncEnv hasConsumed disInOut blkId (address, value) = do
235235
, DB.txOutDataHash = Nothing
236236
, DB.txOutInlineDatumId = Nothing
237237
, DB.txOutReferenceScriptId = Nothing
238-
, DB.txOutAddressDetailId = Nothing
238+
, DB.txOutAddressId = Nothing
239239
}
240240
where
241-
insertAddressDetail ::
241+
insertAddress ::
242242
(MonadBaseControl IO m, MonadIO m) =>
243-
ReaderT SqlBackend m DB.AddressDetailId
244-
insertAddressDetail = do
243+
ReaderT SqlBackend m DB.AddressId
244+
insertAddress = do
245245
let addrRaw = serialize' address
246-
mAddrId <- DB.queryAddressDetailId addrRaw
246+
mAddrId <- DB.queryAddressId addrRaw
247247
case mAddrId of
248248
Nothing ->
249-
DB.insertAddressDetail
250-
DB.AddressDetail
251-
{ DB.addressDetailAddress = Text.decodeUtf8 $ Byron.addrToBase58 address
252-
, DB.addressDetailAddressRaw = addrRaw
253-
, DB.addressDetailHasScript = False
254-
, DB.addressDetailPaymentCred = Nothing -- Byron does not have a payment credential.
255-
, DB.addressDetailStakeAddressId = Nothing -- Byron does not have a stake address.
249+
DB.insertAddress
250+
DB.Address
251+
{ DB.addressAddress = Text.decodeUtf8 $ Byron.addrToBase58 address
252+
, DB.addressRaw = addrRaw
253+
, DB.addressHasScript = False
254+
, DB.addressPaymentCred = Nothing -- Byron does not have a payment credential.
255+
, DB.addressStakeAddressId = Nothing -- Byron does not have a stake address.
256256
}
257257
-- this address is already in the database, so we can just return the id to be linked to the txOut.
258258
Just addrId -> pure addrId

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,10 @@ insertTxOut ::
343343
Byron.TxOut ->
344344
ReaderT SqlBackend m ()
345345
insertTxOut syncEnv hasConsumed bootStrap txId index txout =
346-
do
347-
-- check if we should use AddressDetail or not
348-
if ioAddressDetail . soptInsertOptions $ envOptions syncEnv
346+
case ioAddress . soptInsertOptions $ envOptions syncEnv of
347+
DB.AddressExtended -> do
349348
then do
350-
addrDetailId <- insertAddressDetail
349+
addrDetailId <- insertAddress
351350
DB.insertTxOutPlex hasConsumed bootStrap $
352351
DB.TxOut
353352
{ DB.txOutTxId = txId
@@ -360,9 +359,9 @@ insertTxOut syncEnv hasConsumed bootStrap txId index txout =
360359
, DB.txOutDataHash = Nothing
361360
, DB.txOutInlineDatumId = Nothing
362361
, DB.txOutReferenceScriptId = Nothing
363-
, DB.txOutAddressDetailId = Just addrDetailId
362+
, DB.txOutAddressId = Just addrDetailId
364363
}
365-
else
364+
DB.AddressBasic -> do
366365
DB.insertTxOutPlex hasConsumed bootStrap $
367366
DB.TxOut
368367
{ DB.txOutTxId = txId
@@ -375,24 +374,24 @@ insertTxOut syncEnv hasConsumed bootStrap txId index txout =
375374
, DB.txOutDataHash = Nothing
376375
, DB.txOutInlineDatumId = Nothing
377376
, DB.txOutReferenceScriptId = Nothing
378-
, DB.txOutAddressDetailId = Nothing
377+
, DB.txOutAddressId = Nothing
379378
}
380379
where
381-
insertAddressDetail ::
380+
insertAddress ::
382381
(MonadBaseControl IO m, MonadIO m) =>
383-
ReaderT SqlBackend m DB.AddressDetailId
384-
insertAddressDetail = do
382+
ReaderT SqlBackend m DB.AddressId
383+
insertAddress = do
385384
let addrRaw = serialize' (Byron.txOutAddress txout)
386-
mAddrId <- DB.queryAddressDetailId addrRaw
385+
mAddrId <- DB.queryAddressId addrRaw
387386
case mAddrId of
388387
Nothing ->
389-
DB.insertAddressDetail
390-
DB.AddressDetail
391-
{ DB.addressDetailAddress = Text.decodeUtf8 $ Byron.addrToBase58 (Byron.txOutAddress txout)
392-
, DB.addressDetailAddressRaw = addrRaw
393-
, DB.addressDetailHasScript = False
394-
, DB.addressDetailPaymentCred = Nothing -- Byron does not have a payment credential.
395-
, DB.addressDetailStakeAddressId = Nothing -- Byron does not have a stake address.
388+
DB.insertAddress
389+
DB.Address
390+
{ DB.addressAddress = Text.decodeUtf8 $ Byron.addrToBase58 (Byron.txOutAddress txout)
391+
, DB.addressRaw = addrRaw
392+
, DB.addressHasScript = False
393+
, DB.addressPaymentCred = Nothing -- Byron does not have a payment credential.
394+
, DB.addressStakeAddressId = Nothing -- Byron does not have a stake address.
396395
}
397396
-- this address is already in the database, so we can just return the id to be linked to the txOut.
398397
Just addrId -> pure addrId

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ insertTxOuts syncEnv trce hasConsumed disInOut blkId (TxIn txInId _, txOut) = do
249249

250250
tryUpdateCacheTx (envCache syncEnv) txInId txId
251251
_ <- insertStakeAddressRefIfMissing trce useNoCache (txOut ^. Core.addrTxOutL)
252-
-- TODO: use the `ioAddressDetail` field to insert the extended address.
253-
if ioAddressDetail . soptInsertOptions $ envOptions syncEnv
254-
then do
255-
addrDetailId <- insertAddressDetail
252+
-- TODO: use the `ioAddress` field to insert the extended address.
253+
case ioAddress . soptInsertOptions $ envOptions syncEnv of
254+
DB.AddressExtended -> do
255+
addrDetailId <- insertAddress
256256
DB.insertTxOutPlex hasConsumed disInOut $
257257
DB.TxOut
258258
{ DB.txOutTxId = txId
@@ -265,13 +265,13 @@ insertTxOuts syncEnv trce hasConsumed disInOut blkId (TxIn txInId _, txOut) = do
265265
, DB.txOutDataHash = Nothing -- No output datum in Shelley Genesis
266266
, DB.txOutInlineDatumId = Nothing
267267
, DB.txOutReferenceScriptId = Nothing
268-
, DB.txOutAddressDetailId = Just addrDetailId
268+
, DB.txOutAddressId = Just addrDetailId
269269
}
270-
else
270+
DB.AddressBasic ->
271271
DB.insertTxOutPlex hasConsumed disInOut $
272272
DB.TxOut
273273
{ DB.txOutAddress = Just $ Generic.renderAddress addr
274-
, DB.txOutAddressDetailId = Nothing
274+
, DB.txOutAddressId = Nothing
275275
, DB.txOutAddressHasScript = hasScript
276276
, DB.txOutDataHash = Nothing -- No output datum in Shelley Genesis
277277
, DB.txOutIndex = 0
@@ -286,21 +286,21 @@ insertTxOuts syncEnv trce hasConsumed disInOut blkId (TxIn txInId _, txOut) = do
286286
addr = txOut ^. Core.addrTxOutL
287287
hasScript = maybe False Generic.hasCredScript (Generic.getPaymentCred addr)
288288

289-
insertAddressDetail ::
289+
insertAddress ::
290290
(MonadBaseControl IO m, MonadIO m) =>
291-
ReaderT SqlBackend m DB.AddressDetailId
292-
insertAddressDetail = do
291+
ReaderT SqlBackend m DB.AddressId
292+
insertAddress = do
293293
let addrRaw = serialiseAddr addr
294-
mAddrId <- DB.queryAddressDetailId addrRaw
294+
mAddrId <- DB.queryAddressId addrRaw
295295
case mAddrId of
296296
Nothing ->
297-
DB.insertAddressDetail
298-
DB.AddressDetail
299-
{ DB.addressDetailAddress = Generic.renderAddress addr
300-
, DB.addressDetailAddressRaw = addrRaw
301-
, DB.addressDetailHasScript = hasScript
302-
, DB.addressDetailPaymentCred = Generic.maybePaymentCred addr
303-
, DB.addressDetailStakeAddressId = Nothing -- No stake addresses in Shelley Genesis
297+
DB.insertAddress
298+
DB.Address
299+
{ DB.addressAddress = Generic.renderAddress addr
300+
, DB.addressRaw = addrRaw
301+
, DB.addressHasScript = hasScript
302+
, DB.addressPaymentCred = Generic.maybePaymentCred addr
303+
, DB.addressStakeAddressId = Nothing -- No stake addresses in Shelley Genesis
304304
}
305305
-- this address is already in the database, so we can just return the id to be linked to the txOut.
306306
Just addrId -> pure addrId

0 commit comments

Comments
 (0)