Skip to content

Commit e552611

Browse files
committed
Some updates based on PR, basic simplification, overshadow correction
1 parent e3de440 commit e552611

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

codegenerator/cli/npm/envio/src/Address.res

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ module Evm = {
1313

1414
// NOTE: We could use a regex for this instead, not sure if it is faster/slower than viem's 'isAddress' function
1515
// `/^0x[a-fA-F0-9]{40}$/`
16-
@module("viem") @private
17-
external isAddress: string => bool = "isAddress"
16+
// ALSO: the function is named to be overshadowed by the one below, so that we don't have to import viem in the handler code
17+
@module("viem")
18+
external fromStringLowercaseOrThrow: string => bool = "isAddress"
1819

20+
// Reassign since the function might be used in the handler code
21+
// and we don't want to have a "viem" import there. It's needed to keep "viem" a dependency
22+
// of generated code instead of adding it to the indexer project dependencies.
23+
// Also, we want a custom error message, which is searchable in our codebase.
1924
// Validate that the string is a proper address but return a lowercased value
2025
let fromStringLowercaseOrThrow = string => {
2126
// NOTE: We could use a regex for this and make this function more strict, so it only accepts lower case addresses as input
2227
// eg this regex: `/^0x[a-f0-9]{40}$/`
23-
if (isAddress(string)) {
28+
if (fromStringLowercaseOrThrow(string)) {
2429
unsafeFromString(string->Js.String2.toLowerCase)
2530
} else {
2631
Js.Exn.raiseError(

codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSyncSource.res

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,24 +172,13 @@ let make = (
172172
let apiToken =
173173
Env.envioApiToken->Belt.Option.getWithDefault("3dc856dd-b0ea-494f-b27e-017b8b6b7e07")
174174

175-
let client =
176-
if lowercaseAddresses {
177-
HyperSyncClient.make(
178-
~url=endpointUrl,
179-
~apiToken,
180-
~maxNumRetries=Env.hyperSyncClientMaxRetries,
181-
~httpReqTimeoutMillis=Env.hyperSyncClientTimeoutMillis,
182-
~enableChecksumAddresses=false,
183-
)
184-
} else {
185-
HyperSyncClient.make(
186-
~url=endpointUrl,
187-
~apiToken,
188-
~maxNumRetries=Env.hyperSyncClientMaxRetries,
189-
~httpReqTimeoutMillis=Env.hyperSyncClientTimeoutMillis,
190-
~enableChecksumAddresses=true,
191-
)
192-
}
175+
let client = HyperSyncClient.make(
176+
~url=endpointUrl,
177+
~apiToken,
178+
~maxNumRetries=Env.hyperSyncClientMaxRetries,
179+
~httpReqTimeoutMillis=Env.hyperSyncClientTimeoutMillis,
180+
~enableChecksumAddresses=!lowercaseAddresses,
181+
)
193182

194183
let hscDecoder: ref<option<HyperSyncClient.Decoder.t>> = ref(None)
195184
let getHscDecoder = () => {

0 commit comments

Comments
 (0)