Skip to content

Commit 85b9f78

Browse files
authored
use k: accounts by default (#17)
* use k: accounts by default * enable test during build * update haskell setup action * reset build cache * add --account option * put upper bound on sydtest
1 parent d3cdd5d commit 85b9f78

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

.github/workflows/build-application.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
ghc: ['8.8.4', '8.10.7', '9.0.1']
16-
cabal: ['3.4.0.0']
16+
cabal: ['3.6']
1717
os: ['ubuntu-18.04', 'ubuntu-20.04', 'macOS-latest']
1818

1919
steps:
@@ -32,7 +32,7 @@ jobs:
3232
- name: Checkout repository
3333
uses: actions/checkout@v2
3434
- name: Install GHC and Cabal
35-
uses: larskuhtz/actions/setup@e0f107055073590682bc5264b8da5c2b6af39a65
35+
uses: haskell/actions/setup@v1.2.7
3636
with:
3737
ghc-version: ${{ matrix.ghc }}
3838
cabal-version: ${{ matrix.cabal }}
@@ -47,18 +47,18 @@ jobs:
4747
~/.cabal/packages
4848
~/.cabal/store
4949
dist-newstyle
50-
key: ${{ matrix.os }}-${{ matrix.ghc }}-0-cabal
50+
key: ${{ matrix.os }}-${{ matrix.ghc }}-1-cabal
5151

5252
# Build
5353
- name: Update package database
5454
run: cabal update
5555
- name: Configure build
5656
run: |
5757
rm -rf dist-newstyle/build/*/ghc-*/chainweb-mining-client-*/build/chainweb-mining-client/chainweb-mining-client
58-
cabal build all --dry-run
59-
cabal freeze
58+
cabal build all --dry-run --enable-tests
59+
cabal freeze --enable-tests
6060
- name: Install build dependencies
61-
run: cabal build --only-dependencies
61+
run: cabal build --only-dependencies --enable-tests
6262
- name: Build
6363
run: cabal build
6464

cabal.project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
packages: .
22
allow-newer:
33
streaming-events:*
4+
5+
constraints: sydtest <0.5

main/Main.hs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import qualified Data.ByteString.Lazy as BL
5151
import qualified Data.ByteString.Short as BS
5252
import Data.Hashable
5353
import qualified Data.HashMap.Strict as HM
54+
import Data.Maybe
5455
import Data.Streaming.Network
5556
import qualified Data.Text as T
5657
import qualified Data.Text.Encoding as T
@@ -179,13 +180,17 @@ instance FromJSON MinerPublicKey where
179180
{-# INLINE parseJSON #-}
180181
-- TODO perform well-formedness checks
181182

182-
newtype Miner = Miner MinerPublicKey
183+
newtype MinerAccount = MinerAccount T.Text
183184
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)
185190

186191
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
189194
, "public-keys" .= [ k ]
190195
, "predicate" .= ("keys-all" :: T.Text)
191196
]
@@ -237,6 +242,7 @@ data Config = Config
237242
, _configUseTls :: !Bool
238243
, _configInsecure :: !Bool
239244
, _configPublicKey :: !MinerPublicKey
245+
, _configAccount :: !(Maybe MinerAccount)
240246
, _configThreadCount :: !Natural
241247
, _configGenerateKey :: !Bool
242248
, _configLogLevel :: !LogLevel
@@ -257,6 +263,7 @@ defaultConfig = Config
257263
, _configUseTls = True
258264
, _configInsecure = True
259265
, _configPublicKey = MinerPublicKey ""
266+
, _configAccount = Nothing
260267
, _configThreadCount = 10
261268
, _configGenerateKey = False
262269
, _configLogLevel = Info
@@ -274,6 +281,7 @@ instance ToJSON Config where
274281
, "useTls" .= _configUseTls c
275282
, "insecure" .= _configInsecure c
276283
, "publicKey" .= _configPublicKey c
284+
, "account" .= _configAccount c
277285
, "threadCount" .= _configThreadCount c
278286
, "generateKey" .= _configGenerateKey c
279287
, "logLevel" .= logLevelToText @T.Text (_configLogLevel c)
@@ -291,6 +299,7 @@ instance FromJSON (Config -> Config) where
291299
<*< configUseTls ..: "useTls" % o
292300
<*< configInsecure ..: "insecure" % o
293301
<*< configPublicKey ..: "publicKey" % o
302+
<*< configAccount ..: "account" % o
294303
<*< configThreadCount ..: "threadCount" % o
295304
<*< configGenerateKey ..: "generateKey" % o
296305
<*< setProperty configLogLevel "logLevel" parseLogLevel o
@@ -324,7 +333,11 @@ parseConfig = id
324333
<*< configPublicKey .:: fmap MinerPublicKey . strOption
325334
% short 'k'
326335
<> 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:')"
328341
<*< configThreadCount .:: option auto
329342
% short 'c'
330343
<> long "thread-count"
@@ -494,7 +507,11 @@ getJob conf ver mgr = do
494507
Right (a,b,c) -> return (a, b, c)
495508
where
496509
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)
498515
, HTTP.requestHeaders = [("content-type", "application/json")]
499516
}
500517

0 commit comments

Comments
 (0)