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

refactor(SPV-1057): rename draft to transaction outlines in new tx flow. #739

Merged
merged 4 commits into from
Oct 17, 2024
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
chris-4chain marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import (
"reflect"

"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/draft"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/draft/outputs"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/outlines"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/outlines/outputs"
"github.com/bitcoin-sv/spv-wallet/models/request"
"github.com/bitcoin-sv/spv-wallet/models/request/opreturn"
paymailreq "github.com/bitcoin-sv/spv-wallet/models/request/paymail"
"github.com/mitchellh/mapstructure"
)

// Request is a draft transaction request model.
type Request request.DraftTransaction
// Request is a transaction outline request model.
type Request request.TransactionSpecification

// ToEngine converts a draft transaction request model to the engine model.
func (tx Request) ToEngine(xPubID string) (*draft.TransactionSpec, error) {
spec := &draft.TransactionSpec{
// ToEngine converts a transaction outline request model to the engine model.
func (tx Request) ToEngine(xPubID string) (*outlines.TransactionSpec, error) {
spec := &outlines.TransactionSpec{
XPubID: xPubID,
}
config := mapstructure.DecoderConfig{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package outline

import (
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/draft"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/outlines"
model "github.com/bitcoin-sv/spv-wallet/models/transaction"
"github.com/mitchellh/mapstructure"
)

// ToResponse converts a draft transaction to a response model.
func ToResponse(tx *draft.Transaction) (*model.AnnotatedTransaction, error) {
// ToResponse converts a transaction outline to a response model.
func ToResponse(tx *outlines.Transaction) (*model.AnnotatedTransaction, error) {
res := &model.AnnotatedTransaction{}
err := mapstructure.Decode(tx, res)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions actions/transactions/outlines.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func transactionOutlines(c *gin.Context, userCtx *reqctx.UserContext) {
logger := reqctx.Logger(c)

var requestBody request.DraftTransaction
var requestBody request.TransactionSpecification
err := c.ShouldBindWith(&requestBody, binding.JSON)
if err != nil {
spverrors.ErrorResponse(c, spverrors.ErrCannotBindRequest.Wrap(err), logger)
Expand All @@ -25,7 +25,7 @@ func transactionOutlines(c *gin.Context, userCtx *reqctx.UserContext) {
return
}

txOutline, err := reqctx.Engine(c).TransactionDraftService().Create(c, spec)
txOutline, err := reqctx.Engine(c).TransactionOutlinesService().Create(c, spec)
if err != nil {
spverrors.ErrorResponse(c, err, logger)
return
Expand Down
12 changes: 6 additions & 6 deletions actions/transactions/outlines_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
Post(transactionsOutlinesURL)

// then:
then.Response(res).IsBadRequest().WithJSONf(apierror.ExpectedJSON("error-draft-paymail-address-no-default", "cannot choose paymail address of the sender"))
then.Response(res).IsBadRequest().WithJSONf(apierror.ExpectedJSON("error-tx-spec-paymail-address-no-default", "cannot choose paymail address of the sender"))
})

t.Run("Bad Request: no body", func(t *testing.T) {
Expand All @@ -244,13 +244,13 @@ func TestPOSTTransactionOutlines(t *testing.T) {
}{
"Bad Request: Empty request": {
json: `{}`,
expectedErr: apierror.ExpectedJSON("draft-output-required", "draft requires at least one output"),
expectedErr: apierror.ExpectedJSON("tx-spec-output-required", "transaction outline requires at least one output"),
},
"Bad Request: Empty outputs": {
json: `{
"outputs": []
}`,
expectedErr: apierror.ExpectedJSON("draft-output-required", "draft requires at least one output"),
expectedErr: apierror.ExpectedJSON("tx-spec-output-required", "transaction outline requires at least one output"),
},
"Bad Request: Unsupported output type": {
json: `{
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
}
]
}`,
expectedErr: apierror.ExpectedJSON("draft-op-return-data-required", "data is required for OP_RETURN output"),
expectedErr: apierror.ExpectedJSON("tx-spec-op-return-data-required", "data is required for OP_RETURN output"),
},
"Bad Request: OP_RETURN output with unknown data type": {
json: `{
Expand All @@ -305,7 +305,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
}
]
}`,
expectedErr: apierror.ExpectedJSON("draft-op-return-data-required", "data is required for OP_RETURN output"),
expectedErr: apierror.ExpectedJSON("tx-spec-op-return-data-required", "data is required for OP_RETURN output"),
},
"Bad Request: OP_RETURN strings output with string instead of array as data": {
json: `{
Expand All @@ -329,7 +329,7 @@ func TestPOSTTransactionOutlines(t *testing.T) {
}
]
}`,
expectedErr: apierror.ExpectedJSON("draft-op-return-data-required", "data is required for OP_RETURN output"),
expectedErr: apierror.ExpectedJSON("tx-spec-op-return-data-required", "data is required for OP_RETURN output"),
},
"Bad Request: OP_RETURN hexes output with invalid hex": {
json: `{
Expand Down
46 changes: 23 additions & 23 deletions engine/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/bitcoin-sv/spv-wallet/engine/paymailaddress"
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/engine/taskmanager"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/draft"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/outlines"
"github.com/go-resty/resty/v2"
"github.com/mrz1836/go-cachestore"
"github.com/rs/zerolog"
Expand All @@ -33,27 +33,27 @@ type (

// clientOptions holds all the configuration for the client
clientOptions struct {
cacheStore *cacheStoreOptions // Configuration options for Cachestore (ristretto, redis, etc.)
cluster *clusterOptions // Configuration options for the cluster coordinator
chainstate *chainstateOptions // Configuration options for Chainstate (broadcast, sync, etc.)
dataStore *dataStoreOptions // Configuration options for the DataStore (PostgreSQL, etc.)
debug bool // If the client is in debug mode
encryptionKey string // Encryption key for encrypting sensitive information (IE: paymail xPub) (hex encoded key)
httpClient *resty.Client // HTTP client to use for http calls
iuc bool // (Input UTXO Check) True will check input utxos when saving transactions
logger *zerolog.Logger // Internal logging
metrics *metrics.Metrics // Metrics with a collector interface
models *modelOptions // Configuration options for the loaded models
notifications *notificationsOptions // Configuration options for Notifications
paymail *paymailOptions // Paymail options & client
transactionDraftService draft.Service // Service for transaction drafts
paymailAddressService paymailaddress.Service // Service for paymail addresses
taskManager *taskManagerOptions // Configuration options for the TaskManager (TaskQ, etc.)
userAgent string // User agent for all outgoing requests
chainService chain.Service // Chain service
arcConfig chainmodels.ARCConfig // Configuration for ARC
bhsConfig chainmodels.BHSConfig // Configuration for BHS
txCallbackConfig *txCallbackConfig // Configuration for TX callback received from ARC; disabled if nil
cacheStore *cacheStoreOptions // Configuration options for Cachestore (ristretto, redis, etc.)
cluster *clusterOptions // Configuration options for the cluster coordinator
chainstate *chainstateOptions // Configuration options for Chainstate (broadcast, sync, etc.)
dataStore *dataStoreOptions // Configuration options for the DataStore (PostgreSQL, etc.)
debug bool // If the client is in debug mode
encryptionKey string // Encryption key for encrypting sensitive information (IE: paymail xPub) (hex encoded key)
httpClient *resty.Client // HTTP client to use for http calls
iuc bool // (Input UTXO Check) True will check input utxos when saving transactions
logger *zerolog.Logger // Internal logging
metrics *metrics.Metrics // Metrics with a collector interface
models *modelOptions // Configuration options for the loaded models
notifications *notificationsOptions // Configuration options for Notifications
paymail *paymailOptions // Paymail options & client
transactionOutlinesService outlines.Service // Service for transaction drafts
paymailAddressService paymailaddress.Service // Service for paymail addresses
taskManager *taskManagerOptions // Configuration options for the TaskManager (TaskQ, etc.)
userAgent string // User agent for all outgoing requests
chainService chain.Service // Chain service
arcConfig chainmodels.ARCConfig // Configuration for ARC
bhsConfig chainmodels.BHSConfig // Configuration for BHS
txCallbackConfig *txCallbackConfig // Configuration for TX callback received from ARC; disabled if nil
}

txCallbackConfig struct {
Expand Down Expand Up @@ -182,7 +182,7 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
return nil, err
}

if err = client.loadTransactionDraftService(); err != nil {
if err = client.loadTransactionOutlinesService(); err != nil {
return nil, err
}

Expand Down
10 changes: 5 additions & 5 deletions engine/client_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/bitcoin-sv/spv-wallet/engine/paymailaddress"
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/engine/taskmanager"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/draft"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/outlines"
"github.com/mrz1836/go-cachestore"
)

Expand Down Expand Up @@ -196,10 +196,10 @@ func (c *Client) loadPaymailAddressService() error {
return nil
}

func (c *Client) loadTransactionDraftService() error {
if c.options.transactionDraftService == nil {
logger := c.Logger().With().Str("subservice", "transactionDraft").Logger()
c.options.transactionDraftService = draft.NewDraftService(c.PaymailService(), c.options.paymailAddressService, logger)
func (c *Client) loadTransactionOutlinesService() error {
if c.options.transactionOutlinesService == nil {
logger := c.Logger().With().Str("subservice", "transactionOutlines").Logger()
c.options.transactionOutlinesService = outlines.NewService(c.PaymailService(), c.options.paymailAddressService, logger)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions engine/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func defaultClientOptions() *clientOptions {
},
},

// Blank transaction draft config
transactionDraftService: nil,
// Blank transaction outline
transactionOutlinesService: nil,

// Blank TaskManager config
taskManager: &taskManagerOptions{
Expand Down
10 changes: 5 additions & 5 deletions engine/client_transaction.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package engine

import (
"github.com/bitcoin-sv/spv-wallet/engine/transaction/draft"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/outlines"
)

// TransactionDraftService will return the draft.Service if it exists
func (c *Client) TransactionDraftService() draft.Service {
if c.options.transactionDraftService != nil {
return c.options.transactionDraftService
// TransactionOutlinesService will return the outlines.Service if it exists
func (c *Client) TransactionOutlinesService() outlines.Service {
if c.options.transactionOutlinesService != nil {
return c.options.transactionOutlinesService
}
return nil
}
4 changes: 2 additions & 2 deletions engine/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/bitcoin-sv/spv-wallet/engine/notifications"
paymailclient "github.com/bitcoin-sv/spv-wallet/engine/paymail"
"github.com/bitcoin-sv/spv-wallet/engine/taskmanager"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/draft"
"github.com/bitcoin-sv/spv-wallet/engine/transaction/outlines"
"github.com/mrz1836/go-cachestore"
"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -57,7 +57,7 @@ type ClientService interface {
Notifications() *notifications.Notifications
PaymailClient() paymail.ClientInterface
PaymailService() paymailclient.ServiceClient
TransactionDraftService() draft.Service
TransactionOutlinesService() outlines.Service
Taskmanager() taskmanager.TaskEngine
}

Expand Down
54 changes: 0 additions & 54 deletions engine/transaction/draft/create_draft_test.go

This file was deleted.

This file was deleted.

Loading
Loading