Skip to content

Commit

Permalink
ChangeToJSONKey Voter instance to flat text representation
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Sep 1, 2023
1 parent 4a5566f commit 9e2f815
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.8.0.0

* Change `ToJSONKey` implementation of `Voter` to flat text
* Add DRep refund calculation #3688
* Add `conwayConsumedValue` as `getConsumedValue` for Conway
* Change `PredicateFailure (ConwayENACT era)` to `Void`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import Cardano.Ledger.Binary.Coders (
)
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Core (Era (..), EraPParams (..), PParamsUpdate)
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Credential (Credential (..), credToText)
import Cardano.Ledger.Crypto (Crypto)
import Cardano.Ledger.Keys (KeyHash, KeyRole (..))
import Cardano.Ledger.SafeHash (extractHash)
Expand All @@ -81,7 +81,13 @@ import Cardano.Ledger.TxIn (TxId (..))
import Cardano.Slotting.Slot (EpochNo)
import Control.DeepSeq (NFData (..))
import Control.Monad (when)
import Data.Aeson (KeyValue (..), ToJSON (..), ToJSONKey (..), object, pairs)
import Data.Aeson (
KeyValue (..),
ToJSON (..),
ToJSONKey (..),
object,
pairs,
)
import Data.Aeson.Types (toJSONKeyText)
import Data.Map.Strict (Map)
import Data.Maybe.Strict (StrictMaybe (..))
Expand Down Expand Up @@ -162,9 +168,14 @@ data Voter c

instance Crypto c => ToJSON (Voter c)

-- TODO: Make it nicer, eg. "DRep-ScriptHash<0xdeadbeef>..."
-- Will also need a ToJSONKey instance for Credential.
instance Crypto c => ToJSONKey (Voter c)
instance Crypto c => ToJSONKey (Voter c) where
toJSONKey = toJSONKeyText $ \case
CommitteeVoter cred ->
"committee-" <> credToText cred
DRepVoter cred ->
"drep-" <> credToText cred
StakePoolVoter kh ->
"stakepool-" <> credToText (KeyHashObj kh)

instance Crypto c => DecCBOR (Voter c) where
decCBOR = decodeRecordSum "Voter" $ \case
Expand Down

0 comments on commit 9e2f815

Please sign in to comment.