Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Change network value from mainnet to regtest #26

Merged
merged 4 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cmd/rest-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ func main() {
WithLog().
WithPayD().
Load()
// validate the config, fail if it fails.
if err := cfg.Validate(); err != nil {
log.Fatal(err)
}
config.SetupLog(cfg.Logging)
log.Infof("\n------Environment: %s -----\n", cfg.Server)

Expand Down
27 changes: 0 additions & 27 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package config

import (
"fmt"
"regexp"
"time"

validator "github.com/theflyingcodr/govalidator"
)

// Environment variable constants.
Expand All @@ -15,7 +12,6 @@ const (
EnvServerFQDN = "server.fqdn"
EnvServerSwaggerEnabled = "server.swagger.enabled"
EnvEnvironment = "env.environment"
EnvBitcoinNetwork = "env.bitcoin.network"
EnvRegion = "env.region"
EnvVersion = "env.version"
EnvCommit = "env.commit"
Expand All @@ -33,19 +29,6 @@ const (
LogWarn = "warn"
)

var reNetworks = regexp.MustCompile(`^(regtest|stn|testnet|mainnet)$`)

// NetworkType is used to restrict the networks we can support.
type NetworkType string

// Supported bitcoin network types.
const (
NetworkRegtest NetworkType = "mainnet"
NetworkSTN NetworkType = "stn"
NetworkTestnet NetworkType = "testnet"
NetworkMainet NetworkType = "mainnet"
)

// Config returns strongly typed config values.
type Config struct {
Logging *Logging
Expand All @@ -54,15 +37,6 @@ type Config struct {
PayD *PayD
}

// Validate will ensure the config matches certain parameters.
func (c *Config) Validate() error {
vl := validator.New()
if c.Deployment != nil {
vl = vl.Validate("deployment.network", validator.MatchString(string(c.Deployment.Network), reNetworks))
}
return vl.Err()
}

// Deployment contains information relating to the current
// deployed instance.
type Deployment struct {
Expand All @@ -72,7 +46,6 @@ type Deployment struct {
Version string
Commit string
BuildDate time.Time
Network NetworkType
}

// IsDev determines if this app is running on a dev environment.
Expand Down
71 changes: 0 additions & 71 deletions config/config_test.go

This file was deleted.

1 change: 0 additions & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func SetupDefaults() {
viper.SetDefault(EnvCommit, "test")
viper.SetDefault(EnvVersion, "v0.0.0")
viper.SetDefault(EnvBuildDate, time.Now().UTC())
viper.SetDefault(EnvBitcoinNetwork, "regtest")

// Log level defaults
viper.SetDefault(EnvLogLevel, "info")
Expand Down
1 change: 0 additions & 1 deletion config/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (v *ViperConfig) WithDeployment(appName string) ConfigurationLoader {
Commit: viper.GetString(EnvCommit),
BuildDate: viper.GetTime(EnvBuildDate),
AppName: appName,
Network: NetworkType(viper.GetString(EnvBitcoinNetwork)),
}
return v
}
Expand Down
1 change: 1 addition & 0 deletions data/payd/models/payd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Destination struct {
// DestinationResponse is the response for the destinations api.
type DestinationResponse struct {
SPVRequired bool `json:"spvRequired"`
Network string `json:"network"`
Outputs []Destination `json:"outputs"`
Fees *bt.FeeQuote `json:"fees"`
}
1 change: 1 addition & 0 deletions data/payd/payd.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (p *payd) Destinations(ctx context.Context, args p4.PaymentRequestArgs) (*p
}
dests := &p4.Destinations{
SPVRequired: resp.SPVRequired,
Network: resp.Network,
Outputs: make([]p4.Output, 0),
Fees: resp.Fees,
}
Expand Down
1 change: 1 addition & 0 deletions destinations.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type PaymentDestinations struct {
// Destinations message containing outputs and their fees.
type Destinations struct {
SPVRequired bool
Network string
Outputs []Output
Fees *bt.FeeQuote
}
Expand Down
2 changes: 1 addition & 1 deletion service/paymentrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (p *paymentRequest) CreatePaymentRequest(ctx context.Context, args p4.Payme
// here we store paymentRef in extended data to allow some validation in payment flow
merchant.ExtendedData["paymentReference"] = args.PaymentID
return &p4.PaymentRequest{
Network: "mainnet",
Network: dests.Network,
SPVRequired: dests.SPVRequired,
Destinations: p4.PaymentDestinations{Outputs: dests.Outputs},
FeeRate: dests.Fees,
Expand Down