packages feed

rosa 0.5.0.1 → 0.6.0.0

raw patch · 5 files changed

+19/−54 lines, 5 filesdep −lensdep −unordered-containersdep −wreqsetup-changed

Dependencies removed: lens, unordered-containers, wreq

Files

README.md view
@@ -1,11 +1,13 @@ # Rosa+ ## Query the namecoin blockchain  Rosa is a commmand line tool to query the namecoin blockchain. -It gets the JSON value of a name and other data using namecoind local server or the dnschain REST api and displays it in a pretty format.+It gets the JSON value of a name and other data using namecoind local server and displays it in a pretty format.  ### Usage+ Run rosa -h for help  Show the value for a name with@@ -35,7 +37,7 @@  ### License -Copyright (C) 2015 Michele Guerini Rocco+Copyright (C) 2022 Michele Guerini Rocco  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
rosa.cabal view
@@ -1,18 +1,17 @@ name:                rosa-version:             0.5.0.1+version:             0.6.0.0 synopsis:            Query the namecoin blockchain description:    Rosa is a commmand line tool to query the namecoin blockhain.   It gets the JSON value of a name and other infos using namecoind-  local server or the dnschain REST api and display them in a pretty -  format.+  local server and displays them in a pretty format.                       license:             GPL-3 license-file:        LICENSE author:              rnhmjoj maintainer:          rnhmjoj@inventati.org-copyright:           (C) Michele Guerini Rocco 2019+copyright:           (C) Michele Guerini Rocco 2022 category:            Utility build-type:          Simple extra-source-files:  README.md, LICENSE@@ -29,7 +28,7 @@   default-language:    Haskell2010   other-extensions:    RecordWildCards, OverloadedStrings   build-depends:       base >=4.8 && <5.0 , aeson, text,-                       vector, uri-encode, unordered-containers,-                       wreq, lens, bytestring, directory,+                       vector, uri-encode,+                       bytestring, directory,                        optparse-applicative, namecoin-update   ghc-options:         -O2
src/Json.hs view
@@ -3,21 +3,22 @@  import Data.Aeson import Data.Aeson.Types (parse)-import Data.Text        (Text, unpack)+import Data.Text        (unpack) import Data.List        (intercalate) -import qualified Data.Vector         as V-import qualified Data.HashMap.Strict as H+import qualified Data.Vector       as V+import qualified Data.Aeson.KeyMap as K+import qualified Data.Aeson.Key    as K  -- | Gets the JSON value of a key-(|.) :: Object -> Text -> Value+(|.) :: Object -> Key -> Value obj |. key = case parse (.: key) obj of   Success val -> val   Error err -> toJSON err   -- | Gets the 'String' value of a key-(|:) :: Object -> Text -> String+(|:) :: Object -> Key -> String obj |: key = repr (obj |. key)  @@ -27,7 +28,7 @@   repr' val lev =     case val of       Array  x -> intercalate ", " $ mapl (\i -> repr' i lev) x-      Object x -> newline lev $ concat $ map (dump x lev) $ H.keys x+      Object x -> newline lev $ concat $ map (dump x lev) $ K.keys x       String x -> unpack x       Number x -> show x       Bool   x -> show x@@ -35,7 +36,7 @@   mapl f v = V.toList (V.map f v)   newline n = if n /= 0 then id else drop 1   indent l = '\n' : (concat . replicate l) "  "-  dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)]+  dump o l k = concat [indent l, K.toString k, ": ", repr' (o |. k) (l+1)]   -- | Pretty print a JSON 'Value'
src/Main.hs view
@@ -9,7 +9,6 @@  -- Networking import Namecoin                    (rpcRequest, uri)-import Network.Wreq                (get, responseBody) import qualified Network.URI.Encode as U  -- IO@@ -18,14 +17,12 @@ import qualified Data.Text.IO      as T  -- Data manipulation-import Data.Text                   (Text) import Data.Aeson                  (Value(..), encode, decode, toJSON)-import Data.HashMap.Strict         (delete)+import Data.Aeson.KeyMap           (delete) import Data.ByteString.Lazy.Char8  (pack, unpack)  -- Misc import Data.Maybe                  (fromMaybe)-import Control.Lens                (view) import Control.Monad               (when)  @@ -34,9 +31,7 @@ -- | Program arguments record data Options = Options   { name     :: String-  , url      :: String   , conf     :: Maybe FilePath-  , dnschain :: Bool   , block    :: Bool   , raw      :: Bool   }@@ -47,22 +42,12 @@   <$> strArgument       ( metavar "NAME"      <> help "Namecoin name id" )-  <*> strOption-      ( long "url"-     <> short 'u'-     <> value "http://namecoin.dns"-     <> metavar "URL"-     <> help "Use custom API URL" )   <*> (optional $ strOption $         long "conf"      <> short 'c'      <> metavar "FILE"      <> help "Use custom namecoin config file" )   <*> switch-      ( long "dnschain"-     <> short 'd'-     <> help "Use dnschain API " )-  <*> switch       ( long "block"      <> short 'b'      <> help "Show blockchain data" )@@ -86,10 +71,7 @@ -- | Main function main :: IO () main = execParser description >>= exec where-  exec Options{..} =-    if dnschain-      then doDnschain url name raw block-      else doLocal name raw block conf+  exec Options{..} = doLocal name raw block conf   -- | Load namecoin configuration@@ -118,20 +100,3 @@       where         tryParse  = fromMaybe (res |. "value") . decode . pack         blockInfo = toJSON (delete "value" res)----- | Connect to dnschain API endpoint-doDnschain :: String -> String -> Bool -> Bool -> IO ()-doDnschain url name raw block = do-  body <- view responseBody <$> get (url++"/v1/namecoin/key/"++U.encode name)-  if raw-    then putStrLn (unpack body)-    else do-      case decode body of-        Nothing  -> putStrLn "Error parsing data"-        Just res -> putStrLn $-            if block-              then repr res-              else repr $ (res .| "data") .| "value"--  where (Object x) .| y = x |. y