Skip to content

Commit

Permalink
add DefineDRepKey Action
Browse files Browse the repository at this point in the history
  • Loading branch information
NadiaYvette authored and mgmeier committed Nov 26, 2024
1 parent 4e8f32a commit a29d6a9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
5 changes: 3 additions & 2 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import qualified Data.Text as Text (unpack)
-- the cases' fields to functions with very similar names to the
-- constructors.
action :: Action -> ActionM ()
action a = case a of
action = \case
SetNetworkId val -> setEnvNetworkId val
SetSocketPath val -> setEnvSocketPath val
InitWallet name -> initWallet name
Expand All @@ -44,8 +44,9 @@ action a = case a of
ReadSigningKey name filePath -> readSigningKey name filePath
ReadDRepKeys filepath -> readDRepKeys filepath
ReadStakeKeys filepath -> readStakeCredentials filepath
DefineDRepKey drepKey -> defineDRepCredential drepKey
DefineSigningKey name descr -> defineSigningKey name descr
DefineStakeKey k -> defineStakeCrendential k
DefineStakeKey k -> defineStakeCredential k
AddFund era wallet txIn lovelace keyName -> addFund era wallet txIn lovelace keyName
Delay t -> delay t
Submit era submitMode txParams generator -> submitAction era submitMode generator txParams
Expand Down
20 changes: 20 additions & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ instance FromJSON (SigningKey PaymentKey) where
Right k -> pure k
Left err -> fail $ show err

-- FIXME: workaround instance
instance ToJSON (SigningKey DRepKey) where
toJSON = toJSON . serialiseToTextEnvelope Nothing
instance FromJSON (SigningKey DRepKey) where
parseJSON o = do
te <- parseJSON o
case deserialiseFromTextEnvelope (AsSigningKey AsDRepKey) te of
Right k -> pure k
Left err -> fail $ show err

-- FIXME: workaround instance
instance ToJSON (VerificationKey DRepKey) where
toJSON = toJSON . serialiseToTextEnvelope Nothing
instance FromJSON (VerificationKey DRepKey) where
parseJSON o = do
te <- parseJSON o
case deserialiseFromTextEnvelope (AsVerificationKey AsDRepKey) te of
Right k -> pure k
Left err -> fail $ show err

-- FIXME: workaround instance
instance ToJSON (VerificationKey StakeKey) where
toJSON = toJSON . serialiseToTextEnvelope Nothing
Expand Down
7 changes: 5 additions & 2 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ readSigningKey name filePath =
defineSigningKey :: String -> SigningKey PaymentKey -> ActionM ()
defineSigningKey = setEnvKeys

defineStakeCrendential :: VerificationKey StakeKey -> ActionM ()
defineStakeCrendential = setEnvStakeCredentials . (: []) . StakeCredentialByKey . verificationKeyHash
defineDRepCredential :: SigningKey DRepKey -> ActionM ()
defineDRepCredential = setEnvDRepKeys . (: [])

defineStakeCredential :: VerificationKey StakeKey -> ActionM ()
defineStakeCredential = setEnvStakeCredentials . (: []) . StakeCredentialByKey . verificationKeyHash

readDRepKeys :: FilePath -> ActionM ()
readDRepKeys ncFile = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ testScriptVoting protocolFile submitMode =

, DefineStakeKey stakeKey

-- TODO: manually inject an (unnamed) DRep key into the Env by means of a new Action constructor
-- DefineDRepKey _drepKey
-- manually inject an (unnamed) DRep key into the Env by means of an Action constructor
, DefineDRepKey drepKey

, Submit era submitMode txParams
EmptyStream
Expand All @@ -150,8 +150,8 @@ testScriptVoting protocolFile submitMode =
, teRawCBOR = "X \vl1~\182\201v(\152\250A\202\157h0\ETX\248h\153\171\SI/m\186\242D\228\NAK\182(&\162"
}

_drepKey :: SigningKey DRepKey
_drepKey = fromRight (error "could not parse hardcoded drep key") $
drepKey :: SigningKey DRepKey
drepKey = error "could not parse hardcoded drep key" `fromRight`
parseDRepKeyBase16 "5820aa7f780a2dcd099762ebc31a43860c1373970c2e2062fcd02cceefe682f39ed8"

stakeKey :: VerificationKey StakeKey
Expand Down
4 changes: 4 additions & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ data Action where
ReadStakeKeys :: !FilePath -> Action
-- | 'DefineSigningKey' is just a 'Map.insert' on the state variable.
DefineSigningKey :: !String -> !(SigningKey PaymentKey) -> Action
-- | inject a singleton DRepCredential into the environment
DefineDRepKey :: !(SigningKey DRepKey) -> Action
-- | inject a singleton StakeCredential into the environment
DefineStakeKey :: !(VerificationKey StakeKey) -> Action
-- | 'AddFund' is mostly a wrapper around
Expand Down Expand Up @@ -131,6 +133,8 @@ data Action where
deriving (Show, Eq)
deriving instance Generic Action

deriving instance Eq (SigningKey DRepKey)

-- | 'Generator' is interpreted by
-- 'Cardano.Bencmarking.Script.Core.evalGenerator' as a series of
-- transactions, albeit in the form of precursors to UTxO's.
Expand Down

0 comments on commit a29d6a9

Please sign in to comment.