mirror of
https://github.com/grassrootseconomics/cic-go.git
synced 2024-11-22 05:56:46 +01:00
Mohamed Sohail
7eba3182ed
- provider now lives on its own - existing modules need the provider as a param
49 lines
807 B
Go
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
|
|
}
|