Skip to content

Commit

Permalink
SomeWitness refactor WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Nov 25, 2020
1 parent d67d879 commit cb66e64
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ readProtocolParameters (ProtocolParamsFile fpath) = do
firstExceptT (ShelleyTxCmdAesonDecodeProtocolParamsError fpath . Text.pack) . hoistEither $
Aeson.eitherDecode' pparams

data Witnessess era where
ByronWitnesses :: [Witness ByronEra] -> Witnessess ByronEra
ShelleyBasedWitnesses :: ShelleyBasedEra era -> Witness era -> Witnessess era

data SomeWitness
= AByronSigningKey (Api.SigningKey Api.ByronKey) (Maybe (Address ByronAddr))
| APaymentSigningKey (Api.SigningKey Api.PaymentKey)
Expand Down Expand Up @@ -372,6 +376,28 @@ renderReadWitnessSigningDataError err =
ReadWitnessSigningDataNoByronScripts fp ->
"Scripts do not exist in the Byron era: " <> Text.pack fp


readWitnessSigningData'
:: UseCardanoEra
-> WitnessSigningData
-> ExceptT ReadWitnessSigningDataError IO (Witnessess era)
readWitnessSigningData' useEra (ScriptWitnessSigningData (ScriptFile fp)) = do
msJson <- handleIOExceptT (ReadWitnessSigningDataScriptError . FileIOError fp)
$ LBS.readFile fp
withCardanoEra useEra $ \_era _eraStyle ->
case useEra of
UseByronEra -> left $ ReadWitnessSigningDataNoByronScripts fp
UseShelleyEra -> do w <- firstExceptT (ReadWitnessSigningDataScriptError . FileError fp . ScriptJsonDecodeError) (hoistEither $ decodeScript msJson)
return $ ShelleyBasedWitnesses ShelleyBasedEraShelley $ Api.makeScriptWitness $ SimpleScript w
UseAllegraEra -> panic ""
UseMaryEra -> panic ""
where
decodeScript :: HasScriptFeatures era => LBS.ByteString -> Either String (SimpleScript era)
decodeScript bs = Aeson.eitherDecode bs

readWitnessSigningData' _ _ = panic "placeholder"


readWitnessSigningData
:: UseCardanoEra
-> WitnessSigningData
Expand Down

0 comments on commit cb66e64

Please sign in to comment.