Skip to content
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

Use block height for id on contract import #209

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ impl Event {
}
.to_string();

let second_part = match is_fuel {
true => format!("${{{event_var_name}.transaction.id}}"),
false => format!("${{{event_var_name}.block.number}}"),
let block_number_field = match is_fuel {
true => "height",
false => "humber",
DZakh marked this conversation as resolved.
Show resolved Hide resolved
};

format!(
"`${{{event_var_name}.chainId}}_{second_part}_${{{event_var_name}.logIndex{}}}`",
"`${{{event_var_name}.chainId}}_${{{event_var_name}.block.{block_number_field}}}_${{{event_var_name}.logIndex{}}}`",
to_string_code
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ module HeightQuery = {
//height to be set in loop
let height = ref(0)

//Retry if the heigth is 0 (expect height to be greater)
//Retry if the height is 0 (expect height to be greater)
while height.contents <= 0 {
let res = await HyperFuelJsonApi.getArchiveHeight(~serverUrl)
Logging.debug({"msg": "querying height", "response": res})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,18 @@ module LogsQuery = {
switch returnedObj
->(Utils.magic: 'a => Js.Dict.t<unknown>)
->Utils.Dict.dangerouslyGetNonOption(fieldName) {
| Some(_) => ()
| None => acc->Array.push(prefix ++ "." ++ fieldName)->ignore
| Some(_) => ()
| None => acc->Array.push(prefix ++ "." ++ fieldName)->ignore
}
})
}

//Note this function can throw an error
let convertEvent = (event: HyperSyncClient.ResponseTypes.event, ~nonOptionalBlockFieldNames, ~nonOptionalTransactionFieldNames): logsQueryPageItem => {
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")
Expand Down Expand Up @@ -150,12 +154,17 @@ module LogsQuery = {
}
}

let convertResponse = (res: HyperSyncClient.ResponseTypes.eventResponse, ~nonOptionalBlockFieldNames, ~nonOptionalTransactionFieldNames): queryResponse<
logsQueryPage,
> => {
let convertResponse = (
res: HyperSyncClient.ResponseTypes.eventResponse,
~nonOptionalBlockFieldNames,
~nonOptionalTransactionFieldNames,
): queryResponse<logsQueryPage> => {
try {
let {nextBlock, archiveHeight, rollbackGuard} = res
let items = res.data->Array.map(item => item->convertEvent(~nonOptionalBlockFieldNames, ~nonOptionalTransactionFieldNames))
let items =
res.data->Array.map(item =>
item->convertEvent(~nonOptionalBlockFieldNames, ~nonOptionalTransactionFieldNames)
)
let page: logsQueryPage = {
items,
nextBlock,
Expand Down Expand Up @@ -191,7 +200,12 @@ module LogsQuery = {
})
)

let query = makeRequestBody(~fromBlock, ~toBlockInclusive=toBlock, ~addressesWithTopics, ~fieldSelection)
let query = makeRequestBody(
~fromBlock,
~toBlockInclusive=toBlock,
~addressesWithTopics,
~fieldSelection,
)

let hyperSyncClient = CachedClients.getClient(serverUrl)

Expand All @@ -216,7 +230,7 @@ module HeightQuery = {
//height to be set in loop
let height = ref(0)

//Retry if the heigth is 0 (expect height to be greater)
//Retry if the height is 0 (expect height to be greater)
while height.contents <= 0 {
let res = await HyperSyncJsonApi.getArchiveHeight(~serverUrl)
switch res {
Expand Down
Loading