kh: improve Dawn code style

Based on PR feedback. Explicit argument types, improved NOTE style,
updated comments.
This commit is contained in:
Fang 2021-09-01 17:32:59 +02:00
parent 5fcf570c99
commit 307bc27913
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
2 changed files with 12 additions and 14 deletions

View File

@ -255,7 +255,7 @@ ethNode = strOption
$ short 'e'
<> long "l2-endpoint"
<> value "https://l2.urbit.org/v1/azimuth" --TODO
<> help "L2 RPC API endpoint URL"
<> help "Azimuth Layer 2 RPC API endpoint URL"
<> hidden
new :: Parser New

View File

@ -74,10 +74,8 @@ ringToPass Ring{..} = Pass{..}
-- JSONRPC Functions -----------------------------------------------------------
-- Network.JSONRPC appeared to not like something about the JSON that Infura
-- returned; it just hung? Also no documentation.
--
-- Our use case here is simple enough.
-- Network.JSONRPC appeared fragile and has no documentation.
-- So, like with Vere, we roll our own.
dawnSendHTTP :: String -> L.ByteString -> RIO e (Either Int L.ByteString)
@ -212,7 +210,7 @@ instance FromJSON PointSponsor where
data PointRequest = PointRequest Ship
instance RequestMethod PointRequest where
getRequestMethod _ = "getPoint"
getRequestMethod PointRequest{} = "getPoint"
instance ToJSON PointRequest where
toJSON (PointRequest point) = object [ "ship" .= renderShip point ]
@ -228,7 +226,7 @@ parseAzimuthPoint (PointRequest point) response = EthPoint{..}
epOwn = (0, 0, 0, 0)
sponsorShip = Ob.parsePatp $ psWho $ pnSponsor net
epNet = if (pkLife key) == 0
epNet = if pkLife key == 0
then Nothing
else case sponsorShip of
Left _ -> Nothing
@ -267,16 +265,16 @@ removePrefix withOhEx
where
(prefix, suffix) = splitAt 2 withOhEx
data TurfRequest = TurfRequest ()
data TurfRequest = TurfRequest
instance RequestMethod TurfRequest where
getRequestMethod _ = "getDns"
getRequestMethod TurfRequest = "getDns"
instance ToJSON TurfRequest where
toJSON _ = object [] --NOTE getDns takes no parameters
toJSON TurfRequest = object [] -- NOTE getDns takes no parameters
parseTurfResponse :: TurfRequest -> [Text] -> [Turf]
parseTurfResponse _ = map turf
parseTurfResponse TurfRequest = map turf
where
turf t = Turf $ fmap Cord $ reverse $ splitOn "." t
@ -397,7 +395,7 @@ dawnVent provider feed =
(dawnPostRequests provider parseGalaxyTableEntry (map (PointRequest . Ship . fromIntegral) [0..255]))
putStrLn "boot: retrieving network domains"
dTurf <- (dawnPostRequests provider parseTurfResponse [TurfRequest ()])
dTurf <- (dawnPostRequests provider parseTurfResponse [TurfRequest])
>>= \case
[] -> pure []
[t] -> pure (nub t)