Skip to content

Commit

Permalink
Simplify field names
Browse files Browse the repository at this point in the history
  • Loading branch information
ngua committed May 20, 2022
1 parent 0095aa3 commit 391f8cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions server/ctl-server.cabal
Expand Up @@ -15,6 +15,8 @@ common common-language
DeriveLift
DeriveTraversable
DerivingStrategies
DerivingVia
DuplicateRecordFields
ExplicitForAll
FlexibleContexts
FlexibleInstances
Expand Down
8 changes: 3 additions & 5 deletions server/src/Types.hs
@@ -1,5 +1,3 @@
{-# LANGUAGE DerivingVia #-}

module Types (
AppM (AppM),
ServerOptions (..),
Expand Down Expand Up @@ -171,8 +169,8 @@ newtype AppliedScript = AppliedScript Ledger.Script
deriving newtype (Eq, FromJSON, ToJSON)

data HashBytesRequest = HashBytesRequest
{ methodToUse :: HashMethod
, bytesToHash :: BytesToHash
{ method :: HashMethod
, bytes :: BytesToHash
}
deriving stock (Show, Eq, Generic)
deriving anyclass (FromJSON, ToJSON)
Expand Down Expand Up @@ -208,7 +206,7 @@ instance ToJSON HashMethod where
}

data ByteStringHash = ByteStringHash
{ methodUsed :: HashMethod
{ method :: HashMethod
, hash :: HashedBytes
}
deriving stock (Show, Eq, Generic)
Expand Down
8 changes: 4 additions & 4 deletions src/QueryM/Crypto.purs
Expand Up @@ -76,20 +76,20 @@ plutusHash meth bytes = do
bytesJson = encodeJson $ byteArrayToHex bytes

requestJson :: Json
requestJson = "bytesToHash" := bytesJson
~> "methodToUse" := methJson
requestJson = "bytes" := bytesJson
~> "method" := methJson
~> jsonEmptyObject

reqBody :: Affjax.RequestBody.RequestBody
reqBody = Affjax.RequestBody.Json requestJson
response <- liftAff
(Affjax.post Affjax.ResponseFormat.json url (pure reqBody))
pure $ do
responseJson :: ({ methodUsed :: String, hash :: ByteArray }) <-
responseJson :: ({ method :: String, hash :: ByteArray }) <-
lmap Affjax.printError response >>= _.body >>> decodeJson >>> lmap
printJsonDecodeError
goal <- lmap printJsonDecodeError $ decodeJson methJson
unless (responseJson.methodUsed == goal) $
unless (responseJson.method == goal) $
throwError "responseJson wasn't hashed with the method requested"
pure responseJson.hash

Expand Down

0 comments on commit 391f8cb

Please sign in to comment.