|
1 | 1 | {-# LANGUAGE ConstraintKinds #-} |
2 | 2 | {-# LANGUAGE DeriveGeneric #-} |
3 | 3 | {-# LANGUAGE DuplicateRecordFields #-} |
| 4 | +{-# LANGUAGE FlexibleInstances #-} |
4 | 5 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} |
| 6 | +{-# LANGUAGE MultiParamTypeClasses #-} |
5 | 7 | {-# LANGUAGE OverloadedStrings #-} |
6 | 8 | {-# LANGUAGE TemplateHaskell #-} |
| 9 | +{-# LANGUAGE TypeFamilies #-} |
7 | 10 | {-# LANGUAGE ViewPatterns #-} |
8 | 11 | {-# OPTIONS_GHC -Wall #-} |
9 | 12 | module Cardano.Faucet.Types ( |
10 | | - FaucetConfig(..), mkFaucetConfig, testFC |
| 13 | + FaucetConfig(..), mkFaucetConfig |
11 | 14 | , HasFaucetConfig(..) |
12 | 15 | , FaucetEnv(..), initEnv |
13 | 16 | , HasFaucetEnv(..) |
@@ -46,12 +49,11 @@ import System.Metrics.Counter (Counter) |
46 | 49 | import qualified System.Metrics.Counter as Counter |
47 | 50 | import System.Metrics.Gauge (Gauge) |
48 | 51 | import qualified System.Metrics.Gauge as Gauge |
49 | | -import System.Remote.Monitoring.Statsd (StatsdOptions, defaultStatsdOptions) |
| 52 | +import System.Remote.Monitoring.Statsd (StatsdOptions (..)) |
50 | 53 | import System.Wlog (CanLog, HasLoggerName, LoggerName (..), LoggerNameBox (..), |
51 | 54 | WithLogger, launchFromFile) |
52 | 55 |
|
53 | | -import Cardano.Wallet.API.V1.Types (PaymentSource (..), Transaction, |
54 | | - V1, WalletId (..)) |
| 56 | +import Cardano.Wallet.API.V1.Types (PaymentSource (..), Transaction, V1) |
55 | 57 | import Cardano.Wallet.Client (ClientError (..), WalletClient) |
56 | 58 | import Cardano.Wallet.Client.Http (mkHttpClient) |
57 | 59 | import Pos.Core (Address (..), Coin (..)) |
@@ -104,34 +106,58 @@ data DepositResult = DepositResult |
104 | 106 |
|
105 | 107 | instance ToJSON DepositResult |
106 | 108 |
|
| 109 | +-------------------------------------------------------------------------------- |
| 110 | +newtype FaucetStatsdOpts = FaucetStatsdOpts StatsdOptions deriving (Generic) |
| 111 | + |
| 112 | +makeWrapped ''FaucetStatsdOpts |
107 | 113 | -------------------------------------------------------------------------------- |
108 | 114 | data FaucetConfig = FaucetConfig { |
109 | 115 | _fcWalletApiHost :: String |
110 | 116 | , _fcWalletApiPort :: Int |
111 | 117 | , _fcFaucetPaymentSource :: PaymentSource |
112 | | - , _fcStatsdOpts :: StatsdOptions |
| 118 | + , _fcSpendingPassword :: Text |
| 119 | + , _fcStatsdOpts :: FaucetStatsdOpts |
113 | 120 | , _fcLoggerConfigFile :: FilePath |
114 | 121 | , _fcPubCertFile :: FilePath |
115 | 122 | , _fcPrivKeyFile :: FilePath |
116 | 123 | } |
117 | 124 |
|
118 | 125 | makeClassy ''FaucetConfig |
119 | 126 |
|
| 127 | +instance FromJSON FaucetStatsdOpts where |
| 128 | + parseJSON = fmap FaucetStatsdOpts . (withObject "StatsdOptions" $ \v -> |
| 129 | + StatsdOptions |
| 130 | + <$> v .: "host" |
| 131 | + <*> v .: "port" |
| 132 | + <*> v .: "flush-interval" |
| 133 | + <*> pure False |
| 134 | + <*> pure "faucet" |
| 135 | + <*> pure "") |
| 136 | + |
| 137 | +instance FromJSON FaucetConfig where |
| 138 | + parseJSON = withObject "FaucetConfig" $ \v -> |
| 139 | + FaucetConfig |
| 140 | + <$> v .: "wallet-host" |
| 141 | + <*> v .: "wallet-port" |
| 142 | + <*> v .: "payment-source" |
| 143 | + <*> v .: "spending-password" |
| 144 | + <*> v .: "statsd" |
| 145 | + <*> v .: "logging-config" |
| 146 | + <*> v .: "public-certificate" |
| 147 | + <*> v .: "private-key" |
| 148 | + |
120 | 149 | mkFaucetConfig |
121 | 150 | :: String |
122 | 151 | -> Int |
123 | 152 | -> PaymentSource |
124 | | - -> StatsdOptions |
| 153 | + -> Text |
| 154 | + -> FaucetStatsdOpts |
125 | 155 | -> FilePath |
126 | 156 | -> FilePath |
127 | 157 | -> FilePath |
128 | 158 | -> FaucetConfig |
129 | 159 | mkFaucetConfig = FaucetConfig |
130 | 160 |
|
131 | | -testFC :: FaucetConfig |
132 | | -testFC = FaucetConfig "127.0.0.1" 8090 ps defaultStatsdOptions "./logging.cfg" "./tls/ca.crt" "./tls/server.key" |
133 | | - where |
134 | | - ps = PaymentSource (WalletId "Ae2tdPwUPEZLBG2sEmiv8Y6DqD4LoZKQ5wosXucbLnYoacg2YZSPhMn4ETi") 2147483648 |
135 | 161 |
|
136 | 162 | -------------------------------------------------------------------------------- |
137 | 163 | data FaucetEnv = FaucetEnv { |
|
0 commit comments