Skip to content

Commit 7694c6e

Browse files
committed
Upgrade to avalanche rosetta v0.1.42
1 parent 637e364 commit 7694c6e

File tree

127 files changed

+20258
-1952
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+20258
-1952
lines changed

server/client/client.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,50 @@ import (
66
"strings"
77

88
"github.com/ava-labs/avalanchego/api/info"
9+
"github.com/ava-labs/avalanchego/ids"
910
"github.com/ava-labs/avalanchego/utils/rpc"
10-
ethtypes "github.com/ava-labs/coreth/core/types"
11+
"github.com/ava-labs/coreth/core/types"
1112
"github.com/ava-labs/coreth/interfaces"
12-
ethcommon "github.com/ethereum/go-ethereum/common"
13+
"github.com/ava-labs/coreth/plugin/evm"
14+
"github.com/ethereum/go-ethereum/common"
15+
16+
"github.com/ava-labs/avalanche-rosetta/constants"
1317
)
1418

1519
// Interface compliance
1620
var _ Client = &client{}
1721

1822
type Client interface {
19-
IsBootstrapped(context.Context, string, ...rpc.Option) (bool, error)
23+
// info.Client methods
24+
InfoClient
25+
2026
ChainID(context.Context) (*big.Int, error)
21-
BlockByHash(context.Context, ethcommon.Hash) (*ethtypes.Block, error)
22-
BlockByNumber(context.Context, *big.Int) (*ethtypes.Block, error)
23-
HeaderByHash(context.Context, ethcommon.Hash) (*ethtypes.Header, error)
24-
HeaderByNumber(context.Context, *big.Int) (*ethtypes.Header, error)
25-
TransactionByHash(context.Context, ethcommon.Hash) (*ethtypes.Transaction, bool, error)
26-
TransactionReceipt(context.Context, ethcommon.Hash) (*ethtypes.Receipt, error)
27+
BlockByHash(context.Context, common.Hash) (*types.Block, error)
28+
BlockByNumber(context.Context, *big.Int) (*types.Block, error)
29+
HeaderByHash(context.Context, common.Hash) (*types.Header, error)
30+
HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
31+
TransactionByHash(context.Context, common.Hash) (*types.Transaction, bool, error)
32+
TransactionReceipt(context.Context, common.Hash) (*types.Receipt, error)
2733
TraceTransaction(context.Context, string) (*Call, []*FlatCall, error)
2834
TraceBlockByHash(context.Context, string) ([]*Call, [][]*FlatCall, error)
29-
SendTransaction(context.Context, *ethtypes.Transaction) error
30-
BalanceAt(context.Context, ethcommon.Address, *big.Int) (*big.Int, error)
31-
NonceAt(context.Context, ethcommon.Address, *big.Int) (uint64, error)
35+
SendTransaction(context.Context, *types.Transaction) error
36+
BalanceAt(context.Context, common.Address, *big.Int) (*big.Int, error)
37+
NonceAt(context.Context, common.Address, *big.Int) (uint64, error)
3238
SuggestGasPrice(context.Context) (*big.Int, error)
3339
EstimateGas(context.Context, interfaces.CallMsg) (uint64, error)
3440
TxPoolContent(context.Context) (*TxPoolContent, error)
35-
GetNetworkName(context.Context, ...rpc.Option) (string, error)
36-
Peers(context.Context, ...rpc.Option) ([]info.Peer, error)
37-
GetContractInfo(ethcommon.Address, bool) (string, uint8, error)
41+
GetContractInfo(common.Address, bool) (string, uint8, error)
3842
CallContract(context.Context, interfaces.CallMsg, *big.Int) ([]byte, error)
43+
IssueTx(ctx context.Context, txBytes []byte, options ...rpc.Option) (ids.ID, error)
44+
GetAtomicUTXOs(ctx context.Context, addrs []ids.ShortID, sourceChain string, limit uint32, startAddress ids.ShortID, startUTXOID ids.ID, options ...rpc.Option) ([][]byte, ids.ShortID, ids.ID, error)
45+
EstimateBaseFee(ctx context.Context) (*big.Int, error)
3946
}
4047

48+
type EvmClient evm.Client
49+
4150
type client struct {
4251
info.Client
52+
EvmClient
4353
*EthClient
4454
*ContractClient
4555
}
@@ -53,8 +63,9 @@ func NewClient(ctx context.Context, endpoint string) (Client, error) {
5363
return nil, err
5464
}
5565

56-
return client{
66+
return &client{
5767
Client: info.NewClient(endpoint),
68+
EvmClient: evm.NewClient(endpoint, constants.CChain.String()),
5869
EthClient: eth,
5970
ContractClient: NewContractClient(eth.Client),
6071
}, nil

server/client/contract.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,28 @@ const (
1313
// ContractClient is a client for the calling contract information
1414
type ContractClient struct {
1515
ethClient ethclient.Client
16-
cache *cache.LRU
16+
cache *cache.LRU[common.Address, *ContractInfo]
17+
}
18+
19+
type ContractInfo struct {
20+
Symbol string
21+
Decimals uint8
1722
}
1823

1924
// NewContractClient returns a new ContractInfo client
2025
func NewContractClient(c ethclient.Client) *ContractClient {
2126
return &ContractClient{
2227
ethClient: c,
23-
cache: &cache.LRU{Size: contractCacheSize},
28+
cache: &cache.LRU[common.Address, *ContractInfo]{Size: contractCacheSize},
2429
}
2530
}
2631

2732
// GetContractInfo returns the symbol and decimals for [addr].
2833
func (c *ContractClient) GetContractInfo(addr common.Address, erc20 bool) (string, uint8, error) {
2934
// We don't define another struct because this is never used outside of this
3035
// function.
31-
type ContractInfo struct {
32-
Symbol string
33-
Decimals uint8
34-
}
35-
3636
if currency, cached := c.cache.Get(addr); cached {
37-
cast := currency.(*ContractInfo)
38-
return cast.Symbol, cast.Decimals, nil
37+
return currency.Symbol, currency.Decimals, nil
3938
}
4039

4140
token, err := NewContractInfoToken(addr, c.ethClient)

server/client/eth.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package client
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/ava-labs/coreth/eth/tracers"
87
"github.com/ava-labs/coreth/ethclient"
@@ -24,7 +23,7 @@ type EthClient struct {
2423

2524
// NewEthClient returns a new EVM client
2625
func NewEthClient(ctx context.Context, endpoint string) (*EthClient, error) {
27-
endpointURL := fmt.Sprintf("%s%s", endpoint, prefixEth)
26+
endpointURL := endpoint + prefixEth
2827

2928
c, err := rpc.DialContext(ctx, endpointURL)
3029
if err != nil {

server/client/info_client.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package client
2+
3+
import (
4+
"context"
5+
6+
"github.com/ava-labs/avalanchego/api/info"
7+
"github.com/ava-labs/avalanchego/ids"
8+
"github.com/ava-labs/avalanchego/utils/rpc"
9+
)
10+
11+
// InfoClient collects all Avalanchego info.Client methods common
12+
// to Rosetta Clients
13+
type InfoClient interface {
14+
GetBlockchainID(context.Context, string, ...rpc.Option) (ids.ID, error)
15+
IsBootstrapped(context.Context, string, ...rpc.Option) (bool, error)
16+
Peers(context.Context, ...rpc.Option) ([]info.Peer, error)
17+
}

0 commit comments

Comments
 (0)