diff --git a/actions/access_keys/count.go b/actions/access_keys/count.go deleted file mode 100644 index 578baee82..000000000 --- a/actions/access_keys/count.go +++ /dev/null @@ -1,45 +0,0 @@ -package accesskeys - -import ( - "net/http" - - "github.com/bitcoin-sv/spv-wallet/engine/spverrors" - "github.com/bitcoin-sv/spv-wallet/mappings" - "github.com/bitcoin-sv/spv-wallet/models/filter" - "github.com/bitcoin-sv/spv-wallet/server/reqctx" - "github.com/gin-gonic/gin" -) - -// count will fetch a count of access keys filtered by metadata -// Count of access keys godoc -// @Summary Count of access keys - Use (GET) /api/v1/users/current/keys instead. -// @Description This endpoint has been deprecated. Use (GET) /api/v1/users/current/keys instead. -// @Tags Access-key -// @Produce json -// @Param CountAccessKeys body filter.CountAccessKeys false "Enables filtering of elements to be counted" -// @Success 200 {number} int64 "Count of access keys" -// @Failure 400 "Bad request - Error while parsing CountAccessKeys from request body" -// @Failure 500 "Internal Server Error - Error while fetching count of access keys" -// @DeprecatedRouter /v1/access-key/count [post] -// @Security x-auth-xpub -func count(c *gin.Context, userContext *reqctx.UserContext) { - logger := reqctx.Logger(c) - var reqParams filter.CountAccessKeys - if err := c.Bind(&reqParams); err != nil { - spverrors.ErrorResponse(c, spverrors.ErrCannotBindRequest, logger) - return - } - - count, err := reqctx.Engine(c).GetAccessKeysByXPubIDCount( - c.Request.Context(), - userContext.GetXPubID(), - mappings.MapToMetadata(reqParams.Metadata), - reqParams.Conditions.ToDbConditions(), - ) - if err != nil { - spverrors.ErrorResponse(c, err, logger) - return - } - - c.JSON(http.StatusOK, count) -} diff --git a/actions/access_keys/create.go b/actions/access_keys/create.go index ec9929064..ad2d17c9d 100644 --- a/actions/access_keys/create.go +++ b/actions/access_keys/create.go @@ -10,27 +10,6 @@ import ( "github.com/gin-gonic/gin" ) -// create will make a new model using the services defined in the action object -// Create access key godoc -// @Summary Create access key - Use (POST) /api/v1/users/current/keys instead. -// @Description This endpoint has been deprecated. Use (POST) /api/v1/users/current/keys instead. -// @Tags Access-key -// @Produce json -// @Param CreateAccessKey body CreateAccessKey true " " -// @Success 201 {object} models.AccessKey "Created AccessKey" -// @Failure 400 "Bad request - Error while parsing CreateAccessKey from request body" -// @Failure 500 "Internal server error - Error while creating new access key" -// @DeprecatedRouter /v1/access-key [post] -// @Security x-auth-xpub -func oldCreate(c *gin.Context, userContext *reqctx.UserContext) { - xpub, err := userContext.ShouldGetXPub() - if err != nil { - spverrors.AbortWithErrorResponse(c, err, reqctx.Logger(c)) - return - } - createHelper(c, true, xpub) -} - // create will make a new model using the services defined in the action object // Create access key godoc // @Summary Create access key @@ -49,10 +28,7 @@ func create(c *gin.Context, userContext *reqctx.UserContext) { spverrors.AbortWithErrorResponse(c, err, reqctx.Logger(c)) return } - createHelper(c, false, xpub) -} -func createHelper(c *gin.Context, snakeCase bool, xpub string) { logger := reqctx.Logger(c) var requestBody CreateAccessKey if err := c.Bind(&requestBody); err != nil { @@ -71,12 +47,6 @@ func createHelper(c *gin.Context, snakeCase bool, xpub string) { return } - if snakeCase { - contract := mappings.MapToOldAccessKeyContract(accessKey) - c.JSON(http.StatusCreated, contract) - return - } - contract := mappings.MapToAccessKeyContract(accessKey) c.JSON(http.StatusCreated, contract) } diff --git a/actions/access_keys/get.go b/actions/access_keys/get.go index 6cec5c77b..e2b4f1c01 100644 --- a/actions/access_keys/get.go +++ b/actions/access_keys/get.go @@ -9,25 +9,6 @@ import ( "github.com/gin-gonic/gin" ) -// get will get an existing model -// Get access key godoc -// @Summary Get access key - Use (GET) /api/v1/users/current/keys/{id} instead. -// @Description This endpoint has been deprecated. Use (GET) /api/v1/users/current/keys/{id} instead. -// @Tags Access-key -// @Produce json -// @Param id query string true "id of the access key" -// @Success 200 {object} models.AccessKey "AccessKey with given id" -// @Failure 400 "Bad request - Missing required field: id" -// @Failure 403 "Forbidden - Access key is not owned by the user" -// @Failure 500 "Internal server error - Error while getting access key" -// @DeprecatedRouter /v1/access-key [get] -// @Security x-auth-xpub -func oldGet(c *gin.Context, userContext *reqctx.UserContext) { - id := c.Query("id") - - getHelper(c, id, true, userContext.GetXPubID()) -} - // get will get an existing model // Get access key godoc // @Summary Get access key @@ -43,11 +24,8 @@ func oldGet(c *gin.Context, userContext *reqctx.UserContext) { // @Security x-auth-xpub func get(c *gin.Context, userContext *reqctx.UserContext) { id := c.Params.ByName("id") + reqXPubID := userContext.GetXPubID() - getHelper(c, id, false, userContext.GetXPubID()) -} - -func getHelper(c *gin.Context, id string, snakeCase bool, reqXPubID string) { logger := reqctx.Logger(c) if id == "" { @@ -69,12 +47,6 @@ func getHelper(c *gin.Context, id string, snakeCase bool, reqXPubID string) { return } - if snakeCase { - contract := mappings.MapToOldAccessKeyContract(accessKey) - c.JSON(http.StatusOK, contract) - return - } - contract := mappings.MapToAccessKeyContract(accessKey) c.JSON(http.StatusOK, contract) } diff --git a/actions/access_keys/revoke.go b/actions/access_keys/revoke.go index 00eeb467a..1efd073ac 100644 --- a/actions/access_keys/revoke.go +++ b/actions/access_keys/revoke.go @@ -4,34 +4,10 @@ import ( "net/http" "github.com/bitcoin-sv/spv-wallet/engine/spverrors" - "github.com/bitcoin-sv/spv-wallet/mappings" "github.com/bitcoin-sv/spv-wallet/server/reqctx" "github.com/gin-gonic/gin" ) -// revoke will revoke the intended model by id -// Revoke access key godoc -// @Summary Revoke access key - Use (DELETE) /api/v1/users/current/keys/{id} instead. -// @Description This endpoint has been deprecated. Use (DELETE) /api/v1/users/current/keys/{id} instead. -// @Tags Access-key -// @Produce json -// @Param id query string true "id of the access key" -// @Success 200 {object} models.AccessKey "Revoked AccessKey" -// @Failure 400 "Bad request - Missing required field: id" -// @Failure 500 "Internal server error - Error while revoking access key" -// @DeprecatedRouter /v1/access-key [delete] -// @Security x-auth-xpub -func oldRevoke(c *gin.Context, userContext *reqctx.UserContext) { - id := c.Query("id") - xpub, err := userContext.ShouldGetXPub() - if err != nil { - spverrors.AbortWithErrorResponse(c, err, reqctx.Logger(c)) - return - } - - revokeHelper(c, id, true, xpub) -} - // revoke will revoke the intended model by id // Revoke access key godoc // @Summary Revoke access key @@ -51,10 +27,6 @@ func revoke(c *gin.Context, userContext *reqctx.UserContext) { spverrors.AbortWithErrorResponse(c, err, reqctx.Logger(c)) return } - revokeHelper(c, id, false, xpub) -} - -func revokeHelper(c *gin.Context, id string, snakeCase bool, xpub string) { logger := reqctx.Logger(c) if id == "" { @@ -62,7 +34,7 @@ func revokeHelper(c *gin.Context, id string, snakeCase bool, xpub string) { return } - accessKey, err := reqctx.Engine(c).RevokeAccessKey( + _, err = reqctx.Engine(c).RevokeAccessKey( c.Request.Context(), xpub, id, @@ -72,11 +44,5 @@ func revokeHelper(c *gin.Context, id string, snakeCase bool, xpub string) { return } - if snakeCase { - contract := mappings.MapToOldAccessKeyContract(accessKey) - c.JSON(http.StatusCreated, contract) - return - } - c.Status(http.StatusOK) } diff --git a/actions/access_keys/routes.go b/actions/access_keys/routes.go index 2d04b4488..a61d76683 100644 --- a/actions/access_keys/routes.go +++ b/actions/access_keys/routes.go @@ -6,13 +6,6 @@ import ( // RegisterRoutes creates the specific package routes func RegisterRoutes(handlersManager *handlers.Manager) { - old := handlersManager.Group(handlers.GroupOldAPI, "/access-key") - old.POST("", handlers.AsUser(oldCreate)) - old.GET("", handlers.AsUser(oldGet)) - old.DELETE("", handlers.AsUser(oldRevoke)) - old.POST("/count", handlers.AsUser(count)) - old.POST("/search", handlers.AsUser(oldSearch)) - group := handlersManager.Group(handlers.GroupAPI, "/users/current/keys") group.GET("/:id", handlers.AsUser(get)) group.POST("", handlers.AsUser(create)) diff --git a/actions/access_keys/routes_test.go b/actions/access_keys/routes_test.go index ae43d6d31..62228bd78 100644 --- a/actions/access_keys/routes_test.go +++ b/actions/access_keys/routes_test.go @@ -14,11 +14,6 @@ func (ts *TestSuite) TestRegisterRoutes() { method string url string }{ - {"GET", "/" + config.APIVersion + "/access-key"}, - {"POST", "/" + config.APIVersion + "/access-key"}, - {"DELETE", "/" + config.APIVersion + "/access-key"}, - {"POST", "/" + config.APIVersion + "/access-key/search"}, - {"GET", "/api/" + config.APIVersion + "/users/current/keys/:id"}, {"POST", "/api/" + config.APIVersion + "/users/current/keys"}, {"DELETE", "/api/" + config.APIVersion + "/users/current/keys/:id"}, diff --git a/actions/access_keys/search.go b/actions/access_keys/search.go index 481b0b256..6f7059244 100644 --- a/actions/access_keys/search.go +++ b/actions/access_keys/search.go @@ -7,54 +7,12 @@ import ( "github.com/bitcoin-sv/spv-wallet/engine/spverrors" "github.com/bitcoin-sv/spv-wallet/internal/query" "github.com/bitcoin-sv/spv-wallet/mappings" - "github.com/bitcoin-sv/spv-wallet/models" "github.com/bitcoin-sv/spv-wallet/models/filter" "github.com/bitcoin-sv/spv-wallet/models/response" "github.com/bitcoin-sv/spv-wallet/server/reqctx" "github.com/gin-gonic/gin" ) -// oldSearch will fetch a list of access keys filtered by metadata -// Search access key godoc -// @Summary Search access key - Use (GET) /api/v1/users/current/keys instead. -// @Description This endpoint has been deprecated. Use (GET) /api/v1/users/current/keys instead. -// @Tags Access-key -// @Produce json -// @Param SearchAccessKeys body filter.SearchAccessKeys false "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis" -// @Success 200 {object} []models.AccessKey "List of access keys" -// @Failure 400 "Bad request - Error while SearchAccessKeys from request body" -// @Failure 500 "Internal server error - Error while searching for access keys" -// @DeprecatedRouter /v1/access-key/search [post] -// @Security x-auth-xpub -func oldSearch(c *gin.Context, userContext *reqctx.UserContext) { - logger := reqctx.Logger(c) - - var reqParams filter.SearchAccessKeys - if err := c.Bind(&reqParams); err != nil { - spverrors.ErrorResponse(c, spverrors.ErrCannotBindRequest, logger) - return - } - - accessKeys, err := reqctx.Engine(c).GetAccessKeysByXPubID( - c.Request.Context(), - userContext.GetXPubID(), - mappings.MapToMetadata(reqParams.Metadata), - reqParams.Conditions.ToDbConditions(), - mappings.MapToQueryParams(reqParams.QueryParams), - ) - if err != nil { - spverrors.ErrorResponse(c, err, logger) - return - } - - accessKeyContracts := make([]*models.AccessKey, 0) - for _, accessKey := range accessKeys { - accessKeyContracts = append(accessKeyContracts, mappings.MapToOldAccessKeyContract(accessKey)) - } - - c.JSON(http.StatusOK, accessKeyContracts) -} - // search will fetch a list of access keys filtered by metadata // Search access key godoc // @Summary Search access key @@ -112,10 +70,10 @@ func search(c *gin.Context, userContext *reqctx.UserContext) { return } - response := response.PageModel[response.AccessKey]{ + res := response.PageModel[response.AccessKey]{ Content: accessKeyContracts, Page: common.GetPageDescriptionFromSearchParams(pageOptions, count), } - c.JSON(http.StatusOK, response) + c.JSON(http.StatusOK, res) } diff --git a/actions/admin/access_keys_old.go b/actions/admin/access_keys_old.go deleted file mode 100644 index 36ee42eac..000000000 --- a/actions/admin/access_keys_old.go +++ /dev/null @@ -1,86 +0,0 @@ -package admin - -import ( - "net/http" - - "github.com/bitcoin-sv/spv-wallet/engine/spverrors" - "github.com/bitcoin-sv/spv-wallet/mappings" - "github.com/bitcoin-sv/spv-wallet/models" - "github.com/bitcoin-sv/spv-wallet/models/filter" - "github.com/bitcoin-sv/spv-wallet/server/reqctx" - "github.com/gin-gonic/gin" -) - -// accessKeysSearchOld will fetch a list of access keys filtered by metadata -// Access Keys Search godoc -// @DeprecatedRouter /v1/admin/access-keys/search [post] -// @Summary Access Keys Search -// @Description Access Keys Search -// @Tags Admin -// @Produce json -// @Param SearchAccessKeys body filter.AdminSearchAccessKeys false "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis" -// @Success 200 {object} []models.AccessKey "List of access keys" -// @Failure 400 "Bad request - Error while parsing SearchAccessKeys from request body" -// @Failure 500 "Internal server error - Error while searching for access keys" -// @Router /v1/admin/access-keys/search [post] -// @Security x-auth-xpub -func accessKeysSearchOld(c *gin.Context, _ *reqctx.AdminContext) { - logger := reqctx.Logger(c) - var reqParams filter.AdminSearchAccessKeys - if err := c.Bind(&reqParams); err != nil { - spverrors.ErrorResponse(c, spverrors.ErrCannotBindRequest, logger) - return - } - - accessKeys, err := reqctx.Engine(c).GetAccessKeys( - c.Request.Context(), - mappings.MapToMetadata(reqParams.Metadata), - reqParams.Conditions.ToDbConditions(), - mappings.MapToQueryParams(reqParams.QueryParams), - ) - if err != nil { - spverrors.ErrorResponse(c, err, logger) - return - } - - accessKeyContracts := make([]*models.AccessKey, 0) - for _, accessKey := range accessKeys { - accessKeyContracts = append(accessKeyContracts, mappings.MapToOldAccessKeyContract(accessKey)) - } - - c.JSON(http.StatusOK, accessKeyContracts) -} - -// accessKeysCount will count all access keys filtered by metadata -// Access Keys Count godoc -// @DeprecatedRouter /v1/admin/access-keys/count [post] -// @Summary Access Keys Count -// @Description Access Keys Count -// @Tags Admin -// @Produce json -// @Param CountAccessKeys body filter.AdminCountAccessKeys false "Enables filtering of elements to be counted" -// @Success 200 {number} int64 "Count of access keys" -// @Failure 400 "Bad request - Error while parsing CountAccessKeys from request body" -// @Failure 500 "Internal Server Error - Error while fetching count of access keys" -// @Router /v1/admin/access-keys/count [post] -// @Security x-auth-xpub -func accessKeysCount(c *gin.Context, _ *reqctx.AdminContext) { - logger := reqctx.Logger(c) - var reqParams filter.AdminCountAccessKeys - if err := c.Bind(&reqParams); err != nil { - spverrors.ErrorResponse(c, spverrors.ErrCannotBindRequest, logger) - return - } - - count, err := reqctx.Engine(c).GetAccessKeysCount( - c.Request.Context(), - mappings.MapToMetadata(reqParams.Metadata), - reqParams.Conditions.ToDbConditions(), - ) - if err != nil { - spverrors.ErrorResponse(c, err, logger) - return - } - - c.JSON(http.StatusOK, count) -} diff --git a/actions/admin/routes.go b/actions/admin/routes.go index d18013458..924d81b86 100644 --- a/actions/admin/routes.go +++ b/actions/admin/routes.go @@ -10,8 +10,6 @@ func RegisterRoutes(handlersManager *handlers.Manager) { adminGroupOld.GET("/status", handlers.AsAdmin(statusOld)) adminGroupOld.GET("/stats", handlers.AsAdmin(statsOld)) - adminGroupOld.POST("/access-keys/search", handlers.AsAdmin(accessKeysSearchOld)) - adminGroupOld.POST("/access-keys/count", handlers.AsAdmin(accessKeysCount)) adminGroupOld.POST("/contact/search", handlers.AsAdmin(contactsSearchOld)) adminGroupOld.PATCH("/contact/:id", handlers.AsAdmin(contactsUpdateOld)) adminGroupOld.POST("/contact/:paymail", handlers.AsAdmin(contactsCreate)) diff --git a/actions/admin/routes_test.go b/actions/admin/routes_test.go index 23c684923..686fcb1d9 100644 --- a/actions/admin/routes_test.go +++ b/actions/admin/routes_test.go @@ -17,8 +17,6 @@ func (ts *TestSuite) TestXPubRegisterRoutes() { }{ {"GET", "/" + config.APIVersion + "/admin/stats"}, {"GET", "/" + config.APIVersion + "/admin/status"}, - {"POST", "/" + config.APIVersion + "/admin/access-keys/search"}, - {"POST", "/" + config.APIVersion + "/admin/access-keys/count"}, {"POST", "/" + config.APIVersion + "/admin/destinations/search"}, {"POST", "/" + config.APIVersion + "/admin/destinations/count"}, {"POST", "/" + config.APIVersion + "/admin/paymail/get"}, diff --git a/mappings/access_keys_old.go b/mappings/access_keys_old.go deleted file mode 100644 index 83f2c7086..000000000 --- a/mappings/access_keys_old.go +++ /dev/null @@ -1,30 +0,0 @@ -// Package mappings is a package that contains the mappings for the access keys package. -package mappings - -import ( - "time" - - "github.com/bitcoin-sv/spv-wallet/engine" - "github.com/bitcoin-sv/spv-wallet/mappings/common" - "github.com/bitcoin-sv/spv-wallet/models" -) - -// MapToOldAccessKeyContract will map the access key to the spv-wallet-models contract -func MapToOldAccessKeyContract(ac *engine.AccessKey) *models.AccessKey { - if ac == nil { - return nil - } - - var revokedAt *time.Time - if !ac.RevokedAt.IsZero() { - revokedAt = &ac.RevokedAt.Time - } - - return &models.AccessKey{ - Model: *common.MapToOldContract(&ac.Model), - ID: ac.ID, - XpubID: ac.XpubID, - RevokedAt: revokedAt, - Key: ac.Key, - } -} diff --git a/models/access_key.go b/models/access_key.go deleted file mode 100644 index b23e3b916..000000000 --- a/models/access_key.go +++ /dev/null @@ -1,22 +0,0 @@ -// Package models contains all models (contracts) between spv-wallet api and other spv-wallet solutions -package models - -import ( - "time" - - "github.com/bitcoin-sv/spv-wallet/models/common" -) - -// AccessKey is a model that represents an access key. -type AccessKey struct { - // Model is a common model that contains common fields for all models. - common.Model - // ID is an hash of the compressed public key. - ID string `json:"id" example:"874b86d6fd1d6c85a857e73180164203d8d23211bfd9d04d210f9f7fde5b82d8"` - // XpubID is an access key's xpub related id. - XpubID string `json:"xpub_id" example:"bb8593f85ef8056a77026ad415f02128f3768906de53e9e8bf8749fe2d66cf50"` - // RevokedAt is a time when access key was revoked. - RevokedAt *time.Time `json:"revoked_at,omitempty" example:"2024-02-26T11:02:28.069911Z"` - // Key is a string representation of an access key. - Key string `json:"key,omitempty" example:"3fd870d6bf1725f04084cf31209c04be5bd9bed001a390ad3bc632a55a3ee078"` -} diff --git a/models/models_test.go b/models/models_test.go deleted file mode 100644 index fda2516f1..000000000 --- a/models/models_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package models - -import ( - "fmt" - "testing" - "time" - - "github.com/stretchr/testify/require" -) - -// TestAccessKey tests AccessKey model. -func TestAccessKey(t *testing.T) { - ac := new(AccessKey) - ac.Model.UpdatedAt = time.Now().UTC() - ac.Model.CreatedAt = time.Now().UTC() - deletedAt := time.Now().UTC() - ac.Model.DeletedAt = &deletedAt - ac.XpubID = "123" - ac.ID = "123" - - require.Equal(t, "123", ac.ID) -} - -// ExampleAccessKey is an example for AccessKey model. -func ExampleAccessKey() { - ac := new(AccessKey) - ac.Model.UpdatedAt = time.Now().UTC() - ac.Model.CreatedAt = time.Now().UTC() - deletedAt := time.Now().UTC() - ac.Model.DeletedAt = &deletedAt - ac.XpubID = "123" - ac.ID = "123" - fmt.Printf("%s", ac.ID) - // Output: 123 -}