Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion dex/testing/dcrdex/harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,23 @@ EOF
fi

if [ $ETH_ON -eq 0 ]; then

ETH_CONFIG_PATH=${TEST_ROOT}/eth.conf
ETH_IPC_FILE=${TEST_ROOT}/eth/alpha/node/geth.ipc
cat << EOF >> $ETH_CONFIG_PATH
ws://localhost:38557
# comments are respected
# http://localhost:38556
${ETH_IPC_FILE}
EOF
cat << EOF >> "./markets.json"
},
"ETH_simnet": {
"bip44symbol": "eth",
"network": "simnet",
"maxFeeRate": 200,
"swapConf": 2,
"configPath": "ws://localhost:38557"
"configPath": "$ETH_CONFIG_PATH"
},
"DEXTT_simnet": {
"bip44symbol": "dextt.eth",
Expand Down
7 changes: 1 addition & 6 deletions server/asset/eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
package eth

import (
"path/filepath"

"github.com/decred/dcrd/dcrutil/v4"
)

var (
ethHomeDir = dcrutil.AppDataDir("ethereum", false)
defaultIPC = filepath.Join(ethHomeDir, "geth/geth.ipc")
)
var ethHomeDir = dcrutil.AppDataDir("ethereum", false)

// For tokens, the file at the config path can contain overrides for
// token gas values. Gas used for token swaps is dependent on the token contract
Expand Down
38 changes: 30 additions & 8 deletions server/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
package eth

import (
"bufio"
"bytes"
"context"
"crypto/sha256"
"errors"
"fmt"
"math/big"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -161,7 +163,7 @@ type ethFetcher interface {
bestHeader(ctx context.Context) (*types.Header, error)
blockNumber(ctx context.Context) (uint64, error)
headerByHeight(ctx context.Context, height uint64) (*types.Header, error)
connect(ctx context.Context, log dex.Logger) error
connect(ctx context.Context) error
shutdown()
suggestGasTipCap(ctx context.Context) (*big.Int, error)
syncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
Expand Down Expand Up @@ -265,7 +267,7 @@ func unconnectedETH(logger dex.Logger, net dex.Network) (*ETHBackend, error) {

// NewBackend is the exported constructor by which the DEX will import the
// Backend.
func NewBackend(endpoint string, logger dex.Logger, net dex.Network) (*ETHBackend, error) {
func NewBackend(configPath string, log dex.Logger, net dex.Network) (*ETHBackend, error) {
switch net {
case dex.Simnet:
case dex.Testnet:
Expand All @@ -276,15 +278,34 @@ func NewBackend(endpoint string, logger dex.Logger, net dex.Network) (*ETHBacken
return nil, fmt.Errorf("unknown network ID: %d", net)
}

if endpoint == "" {
endpoint = defaultIPC
file, err := os.Open(configPath)
if err != nil {
return nil, err
}
defer file.Close()

var endpoints []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.Trim(scanner.Text(), " ")
if line == "" || strings.HasPrefix(line, "#") {
continue
Comment thread
chappjc marked this conversation as resolved.
}
endpoints = append(endpoints, line)
}
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("error reading eth config file at %q. %v", configPath, err)
}
if len(endpoints) == 0 {
return nil, fmt.Errorf("no endpoint found in the eth config file at %q", configPath)
}
log.Debugf("Parsed %d endpoints from the ETH config file", len(endpoints))

eth, err := unconnectedETH(logger, net)
eth, err := unconnectedETH(log, net)
if err != nil {
return nil, err
}
eth.node = newRPCClient(eth.net, endpoint)
eth.node = newRPCClient(eth.net, endpoints, log.SubLogger("RPC"))
return eth, nil
}

Expand All @@ -296,7 +317,7 @@ func (eth *baseBackend) shutdown() {
func (eth *ETHBackend) Connect(ctx context.Context) (*sync.WaitGroup, error) {
eth.baseBackend.ctx = ctx

if err := eth.node.connect(ctx, eth.log); err != nil {
if err := eth.node.connect(ctx); err != nil {
return nil, err
}

Expand Down Expand Up @@ -338,7 +359,8 @@ func (eth *TokenBackend) Connect(ctx context.Context) (*sync.WaitGroup, error) {
}

// TokenBackend creates an *AssetBackend for a token. Part of the
// asset.TokenBacker interface.
// asset.TokenBacker interface. Do not call TokenBackend concurrently for the
// same asset.
func (eth *ETHBackend) TokenBackend(assetID uint32, configPath string) (asset.Backend, error) {
if _, found := eth.baseBackend.tokens[assetID]; found {
return nil, fmt.Errorf("asset %d backend already loaded", assetID)
Expand Down
2 changes: 1 addition & 1 deletion server/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type testNode struct {
acctBalErr error
}

func (n *testNode) connect(ctx context.Context, log dex.Logger) error {
func (n *testNode) connect(ctx context.Context) error {
return n.connectErr
}

Expand Down
Loading