Unverified Commit 6aca043f authored by Mark Beamer Jr's avatar Mark Beamer Jr
Browse files

Add disabling of blob uploading for local testing until reflector docker image...

Add disabling of blob uploading for local testing until reflector docker image can be created( not urgent now ).
Add ability to generate blocks when in regtest mode and using docker.
Add refactor of environment variable accessing.
parent f99aacc8
......@@ -42,6 +42,9 @@ func loadConfig(path string) (cmd.Config, error) {
}
func reflectBlobs() error {
if util.IsBlobReflectionOff() {
return nil
}
//make sure lbrynet is off
running, err := isLbrynetRunning()
if err != nil {
......@@ -127,7 +130,7 @@ func cleanupLbrynet() error {
func isLbrynetRunning() (bool, error) {
if util.IsUsingDocker() {
container, err := util.GetLBRYNetContainer(false)
container, err := util.GetLBRYNetContainer(util.ONLINE)
if err != nil {
return false, err
}
......
......@@ -11,8 +11,6 @@ import (
"github.com/lbryio/lbry.go/extras/errors"
"github.com/lbryio/lbry.go/extras/jsonrpc"
"github.com/lbryio/lbry.go/extras/util"
"github.com/lbryio/lbry.go/lbrycrd"
"github.com/lbryio/ytsync/tagsManager"
"github.com/lbryio/ytsync/thumbs"
logUtils "github.com/lbryio/ytsync/util"
......@@ -224,6 +222,16 @@ func (s *Sync) ensureEnoughUTXOs() error {
}
func (s *Sync) waitForNewBlock() error {
if logUtils.IsRegTest() && logUtils.IsUsingDocker() {
lbrycrd, err := logUtils.GetLbrycrdClient(s.LbrycrdString)
if err != nil {
return errors.Prefix("error getting lbrycrd client: ", err)
}
txs, err := lbrycrd.Generate(1)
for _, tx := range txs {
log.Info("Generated tx: ", tx.String())
}
}
status, err := s.daemon.Status()
if err != nil {
return err
......@@ -417,18 +425,9 @@ func allUTXOsConfirmed(utxolist *jsonrpc.UTXOListResponse) bool {
func (s *Sync) addCredits(amountToAdd float64) error {
log.Printf("Adding %f credits", amountToAdd)
var lbrycrdd *lbrycrd.Client
var err error
if s.LbrycrdString == "" {
lbrycrdd, err = lbrycrd.NewWithDefaultURL()
if err != nil {
return err
}
} else {
lbrycrdd, err = lbrycrd.New(s.LbrycrdString)
if err != nil {
return err
}
lbrycrdd, err := logUtils.GetLbrycrdClient(s.LbrycrdString)
if err != nil {
return err
}
addressResp, err := s.daemon.AddressUnused(nil)
......
......@@ -6,12 +6,13 @@ import (
"os"
"os/user"
"github.com/lbryio/lbry.go/extras/errors"
"github.com/lbryio/lbry.go/lbrycrd"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/lbryio/lbry.go/extras/errors"
"github.com/prometheus/common/log"
log "github.com/sirupsen/logrus"
)
func GetBlobsDir() string {
......@@ -19,7 +20,7 @@ func GetBlobsDir() string {
if blobsDir == "" {
usr, err := user.Current()
if err != nil {
log.Errorln(err.Error())
log.Error(err.Error())
return ""
}
blobsDir = usr.HomeDir + "/.lbrynet/blobfiles/"
......@@ -28,6 +29,10 @@ func GetBlobsDir() string {
return blobsDir
}
func IsBlobReflectionOff() bool {
return os.Getenv("REFLECT_BLOBS") == "false"
}
func GetLBRYNetDir() string {
lbrynetDir := os.Getenv("LBRYNET_DIR")
if lbrynetDir == "" {
......@@ -41,13 +46,20 @@ func GetLBRYNetDir() string {
return lbrynetDir
}
const ALL = true
const ONLINE = false
func GetLBRYNetContainer(all bool) (*types.Container, error) {
return getDockerContainer("lbrynet", all)
}
func getDockerContainer(name string, all bool) (*types.Container, error) {
cli, err := client.NewEnvClient()
if err != nil {
panic(err)
}
filters := filters.NewArgs()
filters.Add("name", "lbrynet")
filters.Add("name", name)
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: all, Filters: filters})
if err != nil {
panic(err)
......@@ -59,7 +71,7 @@ func GetLBRYNetContainer(all bool) (*types.Container, error) {
return nil, nil
}
if len(containers) > 1 {
return nil, errors.Err("more than one lbrynet container found")
return nil, errors.Err("more than one %s container found", name)
}
return &containers[0], nil
......@@ -68,3 +80,25 @@ func GetLBRYNetContainer(all bool) (*types.Container, error) {
func IsUsingDocker() bool {
return os.Getenv("LBRYNET_USE_DOCKER") == "true"
}
func IsRegTest() bool {
return os.Getenv("REGTEST") == "true"
}
func GetLbrycrdClient(lbrycrdString string) (*lbrycrd.Client, error) {
var lbrycrdd *lbrycrd.Client
var err error
if lbrycrdString == "" {
lbrycrdd, err = lbrycrd.NewWithDefaultURL()
if err != nil {
return nil, err
}
} else {
lbrycrdd, err = lbrycrd.New(lbrycrdString)
if err != nil {
return nil, err
}
}
return lbrycrdd, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment