Skip to content

Commit

Permalink
simplify transmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
makramkd committed Jul 15, 2024
1 parent 58e96b3 commit cbc6a3e
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions core/services/ccipcapability/ocrimpls/contract_transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,21 @@ import (
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
)

type Calldata interface {
ToAny() any
}

type commitCalldata struct {
ReportContext [3][32]byte
Report []byte
Rs [][32]byte
Ss [][32]byte
RawVs [32]byte
}

func (c commitCalldata) ToAny() any {
return c
}

type execCalldata struct {
ReportContext [3][32]byte
Report []byte
}

func (e execCalldata) ToAny() any {
return e
}

type ToCalldataFunc func(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte, vs [32]byte) Calldata

func ToCommitCalldata(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte, vs [32]byte) Calldata {
return commitCalldata{
type ToCalldataFunc func(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte, vs [32]byte) any

func ToCommitCalldata(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte, vs [32]byte) any {
// Note that the name of the struct field is very important, since the encoder used
// by the chainwriter uses mapstructure, which will use the struct field name to map
// to the argument name in the function call.
// If, for whatever reason, we want to change the field name, make sure to add a `mapstructure:"<arg_name>"` tag
// for that field.
return struct {
ReportContext [3][32]byte
Report []byte
Rs [][32]byte
Ss [][32]byte
RawVs [32]byte
}{
ReportContext: rawReportCtx,
Report: report,
Rs: rs,
Expand All @@ -52,8 +38,16 @@ func ToCommitCalldata(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte
}
}

func ToExecCalldata(rawReportCtx [3][32]byte, report []byte, _, _ [][32]byte, _ [32]byte) Calldata {
return execCalldata{
func ToExecCalldata(rawReportCtx [3][32]byte, report []byte, _, _ [][32]byte, _ [32]byte) any {
// Note that the name of the struct field is very important, since the encoder used
// by the chainwriter uses mapstructure, which will use the struct field name to map
// to the argument name in the function call.
// If, for whatever reason, we want to change the field name, make sure to add a `mapstructure:"<arg_name>"` tag
// for that field.
return struct {
ReportContext [3][32]byte
Report []byte
}{
ReportContext: rawReportCtx,
Report: report,
}
Expand Down

0 comments on commit cbc6a3e

Please sign in to comment.