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.
This commit is contained in:
parent
c84e1e6fb9
commit
517c2c56a3
3 changed files with 57 additions and 21 deletions
|
@ -42,6 +42,9 @@ func loadConfig(path string) (cmd.Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func reflectBlobs() error {
|
func reflectBlobs() error {
|
||||||
|
if util.IsBlobReflectionOff() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
//make sure lbrynet is off
|
//make sure lbrynet is off
|
||||||
running, err := isLbrynetRunning()
|
running, err := isLbrynetRunning()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -127,7 +130,7 @@ func cleanupLbrynet() error {
|
||||||
|
|
||||||
func isLbrynetRunning() (bool, error) {
|
func isLbrynetRunning() (bool, error) {
|
||||||
if util.IsUsingDocker() {
|
if util.IsUsingDocker() {
|
||||||
container, err := util.GetLBRYNetContainer(false)
|
container, err := util.GetLBRYNetContainer(util.ONLINE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,6 @@ import (
|
||||||
"github.com/lbryio/lbry.go/extras/errors"
|
"github.com/lbryio/lbry.go/extras/errors"
|
||||||
"github.com/lbryio/lbry.go/extras/jsonrpc"
|
"github.com/lbryio/lbry.go/extras/jsonrpc"
|
||||||
"github.com/lbryio/lbry.go/extras/util"
|
"github.com/lbryio/lbry.go/extras/util"
|
||||||
"github.com/lbryio/lbry.go/lbrycrd"
|
|
||||||
|
|
||||||
"github.com/lbryio/ytsync/tagsManager"
|
"github.com/lbryio/ytsync/tagsManager"
|
||||||
"github.com/lbryio/ytsync/thumbs"
|
"github.com/lbryio/ytsync/thumbs"
|
||||||
logUtils "github.com/lbryio/ytsync/util"
|
logUtils "github.com/lbryio/ytsync/util"
|
||||||
|
@ -224,6 +222,16 @@ func (s *Sync) ensureEnoughUTXOs() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sync) waitForNewBlock() 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()
|
status, err := s.daemon.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -417,19 +425,10 @@ func allUTXOsConfirmed(utxolist *jsonrpc.UTXOListResponse) bool {
|
||||||
|
|
||||||
func (s *Sync) addCredits(amountToAdd float64) error {
|
func (s *Sync) addCredits(amountToAdd float64) error {
|
||||||
log.Printf("Adding %f credits", amountToAdd)
|
log.Printf("Adding %f credits", amountToAdd)
|
||||||
var lbrycrdd *lbrycrd.Client
|
lbrycrdd, err := logUtils.GetLbrycrdClient(s.LbrycrdString)
|
||||||
var err error
|
|
||||||
if s.LbrycrdString == "" {
|
|
||||||
lbrycrdd, err = lbrycrd.NewWithDefaultURL()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
lbrycrdd, err = lbrycrd.New(s.LbrycrdString)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
addressResp, err := s.daemon.AddressUnused(nil)
|
addressResp, err := s.daemon.AddressUnused(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
46
util/util.go
46
util/util.go
|
@ -6,12 +6,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"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"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/lbryio/lbry.go/extras/errors"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/prometheus/common/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetBlobsDir() string {
|
func GetBlobsDir() string {
|
||||||
|
@ -19,7 +20,7 @@ func GetBlobsDir() string {
|
||||||
if blobsDir == "" {
|
if blobsDir == "" {
|
||||||
usr, err := user.Current()
|
usr, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln(err.Error())
|
log.Error(err.Error())
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
blobsDir = usr.HomeDir + "/.lbrynet/blobfiles/"
|
blobsDir = usr.HomeDir + "/.lbrynet/blobfiles/"
|
||||||
|
@ -28,6 +29,10 @@ func GetBlobsDir() string {
|
||||||
return blobsDir
|
return blobsDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsBlobReflectionOff() bool {
|
||||||
|
return os.Getenv("REFLECT_BLOBS") == "false"
|
||||||
|
}
|
||||||
|
|
||||||
func GetLBRYNetDir() string {
|
func GetLBRYNetDir() string {
|
||||||
lbrynetDir := os.Getenv("LBRYNET_DIR")
|
lbrynetDir := os.Getenv("LBRYNET_DIR")
|
||||||
if lbrynetDir == "" {
|
if lbrynetDir == "" {
|
||||||
|
@ -41,13 +46,20 @@ func GetLBRYNetDir() string {
|
||||||
return lbrynetDir
|
return lbrynetDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ALL = true
|
||||||
|
const ONLINE = false
|
||||||
|
|
||||||
func GetLBRYNetContainer(all bool) (*types.Container, error) {
|
func GetLBRYNetContainer(all bool) (*types.Container, error) {
|
||||||
|
return getDockerContainer("lbrynet", all)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDockerContainer(name string, all bool) (*types.Container, error) {
|
||||||
cli, err := client.NewEnvClient()
|
cli, err := client.NewEnvClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
filters.Add("name", "lbrynet")
|
filters.Add("name", name)
|
||||||
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: all, Filters: filters})
|
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: all, Filters: filters})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -59,7 +71,7 @@ func GetLBRYNetContainer(all bool) (*types.Container, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if len(containers) > 1 {
|
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
|
return &containers[0], nil
|
||||||
|
@ -68,3 +80,25 @@ func GetLBRYNetContainer(all bool) (*types.Container, error) {
|
||||||
func IsUsingDocker() bool {
|
func IsUsingDocker() bool {
|
||||||
return os.Getenv("LBRYNET_USE_DOCKER") == "true"
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue