Skip to content

Commit

Permalink
refactored CallFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
lmittmann committed Aug 31, 2023
1 parent 990d7ad commit 95ee218
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions module/eth/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ func msgArgsWrapper(slice []any) ([]any, error) {
// CallFunc requests the returns of Func f at common.Address contract with the
// given args.
func CallFunc(contract common.Address, f w3types.Func, args ...any) *CallFuncFactory {
return &CallFuncFactory{contract: contract, f: f, args: args}
return &CallFuncFactory{msg: &w3types.Message{
To: &contract,
Func: f,
Args: args,
}}
}

type CallFuncFactory struct {
// args
contract common.Address
f w3types.Func
args []any
msg *w3types.Message
atBlock *big.Int
overrides w3types.State

Expand All @@ -124,16 +126,14 @@ func (f *CallFuncFactory) Overrides(overrides w3types.State) *CallFuncFactory {
}

func (f *CallFuncFactory) CreateRequest() (rpc.BatchElem, error) {
input, err := f.f.EncodeArgs(f.args...)
input, err := f.msg.Func.EncodeArgs(f.msg.Args...)
if err != nil {
return rpc.BatchElem{}, err
}
f.msg.Input = input

args := []any{
&w3types.Message{
To: &f.contract,
Input: input,
},
f.msg,
module.BlockNumberArg(f.atBlock),
}
if len(f.overrides) > 0 {
Expand All @@ -152,7 +152,7 @@ func (f *CallFuncFactory) HandleResponse(elem rpc.BatchElem) error {
return err
}

if err := f.f.DecodeReturns(f.result, f.returns...); err != nil {
if err := f.msg.Func.DecodeReturns(f.result, f.returns...); err != nil {
return err
}
return nil
Expand Down

0 comments on commit 95ee218

Please sign in to comment.