call.go 1.78 KB
Newer Older
1 2 3 4 5
package batching

import (
	"math/big"

6
	"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
7 8
	"github.com/ethereum/go-ethereum/accounts/abi"
	"github.com/ethereum/go-ethereum/common"
9
	"github.com/ethereum/go-ethereum/rpc"
10 11
)

12
type BatchElementCreator func(block rpcblock.Block) (any, rpc.BatchElem)
13

14 15 16
type Call interface {
	ToBatchElemCreator() (BatchElementCreator, error)
	HandleResult(interface{}) (*CallResult, error)
17 18
}

19 20 21 22 23 24 25 26 27 28 29 30
type CallResult struct {
	out []interface{}
}

func (c *CallResult) GetUint8(i int) uint8 {
	return *abi.ConvertType(c.out[i], new(uint8)).(*uint8)
}

func (c *CallResult) GetUint32(i int) uint32 {
	return *abi.ConvertType(c.out[i], new(uint32)).(*uint32)
}

Adrian Sutton's avatar
Adrian Sutton committed
31 32 33 34
func (c *CallResult) GetUint64(i int) uint64 {
	return *abi.ConvertType(c.out[i], new(uint64)).(*uint64)
}

35 36 37 38 39 40 41 42
func (c *CallResult) GetBool(i int) bool {
	return *abi.ConvertType(c.out[i], new(bool)).(*bool)
}

func (c *CallResult) GetHash(i int) common.Hash {
	return *abi.ConvertType(c.out[i], new([32]byte)).(*[32]byte)
}

43 44 45 46
func (c *CallResult) GetAddress(i int) common.Address {
	return *abi.ConvertType(c.out[i], new([20]byte)).(*[20]byte)
}

47 48 49
func (c *CallResult) GetBigInt(i int) *big.Int {
	return *abi.ConvertType(c.out[i], new(*big.Int)).(**big.Int)
}
50 51 52 53

func (c *CallResult) GetStruct(i int, target interface{}) {
	abi.ConvertType(c.out[i], target)
}
54

55 56 57 58
func (c *CallResult) GetBytes(i int) []byte {
	return *abi.ConvertType(c.out[i], new([]byte)).(*[]byte)
}

59 60 61
func (c *CallResult) GetBytes32(i int) [32]byte {
	return *abi.ConvertType(c.out[i], new([32]byte)).(*[32]byte)
}
62 63 64 65

func (c *CallResult) GetBytes32Slice(i int) [][32]byte {
	return *abi.ConvertType(c.out[i], new([][32]byte)).(*[][32]byte)
}
66 67 68 69

func (c *CallResult) GetString(i int) string {
	return *abi.ConvertType(c.out[i], new(string)).(*string)
}