Skip to content

Commit

Permalink
WIP: Update "build-script" to use withCardanoEra
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 authored and dcoutts committed Nov 26, 2020
1 parent 7b08b68 commit cb23382
Showing 1 changed file with 60 additions and 12 deletions.
72 changes: 60 additions & 12 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

Expand All @@ -8,7 +10,7 @@ module Cardano.CLI.Shelley.Run.Address
) where

import Cardano.Prelude hiding (putStrLn)
import Prelude (String)
--import Prelude (String)

import Data.Aeson
import qualified Data.ByteString.Char8 as BS
Expand Down Expand Up @@ -67,8 +69,8 @@ runAddressKeyGen :: AddressKeyType
runAddressKeyGen kt (VerificationKeyFile vkeyPath) (SigningKeyFile skeyPath) =
case kt of
AddressKeyShelley -> generateAndWriteKeyFiles AsPaymentKey
AddressKeyShelleyExtended -> generateAndWriteKeyFiles AsPaymentExtendedKey
AddressKeyByron -> generateAndWriteKeyFiles AsByronKey
AddressKeyShelleyExtended -> generateAndWriteKeyFiles (panic "what is happening here?")--AsPaymentExtendedKey
AddressKeyByron -> generateAndWriteKeyFiles (panic "what is happening here?")--AsByronKey
where
generateAndWriteKeyFiles asType = do
skey <- liftIO $ generateSigningKey asType
Expand Down Expand Up @@ -207,14 +209,60 @@ runAddressBuildScript
-> NetworkId
-> Maybe OutputFile
-> ExceptT ShelleyAddressCmdError IO ()
runAddressBuildScript _useEra (ScriptFile fp) nId mOutFp = do
runAddressBuildScript useEra sF nId mOutFp =
withCardanoEra useEra $ \era -> do
script <- readScript' era sF
case era of
ByronEra -> panic "feature mismatch"
ShelleyEra -> do
let payCred = PaymentCredentialByScript . scriptHash $ SimpleScript script
scriptAddr = serialiseAddress $ makeShelleyAddress nId payCred NoStakeAddress

writeScript = case mOutFp of
Just (OutputFile oFp) -> liftIO $ Text.writeFile oFp scriptAddr
Nothing -> liftIO $ Text.putStr scriptAddr
writeScript
AllegraEra -> do
let payCred = PaymentCredentialByScript . scriptHash $ SimpleScript script
scriptAddr = serialiseAddress $ makeShelleyAddress nId payCred NoStakeAddress

writeScript = case mOutFp of
Just (OutputFile oFp) -> liftIO $ Text.writeFile oFp scriptAddr
Nothing -> liftIO $ Text.putStr scriptAddr
writeScript

MaryEra -> do
let payCred = PaymentCredentialByScript . scriptHash $ SimpleScript script
scriptAddr = serialiseAddress $ makeShelleyAddress nId payCred NoStakeAddress

writeScript = case mOutFp of
Just (OutputFile oFp) -> liftIO $ Text.writeFile oFp scriptAddr
Nothing -> liftIO $ Text.putStr scriptAddr
writeScript

readScript'
:: CardanoEra era
-> ScriptFile
-> ExceptT ShelleyAddressCmdError IO (SimpleScript era)
readScript' cEra (ScriptFile fp) = do
scriptLB <- handleIOExceptT (ShelleyAddressCmdReadFileException . FileIOError fp)
$ LB.readFile fp
script <- case eitherDecode scriptLB :: Either String (MultiSigScript ShelleyEra) of
Right mss -> return $ makeMultiSigScript mss
Left err -> left . ShelleyAddressCmdAesonDecodeError fp $ Text.pack err
let payCred = PaymentCredentialByScript $ scriptHash script
scriptAddr = serialiseAddress $ makeShelleyAddress nId payCred NoStakeAddress
case mOutFp of
Just (OutputFile oFp) -> liftIO $ Text.writeFile oFp scriptAddr
Nothing -> liftIO $ Text.putStr scriptAddr
case cEra of
ByronEra -> panic "feature mismatch"
ShelleyEra ->
case eitherDecode scriptLB of
Right simpleScript -> return simpleScript
Left err -> left . ShelleyAddressCmdAesonDecodeError fp $ Text.pack err

AllegraEra ->
case eitherDecode scriptLB of
Right simpleScript -> return simpleScript
Left err -> left . ShelleyAddressCmdAesonDecodeError fp $ Text.pack err
MaryEra ->
case eitherDecode scriptLB of
Right simpleScript -> return simpleScript
Left err -> left . ShelleyAddressCmdAesonDecodeError fp $ Text.pack err




0 comments on commit cb23382

Please sign in to comment.