Skip to content

Feat/hydra #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 53 commits into from
May 26, 2025
Merged

Feat/hydra #51

merged 53 commits into from
May 26, 2025

Conversation

reeshavacharya
Copy link
Collaborator

  • Hydra Relay APIs
  • Hydra Query API
  • Hydra Transaction Submission API

@reeshavacharya reeshavacharya requested a review from mesudip May 7, 2025 08:52
Just "websocket" -> True
_ -> False

fetch :: IO (T.Text -> IO T.Text)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a Hydra config object and pass it along instead of fetching it directly

@reeshavacharya reeshavacharya requested a review from mesudip May 9, 2025 07:27
loadFile defaultConfig
hydraIp <- getEnv "HYDRA_IP"
hydraPort <- getEnv "HYDRA_PORT"
serverPort <- getEnv "SERVER_PORT"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a log showing the hydra ip / port

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

case convertText (T.pack cborHex) <&> unBase16 of
Nothing -> pure $ Left $ FrameworkError ParserError "Invalid CBOR hex in commit transaction"
Just bs ->
case deserialiseFromCBOR (AsTx AsConwayEra) bs of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have a AnyEra transaction parser in kuber already

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a function parseRawTxInAnyEra . And it will be used like this:

parsedTxAnyEra :: Either FrameworkError (Tx ConwayEra)
parsedTxAnyEra =
  case parseRawTxInAnyEra bs of
    Just (InAnyCardanoEra ConwayEra tx) -> Right (tx :: Tx ConwayEra)
    Just (InAnyCardanoEra _ _) -> Left $ FrameworkError ParserError "Unexpected era, expected ConwayEra"
    Nothing -> Left $ FrameworkError ParserError "Error parsing transaction cbor"

Do you think we should use it like this or stick with

case deserialiseFromCBOR (AsTx AsConwayEra) bs of ...

?

( \x -> case parseTxIn x of
Just txin -> pure txin
Nothing -> error $ "Error parsing TxIn: " <> T.unpack x
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raise error if a given tx-in is nto present in responded Utxo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

hydraProtocolParameters <- fetch hydraHost >>= \query -> query (T.pack "protocol-parameters")
pure $ textToJSON hydraProtocolParameters

getHydraState :: AppConfig -> IO (Either FrameworkError A.Value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a datastructure for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

in sendResponse res'

errorMiddleware :: (Eq a, Num a) => a -> ServerError
errorMiddleware status
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-review why this is necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary because haskell sends 500 on every error.
Responses from the hydra websocket can have different status codes. this is a middleware that parses the responses to have proper status code in response.

import Websocket.Utils (textToJSON)

handleHydraDecommitTx :: AppConfig -> [T.Text] -> Maybe (SigningKey PaymentKey) -> Bool -> Bool -> IO (Either FrameworkError A.Value)
handleHydraDecommitTx appConfig utxosToDecommit sk wait submit = do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use TxIn instead of T.Text for txin

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

Left err -> pure $ Left $ FrameworkError ParserError err
Right (hpp :: HydraProtocolParameters) -> pure $ Right hpp

groupUtxosByAddress :: M.Map T.Text A.Value -> [GroupedUTXO]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same Here Use TxIn here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

Left fe -> return $ Left fe
Right tx -> return $ Right tx

queryUTxO :: AppConfig -> Maybe T.Text -> Maybe T.Text -> IO (Either FrameworkError A.Value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. Use TxIn

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

[] -> Nothing
a : _ -> Just a

getUTxOFromInputs :: AppConfig -> TxInput ConwayEra -> IO (Either FrameworkError [UTxO ConwayEra])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead collect all the Txins and make single query to hydra

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed

@reeshavacharya reeshavacharya requested a review from mesudip May 22, 2025 09:55
@reeshavacharya reeshavacharya merged commit 44ad178 into master May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants