Skip to content

Commit

Permalink
TRD-558 add log for rpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
linhnt3400 committed Sep 9, 2024
1 parent b99bcdd commit 6375dcc
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/tradelogs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func run(c *cli.Context) error {
ethClients[i] = client
}

traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClients...))
traceCalls := tracecall.NewCache(rpcnode.NewClient(l, ethClients...))

parsers := []parser.Parser{kyberswap.MustNewParser(),
zxotc.MustNewParser(),
Expand Down
9 changes: 5 additions & 4 deletions pkg/parser/bebop/bebop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/test-go/testify/require"
"go.uber.org/zap"
)

const rpcURL = ""
Expand All @@ -24,7 +25,7 @@ func TestFetchEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
require.Equal(t, p.abi.Events[TradeEvent].ID, common.HexToHash("0xadd7095becdaa725f0f33243630938c861b0bba83dfd217d4055701aa768ec2e"))
client, err := ethclient.Dial(rpcURL)
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestParseAggregateOrderEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
log, err := p.Parse(events, uint64(time.Now().Unix()))
require.NoError(t, err)
Expand All @@ -79,7 +80,7 @@ func TestParseMultiOrderEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
log, err := p.Parse(events, uint64(time.Now().Unix()))
require.NoError(t, err)
Expand All @@ -102,7 +103,7 @@ func TestParseSingleOrderEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
log, err := p.Parse(events, uint64(time.Now().Unix()))
require.NoError(t, err)
Expand Down
9 changes: 5 additions & 4 deletions pkg/parser/oneinch/oneinch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/KyberNetwork/tradelogs/pkg/tracecall"
tradelogstype "github.com/KyberNetwork/tradelogs/pkg/types"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"go.uber.org/zap"
)

const rpcURL = ""
Expand All @@ -29,7 +30,7 @@ func TestFetchEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
require.Equal(t, p.abi.Events[FilledEvent].ID, common.HexToHash("0xc3b639f02b125bfa160e50739b8c44eb2d1b6908e2b6d5925c6d770f2ca78127"))
client, err := ethclient.Dial(rpcURL)
Expand Down Expand Up @@ -69,7 +70,7 @@ func TestParseEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
log, err := p.Parse(event, uint64(time.Now().Unix()))
require.NoError(t, err)
Expand All @@ -83,7 +84,7 @@ func TestParseOneinchTradeLog(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
client, err := ethclient.Dial(rpcURL)
require.NoError(t, err)
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestParseWithCallFrame(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
client, err := ethclient.Dial(rpcURL)
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/parser/oneinchv6/oneinchv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

const rpcURL = ""
Expand All @@ -24,7 +25,7 @@ func TestFetchEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
require.Equal(t, p.abi.Events[FilledEvent].ID, common.HexToHash("0xfec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e07"))
client, err := ethclient.Dial(rpcURL)
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestParseEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
for _, event := range events {
log, err := p.Parse(event, uint64(time.Now().Unix()))
Expand Down
5 changes: 3 additions & 2 deletions pkg/parser/uniswapx/uniswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

const rpcURL = ""
Expand All @@ -24,7 +25,7 @@ func TestFetchEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
require.Equal(t, p.abi.Events[FilledEvent].ID, common.HexToHash("0x78ad7ec0e9f89e74012afa58738b6b661c024cb0fd185ee2f616c0a28924bd66"))
logs, err := ethClient.FilterLogs(context.Background(), ethereum.FilterQuery{
Expand Down Expand Up @@ -54,7 +55,7 @@ func TestParseEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
log, err := p.Parse(event, 1713889895)
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/parser/uniswapx_v1/uniswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

const rpcURL = ""
Expand All @@ -24,7 +25,7 @@ func TestFetchEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
require.Equal(t, p.abi.Events[FilledEvent].ID, common.HexToHash("0x78ad7ec0e9f89e74012afa58738b6b661c024cb0fd185ee2f616c0a28924bd66"))
logs, err := ethClient.FilterLogs(context.Background(), ethereum.FilterQuery{
Expand Down Expand Up @@ -54,7 +55,7 @@ func TestParseEvent(t *testing.T) {
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
log, err := p.Parse(event, 1713889895)
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/parser/zxrfqv3/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

const rpcURL = ""
Expand All @@ -25,7 +26,7 @@ func newParserTest(t *testing.T, contractABI ContractABI, needRpc bool) *Parser
if err != nil {
panic(err)
}
cache = tracecall.NewCache(rpcnode.NewClient(ethClient))
cache = tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
}
return MustNewParser(cache, contractABI)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/rpcnode/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import (

"github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum/ethclient"
"go.uber.org/zap"
)

type Client struct {
l *zap.SugaredLogger
ethClient []*ethclient.Client
}

func NewClient(ethClient ...*ethclient.Client) *Client {
func NewClient(l *zap.SugaredLogger, ethClient ...*ethclient.Client) *Client {
return &Client{
l: l,
ethClient: ethClient,
}
}
Expand All @@ -22,14 +25,15 @@ func (c *Client) FetchTraceCall(ctx context.Context, txHash string) (types.CallF
result types.CallFrame
err error
)
for _, ethClient := range c.ethClient {
for i, ethClient := range c.ethClient {
err = ethClient.Client().CallContext(ctx, &result, "debug_traceTransaction", txHash, map[string]interface{}{
"tracer": "callTracer",
"tracerConfig": map[string]interface{}{
"withLog": true,
},
})
if err != nil {
c.l.Errorw("fetch trace call failed", "error", err, "txHash", txHash, "clientID", i)
continue
}
return result, nil
Expand Down

0 comments on commit 6375dcc

Please sign in to comment.