fix support for eth testnet chains (use correct tx signer)
This commit is contained in:
parent
c4876739a1
commit
52b5c99760
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
||||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/btc"
|
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/btc"
|
||||||
@ -124,14 +123,18 @@ func NewPaylaodFetcher(chain shared.ChainType, client interface{}, timeout time.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewPayloadConverter constructs a PayloadConverter for the provided chain type
|
// NewPayloadConverter constructs a PayloadConverter for the provided chain type
|
||||||
func NewPayloadConverter(chain shared.ChainType) (shared.PayloadConverter, error) {
|
func NewPayloadConverter(chainType shared.ChainType, chainID uint64) (shared.PayloadConverter, error) {
|
||||||
switch chain {
|
switch chainType {
|
||||||
case shared.Ethereum:
|
case shared.Ethereum:
|
||||||
return eth.NewPayloadConverter(params.MainnetChainConfig), nil
|
chainConfig, err := eth.ChainConfig(chainID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return eth.NewPayloadConverter(chainConfig), nil
|
||||||
case shared.Bitcoin:
|
case shared.Bitcoin:
|
||||||
return btc.NewPayloadConverter(&chaincfg.MainNetParams), nil
|
return btc.NewPayloadConverter(&chaincfg.MainNetParams), nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("invalid chain %s for converter constructor", chain.String())
|
return nil, fmt.Errorf("invalid chain %s for converter constructor", chainType.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +191,7 @@ func NewIPLDPublisher(chain shared.ChainType, ipfsPath string, db *postgres.DB,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewPublicAPI constructs a PublicAPI for the provided chain type
|
// NewPublicAPI constructs a PublicAPI for the provided chain type
|
||||||
func NewPublicAPI(chain shared.ChainType, db *postgres.DB, ipfsPath string) (rpc.API, error) {
|
func NewPublicAPI(chain shared.ChainType, db *postgres.DB) (rpc.API, error) {
|
||||||
switch chain {
|
switch chain {
|
||||||
case shared.Ethereum:
|
case shared.Ethereum:
|
||||||
backend, err := eth.NewEthBackend(db)
|
backend, err := eth.NewEthBackend(db)
|
||||||
|
@ -16,7 +16,11 @@
|
|||||||
|
|
||||||
package eth
|
package eth
|
||||||
|
|
||||||
import "github.com/ethereum/go-ethereum/statediff"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff"
|
||||||
|
)
|
||||||
|
|
||||||
func ResolveFromNodeType(nodeType statediff.NodeType) int {
|
func ResolveFromNodeType(nodeType statediff.NodeType) int {
|
||||||
switch nodeType {
|
switch nodeType {
|
||||||
@ -47,3 +51,19 @@ func ResolveToNodeType(nodeType int) statediff.NodeType {
|
|||||||
return statediff.Unknown
|
return statediff.Unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChainConfig returns the appropriate ethereum chain config for the provided chain id
|
||||||
|
func ChainConfig(chainID uint64) (*params.ChainConfig, error) {
|
||||||
|
switch chainID {
|
||||||
|
case 1:
|
||||||
|
return params.MainnetChainConfig, nil
|
||||||
|
case 3:
|
||||||
|
return params.TestnetChainConfig, nil // Ropsten
|
||||||
|
case 4:
|
||||||
|
return params.RinkebyChainConfig, nil
|
||||||
|
case 5:
|
||||||
|
return params.GoerliChainConfig, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("chain config for chainid %d not available", chainID)
|
||||||
|
}
|
||||||
|
}
|
@ -72,7 +72,7 @@ func NewBackFillService(settings *Config, screenAndServeChan chan shared.Convert
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
converter, err := builders.NewPayloadConverter(settings.Chain)
|
converter, err := builders.NewPayloadConverter(settings.Chain, settings.NodeInfo.ChainID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package node
|
|||||||
type Node struct {
|
type Node struct {
|
||||||
GenesisBlock string
|
GenesisBlock string
|
||||||
NetworkID string
|
NetworkID string
|
||||||
|
ChainID uint64
|
||||||
ID string
|
ID string
|
||||||
ClientName string
|
ClientName string
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func NewResyncService(settings *Config) (Resync, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
converter, err := builders.NewPayloadConverter(settings.Chain)
|
converter, err := builders.NewPayloadConverter(settings.Chain, settings.NodeInfo.ChainID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ const (
|
|||||||
Ethereum
|
Ethereum
|
||||||
Bitcoin
|
Bitcoin
|
||||||
Omni
|
Omni
|
||||||
|
EthereumClassic
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c ChainType) String() string {
|
func (c ChainType) String() string {
|
||||||
@ -39,6 +40,8 @@ func (c ChainType) String() string {
|
|||||||
return "Bitcoin"
|
return "Bitcoin"
|
||||||
case Omni:
|
case Omni:
|
||||||
return "Omni"
|
return "Omni"
|
||||||
|
case EthereumClassic:
|
||||||
|
return "EthereumClassic"
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -52,6 +55,8 @@ func (c ChainType) API() string {
|
|||||||
return "btc"
|
return "btc"
|
||||||
case Omni:
|
case Omni:
|
||||||
return "omni"
|
return "omni"
|
||||||
|
case EthereumClassic:
|
||||||
|
return "etc"
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -65,6 +70,8 @@ func NewChainType(name string) (ChainType, error) {
|
|||||||
return Bitcoin, nil
|
return Bitcoin, nil
|
||||||
case "omni":
|
case "omni":
|
||||||
return Omni, nil
|
return Omni, nil
|
||||||
|
case "classic", "etc":
|
||||||
|
return EthereumClassic, nil
|
||||||
default:
|
default:
|
||||||
return UnknownChain, errors.New("invalid name for chain")
|
return UnknownChain, errors.New("invalid name for chain")
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ const (
|
|||||||
ETH_CLIENT_NAME = "ETH_CLIENT_NAME"
|
ETH_CLIENT_NAME = "ETH_CLIENT_NAME"
|
||||||
ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK"
|
ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK"
|
||||||
ETH_NETWORK_ID = "ETH_NETWORK_ID"
|
ETH_NETWORK_ID = "ETH_NETWORK_ID"
|
||||||
|
ETH_CHAIN_ID = "ETH_CHAIN_ID"
|
||||||
|
|
||||||
BTC_WS_PATH = "BTC_WS_PATH"
|
BTC_WS_PATH = "BTC_WS_PATH"
|
||||||
BTC_HTTP_PATH = "BTC_HTTP_PATH"
|
BTC_HTTP_PATH = "BTC_HTTP_PATH"
|
||||||
@ -48,6 +49,7 @@ const (
|
|||||||
BTC_CLIENT_NAME = "BTC_CLIENT_NAME"
|
BTC_CLIENT_NAME = "BTC_CLIENT_NAME"
|
||||||
BTC_GENESIS_BLOCK = "BTC_GENESIS_BLOCK"
|
BTC_GENESIS_BLOCK = "BTC_GENESIS_BLOCK"
|
||||||
BTC_NETWORK_ID = "BTC_NETWORK_ID"
|
BTC_NETWORK_ID = "BTC_NETWORK_ID"
|
||||||
|
BTC_CHAIN_ID = "BTC_CHAIN_ID"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetEthNodeAndClient returns eth node info and client from path url
|
// GetEthNodeAndClient returns eth node info and client from path url
|
||||||
@ -56,6 +58,7 @@ func GetEthNodeAndClient(path string) (node.Node, *rpc.Client, error) {
|
|||||||
viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME)
|
viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME)
|
||||||
viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK)
|
viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK)
|
||||||
viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID)
|
viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID)
|
||||||
|
viper.BindEnv("ethereum.chainID", ETH_CHAIN_ID)
|
||||||
|
|
||||||
rpcClient, err := rpc.Dial(path)
|
rpcClient, err := rpc.Dial(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,6 +69,7 @@ func GetEthNodeAndClient(path string) (node.Node, *rpc.Client, error) {
|
|||||||
ClientName: viper.GetString("ethereum.clientName"),
|
ClientName: viper.GetString("ethereum.clientName"),
|
||||||
GenesisBlock: viper.GetString("ethereum.genesisBlock"),
|
GenesisBlock: viper.GetString("ethereum.genesisBlock"),
|
||||||
NetworkID: viper.GetString("ethereum.networkID"),
|
NetworkID: viper.GetString("ethereum.networkID"),
|
||||||
|
ChainID: viper.GetUint64("ethereum.chainID"),
|
||||||
}, rpcClient, nil
|
}, rpcClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +105,7 @@ func GetBtcNodeAndClient(path string) (node.Node, *rpcclient.ConnConfig) {
|
|||||||
viper.BindEnv("bitcoin.networkID", BTC_NETWORK_ID)
|
viper.BindEnv("bitcoin.networkID", BTC_NETWORK_ID)
|
||||||
viper.BindEnv("bitcoin.pass", BTC_NODE_PASSWORD)
|
viper.BindEnv("bitcoin.pass", BTC_NODE_PASSWORD)
|
||||||
viper.BindEnv("bitcoin.user", BTC_NODE_USER)
|
viper.BindEnv("bitcoin.user", BTC_NODE_USER)
|
||||||
|
viper.BindEnv("bitcoin.chainID", BTC_CHAIN_ID)
|
||||||
|
|
||||||
// For bitcoin we load in node info from the config because there is no RPC endpoint to retrieve this from the node
|
// For bitcoin we load in node info from the config because there is no RPC endpoint to retrieve this from the node
|
||||||
return node.Node{
|
return node.Node{
|
||||||
@ -108,6 +113,7 @@ func GetBtcNodeAndClient(path string) (node.Node, *rpcclient.ConnConfig) {
|
|||||||
ClientName: viper.GetString("bitcoin.clientName"),
|
ClientName: viper.GetString("bitcoin.clientName"),
|
||||||
GenesisBlock: viper.GetString("bitcoin.genesisBlock"),
|
GenesisBlock: viper.GetString("bitcoin.genesisBlock"),
|
||||||
NetworkID: viper.GetString("bitcoin.networkID"),
|
NetworkID: viper.GetString("bitcoin.networkID"),
|
||||||
|
ChainID: viper.GetUint64("bitcoin.chainID"),
|
||||||
}, &rpcclient.ConnConfig{
|
}, &rpcclient.ConnConfig{
|
||||||
Host: path,
|
Host: path,
|
||||||
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package shared
|
package shared
|
||||||
|
|
||||||
|
// Very loose interface types for generic processing of different blockchains
|
||||||
|
// TODO: split different blockchain support into separate repos
|
||||||
|
|
||||||
// These types serve as very loose wrappers around a generic underlying interface{}
|
// These types serve as very loose wrappers around a generic underlying interface{}
|
||||||
type RawChainData interface{}
|
type RawChainData interface{}
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
package validate
|
|
@ -108,7 +108,7 @@ func NewWatcher(settings *Config) (Watcher, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sn.Converter, err = builders.NewPayloadConverter(settings.Chain)
|
sn.Converter, err = builders.NewPayloadConverter(settings.Chain, settings.NodeInfo.ChainID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ func (sap *Service) Protocols() []p2p.Protocol {
|
|||||||
|
|
||||||
// APIs returns the RPC descriptors the watcher service offers
|
// APIs returns the RPC descriptors the watcher service offers
|
||||||
func (sap *Service) APIs() []rpc.API {
|
func (sap *Service) APIs() []rpc.API {
|
||||||
ifnoAPI := NewInfoAPI()
|
infoAPI := NewInfoAPI()
|
||||||
apis := []rpc.API{
|
apis := []rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: APIName,
|
Namespace: APIName,
|
||||||
@ -165,23 +165,23 @@ func (sap *Service) APIs() []rpc.API {
|
|||||||
{
|
{
|
||||||
Namespace: "rpc",
|
Namespace: "rpc",
|
||||||
Version: APIVersion,
|
Version: APIVersion,
|
||||||
Service: ifnoAPI,
|
Service: infoAPI,
|
||||||
Public: true,
|
Public: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Namespace: "net",
|
Namespace: "net",
|
||||||
Version: APIVersion,
|
Version: APIVersion,
|
||||||
Service: ifnoAPI,
|
Service: infoAPI,
|
||||||
Public: true,
|
Public: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Namespace: "admin",
|
Namespace: "admin",
|
||||||
Version: APIVersion,
|
Version: APIVersion,
|
||||||
Service: ifnoAPI,
|
Service: infoAPI,
|
||||||
Public: true,
|
Public: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
chainAPI, err := builders.NewPublicAPI(sap.chain, sap.db, sap.ipfsPath)
|
chainAPI, err := builders.NewPublicAPI(sap.chain, sap.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return apis
|
return apis
|
||||||
|
Loading…
Reference in New Issue
Block a user