This commit is contained in:
commit
fcdb18a449
39
namecoin-update
Normal file
39
namecoin-update
Normal file
@ -0,0 +1,39 @@
|
||||
{-# Language DeriveGeneric, RecordWildCards #-}
|
||||
|
||||
import System.Process
|
||||
import System.Exit
|
||||
import GHC.Generics
|
||||
import Data.Aeson
|
||||
import Data.ByteString.Lazy.Char8 (pack)
|
||||
|
||||
readCommand = readProcess "namecoind" ["name_list"] ""
|
||||
updateCommand n v = readProcessWithExitCode "namecoind" ["name_update", n, v] ""
|
||||
|
||||
data Name =
|
||||
Name { name :: String
|
||||
, value :: String
|
||||
, address :: String
|
||||
, expires_in :: Int
|
||||
} deriving (Show, Generic)
|
||||
|
||||
instance FromJSON Name
|
||||
|
||||
updateName :: Name -> IO Int
|
||||
updateName Name{..}
|
||||
| expires_in < 100 = do
|
||||
(code, out, err) <- updateCommand name value
|
||||
if code == ExitSuccess
|
||||
then putStrLn (name ++ " updated: " ++ out) >> return 0
|
||||
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"
|
Loading…
Reference in New Issue
Block a user