decouple from sync
This commit is contained in:
+4
-51
@@ -17,79 +17,32 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/node"
|
||||
)
|
||||
|
||||
// Env variables
|
||||
const (
|
||||
HTTP_TIMEOUT = "HTTP_TIMEOUT"
|
||||
|
||||
ETH_WS_PATH = "ETH_WS_PATH"
|
||||
ETH_HTTP_PATH = "ETH_HTTP_PATH"
|
||||
ETH_NODE_ID = "ETH_NODE_ID"
|
||||
ETH_CLIENT_NAME = "ETH_CLIENT_NAME"
|
||||
ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK"
|
||||
ETH_NETWORK_ID = "ETH_NETWORK_ID"
|
||||
ETH_CHAIN_ID = "ETH_CHAIN_ID"
|
||||
|
||||
BTC_WS_PATH = "BTC_WS_PATH"
|
||||
BTC_HTTP_PATH = "BTC_HTTP_PATH"
|
||||
BTC_NODE_PASSWORD = "BTC_NODE_PASSWORD"
|
||||
BTC_NODE_USER = "BTC_NODE_USER"
|
||||
BTC_NODE_ID = "BTC_NODE_ID"
|
||||
BTC_CLIENT_NAME = "BTC_CLIENT_NAME"
|
||||
BTC_GENESIS_BLOCK = "BTC_GENESIS_BLOCK"
|
||||
BTC_NETWORK_ID = "BTC_NETWORK_ID"
|
||||
BTC_CHAIN_ID = "BTC_CHAIN_ID"
|
||||
)
|
||||
|
||||
// GetEthNodeAndClient returns eth node info and client from path url
|
||||
func GetEthNodeAndClient(path string) (node.Node, *rpc.Client, error) {
|
||||
// GetNodeInfo returns the ethereum node info from env variables
|
||||
func GetNodeInfo() node.Info {
|
||||
viper.BindEnv("ethereum.nodeID", ETH_NODE_ID)
|
||||
viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME)
|
||||
viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK)
|
||||
viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID)
|
||||
viper.BindEnv("ethereum.chainID", ETH_CHAIN_ID)
|
||||
|
||||
rpcClient, err := rpc.Dial(path)
|
||||
if err != nil {
|
||||
return node.Node{}, nil, err
|
||||
}
|
||||
return node.Node{
|
||||
return node.Info{
|
||||
ID: viper.GetString("ethereum.nodeID"),
|
||||
ClientName: viper.GetString("ethereum.clientName"),
|
||||
GenesisBlock: viper.GetString("ethereum.genesisBlock"),
|
||||
NetworkID: viper.GetString("ethereum.networkID"),
|
||||
ChainID: viper.GetUint64("ethereum.chainID"),
|
||||
}, rpcClient, nil
|
||||
}
|
||||
|
||||
// GetBtcNodeAndClient returns btc node info from path url
|
||||
func GetBtcNodeAndClient(path string) (node.Node, *rpcclient.ConnConfig) {
|
||||
viper.BindEnv("bitcoin.nodeID", BTC_NODE_ID)
|
||||
viper.BindEnv("bitcoin.clientName", BTC_CLIENT_NAME)
|
||||
viper.BindEnv("bitcoin.genesisBlock", BTC_GENESIS_BLOCK)
|
||||
viper.BindEnv("bitcoin.networkID", BTC_NETWORK_ID)
|
||||
viper.BindEnv("bitcoin.pass", BTC_NODE_PASSWORD)
|
||||
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
|
||||
return node.Node{
|
||||
ID: viper.GetString("bitcoin.nodeID"),
|
||||
ClientName: viper.GetString("bitcoin.clientName"),
|
||||
GenesisBlock: viper.GetString("bitcoin.genesisBlock"),
|
||||
NetworkID: viper.GetString("bitcoin.networkID"),
|
||||
ChainID: viper.GetUint64("bitcoin.chainID"),
|
||||
}, &rpcclient.ConnConfig{
|
||||
Host: path,
|
||||
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
||||
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
||||
Pass: viper.GetString("bitcoin.pass"),
|
||||
User: viper.GetString("bitcoin.user"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"errors"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
)
|
||||
|
||||
// PayloadFetcher mock for tests
|
||||
|
||||
@@ -18,7 +18,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/postgres"
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
)
|
||||
|
||||
// CIDRetriever is a mock CID retriever for use in tests
|
||||
|
||||
@@ -18,7 +18,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
)
|
||||
|
||||
// PayloadStreamer mock struct
|
||||
|
||||
@@ -19,10 +19,11 @@ package shared
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/eth"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/multiformats/go-multihash"
|
||||
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/config"
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/ipfs"
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/node"
|
||||
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/postgres"
|
||||
@@ -30,11 +31,11 @@ import (
|
||||
|
||||
// SetupDB is use to setup a db for watcher tests
|
||||
func SetupDB() (*postgres.DB, error) {
|
||||
return postgres.NewDB(config.Database{
|
||||
return postgres.NewDB(postgres.Config{
|
||||
Hostname: "localhost",
|
||||
Name: "vulcanize_testing",
|
||||
Port: 5432,
|
||||
}, node.Node{})
|
||||
}, node.Info{})
|
||||
}
|
||||
|
||||
// ListContainsString used to check if a list of strings contains a particular string
|
||||
@@ -58,7 +59,7 @@ func IPLDsContainBytes(iplds []ipfs.BlockModel, b []byte) bool {
|
||||
}
|
||||
|
||||
// ListContainsGap used to check if a list of Gaps contains a particular Gap
|
||||
func ListContainsGap(gapList []Gap, gap Gap) bool {
|
||||
func ListContainsGap(gapList []eth.DBGap, gap eth.DBGap) bool {
|
||||
for _, listGap := range gapList {
|
||||
if listGap == gap {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user