Skip to content

Commit

Permalink
Rename client to rpcclient.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Mar 11, 2021
1 parent e8885a0 commit d451fac
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
9 changes: 6 additions & 3 deletions dex/testing/eth/create-node.sh
Expand Up @@ -19,6 +19,8 @@ GROUP_DIR="${NODES_ROOT}/${NAME}"
MINE_JS="${GROUP_DIR}/mine.js"
NODE_DIR="${GROUP_DIR}/node"
mkdir -p "${NODE_DIR}"
mkdir -p "${NODE_DIR}/keystore"
mkdir -p "${NODE_DIR}/geth"

# Write node ctl script.
cat > "${NODES_ROOT}/harness-ctl/${NAME}" <<EOF
Expand Down Expand Up @@ -124,14 +126,15 @@ EOF

echo "Starting simnet ${NAME} node"
if [ "${SYNC_MODE}" = "fast" ]; then
# Start the eth node with both accounts unlocked, listening restricted to
# localhost, and syncmode set to fast.
# Start the eth node with the chain account unlocked, listening restricted to
# localhost, and our custom configuration file.
tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} --nodiscover " \
"--config ${NODE_DIR}/eth.conf --unlock ${CHAIN_ADDRESS} " \
"--password ${GROUP_DIR}/password --light.serve 25" C-m

else
# Start the eth node listening restricted to localhost, and syncmode set to light.
# Start the eth node listening restricted to localhost and our custom
# configuration file.
tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} --nodiscover " \
"--config ${NODE_DIR}/eth.conf" C-m
fi
4 changes: 0 additions & 4 deletions dex/testing/eth/harness.sh
Expand Up @@ -169,10 +169,6 @@ echo "Sending 5000 eth to beta and gamma."
"${NODES_ROOT}/harness-ctl/alpha" "attach --preload ${NODES_ROOT}/harness-ctl/send.js --exec send(\"${ALPHA_ADDRESS}\",\"${GAMMA_ADDRESS}\",${SEND_AMT})"
"${NODES_ROOT}/harness-ctl/alpha" "attach --preload ${NODES_ROOT}/harness-ctl/send.js --exec send(\"${ALPHA_ADDRESS}\",\"${DELTA_ADDRESS}\",${SEND_AMT})"

# TODO: After we start mining blocks on alpha, it seems that we can never mine
# blocks on beta. Doing so sends alpha into some sort of error mode. Find out
# why that is and correct it if a settings miss.
#
# Our transactions will PROBABLY appear in one of these blocks.
echo "Mining some blocks"
"${NODES_ROOT}/harness-ctl/mine-alpha" "15"
Expand Down
9 changes: 7 additions & 2 deletions server/asset/eth/eth.go
Expand Up @@ -47,7 +47,7 @@ func (d *Driver) DecodeCoinID(coinID []byte) (string, error) {
}

// ethFetcher represents a blockchain information fetcher. In practice, it is
// satisfied by client. For testing, it can be satisfied by a stub.
// satisfied by rpcclient. For testing, it can be satisfied by a stub.
type ethFetcher interface {
Shutdown()
Connect(ctx context.Context, IPC string) error
Expand Down Expand Up @@ -104,7 +104,7 @@ func (eth *Backend) shutdown() {

// Connect connects to the node RPC server. A dex.Connector.
func (eth *Backend) Connect(ctx context.Context) (*sync.WaitGroup, error) {
c := client{}
c := rpcclient{}
if err := c.Connect(ctx, eth.cfg.IPC); err != nil {
return nil, err
}
Expand Down Expand Up @@ -135,6 +135,11 @@ func (eth *Backend) Connect(ctx context.Context) (*sync.WaitGroup, error) {
return &wg, nil
}

// TxData fetches the raw transaction data.
func (eth *Backend) TxData(coinID []byte) ([]byte, error) {
return nil, notImplementedErr
}

// InitTxSize is an asset.Backend method that must produce the max size of a
// standardized atomic swap initialization transaction.
func (eth *Backend) InitTxSize() uint32 {
Expand Down
16 changes: 8 additions & 8 deletions server/asset/eth/client.go → server/asset/eth/rpcclient.go
Expand Up @@ -14,16 +14,16 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

// Check that client satisfies the ethFetcher interface.
var _ ethFetcher = (*client)(nil)
// Check that rpcclient satisfies the ethFetcher interface.
var _ ethFetcher = (*rpcclient)(nil)

type client struct {
type rpcclient struct {
ec *ethclient.Client
}

// Connect connects to an ipc socket. It then wraps ethclient's client and
// bundles commands in a form we can easil use.
func (c *client) Connect(ctx context.Context, IPC string) error {
func (c *rpcclient) Connect(ctx context.Context, IPC string) error {
client, err := rpc.DialIPC(ctx, IPC)
if err != nil {
return fmt.Errorf("unable to dial rpc: %v", err)
Expand All @@ -34,23 +34,23 @@ func (c *client) Connect(ctx context.Context, IPC string) error {
}

// Shutdown shuts down the client.
func (c *client) Shutdown() {
func (c *rpcclient) Shutdown() {
if c.ec != nil {
c.ec.Close()
}
}

// BestBlockHash gets the best blocks hash at the time of calling. Due to the
// speed of Ethereum blocks, this changes often.
func (c *client) BestBlockHash(ctx context.Context) (common.Hash, error) {
func (c *rpcclient) BestBlockHash(ctx context.Context) (common.Hash, error) {
header, err := c.bestHeader(ctx)
if err != nil {
return common.Hash{}, err
}
return header.Hash(), nil
}

func (c *client) bestHeader(ctx context.Context) (*types.Header, error) {
func (c *rpcclient) bestHeader(ctx context.Context) (*types.Header, error) {
bn, err := c.ec.BlockNumber(ctx)
if err != nil {
return nil, err
Expand All @@ -63,7 +63,7 @@ func (c *client) bestHeader(ctx context.Context) (*types.Header, error) {
}

// Block gets the block identified by hash.
func (c *client) Block(ctx context.Context, hash common.Hash) (*types.Block, error) {
func (c *rpcclient) Block(ctx context.Context, hash common.Hash) (*types.Block, error) {
block, err := c.ec.BlockByHash(ctx, hash)
if err != nil {
return nil, err
Expand Down
Expand Up @@ -17,7 +17,7 @@ import (
var (
homeDir = os.Getenv("HOME")
ipc = filepath.Join(homeDir, "dextest/eth/alpha/node/geth.ipc")
ethClient = new(client)
ethClient = new(rpcclient)
ctx context.Context
)

Expand Down

0 comments on commit d451fac

Please sign in to comment.