-
Notifications
You must be signed in to change notification settings - Fork 112
CBOR-1: Switch to cbor format in DB #2767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ library | |
| , aeson | ||
| , base | ||
| , bytestring | ||
| , cardano-binary | ||
| , containers | ||
| , hydra-node | ||
| , hydra-prelude | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| {-# OPTIONS_GHC -Wno-orphans #-} | ||
|
|
||
| module Hydra.Cardano.Api.AddressInEra where | ||
|
|
||
| import Hydra.Cardano.Api.Prelude | ||
|
|
||
| import Cardano.Api qualified as Api | ||
| import Cardano.Ledger.Address qualified as Ledger | ||
| import Cardano.Ledger.BaseTypes qualified as Ledger | ||
| import Cardano.Ledger.Credential qualified as Ledger | ||
|
|
@@ -14,6 +17,32 @@ import PlutusLedgerApi.V3 ( | |
| ) | ||
| import PlutusLedgerApi.V3 qualified as Plutus | ||
|
|
||
| -- * Orphans | ||
|
|
||
| -- missing CBOR instances | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of interest is there a reason these instances should be missing? is there some reason upstream declined to provide them? could we open a PR for it somewhere? |
||
|
|
||
| -- NOTE: Encoded as the bech32/base58 address text, consistent with the JSON | ||
| -- representation. | ||
| instance (IsShelleyBasedEra era, Typeable era) => ToCBOR (AddressInEra era) where | ||
| toCBOR = toCBOR . serialiseAddress | ||
|
|
||
| instance (IsShelleyBasedEra era, Typeable era) => FromCBOR (AddressInEra era) where | ||
| fromCBOR = do | ||
| t <- fromCBOR | ||
| case deserialiseAddress (proxyToAsType $ Proxy @(AddressInEra era)) t of | ||
| Nothing -> fail $ "failed to deserialise AddressInEra from " <> show (t :: Text) | ||
| Just addr -> pure addr | ||
|
|
||
| instance ToCBOR (Api.Address ByronAddr) where | ||
| toCBOR = toCBOR . serialiseToRawBytes | ||
|
|
||
| instance FromCBOR (Api.Address ByronAddr) where | ||
| fromCBOR = do | ||
| bs <- fromCBOR | ||
| case deserialiseFromRawBytes (proxyToAsType $ Proxy @(Api.Address ByronAddr)) bs of | ||
| Left err -> fail (show err) | ||
| Right v -> pure v | ||
|
|
||
| -- * Extras | ||
|
|
||
| -- | Construct a Shelley-style address from a verification key. This address has | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,26 @@ getChainPoint header = | |
| ChainPoint slotNo headerHash | ||
| where | ||
| (BlockHeader slotNo headerHash _) = header | ||
|
|
||
| -- * Orphans | ||
|
|
||
| -- missing CBOR instances | ||
|
|
||
| instance ToCBOR ChainPoint where | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can be generic now? |
||
| toCBOR = \case | ||
| ChainPointAtGenesis -> | ||
| toCBOR ("ChainPointAtGenesis" :: Text) | ||
| ChainPoint slotNo headerHash -> | ||
| toCBOR ("ChainPoint" :: Text) <> toCBOR slotNo <> toCBOR (serialiseToRawBytes headerHash) | ||
|
|
||
| instance FromCBOR ChainPoint where | ||
| fromCBOR = | ||
| fromCBOR >>= \case | ||
| ("ChainPointAtGenesis" :: Text) -> pure ChainPointAtGenesis | ||
| "ChainPoint" -> do | ||
| slotNo <- fromCBOR | ||
| bytes <- fromCBOR | ||
| case deserialiseFromRawBytes (proxyToAsType $ Proxy @(Hash BlockHeader)) bytes of | ||
| Left err -> fail (show err) | ||
| Right headerHash -> pure $ ChainPoint slotNo headerHash | ||
| tag -> fail $ show (tag :: Text) <> " is not a proper CBOR-encoded ChainPoint" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,17 @@ instance FromJSON NetworkId where | |
| "Mainnet" -> pure Mainnet | ||
| "Testnet" -> Testnet <$> o .: "magic" | ||
| _ -> fail "Expected tag to be Mainnet | Testnet" | ||
|
|
||
| -- missing CBOR instances | ||
|
|
||
| instance ToCBOR NetworkId where | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And these? |
||
| toCBOR = \case | ||
| Mainnet -> toCBOR ("Mainnet" :: Text) | ||
| Testnet (NetworkMagic magic) -> toCBOR ("Testnet" :: Text) <> toCBOR magic | ||
|
|
||
| instance FromCBOR NetworkId where | ||
| fromCBOR = | ||
| fromCBOR >>= \case | ||
| ("Mainnet" :: Text) -> pure Mainnet | ||
| "Testnet" -> Testnet . NetworkMagic <$> fromCBOR | ||
| tag -> fail $ show tag <> " is not a proper CBOR-encoded NetworkId" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,27 @@ instance ToJSON PolicyAssets where | |
|
|
||
| instance FromJSON PolicyAssets where | ||
| parseJSON v = PolicyAssets <$> parseJSON v | ||
|
|
||
| -- missing CBOR instances | ||
|
|
||
| instance ToCBOR AssetName where | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| toCBOR = toCBOR . serialiseToRawBytes | ||
|
|
||
| instance FromCBOR AssetName where | ||
| fromCBOR = do | ||
| bs <- fromCBOR | ||
| case deserialiseFromRawBytes AsAssetName bs of | ||
| Left err -> fail (show err) | ||
| Right v -> pure v | ||
|
|
||
| instance ToCBOR Quantity where | ||
| toCBOR (Quantity q) = toCBOR q | ||
|
|
||
| instance FromCBOR Quantity where | ||
| fromCBOR = Quantity <$> fromCBOR | ||
|
|
||
| instance ToCBOR PolicyAssets where | ||
| toCBOR (PolicyAssets assets) = toCBOR assets | ||
|
|
||
| instance FromCBOR PolicyAssets where | ||
| fromCBOR = PolicyAssets <$> fromCBOR | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,20 @@ import Cardano.Ledger.Mary.Value qualified as Ledger | |
| import Hydra.Cardano.Api.ScriptHash () | ||
| import PlutusLedgerApi.V3 (CurrencySymbol, fromBuiltin, unCurrencySymbol) | ||
|
|
||
| -- * Orphans | ||
|
|
||
| -- missing CBOR instances | ||
|
|
||
| instance ToCBOR PolicyId where | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| toCBOR = toCBOR . serialiseToRawBytes | ||
|
|
||
| instance FromCBOR PolicyId where | ||
| fromCBOR = do | ||
| bs <- fromCBOR | ||
| case deserialiseFromRawBytes AsPolicyId bs of | ||
| Left err -> fail (show err) | ||
| Right v -> pure v | ||
|
|
||
| -- * Type conversions | ||
|
|
||
| -- | Convert Cardano api 'PolicyId' to Cardano ledger `PolicyID`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ŸhInactivefActivegExpiredÿ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ŸnAutoFanningOutwAwaitingFanoutSelectionÿ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ŸdIdledOpenfClosednFanoutPossiblejFanningOutÿ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ŸlInvalidInputdKnWokQô€¸Œð¤£Ÿ=vÿ |
|
v0d1ch marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ŸfInSyncjCatchingUpÿ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ŸlEmbeddedEtcdjSystemEtcdÿ |
Uh oh!
There was an error while loading. Please reload this page.