mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-04-22 03:00:02 -04:00
removed --ethereum-chain-id flag (#201)
Removes the --ethereum-chain-id flag and updates the code to dynamically determines the chain ID using the ethereum endpoint.
This commit is contained in:
@@ -61,7 +61,6 @@ type Backend interface {
|
||||
// getters
|
||||
Ctx() context.Context
|
||||
Env() common.Environment
|
||||
ChainID() *big.Int
|
||||
CallOpts() *bind.CallOpts
|
||||
TxOpts() (*bind.TransactOpts, error)
|
||||
SwapManager() swap.Manager
|
||||
@@ -103,7 +102,6 @@ type backend struct {
|
||||
ethPrivKey *ecdsa.PrivateKey
|
||||
callOpts *bind.CallOpts
|
||||
ethAddress ethcommon.Address
|
||||
chainID *big.Int
|
||||
gasPrice *big.Int
|
||||
gasLimit uint64
|
||||
|
||||
@@ -125,7 +123,6 @@ type Config struct {
|
||||
EthereumClient *ethclient.Client
|
||||
EthereumPrivateKey *ecdsa.PrivateKey
|
||||
Environment common.Environment
|
||||
ChainID *big.Int
|
||||
GasPrice *big.Int
|
||||
GasLimit uint64
|
||||
|
||||
@@ -148,13 +145,16 @@ func NewBackend(cfg *Config) (Backend, error) {
|
||||
var (
|
||||
addr ethcommon.Address
|
||||
txOpts *txsender.TxOpts
|
||||
err error
|
||||
)
|
||||
if cfg.EthereumPrivateKey != nil {
|
||||
addr = common.EthereumPrivateKeyToAddress(cfg.EthereumPrivateKey)
|
||||
|
||||
chainID, err := cfg.EthereumClient.ChainID(cfg.Ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO: set gas limit + price based on network (#153)
|
||||
txOpts, err = txsender.NewTxOpts(cfg.EthereumPrivateKey, cfg.ChainID)
|
||||
txOpts, err = txsender.NewTxOpts(cfg.EthereumPrivateKey, chainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -175,7 +175,6 @@ func NewBackend(cfg *Config) (Backend, error) {
|
||||
Context: cfg.Ctx,
|
||||
},
|
||||
ethAddress: addr,
|
||||
chainID: cfg.ChainID,
|
||||
gasPrice: cfg.GasPrice,
|
||||
gasLimit: cfg.GasLimit,
|
||||
txOpts: txOpts,
|
||||
@@ -205,10 +204,6 @@ func (b *backend) CallOpts() *bind.CallOpts {
|
||||
return b.callOpts
|
||||
}
|
||||
|
||||
func (b *backend) ChainID() *big.Int {
|
||||
return b.chainID
|
||||
}
|
||||
|
||||
func (b *backend) Contract() *contracts.SwapFactory {
|
||||
return b.contract
|
||||
}
|
||||
@@ -307,7 +302,11 @@ func (b *backend) TransactionReceipt(ctx context.Context, txHash ethcommon.Hash)
|
||||
}
|
||||
|
||||
func (b *backend) TxOpts() (*bind.TransactOpts, error) {
|
||||
txOpts, err := bind.NewKeyedTransactorWithChainID(b.ethPrivKey, b.chainID)
|
||||
chainID, err := b.ethClient.ChainID(b.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
txOpts, err := bind.NewKeyedTransactorWithChainID(b.ethPrivKey, chainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -79,20 +79,6 @@ func (mr *MockBackendMockRecorder) CallOpts() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CallOpts", reflect.TypeOf((*MockBackend)(nil).CallOpts))
|
||||
}
|
||||
|
||||
// ChainID mocks base method.
|
||||
func (m *MockBackend) ChainID() *big.Int {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ChainID")
|
||||
ret0, _ := ret[0].(*big.Int)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ChainID indicates an expected call of ChainID.
|
||||
func (mr *MockBackendMockRecorder) ChainID() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainID", reflect.TypeOf((*MockBackend)(nil).ChainID))
|
||||
}
|
||||
|
||||
// ClearXMRDepositAddress mocks base method.
|
||||
func (m *MockBackend) ClearXMRDepositAddress(arg0 types.Hash) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@@ -73,7 +73,6 @@ func newTestXMRMaker(t *testing.T) *Instance {
|
||||
EthereumClient: ec,
|
||||
EthereumPrivateKey: pk,
|
||||
Environment: common.Development,
|
||||
ChainID: chainID,
|
||||
SwapContract: contract,
|
||||
SwapContractAddress: addr,
|
||||
SwapManager: pswap.NewManager(),
|
||||
|
||||
@@ -68,7 +68,6 @@ func newBackend(t *testing.T) backend.Backend {
|
||||
EthereumClient: ec,
|
||||
EthereumPrivateKey: pk,
|
||||
Environment: common.Development,
|
||||
ChainID: chainID,
|
||||
SwapManager: pswap.NewManager(),
|
||||
SwapContract: contract,
|
||||
SwapContractAddress: addr,
|
||||
@@ -95,7 +94,6 @@ func newXMRMakerBackend(t *testing.T) backend.Backend {
|
||||
EthereumClient: ec,
|
||||
EthereumPrivateKey: pk,
|
||||
Environment: common.Development,
|
||||
ChainID: chainID,
|
||||
SwapManager: pswap.NewManager(),
|
||||
SwapContract: contract,
|
||||
SwapContractAddress: addr,
|
||||
|
||||
Reference in New Issue
Block a user