Fuel merge part 6 - Codegen fuel event type - #155
Conversation
| @@ -0,0 +1 @@ | |||
|
|
|||
There was a problem hiding this comment.
Kept the file, so it's overwritten on the codegen (locally)
There was a problem hiding this comment.
Hmmm, does that mean we should always have empty files for things we remove? I would suggest just remove it. The cli handles cleaning stale generated files if the version changes.
| type interfaceAndAbi = { | ||
| interface: Ethers.Interface.t, | ||
| abi: Ethers.abi, | ||
| sighashes: array<string>, | ||
| } |
There was a problem hiding this comment.
This module doesn't look very useful anymore, probably we should refactor it in the future.
| let getAbiMapping = (self: t) => { | ||
| self.contractAddressMapping.nameByAddress | ||
| ->Js.Dict.entries | ||
| ->Belt.Array.keepMap(((addr, name)) => { | ||
| self.contractNameInterfaceMapping->Js.Dict.get(name)->Belt.Option.map(v => (addr, v.abi)) | ||
| }) | ||
| ->Js.Dict.fromArray | ||
| } |
| let {name, abi} = contract | ||
| let interface = Ethers.Interface.make(~abi) |
There was a problem hiding this comment.
With the change, we don't need to create the Ethers.Interface anymore. It was done at least on every getLogs request. Probably not a bottleneck, but definitely good to avoid it.
| let getLogSelection = (self: t): result<array<LogSelection.t>, exn> => { | ||
| try { | ||
| self.contractAddressMapping.addressesByName | ||
| ->Js.Dict.keys | ||
| ->Belt.Array.map(contractName => { | ||
| let interfaceOpt = self->getInterfaceByName(~contractName) | ||
| switch interfaceOpt { | ||
| | None => UndefinedInterface(contractName)->raise | ||
| | Some({interface}) => { | ||
| let topic0 = [] | ||
| //Add the topic hash from each event on the interface | ||
| interface->Ethers.Interface.forEachEvent((eventFragment, _i) => { | ||
| topic0->Js.Array2.push(eventFragment.topicHash)->ignore | ||
| }) | ||
|
|
||
| let topicSelection = LogSelection.makeTopicSelection(~topic0)->Utils.unwrapResultExn | ||
|
|
||
| let addresses = [] | ||
| //Add the addresses for each contract | ||
| self.contractAddressMapping | ||
| ->ContractAddressingMap.getAddressesFromContractName(~contractName) | ||
| ->Belt.Array.forEach(address => addresses->Js.Array2.push(address)->ignore) | ||
|
|
||
| LogSelection.make(~addresses, ~topicSelections=[topicSelection]) | ||
| } | ||
| } | ||
| }) | ||
| ->Ok | ||
| } catch { | ||
| | exn => exn->Error | ||
| } | ||
| } |
There was a problem hiding this comment.
Sorry, it'll most likely conflict with your changes. But I hope the new version will be more convenient to work with (moved to HyperSync worker)
|
|
||
| // TODO: Remove in v3 | ||
| @genType.import(("./OpaqueTypes.ts", "Address")) | ||
| @deprecated("Use Address.t instead. The type will be removed in v3") |
There was a problem hiding this comment.
Remembered about the attribute :)
|
Thanks @DZakh, I'll do a review in the morning. |
| // TODO: Clean up fuel_abi to include only relevant events | ||
| Ok((events, fuel_abi)) |
There was a problem hiding this comment.
I guess it's probably more complicated with a fuel abi to "treeshake" since there are lots types referencing each other.
I think the main reason I did it with evm code was so that there weren't some unknown discrepancies between defining values inline vs with a json ABI.
There was a problem hiding this comment.
It's possible, since there are a lot of things in the ABI we don't use
| #[derive(Debug, Clone, PartialEq)] | ||
| struct NormalizedEthAbiEvent(EthAbiEvent); |
There was a problem hiding this comment.
I see you've removed these type semantics. Just wanted to make you aware of the new type idiom in rust if you're not familiar: https://doc.rust-lang.org/rust-by-example/generics/new_types.html
It's useful in the sense that it shows when I use this type elsewhere that it's been parsed
| let signatures = abi.get_event_signatures(); | ||
|
|
||
| format!( | ||
| "let abi = Ethers.makeAbi((%raw(`{}`): Js.Json.t))\nlet eventSignatures = [{}]", |
There was a problem hiding this comment.
I don't really mind too much but sometimes these multiline template strings read easier with a rust raw string. Kind of like template strings in js. https://rahul-thakoor.github.io/rust-raw-string-literals/
| let topicSelection = LogSelection.makeTopicSelection(~topic0=contract.sighashes)->Utils.unwrapResultExn | ||
|
|
There was a problem hiding this comment.
Can we rather not unwrap here and then we don't need a try catch block below?
There was a problem hiding this comment.
Then we'll need to convert array<result<_>> to result<array<>>, so I prefer throwing exception. The array is not big here, but still I don't want to add unnecessary performance overhead.
JonoPrest
left a comment
There was a problem hiding this comment.
Awesome, looking good.
Types in the handler work 🔥

Almost 😅
It still doesn't compile, because the rescript-schema is not generated. Also, there needs to be an adjustment for the TestHelpers module. But after it's done, I'll start working on making the engine work 🚀