Handle new changes in namecoin cli
This commit is contained in:
parent
ee17e3c26c
commit
b722fc7a30
25
Main.hs
25
Main.hs
@ -5,17 +5,25 @@ import System.Exit
|
||||
import Data.Aeson
|
||||
import Data.Aeson.TH
|
||||
import Data.ByteString.Lazy.Char8 (pack)
|
||||
import Control.Exception (try)
|
||||
|
||||
readCommand = readProcess "namecoin-cli" ["name_list"] ""
|
||||
updateCommand n v = readProcessWithExitCode "namecoin-cli" ["name_update", n, v] ""
|
||||
|
||||
data Name = Name { name :: String
|
||||
, value :: String
|
||||
, expires_in :: Int
|
||||
}
|
||||
data Name = Name
|
||||
{ name :: String
|
||||
, value :: String
|
||||
, expires_in :: Int
|
||||
}
|
||||
|
||||
deriveJSON defaultOptions ''Name
|
||||
|
||||
|
||||
namecoin :: [String] -> CreateProcess
|
||||
namecoin args = shell ("namecoin-cli -conf=$HOME/.config/namecoin " ++ unwords args)
|
||||
|
||||
|
||||
readCommand = readCreateProcess (namecoin ["name_list"]) ""
|
||||
updateCommand n v = readCreateProcessWithExitCode (namecoin ["name_update", n, v]) ""
|
||||
|
||||
|
||||
updateName :: Name -> IO Int
|
||||
updateName Name{..}
|
||||
| expires_in < 100 = do
|
||||
@ -25,13 +33,14 @@ updateName Name{..}
|
||||
else putStrLn (name ++ " update failed: " ++ err) >> return 1
|
||||
| otherwise = putStrLn ("No need to update " ++ name) >> return 0
|
||||
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
out <- pack <$> readCommand
|
||||
case eitherDecode out of
|
||||
Left err -> putStrLn ("Error communicating with namecoin: " ++ err)
|
||||
Right names -> do
|
||||
errs <- sum <$> mapM updateName (names :: [Name])
|
||||
if errs > 0
|
||||
then putStrLn (show errs ++ " updates failed")
|
||||
else putStrLn "All ok"
|
||||
Left err -> putStrLn ("Error communicating with namecoin: " ++ err)
|
||||
|
Loading…
Reference in New Issue
Block a user