Skip to content

Conversation

@nazrhom
Copy link
Collaborator

@nazrhom nazrhom commented Feb 15, 2022

No description provided.

This endpoint must be enabled by the pcEnableTxEndpoint configuration variable.

Change-type: minor
Change-type: patch
Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
Change-type: patch
Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
Change-type: patch
Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
Copy link
Contributor

@samuelWilliams99 samuelWilliams99 left a comment

Choose a reason for hiding this comment

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

Very nice! Only a few little notes :)


-- type is a reserved keyword in haskell and can not be used as a field name
-- when converting this to JSON we drop the _ prefix from each field
$(deriveJSON defaultOptions {fieldLabelModifier = drop 1} ''RawTx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can lose the $() for root scope TH :)

rawTxHandler :: PABConfig -> Text -> Handler RawTx
rawTxHandler config hash = do
-- Check that endpoint is enabled
assert (pcEnableTxEndpoint config)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use record dot here!

Suggested change
assert (pcEnableTxEndpoint config)
assert config.pcEnableTxEndpoint

as well as a few other places in this file

-- can not generate a client for the websocket endpoint.
txProxy ::
Proxy
( "rawTx"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth maybe type synonym-ing the endpoint part and reusing in both places?

Change-type: patch
Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
@nazrhom nazrhom merged commit 4877e4a into master Feb 15, 2022
:> Post '[JSON] ContractInstanceId -- Start a new instance.

type RawTxEndpoint =
"rawTx"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should avoid using camel case in the URL, how about using dash-case instead?


-- Add/Set .raw extension on path
let suppliedPath :: FilePath
suppliedPath = replaceExtension (txFolderPath </> "tx-" <> unpack hash) ".raw"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be a good idea to put the filename conversion into Files


type RawTxEndpoint =
"rawTx"
:> Capture "hash" Text
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we use TxId instead of Text 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.

Unfortunately we can not use TxId directly, this is because when defining an API including Capture “txId” TxId we also need to have FromHttpApiData and ToHttpApiData instances in scope (this is required to parse the data type to/from the URL)
So in order to avoid orphan instances, we would at least have to wrap TxId in a newtype, what do you think about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like orphan captures become pretty common, but also a newtype wouldn't hurt, can just unpack it in the handler pattern match


-- | This handler will allow to retrieve raw transactions from the pcTxFileDir if pcEnableTxEndpoint is True
rawTxHandler :: PABConfig -> Text -> Handler RawTx
rawTxHandler config hash = do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe txId instead of hash, to improve readability?

txHash :: Text
txHash = "test"

txFileName :: FilePath
Copy link
Collaborator

Choose a reason for hiding this comment

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

Once we have the filename conversion in Files, it could be imported from here

@szg251
Copy link
Collaborator

szg251 commented Feb 15, 2022

@nazrhom sorry, I was late with my review. I had a few comments, could you take a look at them?

@szg251 szg251 deleted the nazrhom/raw-tx branch February 16, 2022 11:45
@samuelWilliams99
Copy link
Contributor

Do we want to tackle these in a separate PR?

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.

4 participants