-
Notifications
You must be signed in to change notification settings - Fork 31
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
Feat/hydra #51
Conversation
reeshavacharya
commented
May 7, 2025
- Hydra Relay APIs
- Hydra Query API
- Hydra Transaction Submission API
Just "websocket" -> True | ||
_ -> False | ||
|
||
fetch :: IO (T.Text -> IO T.Text) |
There was a problem hiding this comment.
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
loadFile defaultConfig | ||
hydraIp <- getEnv "HYDRA_IP" | ||
hydraPort <- getEnv "HYDRA_PORT" | ||
serverPort <- getEnv "SERVER_PORT" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 | ||
) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. Use TxIn
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed