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

feat(SPV-1393): remove old API #862

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5939be9
feat(SPV-1393): remove access keys old api
dorzepowski Jan 16, 2025
d4c5560
feat(SPV-1393): remove old status and stats endpoints
pawellewandowski98 Jan 17, 2025
05b2278
feat: remove old contact api
pawellewandowski98 Jan 17, 2025
4db5c0d
feat: remove old destination api
pawellewandowski98 Jan 17, 2025
67d1f69
feat: remove old transaction api
pawellewandowski98 Jan 21, 2025
0390195
feat: remove paymails api
pawellewandowski98 Jan 21, 2025
11f36f5
remove old utxo api
pawellewandowski98 Jan 21, 2025
a9cd4b4
feat: remove old xpub api
pawellewandowski98 Jan 21, 2025
4be3b99
feat: remove old webhooks api
pawellewandowski98 Jan 21, 2025
ce7666d
tests: fix tests
pawellewandowski98 Jan 21, 2025
1e3a71f
tests: remove old api from tests
pawellewandowski98 Jan 21, 2025
ba61097
fix: linter errors
pawellewandowski98 Jan 21, 2025
9b4ff60
fix: linter errors
pawellewandowski98 Jan 21, 2025
bcd3351
fix: linter errors
pawellewandowski98 Jan 21, 2025
f8eaed3
tests: revert changes in model_xpubs_test
pawellewandowski98 Jan 22, 2025
16c18a5
Merge branch 'main' into feat-remove-old-api
pawellewandowski98 Jan 22, 2025
3e2cee9
feat: remove unused methods from client
pawellewandowski98 Jan 22, 2025
d8fbc4d
fix: linter error
pawellewandowski98 Jan 22, 2025
b32886a
feat: remove ol mappings
pawellewandowski98 Jan 23, 2025
af64a32
chore: regenerate swagger
pawellewandowski98 Jan 23, 2025
f244e31
fix: linter errors
pawellewandowski98 Jan 23, 2025
3c905a9
Merge branch 'main' into feat-remove-old-api
pawellewandowski98 Jan 24, 2025
57feb06
Merge branch 'main' into feat-remove-old-api
pawellewandowski98 Jan 24, 2025
30b8722
fix: revert deleted paymailserver files
pawellewandowski98 Jan 27, 2025
3d6dd74
Merge branch 'main' into feat-remove-old-api
pawellewandowski98 Jan 27, 2025
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
1 change: 0 additions & 1 deletion actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func RegisterRoutes(handlersManager *routes.Manager) {
- `middleware.AppContextMiddleware`
- `middleware.CorsMiddleware`
- `metrics.requestMetricsMiddleware`
- `GroupOldAPI` with `/<api_version>` prefix and `auth_middleware` (besides global middlewares)
- `GroupAPI` with `/api/<api_version> prefix and also `auth_middleware` (besides global middlewares)
- `GroupTransactionCallback` with no prefix but with special `middleware.CallbackTokenMiddleware`
- So... for a new endpoint you'll most probably choose the `GroupAPI`
Expand Down
45 changes: 0 additions & 45 deletions actions/access_keys/count.go

This file was deleted.

30 changes: 0 additions & 30 deletions actions/access_keys/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
}
30 changes: 1 addition & 29 deletions actions/access_keys/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 == "" {
Expand All @@ -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)
}
36 changes: 1 addition & 35 deletions actions/access_keys/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,18 +27,14 @@ 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 == "" {
spverrors.ErrorResponse(c, spverrors.ErrMissingFieldID, logger)
return
}

accessKey, err := reqctx.Engine(c).RevokeAccessKey(
_, err = reqctx.Engine(c).RevokeAccessKey(
c.Request.Context(),
xpub,
id,
Expand All @@ -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)
}
7 changes: 0 additions & 7 deletions actions/access_keys/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 0 additions & 5 deletions actions/access_keys/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
46 changes: 2 additions & 44 deletions actions/access_keys/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Loading
Loading