-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DeployM * move to types * main compiles * fix console log * tests pass
- Loading branch information
Showing
8 changed files
with
308 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
module Main where | ||
|
||
import Prelude | ||
import Control.Monad.Aff (launchAff, liftEff') | ||
import Control.Monad.Aff (launchAff) | ||
import Control.Monad.Eff (Eff) | ||
import Control.Monad.Eff.Console (CONSOLE) | ||
import Control.Monad.Except (runExceptT) | ||
import Data.Either (Either(..)) | ||
import Data.Lens ((?~)) | ||
import Data.Maybe (fromJust) | ||
import Network.Ethereum.Web3 (ETH, defaultTransactionOptions, _from, _gas) | ||
import Network.Ethereum.Web3.Types.BigNumber (parseBigNumber, decimal) | ||
import Node.FS.Aff (FS) | ||
import Node.Process (PROCESS) | ||
import Partial.Unsafe (unsafePartial) | ||
|
||
import Control.Monad.Reader.Class (ask) | ||
import Contracts.SimpleStorage as SimpleStorage | ||
import Contracts.ParkingAuthority as ParkingAuthority | ||
|
||
import Deploy (deployContractWithArgs, deployContractNoArgs) | ||
import Utils (makeDeployConfig, validateDeployArgs) | ||
import ContractConfig (simpleStorageConfig, foamCSRConfig, makeParkingAuthorityConfig) | ||
import Types (DeployConfig(..), runDeployM, logDeployError) | ||
|
||
|
||
-- | TODO: This passing of config indicates a ReaderMonad | ||
main :: forall e. Eff (eth :: ETH, console :: CONSOLE, fs :: FS | e) Unit | ||
main :: forall e. Eff (console :: CONSOLE, eth :: ETH, fs :: FS, process :: PROCESS | e) Unit | ||
main = void <<< launchAff $ do | ||
deployCfg <- makeDeployConfig | ||
let bigGasLimit = unsafePartial fromJust $ parseBigNumber decimal "9000000" | ||
txOpts = defaultTransactionOptions # _from ?~ deployCfg.primaryAccount | ||
# _gas ?~ bigGasLimit | ||
ssConfig <- liftEff' $ validateDeployArgs simpleStorageConfig | ||
_ <- deployContractWithArgs deployCfg ssConfig $ SimpleStorage.constructor txOpts | ||
foamCSR <- deployContractNoArgs deployCfg foamCSRConfig txOpts | ||
let parkingAuthorityConfig = makeParkingAuthorityConfig {foamCSR} | ||
_ <- deployContractWithArgs deployCfg parkingAuthorityConfig $ ParkingAuthority.constructor txOpts | ||
pure unit | ||
edeployConfig <- runExceptT $ makeDeployConfig | ||
case edeployConfig of | ||
Left err -> logDeployError err *> pure unit | ||
Right deployConfig -> do | ||
eRes <- flip runDeployM deployConfig $ do | ||
deployCfg@(DeployConfig {primaryAccount}) <- ask | ||
let bigGasLimit = unsafePartial fromJust $ parseBigNumber decimal "9000000" | ||
txOpts = defaultTransactionOptions # _from ?~ primaryAccount | ||
# _gas ?~ bigGasLimit | ||
ssConfig <- validateDeployArgs simpleStorageConfig | ||
_ <- deployContractWithArgs ssConfig $ SimpleStorage.constructor txOpts | ||
foamCSR <- deployContractNoArgs foamCSRConfig txOpts | ||
let parkingAuthorityConfig = makeParkingAuthorityConfig {foamCSR} | ||
_ <- deployContractWithArgs parkingAuthorityConfig $ ParkingAuthority.constructor txOpts | ||
pure unit | ||
case eRes of | ||
Left err -> logDeployError err | ||
Right _ -> pure unit |
Oops, something went wrong.