Skip to content

Commit

Permalink
feat(SPV-1300): experimental new tx flow feature flag (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain authored Dec 20, 2024
1 parent 1acad0e commit 24e038f
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 61 deletions.
3 changes: 1 addition & 2 deletions actions/access_keys/access_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package accesskeys
import (
"testing"

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/stretchr/testify/suite"
Expand All @@ -27,7 +26,7 @@ func (ts *TestSuite) TearDownSuite() {
// SetupTest runs before each test
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()
handlersManager := handlers.NewManager(ts.Router, config.APIVersion)
handlersManager := handlers.NewManager(ts.Router, ts.AppConfig)
RegisterRoutes(handlersManager)
}

Expand Down
3 changes: 1 addition & 2 deletions actions/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package admin
import (
"testing"

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/stretchr/testify/suite"
Expand All @@ -28,7 +27,7 @@ func (ts *TestSuite) TearDownSuite() {
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

handlersManager := handlers.NewManager(ts.Router, config.APIVersion)
handlersManager := handlers.NewManager(ts.Router, ts.AppConfig)
RegisterRoutes(handlersManager)
}

Expand Down
3 changes: 1 addition & 2 deletions actions/base/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package base
import (
"testing"

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/stretchr/testify/suite"
Expand All @@ -28,7 +27,7 @@ func (ts *TestSuite) TearDownSuite() {
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

handlersManager := handlers.NewManager(ts.Router, config.APIVersion)
handlersManager := handlers.NewManager(ts.Router, ts.AppConfig)
RegisterRoutes(handlersManager)
}

Expand Down
4 changes: 2 additions & 2 deletions actions/contacts/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package contacts
import (
"testing"

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/stretchr/testify/suite"
Expand All @@ -17,6 +16,7 @@ type TestSuite struct {
// SetupSuite runs at the start of the suite
func (ts *TestSuite) SetupSuite() {
ts.BaseSetupSuite()
ts.AppConfig.ExperimentalFeatures.PikeContactsEnabled = true
}

// TearDownSuite runs after the suite finishes
Expand All @@ -28,7 +28,7 @@ func (ts *TestSuite) TearDownSuite() {
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

handlersManager := handlers.NewManager(ts.Router, config.APIVersion)
handlersManager := handlers.NewManager(ts.Router, ts.AppConfig)
RegisterRoutes(handlersManager)
}

Expand Down
3 changes: 1 addition & 2 deletions actions/destinations/destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package destinations
import (
"testing"

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/stretchr/testify/suite"
Expand All @@ -28,7 +27,7 @@ func (ts *TestSuite) TearDownSuite() {
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

handlersManager := handlers.NewManager(ts.Router, config.APIVersion)
handlersManager := handlers.NewManager(ts.Router, ts.AppConfig)
RegisterRoutes(handlersManager)
}

Expand Down
3 changes: 1 addition & 2 deletions actions/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
"github.com/bitcoin-sv/spv-wallet/actions/transactions"
"github.com/bitcoin-sv/spv-wallet/actions/users"
"github.com/bitcoin-sv/spv-wallet/actions/utxos"
"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
)

// Register collects all the action's routes and registers them using the handlersManager
func Register(appConfig *config.AppConfig, handlersManager *handlers.Manager) {
func Register(handlersManager *handlers.Manager) {
admin.RegisterRoutes(handlersManager)
base.RegisterRoutes(handlersManager)
accesskeys.RegisterRoutes(handlersManager)
Expand Down
13 changes: 7 additions & 6 deletions actions/transactions/outlines_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/bitcoin-sv/spv-wallet/actions/testabilities"
"github.com/bitcoin-sv/spv-wallet/actions/testabilities/apierror"
testengine "github.com/bitcoin-sv/spv-wallet/engine/testabilities"
"github.com/bitcoin-sv/spv-wallet/engine/tester/fixtures"
)

Expand Down Expand Up @@ -144,7 +145,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
t.Run(name, func(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand All @@ -164,7 +165,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
t.Run("not allowed for anonymous", func(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand All @@ -180,7 +181,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
t.Run("not allowed for admin", func(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand All @@ -196,7 +197,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
t.Run("Bad Request: when user has no paymail address", func(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand All @@ -223,7 +224,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
t.Run("Bad Request: no body", func(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand Down Expand Up @@ -433,7 +434,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
t.Run(name, func(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand Down
7 changes: 4 additions & 3 deletions actions/transactions/outlines_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/bitcoin-sv/spv-wallet/actions/testabilities"
"github.com/bitcoin-sv/spv-wallet/actions/testabilities/apierror"
chainmodels "github.com/bitcoin-sv/spv-wallet/engine/chain/models"
testengine "github.com/bitcoin-sv/spv-wallet/engine/testabilities"
"github.com/bitcoin-sv/spv-wallet/engine/tester/fixtures"
)

Expand All @@ -24,7 +25,7 @@ func TestOutlinesRecordOpReturn(t *testing.T) {
t.Run("Record op_return data", func(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestOutlinesRecordOpReturnErrorCases(t *testing.T) {
t.Run(name, func(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand All @@ -143,7 +144,7 @@ func TestOutlinesRecordOpReturnErrorCases(t *testing.T) {
func TestOutlinesRecordOpReturnOnBroadcastError(t *testing.T) {
// given:
given, then := testabilities.New(t)
cleanup := given.StartedSPVWallet()
cleanup := given.StartedSPVWalletWithConfiguration(testengine.WithNewTransactionFlowEnabled())
defer cleanup()

// and:
Expand Down
10 changes: 6 additions & 4 deletions actions/transactions/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ func RegisterRoutes(handlersManager *handlers.Manager) {
group.POST("/drafts", handlers.AsUser(newTransactionDraft))
group.POST("", handlers.AsUser(recordTransaction))

v2 := handlersManager.Group(handlers.GroupAPIV2, "/transactions")
v2.POST("/outlines", handlers.AsUser(transactionOutlines))
v2.POST("", handlers.AsUser(transactionRecordOutline))

handlersManager.Get(handlers.GroupTransactionCallback).POST(config.BroadcastCallbackRoute, broadcastCallback)

if handlersManager.GetFeatureFlags().NewTransactionFlowEnabled {
v2 := handlersManager.Group(handlers.GroupAPIV2, "/transactions")
v2.POST("/outlines", handlers.AsUser(transactionOutlines))
v2.POST("", handlers.AsUser(transactionRecordOutline))
}
}
3 changes: 1 addition & 2 deletions actions/transactions/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package transactions
import (
"testing"

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/stretchr/testify/suite"
Expand All @@ -28,7 +27,7 @@ func (ts *TestSuite) TearDownSuite() {
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

handlersManager := handlers.NewManager(ts.Router, config.APIVersion)
handlersManager := handlers.NewManager(ts.Router, ts.AppConfig)
RegisterRoutes(handlersManager)
}

Expand Down
3 changes: 1 addition & 2 deletions actions/utxos/utxo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utxos
import (
"testing"

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/stretchr/testify/suite"
Expand All @@ -28,7 +27,7 @@ func (ts *TestSuite) TearDownSuite() {
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

handlersManager := handlers.NewManager(ts.Router, config.APIVersion)
handlersManager := handlers.NewManager(ts.Router, ts.AppConfig)
RegisterRoutes(handlersManager)
}

Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ type ExperimentalConfig struct {
PikePaymentEnabled bool `json:"pike_payment_enabled" mapstructure:"pike_payment_enabled"`
// Use junglebus external service to fetch missing source transactions for inputs
UseJunglebus bool `json:"use_junglebus" mapstructure:"use_junglebus"`
// NewTransactionFlowEnabled is a flag for enabling the new transaction flow
NewTransactionFlowEnabled bool `json:"new_transaction_flow_enabled" mapstructure:"new_transaction_flow_enabled"`
}

// GetUserAgent will return the outgoing user agent
Expand Down
3 changes: 3 additions & 0 deletions config/config_to_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func (c *AppConfig) addPaymailOpts(options []engine.ClientOps) []engine.ClientOp
if c.ExperimentalFeatures.PikePaymentEnabled {
options = append(options, engine.WithPaymailPikePaymentSupport())
}
if c.ExperimentalFeatures.NewTransactionFlowEnabled {
options = append(options, engine.WithPaymailExperimentalNewTransactionFlow())
}

return options
}
Expand Down
8 changes: 3 additions & 5 deletions engine/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type (
*server.Configuration // Server configuration if Paymail is enabled
options []server.ConfigOps // Options for the paymail server
DefaultFromPaymail string // IE: from@domain.com
ExperimentalProvider bool
}

// taskManagerOptions holds the configuration for taskmanager
Expand Down Expand Up @@ -175,11 +176,8 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
return nil, err
}

// Default paymail server config (generic capabilities and domain check disabled)
if client.options.paymail.serverConfig.Configuration == nil {
if err = client.loadDefaultPaymailConfig(); err != nil {
return nil, err
}
if err = client.loadPaymailServer(); err != nil {
return nil, err
}

if client.options.feeUnit == nil {
Expand Down
35 changes: 21 additions & 14 deletions engine/client_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package engine
import (
"context"

"github.com/bitcoin-sv/go-paymail"
"github.com/bitcoin-sv/go-paymail/server"
paymailclient "github.com/bitcoin-sv/go-paymail"
paymailserver "github.com/bitcoin-sv/go-paymail/server"
"github.com/bitcoin-sv/spv-wallet/engine/chain"
"github.com/bitcoin-sv/spv-wallet/engine/cluster"
"github.com/bitcoin-sv/spv-wallet/engine/database/dao"
"github.com/bitcoin-sv/spv-wallet/engine/datastore"
"github.com/bitcoin-sv/spv-wallet/engine/notifications"
paymailclient "github.com/bitcoin-sv/spv-wallet/engine/paymail"
"github.com/bitcoin-sv/spv-wallet/engine/paymail"
"github.com/bitcoin-sv/spv-wallet/engine/paymailaddress"
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/engine/taskmanager"
Expand Down Expand Up @@ -148,7 +148,7 @@ func (c *Client) loadPaymailComponents() (err error) {

// Only load if it's not set (the client can be overloaded)
if c.options.paymail.client == nil {
c.options.paymail.client, err = paymail.NewClient()
c.options.paymail.client, err = paymailclient.NewClient()
if err != nil {
return
}
Expand All @@ -157,7 +157,7 @@ func (c *Client) loadPaymailComponents() (err error) {

if c.options.paymail.service == nil {
logger := c.Logger().With().Str("subservice", "paymail").Logger()
c.options.paymail.service = paymailclient.NewServiceClient(c.Cachestore(), c.options.paymail.client, logger)
c.options.paymail.service = paymail.NewServiceClient(c.Cachestore(), c.options.paymail.client, logger)
}
return
}
Expand Down Expand Up @@ -251,8 +251,8 @@ func (c *Client) registerCronJobs() error {
return spverrors.Wrapf(err, "failed to init cron jobs")
}

// loadDefaultPaymailConfig will load the default paymail server configuration
func (c *Client) loadDefaultPaymailConfig() (err error) {
// loadPaymailServer will load the default paymail server configuration
func (c *Client) loadPaymailServer() (err error) {
// Default FROM paymail
if len(c.options.paymail.serverConfig.DefaultFromPaymail) == 0 {
c.options.paymail.serverConfig.DefaultFromPaymail = defaultSenderPaymail
Expand All @@ -261,22 +261,29 @@ func (c *Client) loadDefaultPaymailConfig() (err error) {
// Set default options if none are found
if len(c.options.paymail.serverConfig.options) == 0 {
c.options.paymail.serverConfig.options = append(c.options.paymail.serverConfig.options,
server.WithP2PCapabilities(),
server.WithDomainValidationDisabled(),
paymailserver.WithP2PCapabilities(),
paymailserver.WithDomainValidationDisabled(),
)
}

paymailLogger := c.Logger().With().Str("subservice", "go-paymail").Logger()
c.options.paymail.serverConfig.options = append(c.options.paymail.serverConfig.options, server.WithLogger(&paymailLogger))
c.options.paymail.serverConfig.options = append(c.options.paymail.serverConfig.options, paymailserver.WithLogger(&paymailLogger))

// Create the paymail configuration using the client and default service provider
paymailLocator := &server.PaymailServiceLocator{}
paymailService := &PaymailDefaultServiceProvider{client: c}
paymailLocator.RegisterPaymailService(paymailService)
paymailLocator := &paymailserver.PaymailServiceLocator{}

var serviceProvider paymailserver.PaymailServiceProvider
if c.options.paymail.serverConfig.ExperimentalProvider {
serviceProvider = paymail.NewServiceProvider()
} else {
serviceProvider = &PaymailDefaultServiceProvider{client: c}
}

paymailLocator.RegisterPaymailService(serviceProvider)
paymailLocator.RegisterPikeContactService(&PikeContactServiceProvider{client: c})
paymailLocator.RegisterPikePaymentService(&PikePaymentServiceProvider{client: c})

c.options.paymail.serverConfig.Configuration, err = server.NewConfig(
c.options.paymail.serverConfig.Configuration, err = paymailserver.NewConfig(
paymailLocator,
c.options.paymail.serverConfig.options...,
)
Expand Down
Loading

0 comments on commit 24e038f

Please sign in to comment.