Skip to content

Commit 678ff56

Browse files
authored
Fix: Change network value from mainnet to regtest (#26)
* changed regtest network value from mainnet to regtest * correct network config returned * read network from destinations response * removed config test
1 parent ca0d56b commit 678ff56

File tree

9 files changed

+4
-105
lines changed

9 files changed

+4
-105
lines changed

cmd/rest-server/main.go

-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ func main() {
6363
WithLog().
6464
WithPayD().
6565
Load()
66-
// validate the config, fail if it fails.
67-
if err := cfg.Validate(); err != nil {
68-
log.Fatal(err)
69-
}
7066
config.SetupLog(cfg.Logging)
7167
log.Infof("\n------Environment: %s -----\n", cfg.Server)
7268

config/config.go

-27
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package config
22

33
import (
44
"fmt"
5-
"regexp"
65
"time"
7-
8-
validator "github.com/theflyingcodr/govalidator"
96
)
107

118
// Environment variable constants.
@@ -15,7 +12,6 @@ const (
1512
EnvServerFQDN = "server.fqdn"
1613
EnvServerSwaggerEnabled = "server.swagger.enabled"
1714
EnvEnvironment = "env.environment"
18-
EnvBitcoinNetwork = "env.bitcoin.network"
1915
EnvRegion = "env.region"
2016
EnvVersion = "env.version"
2117
EnvCommit = "env.commit"
@@ -33,19 +29,6 @@ const (
3329
LogWarn = "warn"
3430
)
3531

36-
var reNetworks = regexp.MustCompile(`^(regtest|stn|testnet|mainnet)$`)
37-
38-
// NetworkType is used to restrict the networks we can support.
39-
type NetworkType string
40-
41-
// Supported bitcoin network types.
42-
const (
43-
NetworkRegtest NetworkType = "mainnet"
44-
NetworkSTN NetworkType = "stn"
45-
NetworkTestnet NetworkType = "testnet"
46-
NetworkMainet NetworkType = "mainnet"
47-
)
48-
4932
// Config returns strongly typed config values.
5033
type Config struct {
5134
Logging *Logging
@@ -54,15 +37,6 @@ type Config struct {
5437
PayD *PayD
5538
}
5639

57-
// Validate will ensure the config matches certain parameters.
58-
func (c *Config) Validate() error {
59-
vl := validator.New()
60-
if c.Deployment != nil {
61-
vl = vl.Validate("deployment.network", validator.MatchString(string(c.Deployment.Network), reNetworks))
62-
}
63-
return vl.Err()
64-
}
65-
6640
// Deployment contains information relating to the current
6741
// deployed instance.
6842
type Deployment struct {
@@ -72,7 +46,6 @@ type Deployment struct {
7246
Version string
7347
Commit string
7448
BuildDate time.Time
75-
Network NetworkType
7649
}
7750

7851
// IsDev determines if this app is running on a dev environment.

config/config_test.go

-71
This file was deleted.

config/defaults.go

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func SetupDefaults() {
2222
viper.SetDefault(EnvCommit, "test")
2323
viper.SetDefault(EnvVersion, "v0.0.0")
2424
viper.SetDefault(EnvBuildDate, time.Now().UTC())
25-
viper.SetDefault(EnvBitcoinNetwork, "regtest")
2625

2726
// Log level defaults
2827
viper.SetDefault(EnvLogLevel, "info")

config/viper.go

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (v *ViperConfig) WithDeployment(appName string) ConfigurationLoader {
4040
Commit: viper.GetString(EnvCommit),
4141
BuildDate: viper.GetTime(EnvBuildDate),
4242
AppName: appName,
43-
Network: NetworkType(viper.GetString(EnvBitcoinNetwork)),
4443
}
4544
return v
4645
}

data/payd/models/payd.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Destination struct {
2525
// DestinationResponse is the response for the destinations api.
2626
type DestinationResponse struct {
2727
SPVRequired bool `json:"spvRequired"`
28+
Network string `json:"network"`
2829
Outputs []Destination `json:"outputs"`
2930
Fees *bt.FeeQuote `json:"fees"`
3031
CreatedAt time.Time `json:"createdAt"`

data/payd/payd.go

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (p *payd) Destinations(ctx context.Context, args p4.PaymentRequestArgs) (*p
6767
}
6868
dests := &p4.Destinations{
6969
SPVRequired: resp.SPVRequired,
70+
Network: resp.Network,
7071
Outputs: make([]p4.Output, 0),
7172
Fees: resp.Fees,
7273
CreatedAt: resp.CreatedAt,

destinations.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type PaymentDestinations struct {
2727
// Destinations message containing outputs and their fees.
2828
type Destinations struct {
2929
SPVRequired bool
30+
Network string
3031
Outputs []Output
3132
Fees *bt.FeeQuote
3233
CreatedAt time.Time

service/paymentrequest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (p *paymentRequest) CreatePaymentRequest(ctx context.Context, args p4.Payme
5050
// here we store paymentRef in extended data to allow some validation in payment flow
5151
merchant.ExtendedData["paymentReference"] = args.PaymentID
5252
return &p4.PaymentRequest{
53-
Network: "mainnet",
53+
Network: dests.Network,
5454
SPVRequired: dests.SPVRequired,
5555
Destinations: p4.PaymentDestinations{Outputs: dests.Outputs},
5656
FeeRate: dests.Fees,

0 commit comments

Comments
 (0)