Skip to content

Fuel merge part 10 - Fuel specific names for transaction fields#192

Merged
DZakh merged 3 commits into
mainfrom
dz/fuel-merge-9
Sep 12, 2024
Merged

Fuel merge part 10 - Fuel specific names for transaction fields#192
DZakh merged 3 commits into
mainfrom
dz/fuel-merge-9

Conversation

@DZakh

@DZakh DZakh commented Sep 12, 2024

Copy link
Copy Markdown
Member

No description provided.

@DZakh DZakh requested a review from JonoPrest September 12, 2024 12:16
Comment on lines +94 to +100
let dict = Js.Dict.empty()
//Note: if we implement all transaction fields, we will need all
//field names not just non optional ones
Types.Transaction.nonOptionalFieldNames
->Belt.Array.map(name => (name, getTxFieldFromEthersLog(log, name, ~logger)))
->Js.Dict.fromArray
->(Utils.magic: Js.Dict.t<txFieldVal> => Types.Transaction.t)
nonOptionalTransactionFieldNames->Belt.Array.forEach(name => {
dict->Js.Dict.set(name, getTxFieldFromEthersLog(log, name, ~logger))
})
dict->(Utils.magic: Js.Dict.t<txFieldVal> => Types.Transaction.t)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Optimised it a little bit

Comment on lines +44 to +53
/**
Holds the value of the next page fetch happening concurrently to current page processing
*/
type nextPageFetchRes = {
contractInterfaceManager: ContractInterfaceManager.t,
page: HyperSync.logsQueryPage,
pageFetchTime: int,
}

/**
Holds the value of the next page fetch happening concurrently to current page processing
*/
type nextPageFetchRes = {
contractInterfaceManager: ContractInterfaceManager.t,
page: HyperSync.logsQueryPage,
pageFetchTime: int,
}

let waitForBlockGreaterThanCurrentHeight = (~currentBlockHeight, ~logger) => {
HyperSync.pollForHeightGtOrEq(
~serverUrl=T.endpointUrl,
~blockNumber=currentBlockHeight,
~logger,
)
let makeGetNextPage = (~endpointUrl, ~contracts: array<Config.contract>, ~queryLogsPage, ~pollForHeightGtOrEq, ~blockSchema, ~transactionSchema) => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moved it outiside of the functor to simplify testing

Comment on lines +107 to +127
let addMissingParams = (acc, fieldNames, returnedObj, ~prefix) => {
fieldNames->Array.forEach(fieldName => {
switch returnedObj
->(Utils.magic: 'a => Js.Dict.t<unknown>)
->Utils.Dict.dangerouslyGetNonOption(fieldName)
->Utils.Option.mapNone(prefix ++ "." ++ fieldName)
->Utils.Dict.dangerouslyGetNonOption(fieldName) {
| Some(_) => ()
| None => acc->Array.push(prefix ++ "." ++ fieldName)->ignore
}
})
}

//Note this function can throw an error
let convertEvent = (event: HyperSyncClient.ResponseTypes.event, ~nonOptionalBlockFieldNames): logsQueryPageItem => {
let missingParams =
[
getMissingFields(Types.Log.fieldNames, event.log, ~prefix="log"),
getMissingFields(nonOptionalBlockFieldNames, event.block, ~prefix="block"),
getMissingFields(
Types.Transaction.nonOptionalFieldNames,
event.transaction,
~prefix="transaction",
),
]->Array.concatMany

let convertEvent = (event: HyperSyncClient.ResponseTypes.event, ~nonOptionalBlockFieldNames, ~nonOptionalTransactionFieldNames): logsQueryPageItem => {
let missingParams = []
missingParams->addMissingParams(Types.Log.fieldNames, event.log, ~prefix="log")
missingParams->addMissingParams(nonOptionalBlockFieldNames, event.block, ~prefix="block")
missingParams->addMissingParams(
nonOptionalTransactionFieldNames,
event.transaction,
~prefix="transaction",
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Still the same validation, but should be a little bit more performant

Comment on lines +14 to +16
type mock = {queryLogsPageCalls: array<queryLogsPageCall>}

let mock = (~blockSchema=S.object(_ => ()), ~transactionSchema=S.object(_ => ())) => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This mock is not the most flexible, but can be extended to conveniently test the logSelections logic, as well as polling logic

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Awesome Dmitry looks great 👌🏼 🙏🏼

@DZakh DZakh merged commit 977c1d3 into main Sep 12, 2024
@DZakh DZakh deleted the dz/fuel-merge-9 branch September 12, 2024 13:19
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