use batchElem from rpc client

This commit is contained in:
Taka Goto 2019-01-21 14:52:37 -06:00
parent 54d771cb06
commit 3595771825
6 changed files with 30 additions and 16 deletions

View File

@ -2,12 +2,12 @@ package core
import ( import (
"context" "context"
"github.com/ethereum/go-ethereum/rpc" "github.com/vulcanize/vulcanizedb/pkg/geth/client"
) )
type RpcClient interface { type RpcClient interface {
CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
BatchCall(batch []rpc.BatchElem) error BatchCall(batch []client.BatchElem) error
IpcPath() string IpcPath() string
SupportedModules() (map[string]string, error) SupportedModules() (map[string]string, error)
} }

View File

@ -7,8 +7,8 @@ import (
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
) )
type MockEthClient struct { type MockEthClient struct {
@ -33,7 +33,7 @@ type MockEthClient struct {
filterLogsReturnLogs []types.Log filterLogsReturnLogs []types.Log
transactionReceipts map[string]*types.Receipt transactionReceipts map[string]*types.Receipt
err error err error
passedBatch []rpc.BatchElem passedBatch []client.BatchElem
passedMethod string passedMethod string
transactionSenderErr error transactionSenderErr error
transactionReceiptErr error transactionReceiptErr error
@ -122,7 +122,7 @@ func (client *MockEthClient) CallContract(ctx context.Context, msg ethereum.Call
return client.callContractReturnBytes, client.callContractErr return client.callContractReturnBytes, client.callContractErr
} }
func (client *MockEthClient) BatchCall(batch []rpc.BatchElem) error { func (client *MockEthClient) BatchCall(batch []client.BatchElem) error {
client.passedBatch = batch client.passedBatch = batch
client.passedMethod = batch[0].Method client.passedMethod = batch[0].Method

View File

@ -2,7 +2,7 @@ package fakes
import ( import (
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
) )

View File

@ -8,8 +8,8 @@ import (
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/ethereum/go-ethereum/rpc"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
) )
type MockRpcClient struct { type MockRpcClient struct {
@ -19,7 +19,7 @@ type MockRpcClient struct {
passedContext context.Context passedContext context.Context
passedMethod string passedMethod string
passedResult interface{} passedResult interface{}
passedBatch []rpc.BatchElem passedBatch []client.BatchElem
lengthOfBatch int lengthOfBatch int
returnPOAHeader core.POAHeader returnPOAHeader core.POAHeader
returnPOAHeaders []core.POAHeader returnPOAHeaders []core.POAHeader
@ -35,7 +35,7 @@ func (client *MockRpcClient) SetIpcPath(ipcPath string) {
client.ipcPath = ipcPath client.ipcPath = ipcPath
} }
func (client *MockRpcClient) BatchCall(batch []rpc.BatchElem) error { func (client *MockRpcClient) BatchCall(batch []client.BatchElem) error {
client.passedBatch = batch client.passedBatch = batch
client.passedMethod = batch[0].Method client.passedMethod = batch[0].Method
client.lengthOfBatch = len(batch) client.lengthOfBatch = len(batch)

View File

@ -8,8 +8,8 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
vulcCommon "github.com/vulcanize/vulcanizedb/pkg/geth/converters/common" vulcCommon "github.com/vulcanize/vulcanizedb/pkg/geth/converters/common"
"golang.org/x/net/context" "golang.org/x/net/context"
"strconv" "strconv"
@ -68,7 +68,7 @@ func (blockChain *BlockChain) getPOWHeader(blockNumber int64) (header core.Heade
} }
func (blockChain *BlockChain) getPOWHeaders(blockNumbers []int64) (headers []core.Header, err error) { func (blockChain *BlockChain) getPOWHeaders(blockNumbers []int64) (headers []core.Header, err error) {
var batch []rpc.BatchElem var batch []client.BatchElem
var POWHeaders [MAX_BATCH_SIZE]types.Header var POWHeaders [MAX_BATCH_SIZE]types.Header
includeTransactions := false includeTransactions := false
@ -80,7 +80,7 @@ func (blockChain *BlockChain) getPOWHeaders(blockNumbers []int64) (headers []cor
blockNumberArg := hexutil.EncodeBig(big.NewInt(blockNumber)) blockNumberArg := hexutil.EncodeBig(big.NewInt(blockNumber))
batchElem := rpc.BatchElem{ batchElem := client.BatchElem{
Method: "eth_getBlockByNumber", Method: "eth_getBlockByNumber",
Result: &POWHeaders[index], Result: &POWHeaders[index],
Args: []interface{}{blockNumberArg, includeTransactions}, Args: []interface{}{blockNumberArg, includeTransactions},
@ -135,7 +135,7 @@ func (blockChain *BlockChain) getPOAHeader(blockNumber int64) (header core.Heade
func (blockChain *BlockChain) getPOAHeaders(blockNumbers []int64) (headers []core.Header, err error) { func (blockChain *BlockChain) getPOAHeaders(blockNumbers []int64) (headers []core.Header, err error) {
var batch []rpc.BatchElem var batch []client.BatchElem
var POAHeaders [MAX_BATCH_SIZE]core.POAHeader var POAHeaders [MAX_BATCH_SIZE]core.POAHeader
includeTransactions := false includeTransactions := false
@ -147,7 +147,7 @@ func (blockChain *BlockChain) getPOAHeaders(blockNumbers []int64) (headers []cor
blockNumberArg := hexutil.EncodeBig(big.NewInt(blockNumber)) blockNumberArg := hexutil.EncodeBig(big.NewInt(blockNumber))
batchElem := rpc.BatchElem{ batchElem := client.BatchElem{
Method: "eth_getBlockByNumber", Method: "eth_getBlockByNumber",
Result: &POAHeaders[index], Result: &POAHeaders[index],
Args: []interface{}{blockNumberArg, includeTransactions}, Args: []interface{}{blockNumberArg, includeTransactions},

View File

@ -10,6 +10,13 @@ type RpcClient struct {
ipcPath string ipcPath string
} }
type BatchElem struct {
Method string
Args []interface{}
Result interface{}
Error error
}
func NewRpcClient(client *rpc.Client, ipcPath string) RpcClient { func NewRpcClient(client *rpc.Client, ipcPath string) RpcClient {
return RpcClient{ return RpcClient{
client: client, client: client,
@ -36,6 +43,13 @@ func (client RpcClient) SupportedModules() (map[string]string, error) {
return client.client.SupportedModules() return client.client.SupportedModules()
} }
func (client RpcClient) BatchCall(batch []rpc.BatchElem) error { func (client RpcClient) BatchCall(batch []BatchElem) error {
return client.client.BatchCall(batch) var rpcBatch []rpc.BatchElem
for index, batchElem := range batch {
rpcBatch[index].Result = batchElem.Result
rpcBatch[index].Method = batchElem.Method
rpcBatch[index].Args = batchElem.Args
rpcBatch[index].Error = batchElem.Error
}
return client.client.BatchCall(rpcBatch)
} }