ipfs mode enum; configuration
This commit is contained in:
parent
96162e1853
commit
9db0fb219a
@ -18,11 +18,10 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/super_node"
|
"github.com/vulcanize/vulcanizedb/pkg/super_node"
|
||||||
|
@ -52,6 +52,7 @@ type Config struct {
|
|||||||
// Ubiquitous fields
|
// Ubiquitous fields
|
||||||
Chain shared.ChainType
|
Chain shared.ChainType
|
||||||
IPFSPath string
|
IPFSPath string
|
||||||
|
IPFSMode shared.IPFSMode
|
||||||
DB *postgres.DB
|
DB *postgres.DB
|
||||||
DBConfig config.Database
|
DBConfig config.Database
|
||||||
Quit chan bool
|
Quit chan bool
|
||||||
@ -98,10 +99,16 @@ func NewSuperNodeConfig() (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.IPFSMode, err = shared.GetIPFSMode()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if c.IPFSMode == shared.LocalInterface || c.IPFSMode == shared.RemoteClient {
|
||||||
c.IPFSPath, err = shared.GetIPFSPath()
|
c.IPFSPath, err = shared.GetIPFSPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.Sync = viper.GetBool("superNode.sync")
|
c.Sync = viper.GetBool("superNode.sync")
|
||||||
if c.Sync {
|
if c.Sync {
|
||||||
|
@ -52,6 +52,7 @@ type Config struct {
|
|||||||
DB *postgres.DB
|
DB *postgres.DB
|
||||||
DBConfig config.Database
|
DBConfig config.Database
|
||||||
IPFSPath string
|
IPFSPath string
|
||||||
|
IPFSMode shared.IPFSMode
|
||||||
|
|
||||||
HTTPClient interface{} // Note this client is expected to support the retrieval of the specified data type(s)
|
HTTPClient interface{} // Note this client is expected to support the retrieval of the specified data type(s)
|
||||||
NodeInfo core.Node // Info for the associated node
|
NodeInfo core.Node // Info for the associated node
|
||||||
@ -92,10 +93,16 @@ func NewReSyncConfig() (*Config, error) {
|
|||||||
c.ClearOldCache = viper.GetBool("resync.clearOldCache")
|
c.ClearOldCache = viper.GetBool("resync.clearOldCache")
|
||||||
c.ResetValidation = viper.GetBool("resync.resetValidation")
|
c.ResetValidation = viper.GetBool("resync.resetValidation")
|
||||||
|
|
||||||
|
c.IPFSMode, err = shared.GetIPFSMode()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if c.IPFSMode == shared.LocalInterface || c.IPFSMode == shared.RemoteClient {
|
||||||
c.IPFSPath, err = shared.GetIPFSPath()
|
c.IPFSPath, err = shared.GetIPFSPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
resyncType := viper.GetString("resync.type")
|
resyncType := viper.GetString("resync.type")
|
||||||
c.ResyncType, err = shared.GenerateResyncTypeFromString(resyncType)
|
c.ResyncType, err = shared.GenerateResyncTypeFromString(resyncType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
// Env variables
|
// Env variables
|
||||||
const (
|
const (
|
||||||
IPFS_PATH = "IPFS_PATH"
|
IPFS_PATH = "IPFS_PATH"
|
||||||
|
IPFS_MODE = "IPFS_MODE"
|
||||||
HTTP_TIMEOUT = "HTTP_TIMEOUT"
|
HTTP_TIMEOUT = "HTTP_TIMEOUT"
|
||||||
|
|
||||||
ETH_WS_PATH = "ETH_WS_PATH"
|
ETH_WS_PATH = "ETH_WS_PATH"
|
||||||
@ -82,6 +83,16 @@ func GetIPFSPath() (string, error) {
|
|||||||
return ipfsPath, nil
|
return ipfsPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIPFSMode returns the ipfs mode of operation from the config or env variable
|
||||||
|
func GetIPFSMode() (IPFSMode, error) {
|
||||||
|
viper.BindEnv("ipfs.mode", IPFS_MODE)
|
||||||
|
ipfsMode := viper.GetString("ipfs.mode")
|
||||||
|
if ipfsMode == "" {
|
||||||
|
return DirectPostgres, nil
|
||||||
|
}
|
||||||
|
return NewIPLFMode(ipfsMode)
|
||||||
|
}
|
||||||
|
|
||||||
// GetBtcNodeAndClient returns btc node info from path url
|
// GetBtcNodeAndClient returns btc node info from path url
|
||||||
func GetBtcNodeAndClient(path string) (core.Node, *rpcclient.ConnConfig) {
|
func GetBtcNodeAndClient(path string) (core.Node, *rpcclient.ConnConfig) {
|
||||||
viper.BindEnv("bitcoin.nodeID", BTC_NODE_ID)
|
viper.BindEnv("bitcoin.nodeID", BTC_NODE_ID)
|
||||||
|
@ -19,6 +19,9 @@ package shared
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||||
@ -69,3 +72,10 @@ func HandleNullAddr(to common.Address) string {
|
|||||||
}
|
}
|
||||||
return to.Hex()
|
return to.Hex()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rollback sql transaction and log any error
|
||||||
|
func Rollback(tx *sqlx.Tx) {
|
||||||
|
if err := tx.Rollback(); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
58
pkg/super_node/shared/ipfs_mode.go
Normal file
58
pkg/super_node/shared/ipfs_mode.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// VulcanizeDB
|
||||||
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package shared
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IPFSMode enum for specifying how we want to interface and publish objects to IPFS
|
||||||
|
type IPFSMode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
Unknown IPFSMode = iota
|
||||||
|
LocalInterface
|
||||||
|
RemoteClient
|
||||||
|
DirectPostgres
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c IPFSMode) String() string {
|
||||||
|
switch c {
|
||||||
|
case LocalInterface:
|
||||||
|
return "Local"
|
||||||
|
case RemoteClient:
|
||||||
|
return "Remote"
|
||||||
|
case DirectPostgres:
|
||||||
|
return "Postgres"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIPLFMode(name string) (IPFSMode, error) {
|
||||||
|
switch strings.ToLower(name) {
|
||||||
|
case "local", "interface", "minimal":
|
||||||
|
return LocalInterface, nil
|
||||||
|
case "remote", "client":
|
||||||
|
return RemoteClient, nil
|
||||||
|
case "postgres", "direct":
|
||||||
|
return DirectPostgres, nil
|
||||||
|
default:
|
||||||
|
return Unknown, errors.New("invalid name for ipfs mode")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user