1414
1515module Encoins.Relay.Apps.Delegation.Server where
1616
17- import Cardano.Api (writeFileJSON , NetworkId (Mainnet ))
17+ import Cardano.Api (NetworkId (Mainnet ), writeFileJSON )
1818import Cardano.Server.Config (HasCreds , decodeOrErrorFromFile )
1919import Cardano.Server.Main (runCardanoServer )
2020import Cardano.Server.Utils.Logger (logMsg , logSmth , logger , (.<) )
@@ -27,6 +27,7 @@ import Control.Monad (forM, forever, void, wh
2727import Control.Monad.Catch (Exception , MonadCatch (catch ), MonadThrow (.. ), SomeException , handle )
2828import Control.Monad.IO.Class (MonadIO (.. ))
2929import Control.Monad.Reader (MonadReader (ask , local ), ReaderT (.. ))
30+ import Data.Aeson.Types (FromJSON (parseJSON ), Value , parseEither )
3031import Data.ByteString (ByteString )
3132import Data.FileEmbed (embedFileIfExists )
3233import Data.Fixed (Pico )
@@ -48,7 +49,7 @@ import Encoins.Relay.Apps.Delegation.Internal (DelegConfig (..), Deleg
4849 getBalances , removeDuplicates , runDelegationM , setProgress ,
4950 setTokenBalance )
5051import Encoins.Relay.Apps.Internal (formatTime , janitorFiles , loadMostRecentFile , newProgressBar )
51- import Ledger (PubKeyHash , Address )
52+ import Ledger (PubKeyHash )
5253import qualified PlutusAppsExtra.IO.Blockfrost as Bf
5354import PlutusAppsExtra.Utils.Address (addressToBech32 , getStakeKey )
5455import Servant (Get , JSON , ReqBody , err404 , err500 , throwError , type (:<|> ) ((:<|>) ),
@@ -131,7 +132,7 @@ type DelegApi
131132delegApi :: DelegationM (Map Text Integer )
132133 :<|> DelegationM [Text ]
133134 :<|> (Text -> DelegationM (Map Text Integer ))
134- :<|> (Address -> DelegationM (Text , Integer ))
135+ :<|> (Value -> DelegationM (Text , Integer ))
135136delegApi
136137 = getServersHandler
137138 :<|> getCurrentServersHandler
@@ -188,11 +189,13 @@ getServerDelegatesHandler ip = delegationErrorH $ do
188189
189190------------------------------------------- Get specific delegation info by address endpoint -------------------------------------------
190191
191- type GetDelegationInfo = " info" :> ReqBody '[JSON ] Address :> Get '[JSON ] (Text , Integer )
192+ type GetDelegationInfo = " info" :> ReqBody '[JSON ] Value :> Get '[JSON ] (Text , Integer )
192193
193194-- Get ip of delegated server and number of tokens by address endpoint
194- getDelegationInfoHandler :: Address -> DelegationM (Text , Integer )
195- getDelegationInfoHandler addr = delegationErrorH $ do
195+ getDelegationInfoHandler :: Value -> DelegationM (Text , Integer )
196+ getDelegationInfoHandler addrVal = delegationErrorH $ do
197+ logSmth addrVal
198+ let addr = either error id $ parseEither id $ parseJSON addrVal
196199 let pkh = fromMaybe (throw err404) $ getStakeKey addr
197200 mbIp <- fmap delegIp . find ((== pkh) . delegStakeKey) . pDelgations <$> askProgress True
198201 mbBalance <- Map. lookup pkh <$> askTokenBalance
0 commit comments