remove DNSChain mode

It's been dead for a few years now...
This commit is contained in:
Michele Guerini Rocco 2022-06-12 03:51:20 +02:00
parent 387e3b05e4
commit 945f44a63a
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
3 changed files with 9 additions and 43 deletions

View File

@ -1,11 +1,13 @@
# Rosa # Rosa
## Query the namecoin blockchain ## Query the namecoin blockchain
Rosa is a commmand line tool to 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 ### Usage
Run rosa -h for help Run rosa -h for help
Show the value for a name with Show the value for a name with
@ -35,7 +37,7 @@ Connect to namecoind server for blockchain data
### License ### 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 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 it under the terms of the GNU General Public License as published by

View File

@ -5,14 +5,13 @@ description:
Rosa is a commmand line tool to query the namecoin blockhain. Rosa is a commmand line tool to query the namecoin blockhain.
It gets the JSON value of a name and other infos using namecoind 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 local server and displays them in a pretty format.
format.
license: GPL-3 license: GPL-3
license-file: LICENSE license-file: LICENSE
author: rnhmjoj author: rnhmjoj
maintainer: rnhmjoj@inventati.org maintainer: rnhmjoj@inventati.org
copyright: (C) Michele Guerini Rocco 2019 copyright: (C) Michele Guerini Rocco 2022
category: Utility category: Utility
build-type: Simple build-type: Simple
extra-source-files: README.md, LICENSE extra-source-files: README.md, LICENSE
@ -29,7 +28,7 @@ executable rosa
default-language: Haskell2010 default-language: Haskell2010
other-extensions: RecordWildCards, OverloadedStrings other-extensions: RecordWildCards, OverloadedStrings
build-depends: base >=4.8 && <5.0 , aeson, text, build-depends: base >=4.8 && <5.0 , aeson, text,
vector, uri-encode, unordered-containers, vector, uri-encode,
wreq, lens, bytestring, directory, bytestring, directory,
optparse-applicative, namecoin-update optparse-applicative, namecoin-update
ghc-options: -O2 ghc-options: -O2

View File

@ -9,7 +9,6 @@ import Json
-- Networking -- Networking
import Namecoin (rpcRequest, uri) import Namecoin (rpcRequest, uri)
import Network.Wreq (get, responseBody)
import qualified Network.URI.Encode as U import qualified Network.URI.Encode as U
-- IO -- IO
@ -18,14 +17,12 @@ import System.Directory (XdgDirectory(..), getXdgDirectory)
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
-- Data manipulation -- Data manipulation
import Data.Text (Text)
import Data.Aeson (Value(..), encode, decode, toJSON) import Data.Aeson (Value(..), encode, decode, toJSON)
import Data.Aeson.KeyMap (delete) import Data.Aeson.KeyMap (delete)
import Data.ByteString.Lazy.Char8 (pack, unpack) import Data.ByteString.Lazy.Char8 (pack, unpack)
-- Misc -- Misc
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Control.Lens (view)
import Control.Monad (when) import Control.Monad (when)
@ -34,9 +31,7 @@ import Control.Monad (when)
-- | Program arguments record -- | Program arguments record
data Options = Options data Options = Options
{ name :: String { name :: String
, url :: String
, conf :: Maybe FilePath , conf :: Maybe FilePath
, dnschain :: Bool
, block :: Bool , block :: Bool
, raw :: Bool , raw :: Bool
} }
@ -47,21 +42,11 @@ options = Options
<$> strArgument <$> strArgument
( metavar "NAME" ( metavar "NAME"
<> help "Namecoin name id" ) <> help "Namecoin name id" )
<*> strOption
( long "url"
<> short 'u'
<> value "http://namecoin.dns"
<> metavar "URL"
<> help "Use custom API URL" )
<*> (optional $ strOption $ <*> (optional $ strOption $
long "conf" long "conf"
<> short 'c' <> short 'c'
<> metavar "FILE" <> metavar "FILE"
<> help "Use custom namecoin config file" ) <> help "Use custom namecoin config file" )
<*> switch
( long "dnschain"
<> short 'd'
<> help "Use dnschain API " )
<*> switch <*> switch
( long "block" ( long "block"
<> short 'b' <> short 'b'
@ -86,10 +71,7 @@ description = info (helper <*> options)
-- | Main function -- | Main function
main :: IO () main :: IO ()
main = execParser description >>= exec where main = execParser description >>= exec where
exec Options{..} = exec Options{..} = doLocal name raw block conf
if dnschain
then doDnschain url name raw block
else doLocal name raw block conf
-- | Load namecoin configuration -- | Load namecoin configuration
@ -118,20 +100,3 @@ doLocal name raw block conf = do
where where
tryParse = fromMaybe (res |. "value") . decode . pack tryParse = fromMaybe (res |. "value") . decode . pack
blockInfo = toJSON (delete "value" res) 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