diff --git a/actions/access_keys/count.go b/actions/access_keys/count.go index d668cf81d..7615bae03 100644 --- a/actions/access_keys/count.go +++ b/actions/access_keys/count.go @@ -35,7 +35,7 @@ func (a *Action) count(w http.ResponseWriter, req *http.Request, _ httprouter.Pa // Record a new transaction (get the hex from parameters)a var count int64 - if count, err = a.Services.SPV.GetAccessKeysByXPubIDCount( + if count, err = a.Services.SpvWalletEngine.GetAccessKeysByXPubIDCount( req.Context(), reqXPubID, metadata, diff --git a/actions/access_keys/create.go b/actions/access_keys/create.go index 67a9f2d93..3fb2d8d58 100644 --- a/actions/access_keys/create.go +++ b/actions/access_keys/create.go @@ -29,7 +29,7 @@ func (a *Action) create(w http.ResponseWriter, req *http.Request, _ httprouter.P metadata := params.GetJSON("metadata") // Create a new accessKey - accessKey, err := a.Services.SPV.NewAccessKey( + accessKey, err := a.Services.SpvWalletEngine.NewAccessKey( req.Context(), reqXPub, engine.WithMetadatas(metadata), diff --git a/actions/access_keys/get.go b/actions/access_keys/get.go index e41e293d9..5b8b9000b 100644 --- a/actions/access_keys/get.go +++ b/actions/access_keys/get.go @@ -32,7 +32,7 @@ func (a *Action) get(w http.ResponseWriter, req *http.Request, _ httprouter.Para } // Get access key - accessKey, err := a.Services.SPV.GetAccessKey( + accessKey, err := a.Services.SpvWalletEngine.GetAccessKey( req.Context(), reqXPubID, id, ) if err != nil { diff --git a/actions/access_keys/revoke.go b/actions/access_keys/revoke.go index 723d0458a..b64312d80 100644 --- a/actions/access_keys/revoke.go +++ b/actions/access_keys/revoke.go @@ -32,7 +32,7 @@ func (a *Action) revoke(w http.ResponseWriter, req *http.Request, _ httprouter.P } // Create a new accessKey - accessKey, err := a.Services.SPV.RevokeAccessKey( + accessKey, err := a.Services.SpvWalletEngine.RevokeAccessKey( req.Context(), reqXPub, id, diff --git a/actions/access_keys/search.go b/actions/access_keys/search.go index cc3a1c4db..5c9b94b1a 100644 --- a/actions/access_keys/search.go +++ b/actions/access_keys/search.go @@ -6,7 +6,7 @@ import ( "github.com/bitcoin-sv/spv-wallet/actions" "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/julienschmidt/httprouter" apirouter "github.com/mrz1836/go-api-router" ) @@ -40,7 +40,7 @@ func (a *Action) search(w http.ResponseWriter, req *http.Request, _ httprouter.P // Record a new transaction (get the hex from parameters)a var accessKeys []*engine.AccessKey - if accessKeys, err = a.Services.SPV.GetAccessKeysByXPubID( + if accessKeys, err = a.Services.SpvWalletEngine.GetAccessKeysByXPubID( req.Context(), reqXPubID, metadata, @@ -51,7 +51,7 @@ func (a *Action) search(w http.ResponseWriter, req *http.Request, _ httprouter.P return } - accessKeyContracts := make([]*spvwalletmodels.AccessKey, 0) + accessKeyContracts := make([]*models.AccessKey, 0) for _, accessKey := range accessKeys { accessKeyContracts = append(accessKeyContracts, mappings.MapToAccessKeyContract(accessKey)) } diff --git a/actions/admin/access_keys.go b/actions/admin/access_keys.go index bd3087f76..5243500ec 100644 --- a/actions/admin/access_keys.go +++ b/actions/admin/access_keys.go @@ -6,7 +6,7 @@ import ( "github.com/bitcoin-sv/spv-wallet/actions" "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/julienschmidt/httprouter" apirouter "github.com/mrz1836/go-api-router" ) @@ -37,7 +37,7 @@ func (a *Action) accessKeysSearch(w http.ResponseWriter, req *http.Request, _ ht } var accessKeys []*engine.AccessKey - if accessKeys, err = a.Services.SPV.GetAccessKeys( + if accessKeys, err = a.Services.SpvWalletEngine.GetAccessKeys( req.Context(), metadata, conditions, @@ -47,7 +47,7 @@ func (a *Action) accessKeysSearch(w http.ResponseWriter, req *http.Request, _ ht return } - accessKeyContracts := make([]*spvwalletmodels.AccessKey, 0) + accessKeyContracts := make([]*models.AccessKey, 0) for _, accessKey := range accessKeys { accessKeyContracts = append(accessKeyContracts, mappings.MapToAccessKeyContract(accessKey)) } @@ -78,7 +78,7 @@ func (a *Action) accessKeysCount(w http.ResponseWriter, req *http.Request, _ htt } var count int64 - if count, err = a.Services.SPV.GetAccessKeysCount( + if count, err = a.Services.SpvWalletEngine.GetAccessKeysCount( req.Context(), metadata, conditions, diff --git a/actions/admin/destinations.go b/actions/admin/destinations.go index 9974308cf..821c5e2bd 100644 --- a/actions/admin/destinations.go +++ b/actions/admin/destinations.go @@ -36,7 +36,7 @@ func (a *Action) destinationsSearch(w http.ResponseWriter, req *http.Request, _ } var destinations []*engine.Destination - if destinations, err = a.Services.SPV.GetDestinations( + if destinations, err = a.Services.SpvWalletEngine.GetDestinations( req.Context(), metadata, conditions, @@ -72,7 +72,7 @@ func (a *Action) destinationsCount(w http.ResponseWriter, req *http.Request, _ h } var count int64 - if count, err = a.Services.SPV.GetDestinationsCount( + if count, err = a.Services.SpvWalletEngine.GetDestinationsCount( req.Context(), metadata, conditions, diff --git a/actions/admin/paymail_addresses.go b/actions/admin/paymail_addresses.go index 77c33cb7c..f7ec04c12 100644 --- a/actions/admin/paymail_addresses.go +++ b/actions/admin/paymail_addresses.go @@ -29,9 +29,9 @@ func (a *Action) paymailGetAddress(w http.ResponseWriter, req *http.Request, _ h return } - opts := a.Services.SPV.DefaultModelOptions() + opts := a.Services.SpvWalletEngine.DefaultModelOptions() - paymailAddress, err := a.Services.SPV.GetPaymailAddress(req.Context(), address, opts...) + paymailAddress, err := a.Services.SpvWalletEngine.GetPaymailAddress(req.Context(), address, opts...) if err != nil { apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) return @@ -66,7 +66,7 @@ func (a *Action) paymailAddressesSearch(w http.ResponseWriter, req *http.Request } var paymailAddresses []*engine.PaymailAddress - if paymailAddresses, err = a.Services.SPV.GetPaymailAddresses( + if paymailAddresses, err = a.Services.SpvWalletEngine.GetPaymailAddresses( req.Context(), metadata, conditions, @@ -102,7 +102,7 @@ func (a *Action) paymailAddressesCount(w http.ResponseWriter, req *http.Request, } var count int64 - if count, err = a.Services.SPV.GetPaymailAddressesCount( + if count, err = a.Services.SpvWalletEngine.GetPaymailAddressesCount( req.Context(), metadata, conditions, @@ -153,14 +153,14 @@ func (a *Action) paymailCreateAddress(w http.ResponseWriter, req *http.Request, return } - opts := a.Services.SPV.DefaultModelOptions() + opts := a.Services.SpvWalletEngine.DefaultModelOptions() if metadata != nil { opts = append(opts, engine.WithMetadatas(*metadata)) } var paymailAddress *engine.PaymailAddress - paymailAddress, err = a.Services.SPV.NewPaymailAddress(req.Context(), xpub, address, publicName, avatar, opts...) + paymailAddress, err = a.Services.SpvWalletEngine.NewPaymailAddress(req.Context(), xpub, address, publicName, avatar, opts...) if err != nil { apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) return @@ -190,10 +190,10 @@ func (a *Action) paymailDeleteAddress(w http.ResponseWriter, req *http.Request, return } - opts := a.Services.SPV.DefaultModelOptions() + opts := a.Services.SpvWalletEngine.DefaultModelOptions() // Delete a new paymail address - err := a.Services.SPV.DeletePaymailAddress(req.Context(), address, opts...) + err := a.Services.SpvWalletEngine.DeletePaymailAddress(req.Context(), address, opts...) if err != nil { apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) return diff --git a/actions/admin/record.go b/actions/admin/record.go index c38229a88..96890b14a 100644 --- a/actions/admin/record.go +++ b/actions/admin/record.go @@ -31,7 +31,7 @@ func (a *Action) transactionRecord(w http.ResponseWriter, req *http.Request, _ h opts := make([]engine.ModelOps, 0) // Record a new transaction (get the hex from parameters) - transaction, err := a.Services.SPV.RecordRawTransaction( + transaction, err := a.Services.SpvWalletEngine.RecordRawTransaction( req.Context(), hex, opts..., @@ -39,7 +39,7 @@ func (a *Action) transactionRecord(w http.ResponseWriter, req *http.Request, _ h if err != nil { if errors.Is(err, datastore.ErrDuplicateKey) { // already registered, just return the registered transaction - if transaction, err = a.Services.SPV.GetTransactionByHex(req.Context(), hex); err != nil { + if transaction, err = a.Services.SpvWalletEngine.GetTransactionByHex(req.Context(), hex); err != nil { apirouter.ReturnResponse(w, req, http.StatusUnprocessableEntity, err.Error()) return } diff --git a/actions/admin/stats.go b/actions/admin/stats.go index 3443fdaed..f7e68f2ef 100644 --- a/actions/admin/stats.go +++ b/actions/admin/stats.go @@ -18,7 +18,7 @@ import ( // @Router /v1/admin/stats [get] // @Security x-auth-xpub func (a *Action) stats(w http.ResponseWriter, req *http.Request, _ httprouter.Params) { - stats, err := a.Services.SPV.GetStats(req.Context()) + stats, err := a.Services.SpvWalletEngine.GetStats(req.Context()) if err != nil { apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) return diff --git a/actions/admin/transactions.go b/actions/admin/transactions.go index bcfd16fed..97c6e83dd 100644 --- a/actions/admin/transactions.go +++ b/actions/admin/transactions.go @@ -6,7 +6,7 @@ import ( "github.com/bitcoin-sv/spv-wallet/actions" "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/julienschmidt/httprouter" apirouter "github.com/mrz1836/go-api-router" ) @@ -37,7 +37,7 @@ func (a *Action) transactionsSearch(w http.ResponseWriter, req *http.Request, _ } var transactions []*engine.Transaction - if transactions, err = a.Services.SPV.GetTransactions( + if transactions, err = a.Services.SpvWalletEngine.GetTransactions( req.Context(), metadata, conditions, @@ -47,7 +47,7 @@ func (a *Action) transactionsSearch(w http.ResponseWriter, req *http.Request, _ return } - contracts := make([]*spvwalletmodels.Transaction, 0) + contracts := make([]*models.Transaction, 0) for _, transaction := range transactions { contracts = append(contracts, mappings.MapToTransactionContractForAdmin(transaction)) } @@ -78,7 +78,7 @@ func (a *Action) transactionsCount(w http.ResponseWriter, req *http.Request, _ h } var count int64 - if count, err = a.Services.SPV.GetTransactionsCount( + if count, err = a.Services.SpvWalletEngine.GetTransactionsCount( req.Context(), metadata, conditions, diff --git a/actions/admin/utxos.go b/actions/admin/utxos.go index 8aa31681b..289a1f700 100644 --- a/actions/admin/utxos.go +++ b/actions/admin/utxos.go @@ -36,7 +36,7 @@ func (a *Action) utxosSearch(w http.ResponseWriter, req *http.Request, _ httprou } var utxos []*engine.Utxo - if utxos, err = a.Services.SPV.GetUtxos( + if utxos, err = a.Services.SpvWalletEngine.GetUtxos( req.Context(), metadata, conditions, @@ -72,7 +72,7 @@ func (a *Action) utxosCount(w http.ResponseWriter, req *http.Request, _ httprout } var count int64 - if count, err = a.Services.SPV.GetUtxosCount( + if count, err = a.Services.SpvWalletEngine.GetUtxosCount( req.Context(), metadata, conditions, diff --git a/actions/admin/xpubs.go b/actions/admin/xpubs.go index 91f6f9457..280804ee8 100644 --- a/actions/admin/xpubs.go +++ b/actions/admin/xpubs.go @@ -37,7 +37,7 @@ func (a *Action) xpubsSearch(w http.ResponseWriter, req *http.Request, _ httprou } var xpubs []*engine.Xpub - if xpubs, err = a.Services.SPV.GetXPubs( + if xpubs, err = a.Services.SpvWalletEngine.GetXPubs( req.Context(), metadata, conditions, @@ -73,7 +73,7 @@ func (a *Action) xpubsCount(w http.ResponseWriter, req *http.Request, _ httprout } var count int64 - if count, err = a.Services.SPV.GetXPubsCount( + if count, err = a.Services.SpvWalletEngine.GetXPubsCount( req.Context(), metadata, conditions, diff --git a/actions/destinations/count.go b/actions/destinations/count.go index edc718856..b04b774d5 100644 --- a/actions/destinations/count.go +++ b/actions/destinations/count.go @@ -35,7 +35,7 @@ func (a *Action) count(w http.ResponseWriter, req *http.Request, _ httprouter.Pa // Record a new transaction (get the hex from parameters) var count int64 - if count, err = a.Services.SPV.GetDestinationsByXpubIDCount( + if count, err = a.Services.SpvWalletEngine.GetDestinationsByXpubIDCount( req.Context(), reqXPubID, metadata, diff --git a/actions/destinations/create.go b/actions/destinations/create.go index 996437973..e581cb0b0 100644 --- a/actions/destinations/create.go +++ b/actions/destinations/create.go @@ -29,7 +29,7 @@ func (a *Action) create(w http.ResponseWriter, req *http.Request, _ httprouter.P // Get the xPub from the request (via authentication) reqXPub, _ := engine.GetXpubFromRequest(req) - xPub, err := a.Services.SPV.GetXpub(req.Context(), reqXPub) + xPub, err := a.Services.SpvWalletEngine.GetXpub(req.Context(), reqXPub) if err != nil { apirouter.ReturnResponse(w, req, http.StatusUnprocessableEntity, err.Error()) return @@ -53,7 +53,7 @@ func (a *Action) create(w http.ResponseWriter, req *http.Request, _ httprouter.P metadata[engine.ReferenceIDField] = referenceID } - opts := a.Services.SPV.DefaultModelOptions() + opts := a.Services.SpvWalletEngine.DefaultModelOptions() if metadata != nil { opts = append(opts, engine.WithMetadatas(metadata)) @@ -61,7 +61,7 @@ func (a *Action) create(w http.ResponseWriter, req *http.Request, _ httprouter.P // Get a new destination var destination *engine.Destination - if destination, err = a.Services.SPV.NewDestination( + if destination, err = a.Services.SpvWalletEngine.NewDestination( req.Context(), xPub.RawXpub(), uint32(0), // todo: use a constant? protect this? diff --git a/actions/destinations/get.go b/actions/destinations/get.go index 2ac44e142..190b88a0c 100644 --- a/actions/destinations/get.go +++ b/actions/destinations/get.go @@ -38,15 +38,15 @@ func (a *Action) get(w http.ResponseWriter, req *http.Request, _ httprouter.Para var destination *engine.Destination var err error if id != "" { - destination, err = a.Services.SPV.GetDestinationByID( + destination, err = a.Services.SpvWalletEngine.GetDestinationByID( req.Context(), reqXPubID, id, ) } else if address != "" { - destination, err = a.Services.SPV.GetDestinationByAddress( + destination, err = a.Services.SpvWalletEngine.GetDestinationByAddress( req.Context(), reqXPubID, address, ) } else { - destination, err = a.Services.SPV.GetDestinationByLockingScript( + destination, err = a.Services.SpvWalletEngine.GetDestinationByLockingScript( req.Context(), reqXPubID, lockingScript, ) } diff --git a/actions/destinations/search.go b/actions/destinations/search.go index 7f1f51375..5e8f472d1 100644 --- a/actions/destinations/search.go +++ b/actions/destinations/search.go @@ -6,7 +6,7 @@ import ( "github.com/bitcoin-sv/spv-wallet/actions" "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/julienschmidt/httprouter" apirouter "github.com/mrz1836/go-api-router" ) @@ -40,7 +40,7 @@ func (a *Action) search(w http.ResponseWriter, req *http.Request, _ httprouter.P // Record a new transaction (get the hex from parameters)a var destinations []*engine.Destination - if destinations, err = a.Services.SPV.GetDestinationsByXpubID( + if destinations, err = a.Services.SpvWalletEngine.GetDestinationsByXpubID( req.Context(), reqXPubID, metadata, @@ -51,7 +51,7 @@ func (a *Action) search(w http.ResponseWriter, req *http.Request, _ httprouter.P return } - contracts := make([]*spvwalletmodels.Destination, 0) + contracts := make([]*models.Destination, 0) for _, destination := range destinations { contracts = append(contracts, mappings.MapToDestinationContract(destination)) } diff --git a/actions/destinations/update.go b/actions/destinations/update.go index 72968e0d3..82677bb22 100644 --- a/actions/destinations/update.go +++ b/actions/destinations/update.go @@ -41,15 +41,15 @@ func (a *Action) update(w http.ResponseWriter, req *http.Request, _ httprouter.P var destination *engine.Destination var err error if id != "" { - destination, err = a.Services.SPV.UpdateDestinationMetadataByID( + destination, err = a.Services.SpvWalletEngine.UpdateDestinationMetadataByID( req.Context(), reqXPubID, id, metadata, ) } else if address != "" { - destination, err = a.Services.SPV.UpdateDestinationMetadataByAddress( + destination, err = a.Services.SpvWalletEngine.UpdateDestinationMetadataByAddress( req.Context(), reqXPubID, address, metadata, ) } else { - destination, err = a.Services.SPV.UpdateDestinationMetadataByLockingScript( + destination, err = a.Services.SpvWalletEngine.UpdateDestinationMetadataByLockingScript( req.Context(), reqXPubID, lockingScript, metadata, ) } diff --git a/actions/methods.go b/actions/methods.go index 80aafb380..fb60c7970 100644 --- a/actions/methods.go +++ b/actions/methods.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/bitcoin-sv/spv-wallet/dictionary" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/julienschmidt/httprouter" "github.com/mrz1836/go-datastore" "github.com/mrz1836/go-parameters" @@ -51,7 +51,7 @@ func MethodNotAllowed(w http.ResponseWriter, req *http.Request) { } // GetQueryParameters get all filtering parameters related to the db query -func GetQueryParameters(params *parameters.Params) (*datastore.QueryParams, *spvwalletmodels.Metadata, *map[string]interface{}, error) { +func GetQueryParameters(params *parameters.Params) (*datastore.QueryParams, *models.Metadata, *map[string]interface{}, error) { var queryParams *datastore.QueryParams jsonQueryParams, ok := params.GetJSONOk("params") if ok { @@ -73,7 +73,7 @@ func GetQueryParameters(params *parameters.Params) (*datastore.QueryParams, *spv } metadataReq := params.GetJSON(MetadataField) - var metadata *spvwalletmodels.Metadata + var metadata *models.Metadata if len(metadataReq) > 0 { // marshal the metadata into the Metadata model metaJSON, _ := json.Marshal(metadataReq) //nolint:errchkjson // ignore for now diff --git a/actions/middleware.go b/actions/middleware.go index d02e81614..145bc6ec3 100644 --- a/actions/middleware.go +++ b/actions/middleware.go @@ -32,7 +32,7 @@ func (a *Action) RequireAuthentication(fn httprouter.Handle) httprouter.Handle { return func(w http.ResponseWriter, req *http.Request, p httprouter.Params) { // Check the authentication var knownErr dictionary.ErrorMessage - if req, knownErr = CheckAuthentication(a.AppConfig, a.Services.SPV, req, false, true); knownErr.Code > 0 { + if req, knownErr = CheckAuthentication(a.AppConfig, a.Services.SpvWalletEngine, req, false, true); knownErr.Code > 0 { ReturnErrorResponse(w, req, knownErr, "") return } @@ -47,7 +47,7 @@ func (a *Action) RequireBasicAuthentication(fn httprouter.Handle) httprouter.Han return func(w http.ResponseWriter, req *http.Request, p httprouter.Params) { // Check the authentication var knownErr dictionary.ErrorMessage - if req, knownErr = CheckAuthentication(a.AppConfig, a.Services.SPV, req, false, false); knownErr.Code > 0 { + if req, knownErr = CheckAuthentication(a.AppConfig, a.Services.SpvWalletEngine, req, false, false); knownErr.Code > 0 { ReturnErrorResponse(w, req, knownErr, "") return } @@ -62,7 +62,7 @@ func (a *Action) RequireAdminAuthentication(fn httprouter.Handle) httprouter.Han return func(w http.ResponseWriter, req *http.Request, p httprouter.Params) { // Check the authentication var knownErr dictionary.ErrorMessage - if req, knownErr = CheckAuthentication(a.AppConfig, a.Services.SPV, req, true, true); knownErr.Code > 0 { + if req, knownErr = CheckAuthentication(a.AppConfig, a.Services.SpvWalletEngine, req, true, true); knownErr.Code > 0 { ReturnErrorResponse(w, req, knownErr, "") return } diff --git a/actions/paymail/create.go b/actions/paymail/create.go index 4eea99790..90c177e61 100644 --- a/actions/paymail/create.go +++ b/actions/paymail/create.go @@ -34,13 +34,13 @@ func (a *Action) create(w http.ResponseWriter, req *http.Request, _ httprouter.P avatar := params.GetString("avatar") // the avatar metadata := params.GetJSON("metadata") // optional metadata - opts := a.Services.SPV.DefaultModelOptions() + opts := a.Services.SpvWalletEngine.DefaultModelOptions() if metadata != nil { opts = append(opts, engine.WithMetadatas(metadata)) } - paymailAddress, err := a.Services.SPV.NewPaymailAddress(req.Context(), key, address, publicName, avatar, opts...) + paymailAddress, err := a.Services.SpvWalletEngine.NewPaymailAddress(req.Context(), key, address, publicName, avatar, opts...) if err != nil { apirouter.ReturnResponse(w, req, http.StatusUnprocessableEntity, err.Error()) return diff --git a/actions/paymail/delete.go b/actions/paymail/delete.go index 0b3213040..40943120e 100644 --- a/actions/paymail/delete.go +++ b/actions/paymail/delete.go @@ -24,10 +24,10 @@ func (a *Action) delete(w http.ResponseWriter, req *http.Request, _ httprouter.P // params address := params.GetString("address") // the full paymail address - opts := a.Services.SPV.DefaultModelOptions() + opts := a.Services.SpvWalletEngine.DefaultModelOptions() // Delete a new paymail address - err := a.Services.SPV.DeletePaymailAddress( + err := a.Services.SpvWalletEngine.DeletePaymailAddress( req.Context(), address, opts..., ) if err != nil { diff --git a/actions/paymail/routes.go b/actions/paymail/routes.go index 2ddf8cee1..a5b4f1573 100644 --- a/actions/paymail/routes.go +++ b/actions/paymail/routes.go @@ -18,7 +18,7 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi requireAdmin.Use(a.RequireAdminAuthentication) // Register the custom Paymail routes - services.SPV.GetPaymailConfig().RegisterRoutes(router.HTTPRouter) + services.SpvWalletEngine.GetPaymailConfig().RegisterRoutes(router.HTTPRouter) // Create the action action := &Action{actions.Action{AppConfig: a.AppConfig, Services: a.Services}} diff --git a/actions/transactions/broadcast_callback.go b/actions/transactions/broadcast_callback.go index 18f4f002b..3dc131c09 100644 --- a/actions/transactions/broadcast_callback.go +++ b/actions/transactions/broadcast_callback.go @@ -32,7 +32,7 @@ func (a *Action) broadcastCallback(w http.ResponseWriter, req *http.Request, _ h } }() - err = a.Services.SPV.UpdateTransaction(req.Context(), resp) + err = a.Services.SpvWalletEngine.UpdateTransaction(req.Context(), resp) if err != nil { a.Services.Logger.Err(err).Msgf("failed to update transaction - tx: %v", resp) apirouter.ReturnResponse(w, req, http.StatusInternalServerError, "") diff --git a/actions/transactions/count.go b/actions/transactions/count.go index c6289b92a..c5417538c 100644 --- a/actions/transactions/count.go +++ b/actions/transactions/count.go @@ -35,7 +35,7 @@ func (a *Action) count(w http.ResponseWriter, req *http.Request, _ httprouter.Pa // Record a new transaction (get the hex from parameters)a var count int64 - if count, err = a.Services.SPV.GetTransactionsByXpubIDCount( + if count, err = a.Services.SpvWalletEngine.GetTransactionsByXpubIDCount( req.Context(), reqXPubID, metadata, diff --git a/actions/transactions/get.go b/actions/transactions/get.go index e480ec3ba..0011368da 100644 --- a/actions/transactions/get.go +++ b/actions/transactions/get.go @@ -27,7 +27,7 @@ func (a *Action) get(w http.ResponseWriter, req *http.Request, _ httprouter.Para reqXPubID, _ := engine.GetXpubIDFromRequest(req) // Get a transaction by ID - transaction, err := a.Services.SPV.GetTransaction( + transaction, err := a.Services.SpvWalletEngine.GetTransaction( req.Context(), reqXPubID, params.GetString("id"), diff --git a/actions/transactions/new.go b/actions/transactions/new.go index 7987792fb..683b2ec3c 100644 --- a/actions/transactions/new.go +++ b/actions/transactions/new.go @@ -7,7 +7,7 @@ import ( "github.com/bitcoin-sv/spv-wallet/actions" "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/julienschmidt/httprouter" apirouter "github.com/mrz1836/go-api-router" ) @@ -29,7 +29,7 @@ func (a *Action) newTransaction(w http.ResponseWriter, req *http.Request, _ http // Get the xPub from the request (via authentication) reqXPub, _ := engine.GetXpubFromRequest(req) - xPub, err := a.Services.SPV.GetXpub(req.Context(), reqXPub) + xPub, err := a.Services.SpvWalletEngine.GetXpub(req.Context(), reqXPub) if err != nil { apirouter.ReturnResponse(w, req, http.StatusUnprocessableEntity, err.Error()) return @@ -52,14 +52,14 @@ func (a *Action) newTransaction(w http.ResponseWriter, req *http.Request, _ http return } - txContract := spvwalletmodels.TransactionConfig{} + txContract := models.TransactionConfig{} if err = json.Unmarshal(configBytes, &txContract); err != nil { apirouter.ReturnResponse(w, req, http.StatusBadRequest, actions.ErrBadTxConfig.Error()) return } metadata := params.GetJSON(engine.ModelMetadata.String()) - opts := a.Services.SPV.DefaultModelOptions() + opts := a.Services.SpvWalletEngine.DefaultModelOptions() if metadata != nil { opts = append(opts, engine.WithMetadatas(metadata)) } @@ -68,7 +68,7 @@ func (a *Action) newTransaction(w http.ResponseWriter, req *http.Request, _ http // Record a new transaction (get the hex from parameters) var transaction *engine.DraftTransaction - if transaction, err = a.Services.SPV.NewTransaction( + if transaction, err = a.Services.SpvWalletEngine.NewTransaction( req.Context(), xPub.RawXpub(), txConfig, diff --git a/actions/transactions/record.go b/actions/transactions/record.go index c3d238141..2893654ec 100644 --- a/actions/transactions/record.go +++ b/actions/transactions/record.go @@ -3,7 +3,6 @@ package transactions import ( "net/http" - "github.com/bitcoin-sv/spv-wallet/actions" "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings" @@ -29,7 +28,7 @@ func (a *Action) record(w http.ResponseWriter, req *http.Request, _ httprouter.P // Get the xPub from the request (via authentication) reqXPub, _ := engine.GetXpubFromRequest(req) - xPub, err := a.Services.SPV.GetXpub(req.Context(), reqXPub) + xPub, err := a.Services.SpvWalletEngine.GetXpub(req.Context(), reqXPub) if err != nil { apirouter.ReturnResponse(w, req, http.StatusUnprocessableEntity, err.Error()) return @@ -47,7 +46,7 @@ func (a *Action) record(w http.ResponseWriter, req *http.Request, _ httprouter.P // Record a new transaction (get the hex from parameters) var transaction *engine.Transaction - if transaction, err = a.Services.SPV.RecordTransaction( + if transaction, err = a.Services.SpvWalletEngine.RecordTransaction( req.Context(), reqXPub, params.GetString("hex"), diff --git a/actions/transactions/search.go b/actions/transactions/search.go index 0d7680a22..4f8409fa3 100644 --- a/actions/transactions/search.go +++ b/actions/transactions/search.go @@ -6,7 +6,7 @@ import ( "github.com/bitcoin-sv/spv-wallet/actions" "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/julienschmidt/httprouter" apirouter "github.com/mrz1836/go-api-router" ) @@ -40,7 +40,7 @@ func (a *Action) search(w http.ResponseWriter, req *http.Request, _ httprouter.P // Record a new transaction (get the hex from parameters)a var transactions []*engine.Transaction - if transactions, err = a.Services.SPV.GetTransactionsByXpubID( + if transactions, err = a.Services.SpvWalletEngine.GetTransactionsByXpubID( req.Context(), reqXPubID, metadata, @@ -51,7 +51,7 @@ func (a *Action) search(w http.ResponseWriter, req *http.Request, _ httprouter.P return } - contracts := make([]*spvwalletmodels.Transaction, 0) + contracts := make([]*models.Transaction, 0) for _, transaction := range transactions { contracts = append(contracts, mappings.MapToTransactionContract(transaction)) } diff --git a/actions/transactions/update.go b/actions/transactions/update.go index 716577646..e75068f0d 100644 --- a/actions/transactions/update.go +++ b/actions/transactions/update.go @@ -30,7 +30,7 @@ func (a *Action) update(w http.ResponseWriter, req *http.Request, _ httprouter.P metadata := params.GetJSON(actions.MetadataField) // Get a transaction by ID - transaction, err := a.Services.SPV.UpdateTransactionMetadata( + transaction, err := a.Services.SpvWalletEngine.UpdateTransactionMetadata( req.Context(), reqXPubID, params.GetString("id"), diff --git a/actions/utxos/count.go b/actions/utxos/count.go index 8330ef913..419631ed6 100644 --- a/actions/utxos/count.go +++ b/actions/utxos/count.go @@ -42,7 +42,7 @@ func (a *Action) count(w http.ResponseWriter, req *http.Request, _ httprouter.Pa // Get a utxo using a xPub var count int64 - if count, err = a.Services.SPV.GetUtxosCount( + if count, err = a.Services.SpvWalletEngine.GetUtxosCount( req.Context(), metadata, &dbConditions, diff --git a/actions/utxos/get.go b/actions/utxos/get.go index 9d7b61f31..920afb8ba 100644 --- a/actions/utxos/get.go +++ b/actions/utxos/get.go @@ -29,7 +29,7 @@ func (a *Action) get(w http.ResponseWriter, req *http.Request, _ httprouter.Para outputIndex := uint32(params.GetUint64("output_index")) // Get a utxo using a xPub - utxo, err := a.Services.SPV.GetUtxo( + utxo, err := a.Services.SpvWalletEngine.GetUtxo( req.Context(), reqXPubID, txID, diff --git a/actions/utxos/search.go b/actions/utxos/search.go index 3aaff85f7..92b231de5 100644 --- a/actions/utxos/search.go +++ b/actions/utxos/search.go @@ -6,7 +6,7 @@ import ( "github.com/bitcoin-sv/spv-wallet/actions" "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/julienschmidt/httprouter" apirouter "github.com/mrz1836/go-api-router" ) @@ -40,7 +40,7 @@ func (a *Action) search(w http.ResponseWriter, req *http.Request, _ httprouter.P // Record a new transaction (get the hex from parameters)a var utxos []*engine.Utxo - if utxos, err = a.Services.SPV.GetUtxosByXpubID( + if utxos, err = a.Services.SpvWalletEngine.GetUtxosByXpubID( req.Context(), reqXPubID, metadata, @@ -51,7 +51,7 @@ func (a *Action) search(w http.ResponseWriter, req *http.Request, _ httprouter.P return } - contracts := make([]*spvwalletmodels.Utxo, 0) + contracts := make([]*models.Utxo, 0) for _, utxo := range utxos { contracts = append(contracts, mappings.MapToUtxoContract(utxo)) } diff --git a/actions/utxos/unreserve.go b/actions/utxos/unreserve.go index f303bdbef..d23d52fa2 100644 --- a/actions/utxos/unreserve.go +++ b/actions/utxos/unreserve.go @@ -22,7 +22,7 @@ func (a *Action) unreserve(w http.ResponseWriter, req *http.Request, _ httproute reqXPubID, _ := engine.GetXpubIDFromRequest(req) params := apirouter.GetParams(req) - err := a.Services.SPV.UnReserveUtxos( + err := a.Services.SpvWalletEngine.UnReserveUtxos( req.Context(), reqXPubID, params.GetString(engine.ReferenceIDField), diff --git a/actions/xpubs/create.go b/actions/xpubs/create.go index f6c20e349..b6c330ea9 100644 --- a/actions/xpubs/create.go +++ b/actions/xpubs/create.go @@ -30,7 +30,7 @@ func (a *Action) create(w http.ResponseWriter, req *http.Request, _ httprouter.P metadata := params.GetJSON(actions.MetadataField) // Create a new xPub - xPub, err := a.Services.SPV.NewXpub( + xPub, err := a.Services.SpvWalletEngine.NewXpub( req.Context(), key, engine.WithMetadatas(metadata), ) diff --git a/actions/xpubs/get.go b/actions/xpubs/get.go index 402641be3..b955a016b 100644 --- a/actions/xpubs/get.go +++ b/actions/xpubs/get.go @@ -39,11 +39,11 @@ func (a *Action) get(w http.ResponseWriter, req *http.Request, _ httprouter.Para var xPub *engine.Xpub var err error if key != "" { - xPub, err = a.Services.SPV.GetXpub( + xPub, err = a.Services.SpvWalletEngine.GetXpub( req.Context(), key, ) } else { - xPub, err = a.Services.SPV.GetXpubByID( + xPub, err = a.Services.SpvWalletEngine.GetXpubByID( req.Context(), reqXPubID, ) } diff --git a/actions/xpubs/update.go b/actions/xpubs/update.go index c86f88af1..6c25ff3de 100644 --- a/actions/xpubs/update.go +++ b/actions/xpubs/update.go @@ -31,7 +31,7 @@ func (a *Action) update(w http.ResponseWriter, req *http.Request, _ httprouter.P // Get an xPub var xPub *engine.Xpub var err error - xPub, err = a.Services.SPV.UpdateXpubMetadata( + xPub, err = a.Services.SpvWalletEngine.UpdateXpubMetadata( req.Context(), reqXPubID, metadata, ) if err != nil { diff --git a/cmd/server/main.go b/cmd/server/main.go index 4ff050efd..52907f855 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -17,7 +17,7 @@ import ( ) // main method starts everything for the SPV Wallet -// @title SPV: Wallet +// @title SPV Wallet // @version v0.12.0 // @securityDefinitions.apikey x-auth-xpub // @in header diff --git a/config/services.go b/config/services.go index e00da04ce..40985b67c 100644 --- a/config/services.go +++ b/config/services.go @@ -25,9 +25,9 @@ import ( // AppServices is the loaded services via config type ( AppServices struct { - SPV engine.ClientInterface - NewRelic *newrelic.Application - Logger *zerolog.Logger + SpvWalletEngine engine.ClientInterface + NewRelic *newrelic.Application + Logger *zerolog.Logger } ) @@ -115,9 +115,9 @@ func (a *AppConfig) loadNewRelic(services *AppServices) (err error) { // CloseAll will close all connections to all services func (s *AppServices) CloseAll(ctx context.Context) { // Close SPV - if s.SPV != nil { - _ = s.SPV.Close(ctx) - s.SPV = nil + if s.SpvWalletEngine != nil { + _ = s.SpvWalletEngine.Close(ctx) + s.SpvWalletEngine = nil } // Close new relic @@ -202,7 +202,7 @@ func (s *AppServices) loadSPV(ctx context.Context, appConfig *AppConfig, testMod } // Create the new client - s.SPV, err = engine.NewClient(ctx, options...) + s.SpvWalletEngine, err = engine.NewClient(ctx, options...) return } diff --git a/config/services_test.go b/config/services_test.go index 6ed7afc51..d185be0df 100644 --- a/config/services_test.go +++ b/config/services_test.go @@ -34,7 +34,7 @@ func TestAppServices_CloseAll(t *testing.T) { require.NotNil(t, s) s.CloseAll(context.Background()) - assert.Nil(t, s.SPV) + assert.Nil(t, s.SpvWalletEngine) assert.Nil(t, s.NewRelic) }) } diff --git a/engine/paymail_test.go b/engine/paymail_test.go index 9f2d8f27d..a636fa410 100644 --- a/engine/paymail_test.go +++ b/engine/paymail_test.go @@ -49,7 +49,6 @@ func newTestPaymailConfig(t *testing.T, domain string) *server.Configuration { // mockValidResponse is used for mocking the response func mockValidResponse(statusCode int, p2p bool, domain string) { httpmock.Reset() - serverURL := "https://" + domain + "/api/v1/" + paymail.DefaultServiceName // Basic address resolution vs P2P diff --git a/mappings/access_keys.go b/mappings/access_keys.go index 691b81de8..a732aa466 100644 --- a/mappings/access_keys.go +++ b/mappings/access_keys.go @@ -6,11 +6,11 @@ import ( "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings/common" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToAccessKeyContract will map the access key to the spv-wallet-models contract -func MapToAccessKeyContract(ac *engine.AccessKey) *spvwalletmodels.AccessKey { +func MapToAccessKeyContract(ac *engine.AccessKey) *models.AccessKey { if ac == nil { return nil } @@ -20,7 +20,7 @@ func MapToAccessKeyContract(ac *engine.AccessKey) *spvwalletmodels.AccessKey { revokedAt = &ac.RevokedAt.Time } - return &spvwalletmodels.AccessKey{ + return &models.AccessKey{ Model: *common.MapToContract(&ac.Model), ID: ac.ID, XpubID: ac.XpubID, diff --git a/mappings/admin.go b/mappings/admin.go index 8bb549649..06e26388c 100644 --- a/mappings/admin.go +++ b/mappings/admin.go @@ -2,16 +2,16 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToAdminStatsContract will map the model from spv-wallet to the spv-wallet-models contract -func MapToAdminStatsContract(s *engine.AdminStats) *spvwalletmodels.AdminStats { +func MapToAdminStatsContract(s *engine.AdminStats) *models.AdminStats { if s == nil { return nil } - return &spvwalletmodels.AdminStats{ + return &models.AdminStats{ Balance: s.Balance, Destinations: s.Destinations, PaymailAddresses: s.PaymailAddresses, diff --git a/mappings/destination.go b/mappings/destination.go index 80d26dd22..11e545b29 100644 --- a/mappings/destination.go +++ b/mappings/destination.go @@ -3,16 +3,16 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings/common" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToDestinationContract will map the spv-wallet destination model to the spv-wallet-models contract -func MapToDestinationContract(d *engine.Destination) *spvwalletmodels.Destination { +func MapToDestinationContract(d *engine.Destination) *models.Destination { if d == nil { return nil } - return &spvwalletmodels.Destination{ + return &models.Destination{ Model: *common.MapToContract(&d.Model), ID: d.ID, XpubID: d.XpubID, @@ -26,7 +26,7 @@ func MapToDestinationContract(d *engine.Destination) *spvwalletmodels.Destinatio } // MapToDestinationSPV will map the spv-wallet-models destination contract to the spv-wallet destination model -func MapToDestinationSPV(d *spvwalletmodels.Destination) *engine.Destination { +func MapToDestinationSPV(d *models.Destination) *engine.Destination { if d == nil { return nil } diff --git a/mappings/fee_unit.go b/mappings/fee_unit.go index a161bb4f3..89f1d7e88 100644 --- a/mappings/fee_unit.go +++ b/mappings/fee_unit.go @@ -2,23 +2,23 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine/utils" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToFeeUnitContract will map the fee-unit model from spv-wallet to the spv-wallet-models contract -func MapToFeeUnitContract(fu *utils.FeeUnit) (fc *spvwalletmodels.FeeUnit) { +func MapToFeeUnitContract(fu *utils.FeeUnit) (fc *models.FeeUnit) { if fu == nil { return nil } - return &spvwalletmodels.FeeUnit{ + return &models.FeeUnit{ Satoshis: fu.Satoshis, Bytes: fu.Bytes, } } // MapToFeeUnitSPV will map the fee-unit model from spv-wallet-models to the spv-wallet contract -func MapToFeeUnitSPV(fu *spvwalletmodels.FeeUnit) (fc *utils.FeeUnit) { +func MapToFeeUnitSPV(fu *models.FeeUnit) (fc *utils.FeeUnit) { if fu == nil { return nil } diff --git a/mappings/metadata.go b/mappings/metadata.go index 2a7fa1031..f134e0c1c 100644 --- a/mappings/metadata.go +++ b/mappings/metadata.go @@ -2,11 +2,11 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToSPVMetadata will map the *spvwalletmodels.Metadata to *spv.Metadata -func MapToSPVMetadata(metadata *spvwalletmodels.Metadata) *engine.Metadata { +func MapToSPVMetadata(metadata *models.Metadata) *engine.Metadata { if metadata == nil { return nil } diff --git a/mappings/paymail_address.go b/mappings/paymail_address.go index dd4de94ff..ee0e0c954 100644 --- a/mappings/paymail_address.go +++ b/mappings/paymail_address.go @@ -3,16 +3,16 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings/common" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToPaymailContract will map the spv-wallet paymail-address model to the spv-wallet-models contract -func MapToPaymailContract(pa *engine.PaymailAddress) *spvwalletmodels.PaymailAddress { +func MapToPaymailContract(pa *engine.PaymailAddress) *models.PaymailAddress { if pa == nil { return nil } - return &spvwalletmodels.PaymailAddress{ + return &models.PaymailAddress{ Model: *common.MapToContract(&pa.Model), ID: pa.ID, XpubID: pa.XpubID, @@ -25,12 +25,12 @@ func MapToPaymailContract(pa *engine.PaymailAddress) *spvwalletmodels.PaymailAdd } // MapToPaymailP4Contract will map the spv-wallet-models paymail-address contract to the spv-wallet paymail-address model -func MapToPaymailP4Contract(p *engine.PaymailP4) *spvwalletmodels.PaymailP4 { +func MapToPaymailP4Contract(p *engine.PaymailP4) *models.PaymailP4 { if p == nil { return nil } - return &spvwalletmodels.PaymailP4{ + return &models.PaymailP4{ Alias: p.Alias, Domain: p.Domain, FromPaymail: p.FromPaymail, @@ -43,7 +43,7 @@ func MapToPaymailP4Contract(p *engine.PaymailP4) *spvwalletmodels.PaymailP4 { } // MapToPaymailP4SPV will map the spv-wallet-models paymail-address contract to the spv-wallet paymail-address model -func MapToPaymailP4SPV(p *spvwalletmodels.PaymailP4) *engine.PaymailP4 { +func MapToPaymailP4SPV(p *models.PaymailP4) *engine.PaymailP4 { if p == nil { return nil } diff --git a/mappings/script_output.go b/mappings/script_output.go index 244503d4b..82e01c6c8 100644 --- a/mappings/script_output.go +++ b/mappings/script_output.go @@ -2,16 +2,16 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToScriptOutputContract will map the script-output model from spv-wallet to the spv-wallet-models contract -func MapToScriptOutputContract(so *engine.ScriptOutput) (sc *spvwalletmodels.ScriptOutput) { +func MapToScriptOutputContract(so *engine.ScriptOutput) (sc *models.ScriptOutput) { if so == nil { return nil } - return &spvwalletmodels.ScriptOutput{ + return &models.ScriptOutput{ Address: so.Address, Satoshis: so.Satoshis, Script: so.Script, @@ -20,7 +20,7 @@ func MapToScriptOutputContract(so *engine.ScriptOutput) (sc *spvwalletmodels.Scr } // MapToScriptOutputSPV will map the script-output model from spv-wallet-models to the spv-wallet contract -func MapToScriptOutputSPV(so *spvwalletmodels.ScriptOutput) (sc *engine.ScriptOutput) { +func MapToScriptOutputSPV(so *models.ScriptOutput) (sc *engine.ScriptOutput) { if so == nil { return nil } diff --git a/mappings/sync_config.go b/mappings/sync_config.go index b960e6787..caede5697 100644 --- a/mappings/sync_config.go +++ b/mappings/sync_config.go @@ -2,16 +2,16 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToSyncConfigContract will map the sync-config model from spv-wallet to the spv-wallet-models contract -func MapToSyncConfigContract(sc *engine.SyncConfig) *spvwalletmodels.SyncConfig { +func MapToSyncConfigContract(sc *engine.SyncConfig) *models.SyncConfig { if sc == nil { return nil } - return &spvwalletmodels.SyncConfig{ + return &models.SyncConfig{ Broadcast: sc.Broadcast, BroadcastInstant: sc.BroadcastInstant, PaymailP2P: sc.PaymailP2P, @@ -20,7 +20,7 @@ func MapToSyncConfigContract(sc *engine.SyncConfig) *spvwalletmodels.SyncConfig } // MapToSyncConfigSPV will map the sync-config model from spv-wallet-models to the spv-wallet contract -func MapToSyncConfigSPV(sc *spvwalletmodels.SyncConfig) *engine.SyncConfig { +func MapToSyncConfigSPV(sc *models.SyncConfig) *engine.SyncConfig { if sc == nil { return nil } diff --git a/mappings/transaction.go b/mappings/transaction.go index 8bd047290..e40c49bfe 100644 --- a/mappings/transaction.go +++ b/mappings/transaction.go @@ -3,16 +3,16 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings/common" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToTransactionContract will map the model from spv-wallet to the spv-wallet-models contract -func MapToTransactionContract(t *engine.Transaction) *spvwalletmodels.Transaction { +func MapToTransactionContract(t *engine.Transaction) *models.Transaction { if t == nil { return nil } - model := spvwalletmodels.Transaction{ + model := models.Transaction{ Model: *common.MapToContract(&t.Model), ID: t.ID, Hex: t.Hex, @@ -36,12 +36,12 @@ func MapToTransactionContract(t *engine.Transaction) *spvwalletmodels.Transactio } // MapToTransactionContractForAdmin will map the model from spv-wallet to the spv-wallet-models contract for admin -func MapToTransactionContractForAdmin(t *engine.Transaction) *spvwalletmodels.Transaction { +func MapToTransactionContractForAdmin(t *engine.Transaction) *models.Transaction { if t == nil { return nil } - model := spvwalletmodels.Transaction{ + model := models.Transaction{ Model: *common.MapToContract(&t.Model), ID: t.ID, Hex: t.Hex, @@ -63,10 +63,10 @@ func MapToTransactionContractForAdmin(t *engine.Transaction) *spvwalletmodels.Tr return &model } -func processMetadata(t *engine.Transaction, xpubID string, model *spvwalletmodels.Transaction) { +func processMetadata(t *engine.Transaction, xpubID string, model *models.Transaction) { if len(t.XpubMetadata) > 0 && len(t.XpubMetadata[xpubID]) > 0 { if t.Model.Metadata == nil { - model.Model.Metadata = make(spvwalletmodels.Metadata) + model.Model.Metadata = make(models.Metadata) } for key, value := range t.XpubMetadata[xpubID] { model.Model.Metadata[key] = value @@ -74,7 +74,7 @@ func processMetadata(t *engine.Transaction, xpubID string, model *spvwalletmodel } } -func processOutputValue(t *engine.Transaction, xpubID string, model *spvwalletmodels.Transaction) { +func processOutputValue(t *engine.Transaction, xpubID string, model *models.Transaction) { model.OutputValue = int64(0) if len(t.XpubOutputValue) > 0 && t.XpubOutputValue[xpubID] != 0 { model.OutputValue = t.XpubOutputValue[xpubID] @@ -88,7 +88,7 @@ func processOutputValue(t *engine.Transaction, xpubID string, model *spvwalletmo } // MapToTransactionSPV will map the model from spv-wallet-models to the spv-wallet contract -func MapToTransactionSPV(t *spvwalletmodels.Transaction) *engine.Transaction { +func MapToTransactionSPV(t *models.Transaction) *engine.Transaction { if t == nil { return nil } @@ -112,7 +112,7 @@ func MapToTransactionSPV(t *spvwalletmodels.Transaction) *engine.Transaction { } // MapToTransactionConfigSPV will map the transaction-config model from spv-wallet to the spv-wallet-models contract -func MapToTransactionConfigSPV(tx *spvwalletmodels.TransactionConfig) *engine.TransactionConfig { +func MapToTransactionConfigSPV(tx *models.TransactionConfig) *engine.TransactionConfig { if tx == nil { return nil } @@ -135,7 +135,7 @@ func MapToTransactionConfigSPV(tx *spvwalletmodels.TransactionConfig) *engine.Tr } } -func mapToSPVOutputs(tx *spvwalletmodels.TransactionConfig) []*engine.TransactionOutput { +func mapToSPVOutputs(tx *models.TransactionConfig) []*engine.TransactionOutput { if tx.Outputs == nil { return nil } @@ -147,7 +147,7 @@ func mapToSPVOutputs(tx *spvwalletmodels.TransactionConfig) []*engine.Transactio return outputs } -func mapToSPVInputs(tx *spvwalletmodels.TransactionConfig) []*engine.TransactionInput { +func mapToSPVInputs(tx *models.TransactionConfig) []*engine.TransactionInput { if tx.Inputs == nil { return nil } @@ -159,7 +159,7 @@ func mapToSPVInputs(tx *spvwalletmodels.TransactionConfig) []*engine.Transaction return inputs } -func mapToSPVIncludeUtxos(tx *spvwalletmodels.TransactionConfig) []*engine.UtxoPointer { +func mapToSPVIncludeUtxos(tx *models.TransactionConfig) []*engine.UtxoPointer { if tx.IncludeUtxos == nil { return nil } @@ -171,7 +171,7 @@ func mapToSPVIncludeUtxos(tx *spvwalletmodels.TransactionConfig) []*engine.UtxoP return includeUtxos } -func mapToSPVFromUtxos(tx *spvwalletmodels.TransactionConfig) []*engine.UtxoPointer { +func mapToSPVFromUtxos(tx *models.TransactionConfig) []*engine.UtxoPointer { if tx.FromUtxos == nil { return nil } @@ -183,7 +183,7 @@ func mapToSPVFromUtxos(tx *spvwalletmodels.TransactionConfig) []*engine.UtxoPoin return fromUtxos } -func mapToSPVDestinations(tx *spvwalletmodels.TransactionConfig) []*engine.Destination { +func mapToSPVDestinations(tx *models.TransactionConfig) []*engine.Destination { if tx.ChangeDestinations == nil { return nil } @@ -196,12 +196,12 @@ func mapToSPVDestinations(tx *spvwalletmodels.TransactionConfig) []*engine.Desti } // MapToTransactionConfigContract will map the transaction-config model from spv-wallet-models to the spv-wallet contract -func MapToTransactionConfigContract(tx *engine.TransactionConfig) *spvwalletmodels.TransactionConfig { +func MapToTransactionConfigContract(tx *engine.TransactionConfig) *models.TransactionConfig { if tx == nil { return nil } - return &spvwalletmodels.TransactionConfig{ + return &models.TransactionConfig{ ChangeDestinations: mapToContractDestinations(tx), ChangeStrategy: string(tx.ChangeDestinationsStrategy), ChangeMinimumSatoshis: tx.ChangeMinimumSatoshis, @@ -218,60 +218,60 @@ func MapToTransactionConfigContract(tx *engine.TransactionConfig) *spvwalletmode } } -func mapToContractOutputs(tx *engine.TransactionConfig) []*spvwalletmodels.TransactionOutput { +func mapToContractOutputs(tx *engine.TransactionConfig) []*models.TransactionOutput { if tx.Outputs == nil { return nil } - outputs := make([]*spvwalletmodels.TransactionOutput, 0) + outputs := make([]*models.TransactionOutput, 0) for _, output := range tx.Outputs { outputs = append(outputs, MapToTransactionOutputContract(output)) } return outputs } -func mapToContractInputs(tx *engine.TransactionConfig) []*spvwalletmodels.TransactionInput { +func mapToContractInputs(tx *engine.TransactionConfig) []*models.TransactionInput { if tx.Inputs == nil { return nil } - inputs := make([]*spvwalletmodels.TransactionInput, 0) + inputs := make([]*models.TransactionInput, 0) for _, input := range tx.Inputs { inputs = append(inputs, MapToTransactionInputContract(input)) } return inputs } -func mapToContractIncludeUtxos(tx *engine.TransactionConfig) []*spvwalletmodels.UtxoPointer { +func mapToContractIncludeUtxos(tx *engine.TransactionConfig) []*models.UtxoPointer { if tx.IncludeUtxos == nil { return nil } - includeUtxos := make([]*spvwalletmodels.UtxoPointer, 0) + includeUtxos := make([]*models.UtxoPointer, 0) for _, utxo := range tx.IncludeUtxos { includeUtxos = append(includeUtxos, MapToUtxoPointer(utxo)) } return includeUtxos } -func mapToContractFromUtxos(tx *engine.TransactionConfig) []*spvwalletmodels.UtxoPointer { +func mapToContractFromUtxos(tx *engine.TransactionConfig) []*models.UtxoPointer { if tx.FromUtxos == nil { return nil } - fromUtxos := make([]*spvwalletmodels.UtxoPointer, 0) + fromUtxos := make([]*models.UtxoPointer, 0) for _, utxo := range tx.FromUtxos { fromUtxos = append(fromUtxos, MapToUtxoPointer(utxo)) } return fromUtxos } -func mapToContractDestinations(tx *engine.TransactionConfig) []*spvwalletmodels.Destination { +func mapToContractDestinations(tx *engine.TransactionConfig) []*models.Destination { if tx.ChangeDestinations == nil { return nil } - destinations := make([]*spvwalletmodels.Destination, 0) + destinations := make([]*models.Destination, 0) for _, destination := range tx.ChangeDestinations { destinations = append(destinations, MapToDestinationContract(destination)) } @@ -279,12 +279,12 @@ func mapToContractDestinations(tx *engine.TransactionConfig) []*spvwalletmodels. } // MapToDraftTransactionContract will map the transaction-output model from spv-wallet to the spv-wallet-models contract -func MapToDraftTransactionContract(tx *engine.DraftTransaction) *spvwalletmodels.DraftTransaction { +func MapToDraftTransactionContract(tx *engine.DraftTransaction) *models.DraftTransaction { if tx == nil { return nil } - return &spvwalletmodels.DraftTransaction{ + return &models.DraftTransaction{ Model: *common.MapToContract(&tx.Model), ID: tx.ID, Hex: tx.Hex, @@ -295,19 +295,19 @@ func MapToDraftTransactionContract(tx *engine.DraftTransaction) *spvwalletmodels } // MapToTransactionInputContract will map the transaction-output model from spv-wallet-models to the spv-wallet contract -func MapToTransactionInputContract(inp *engine.TransactionInput) *spvwalletmodels.TransactionInput { +func MapToTransactionInputContract(inp *engine.TransactionInput) *models.TransactionInput { if inp == nil { return nil } - return &spvwalletmodels.TransactionInput{ + return &models.TransactionInput{ Utxo: *MapToUtxoContract(&inp.Utxo), Destination: *MapToDestinationContract(&inp.Destination), } } // MapToTransactionInputSPV will map the transaction-output model from spv-wallet to the spv-wallet-models contract -func MapToTransactionInputSPV(inp *spvwalletmodels.TransactionInput) *engine.TransactionInput { +func MapToTransactionInputSPV(inp *models.TransactionInput) *engine.TransactionInput { if inp == nil { return nil } @@ -319,17 +319,17 @@ func MapToTransactionInputSPV(inp *spvwalletmodels.TransactionInput) *engine.Tra } // MapToTransactionOutputContract will map the transaction-output model from spv-wallet to the spv-wallet-models contract -func MapToTransactionOutputContract(out *engine.TransactionOutput) *spvwalletmodels.TransactionOutput { +func MapToTransactionOutputContract(out *engine.TransactionOutput) *models.TransactionOutput { if out == nil { return nil } - scriptOutputs := make([]*spvwalletmodels.ScriptOutput, 0) + scriptOutputs := make([]*models.ScriptOutput, 0) for _, scriptOutput := range out.Scripts { scriptOutputs = append(scriptOutputs, MapToScriptOutputContract(scriptOutput)) } - return &spvwalletmodels.TransactionOutput{ + return &models.TransactionOutput{ OpReturn: MapToOpReturnContract(out.OpReturn), PaymailP4: MapToPaymailP4Contract(out.PaymailP4), Satoshis: out.Satoshis, @@ -341,7 +341,7 @@ func MapToTransactionOutputContract(out *engine.TransactionOutput) *spvwalletmod } // MapToTransactionOutputSPV will map the transaction-output model from spv-wallet-models to the spv-wallet contract -func MapToTransactionOutputSPV(out *spvwalletmodels.TransactionOutput) *engine.TransactionOutput { +func MapToTransactionOutputSPV(out *models.TransactionOutput) *engine.TransactionOutput { if out == nil { return nil } @@ -363,12 +363,12 @@ func MapToTransactionOutputSPV(out *spvwalletmodels.TransactionOutput) *engine.T } // MapToMapProtocolContract will map the transaction-output model from spv-wallet to the spv-wallet-models contract -func MapToMapProtocolContract(mp *engine.MapProtocol) *spvwalletmodels.MapProtocol { +func MapToMapProtocolContract(mp *engine.MapProtocol) *models.MapProtocol { if mp == nil { return nil } - return &spvwalletmodels.MapProtocol{ + return &models.MapProtocol{ App: mp.App, Keys: mp.Keys, Type: mp.Type, @@ -376,7 +376,7 @@ func MapToMapProtocolContract(mp *engine.MapProtocol) *spvwalletmodels.MapProtoc } // MapToMapProtocolSPV will map the transaction-output model from spv-wallet-models to the spv-wallet contract -func MapToMapProtocolSPV(mp *spvwalletmodels.MapProtocol) *engine.MapProtocol { +func MapToMapProtocolSPV(mp *models.MapProtocol) *engine.MapProtocol { if mp == nil { return nil } @@ -389,12 +389,12 @@ func MapToMapProtocolSPV(mp *spvwalletmodels.MapProtocol) *engine.MapProtocol { } // MapToOpReturnContract will map the transaction-output model from spv-wallet to the spv-wallet-models contract -func MapToOpReturnContract(op *engine.OpReturn) *spvwalletmodels.OpReturn { +func MapToOpReturnContract(op *engine.OpReturn) *models.OpReturn { if op == nil { return nil } - return &spvwalletmodels.OpReturn{ + return &models.OpReturn{ Hex: op.Hex, HexParts: op.HexParts, Map: MapToMapProtocolContract(op.Map), @@ -403,7 +403,7 @@ func MapToOpReturnContract(op *engine.OpReturn) *spvwalletmodels.OpReturn { } // MapToOpReturnSPV will map the op-return model from spv-wallet-models to the spv-wallet contract -func MapToOpReturnSPV(op *spvwalletmodels.OpReturn) *engine.OpReturn { +func MapToOpReturnSPV(op *models.OpReturn) *engine.OpReturn { if op == nil { return nil } diff --git a/mappings/utxo.go b/mappings/utxo.go index 122c50433..acaad05a4 100644 --- a/mappings/utxo.go +++ b/mappings/utxo.go @@ -3,24 +3,24 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings/common" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" customtypes "github.com/mrz1836/go-datastore/custom_types" ) // MapToUtxoPointer will map the utxo-pointer model from spv-wallet to the spv-wallet-models contract -func MapToUtxoPointer(u *engine.UtxoPointer) *spvwalletmodels.UtxoPointer { +func MapToUtxoPointer(u *engine.UtxoPointer) *models.UtxoPointer { if u == nil { return nil } - return &spvwalletmodels.UtxoPointer{ + return &models.UtxoPointer{ TransactionID: u.TransactionID, OutputIndex: u.OutputIndex, } } // MapToUtxoPointerSPV will map the utxo-pointer model from spv-wallet-models to the spv-wallet contract -func MapToUtxoPointerSPV(u *spvwalletmodels.UtxoPointer) *engine.UtxoPointer { +func MapToUtxoPointerSPV(u *models.UtxoPointer) *engine.UtxoPointer { if u == nil { return nil } @@ -32,12 +32,12 @@ func MapToUtxoPointerSPV(u *spvwalletmodels.UtxoPointer) *engine.UtxoPointer { } // MapToUtxoContract will map the utxo model from spv-wallet to the spv-wallet-models contract -func MapToUtxoContract(u *engine.Utxo) *spvwalletmodels.Utxo { +func MapToUtxoContract(u *engine.Utxo) *models.Utxo { if u == nil { return nil } - return &spvwalletmodels.Utxo{ + return &models.Utxo{ Model: *common.MapToContract(&u.Model), UtxoPointer: *MapToUtxoPointer(&u.UtxoPointer), ID: u.ID, @@ -52,7 +52,7 @@ func MapToUtxoContract(u *engine.Utxo) *spvwalletmodels.Utxo { } // MapToUtxoSPV will map the utxo model from spv-wallet-models to the spv-wallet contract -func MapToUtxoSPV(u *spvwalletmodels.Utxo) *engine.Utxo { +func MapToUtxoSPV(u *models.Utxo) *engine.Utxo { if u == nil { return nil } diff --git a/mappings/xpub.go b/mappings/xpub.go index c23644e42..a4b12fd0b 100644 --- a/mappings/xpub.go +++ b/mappings/xpub.go @@ -3,16 +3,16 @@ package mappings import ( "github.com/bitcoin-sv/spv-wallet/engine" "github.com/bitcoin-sv/spv-wallet/mappings/common" - spvwalletmodels "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models" ) // MapToXpubContract will map the xpub model from spv-wallet to the spv-wallet-models contract -func MapToXpubContract(xpub *engine.Xpub) *spvwalletmodels.Xpub { +func MapToXpubContract(xpub *engine.Xpub) *models.Xpub { if xpub == nil { return nil } - return &spvwalletmodels.Xpub{ + return &models.Xpub{ Model: *common.MapToContract(&xpub.Model), ID: xpub.ID, CurrentBalance: xpub.CurrentBalance,