@@ -51,6 +51,7 @@ import qualified Data.ByteString.Lazy as BL
51
51
import qualified Data.ByteString.Short as BS
52
52
import Data.Hashable
53
53
import qualified Data.HashMap.Strict as HM
54
+ import Data.Maybe
54
55
import Data.Streaming.Network
55
56
import qualified Data.Text as T
56
57
import qualified Data.Text.Encoding as T
@@ -179,13 +180,17 @@ instance FromJSON MinerPublicKey where
179
180
{-# INLINE parseJSON #-}
180
181
-- TODO perform well-formedness checks
181
182
182
- newtype Miner = Miner MinerPublicKey
183
+ newtype MinerAccount = MinerAccount T. Text
183
184
deriving (Show , Eq , Ord , Generic )
184
- deriving newtype (Hashable )
185
+ deriving newtype (Hashable , ToJSON , FromJSON )
186
+
187
+ data Miner = Miner MinerPublicKey (Maybe MinerAccount )
188
+ deriving (Show , Eq , Ord , Generic )
189
+ deriving anyclass (Hashable )
185
190
186
191
instance ToJSON Miner where
187
- toJSON (Miner (MinerPublicKey k)) = object
188
- [ " account" .= k
192
+ toJSON (Miner (MinerPublicKey k) account ) = object
193
+ [ " account" .= fromMaybe ( MinerAccount ( " k: " <> k)) account
189
194
, " public-keys" .= [ k ]
190
195
, " predicate" .= (" keys-all" :: T. Text )
191
196
]
@@ -237,6 +242,7 @@ data Config = Config
237
242
, _configUseTls :: ! Bool
238
243
, _configInsecure :: ! Bool
239
244
, _configPublicKey :: ! MinerPublicKey
245
+ , _configAccount :: ! (Maybe MinerAccount )
240
246
, _configThreadCount :: ! Natural
241
247
, _configGenerateKey :: ! Bool
242
248
, _configLogLevel :: ! LogLevel
@@ -257,6 +263,7 @@ defaultConfig = Config
257
263
, _configUseTls = True
258
264
, _configInsecure = True
259
265
, _configPublicKey = MinerPublicKey " "
266
+ , _configAccount = Nothing
260
267
, _configThreadCount = 10
261
268
, _configGenerateKey = False
262
269
, _configLogLevel = Info
@@ -274,6 +281,7 @@ instance ToJSON Config where
274
281
, " useTls" .= _configUseTls c
275
282
, " insecure" .= _configInsecure c
276
283
, " publicKey" .= _configPublicKey c
284
+ , " account" .= _configAccount c
277
285
, " threadCount" .= _configThreadCount c
278
286
, " generateKey" .= _configGenerateKey c
279
287
, " logLevel" .= logLevelToText @ T. Text (_configLogLevel c)
@@ -291,6 +299,7 @@ instance FromJSON (Config -> Config) where
291
299
<*< configUseTls ..: " useTls" % o
292
300
<*< configInsecure ..: " insecure" % o
293
301
<*< configPublicKey ..: " publicKey" % o
302
+ <*< configAccount ..: " account" % o
294
303
<*< configThreadCount ..: " threadCount" % o
295
304
<*< configGenerateKey ..: " generateKey" % o
296
305
<*< setProperty configLogLevel " logLevel" parseLogLevel o
@@ -324,7 +333,11 @@ parseConfig = id
324
333
<*< configPublicKey .:: fmap MinerPublicKey . strOption
325
334
% short ' k'
326
335
<> long " public-key"
327
- <> help " the public-key for the mining rewards account"
336
+ <> help " public-key for the mining rewards account"
337
+ <*< configAccount .:: fmap (Just . MinerAccount ) . strOption
338
+ % short ' a'
339
+ <> long " account"
340
+ <> help " account for the mining rewards (default: public-key prefixed with 'k:')"
328
341
<*< configThreadCount .:: option auto
329
342
% short ' c'
330
343
<> long " thread-count"
@@ -494,7 +507,11 @@ getJob conf ver mgr = do
494
507
Right (a,b,c) -> return (a, b, c)
495
508
where
496
509
req = (baseReq conf ver " mining/work" )
497
- { HTTP. requestBody = HTTP. RequestBodyLBS $ encode $ Miner $ _configPublicKey conf
510
+ { HTTP. requestBody = HTTP. RequestBodyLBS
511
+ $ encode
512
+ $ Miner
513
+ (_configPublicKey conf)
514
+ (_configAccount conf)
498
515
, HTTP. requestHeaders = [(" content-type" , " application/json" )]
499
516
}
500
517
0 commit comments