-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheth_eoa_transactor.go
63 lines (51 loc) · 1.97 KB
/
eth_eoa_transactor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package walletutils
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)
type EthClientShimEthEoa struct {
EthClientShimMethods
ethClient *ethclient.Client
}
// NewEthWalletTransactor is a utility method to easily create transaction
// options for use with an Ethereum wallet with an optional passphrase.
func NewEthWalletTransactor(wallet accounts.Wallet, account *accounts.Account, passphrase string, chainID *big.Int, ethClient *ethclient.Client) (*EthClientShim, *bind.TransactOpts, error) {
if chainID == nil {
return nil, nil, bind.ErrNoChainID
}
shimImpl := &EthClientShimEthEoa{ethClient: ethClient}
shimmedEthClient := &EthClientShim{
Client: ethClient,
shim: shimImpl,
}
opts := &bind.TransactOpts{
From: account.Address,
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
if address != account.Address {
return nil, bind.ErrNotAuthorized
}
return wallet.SignTxWithPassphrase(*account, passphrase, tx, chainID)
},
Context: context.Background(),
}
return shimmedEthClient, opts, nil
}
// EthClientShimEthEoa does not actually shim the ethclient, it just provides type consistency for consumers of this package
func (c *EthClientShimEthEoa) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
return c.ethClient.PendingNonceAt(ctx, account)
}
func (c *EthClientShimEthEoa) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) {
return c.ethClient.EstimateGas(ctx, call)
}
func (c *EthClientShimEthEoa) SendTransaction(ctx context.Context, tx *types.Transaction) error {
return c.ethClient.SendTransaction(ctx, tx)
}
func (c *EthClientShimEthEoa) GetOuterTxHash(innerHash common.Hash) common.Hash {
return innerHash
}