cic-go/provider/provider.go
Mohammed Sohail 3601b61c20
refactor: rpc provider
- provider now lives on its own
- existing modules need the provider as a param
2022-05-18 12:50:45 +03:00

49 lines
807 B
Go

package provider
import (
"crypto/ecdsa"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/lmittmann/w3"
)
const (
kitabuMainnetChainId = 6060
)
type Provider struct {
EthClient *w3.Client
Signer types.Signer
}
type WriteTx struct {
From common.Address
To common.Address
GasLimit uint64
Nonce uint64
PrivateKey ecdsa.PrivateKey
}
func NewRpcProvider(rpcEndpoint string) (*Provider, error) {
ethClient, err := w3.Dial(rpcEndpoint)
if err != nil {
return nil, err
}
return &Provider{
EthClient: ethClient,
Signer: types.NewEIP155Signer(big.NewInt(kitabuMainnetChainId)),
}, nil
}
func (c *Provider) CLose() error {
err := c.EthClient.Close()
if err != nil {
return err
}
return nil
}