Skip to content

Commit

Permalink
Add encoder defs for events
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Jan 9, 2024
1 parent 30d2c26 commit dd99acc
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions core/services/relay/evm/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (cr *chainReader) addMethod(
client: cr.client,
})

if err := cr.addEncoderDef(contractName, methodName, method, chainReaderDefinition); err != nil {
if err := cr.addMethodEncoderDef(contractName, methodName, method, chainReaderDefinition); err != nil {
return err
}

Expand All @@ -170,10 +170,15 @@ func (cr *chainReader) addEvent(contractName, eventName string, abi abi.ABI, cha
lp: cr.lp,
hash: event.ID,
})

if err := cr.addEventEncoderDef(contractName, eventName, event, chainReaderDefinition); err != nil {
return err
}

return cr.addDecoderDef(contractName, eventName, event.Inputs, chainReaderDefinition)
}

func (cr *chainReader) addEncoderDef(contractName, methodName string, method abi.Method, chainReaderDefinition types.ChainReaderDefinition) error {
func (cr *chainReader) addMethodEncoderDef(contractName, methodName string, method abi.Method, chainReaderDefinition types.ChainReaderDefinition) error {
// ABI.Pack prepends the method.ID to the encodings, we'll need the encoder to do the same.
input := &codecEntry{Args: method.Inputs, encodingPrefix: method.ID}

Expand All @@ -190,6 +195,24 @@ func (cr *chainReader) addEncoderDef(contractName, methodName string, method abi
return nil
}

func (cr *chainReader) addEventEncoderDef(contractName, methodName string, event abi.Event, chainReaderDefinition types.ChainReaderDefinition) error {
// prepend event sig as encodingPrefix
input := &codecEntry{Args: event.Inputs, encodingPrefix: event.ID.Bytes()}

if err := input.Init(); err != nil {
return err
}

inputMod, err := chainReaderDefinition.InputModifications.ToModifier(evmDecoderHooks...)
if err != nil {
return err
}
input.mod = inputMod

cr.parsed.encoderDefs[wrapItemType(contractName, methodName, true)] = input
return nil
}

func (cr *chainReader) addDecoderDef(contractName, methodName string, outputs abi.Arguments, def types.ChainReaderDefinition) error {
output := &codecEntry{Args: outputs}
mod, err := def.OutputModifications.ToModifier(evmDecoderHooks...)
Expand Down

0 comments on commit dd99acc

Please sign in to comment.