From 35cea210f8d3a22afd24848441b5d34702d83239 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Sat, 12 Apr 2014 15:58:31 +0400 Subject: [PATCH] separate Namecoin RPC from domain data --- NmcJson.hs => NmcDom.hs | 18 +----------------- NmcRpc.hs | 27 +++++++++++++++++++++++++++ PowerDns.hs | 2 +- pdns-pipe-nmc.hs | 3 ++- 4 files changed, 31 insertions(+), 19 deletions(-) rename NmcJson.hs => NmcDom.hs (91%) create mode 100644 NmcRpc.hs diff --git a/NmcJson.hs b/NmcDom.hs similarity index 91% rename from NmcJson.hs rename to NmcDom.hs index 69e693f..b975522 100644 --- a/NmcJson.hs +++ b/NmcDom.hs @@ -1,7 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -module NmcJson ( NmcRes(..) - , NmcDom(..) +module NmcDom ( NmcDom(..) , emptyNmcDom , descendNmc ) where @@ -106,21 +105,6 @@ emptyNmcDom = NmcDom Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing -data NmcRes = NmcRes { resName :: String - , resValue :: ByteString -- string with NmcDom - , resTxid :: String - , resAddress :: String - , resExpires_in :: Int - } deriving (Show) -instance FromJSON NmcRes where - parseJSON (Object o) = NmcRes - <$> o .: "name" - <*> o .: "value" - <*> o .: "txid" - <*> o .: "address" - <*> o .: "expires_in" - parseJSON _ = empty - normalizeDom :: NmcDom -> NmcDom normalizeDom dom | domNs dom /= Nothing = emptyNmcDom { domNs = domNs dom diff --git a/NmcRpc.hs b/NmcRpc.hs new file mode 100644 index 0000000..1f73a73 --- /dev/null +++ b/NmcRpc.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE OverloadedStrings #-} + +module NmcRpc ( NmcRes(..) + ) where + +import Data.ByteString.Lazy (ByteString) +import Data.Text as T (unpack) +import Data.List.Split +import Data.Char +import Data.Map as M (Map, lookup) +import Control.Applicative ((<$>), (<*>), empty) +import Data.Aeson + +data NmcRes = NmcRes { resName :: String + , resValue :: ByteString -- string with NmcDom + , resTxid :: String + , resAddress :: String + , resExpires_in :: Int + } deriving (Show) +instance FromJSON NmcRes where + parseJSON (Object o) = NmcRes + <$> o .: "name" + <*> o .: "value" + <*> o .: "txid" + <*> o .: "address" + <*> o .: "expires_in" + parseJSON _ = empty diff --git a/PowerDns.hs b/PowerDns.hs index 696b9b5..e225b62 100644 --- a/PowerDns.hs +++ b/PowerDns.hs @@ -5,7 +5,7 @@ module PowerDns ( RRType(..) , pdnsOut ) where -import NmcJson +import NmcDom data RRType = RRTypeSRV | RRTypeA | RRTypeAAAA | RRTypeCNAME | RRTypeDNAME | RRTypeSOA | RRTypeRP | RRTypeLOC diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index 304e049..4d47e50 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -16,7 +16,8 @@ import Network.HTTP.Conduit import JsonRpcClient import Config import PowerDns -import NmcJson +import NmcRpc +import NmcDom confFile = "/etc/namecoin.conf" -- 2.39.2