Skip to content

Commit

Permalink
Merge branch 'master' into BUX-246/Linters
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazarii-4chain authored Mar 29, 2024
2 parents 9571594 + 0e728a5 commit aeedfcb
Show file tree
Hide file tree
Showing 168 changed files with 13,997 additions and 3,263 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Run tests
run: make test-all-db-ci
- name: Update code coverage
uses: codecov/codecov-action@v4.0.1
uses: codecov/codecov-action@v4.1.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
Expand Down
13 changes: 7 additions & 6 deletions actions/access_keys/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ import (
// @Description Count of access keys
// @Tags Access-key
// @Produce json
// @Param metadata query string false "metadata"
// @Param conditions query string false "conditions"
// @Success 200
// @Param CountRequestParameters body actions.CountRequestParameters false "Enables precise filtering of resource counts using custom conditions or metadata, catering to specific business or analysis needs"
// @Success 200 {number} int64 "Count of access keys"
// @Failure 400 "Bad request - Error while parsing CountRequestParameters from request body"
// @Failure 500 "Internal Server Error - Error while fetching count of access keys"
// @Router /v1/access-key/count [post]
// @Security x-auth-xpub
func (a *Action) count(c *gin.Context) {
reqXPubID := c.GetString(auth.ParamXPubHashKey)

_, metadata, conditions, err := actions.GetQueryParameters(c)
metadata, conditions, err := actions.GetCountQueryParameters(c)
if err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusBadRequest, err.Error())
return
}

Expand All @@ -35,7 +36,7 @@ func (a *Action) count(c *gin.Context) {
metadata,
conditions,
); err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand Down
8 changes: 5 additions & 3 deletions actions/access_keys/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
// @Description Create access key
// @Tags Access-key
// @Produce json
// @Param metadata query string false "metadata"
// @Success 201
// @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"
// @Router /v1/access-key [post]
// @Security x-auth-xpub
func (a *Action) create(c *gin.Context) {
Expand All @@ -35,7 +37,7 @@ func (a *Action) create(c *gin.Context) {
engine.WithMetadatas(requestBody.Metadata),
)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand Down
9 changes: 6 additions & 3 deletions actions/access_keys/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import (
// @Description Get access key
// @Tags Access-key
// @Produce json
// @Param id query string true "id"
// @Success 200
// @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"
// @Router /v1/access-key [get]
// @Security x-auth-xpub
func (a *Action) get(c *gin.Context) {
Expand All @@ -33,7 +36,7 @@ func (a *Action) get(c *gin.Context) {
c.Request.Context(), reqXPubID, id,
)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand Down
3 changes: 2 additions & 1 deletion actions/access_keys/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import "github.com/bitcoin-sv/spv-wallet/engine"

// CreateAccessKey is the model for creating an access key
type CreateAccessKey struct {
Metadata engine.Metadata `json:"metadata"`
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
}
8 changes: 5 additions & 3 deletions actions/access_keys/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
// @Description Revoke access key
// @Tags Access-key
// @Produce json
// @Param id query string true "id"
// @Success 201
// @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"
// @Router /v1/access-key [delete]
// @Security x-auth-xpub
func (a *Action) revoke(c *gin.Context) {
Expand All @@ -34,7 +36,7 @@ func (a *Action) revoke(c *gin.Context) {
id,
)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand Down
17 changes: 7 additions & 10 deletions actions/access_keys/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ import (
// @Description Search access key
// @Tags Access-key
// @Produce json
// @Param page query int false "page"
// @Param page_size query int false "page_size"
// @Param order_by_field query string false "order_by_field"
// @Param sort_direction query string false "sort_direction"
// @Param metadata query string false "metadata"
// @Param conditions query string false "conditions"
// @Success 200
// @Param SearchRequestParameters body actions.SearchRequestParameters false "Supports targeted resource searches with filters for metadata and custom conditions, 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 SearchRequestParameters from request body"
// @Failure 500 "Internal server error - Error while searching for access keys"
// @Router /v1/access-key/search [post]
// @Security x-auth-xpub
func (a *Action) search(c *gin.Context) {
reqXPubID := c.GetString(auth.ParamXPubHashKey)

queryParams, metadata, conditions, err := actions.GetQueryParameters(c)
queryParams, metadata, conditions, err := actions.GetSearchQueryParameters(c)
if err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusBadRequest, err.Error())
return
}

Expand All @@ -49,7 +46,7 @@ func (a *Action) search(c *gin.Context) {
&dbConditions,
queryParams,
); err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand Down
30 changes: 14 additions & 16 deletions actions/admin/access_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ import (
// @Description Access Keys Search
// @Tags Admin
// @Produce json
// @Param page query int false "page"
// @Param page_size query int false "page_size"
// @Param order_by_field query string false "order_by_field"
// @Param sort_direction query string false "sort_direction"
// @Param metadata query string false "Metadata filter"
// @Param conditions query string false "Conditions filter"
// @Success 200
// @Param SearchRequestParameters body actions.SearchRequestParameters false "Supports targeted resource searches with filters for metadata and custom conditions, 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 SearchRequestParameters 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 (a *Action) accessKeysSearch(c *gin.Context) {
queryParams, metadata, conditions, err := actions.GetQueryParameters(c)
queryParams, metadata, conditions, err := actions.GetSearchQueryParameters(c)
if err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusBadRequest, err.Error())
return
}

Expand All @@ -39,7 +36,7 @@ func (a *Action) accessKeysSearch(c *gin.Context) {
conditions,
queryParams,
); err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand All @@ -57,15 +54,16 @@ func (a *Action) accessKeysSearch(c *gin.Context) {
// @Description Access Keys Count
// @Tags Admin
// @Produce json
// @Param metadata query string false "Metadata filter"
// @Param conditions query string false "Conditions filter"
// @Success 200
// @Param CountRequestParameters body actions.CountRequestParameters false "Enables precise filtering of resource counts using custom conditions or metadata, catering to specific business or analysis needs"
// @Success 200 {number} int64 "Count of access keys"
// @Failure 400 "Bad request - Error while parsing CountRequestParameters 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 (a *Action) accessKeysCount(c *gin.Context) {
_, metadata, conditions, err := actions.GetQueryParameters(c)
metadata, conditions, err := actions.GetCountQueryParameters(c)
if err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusBadRequest, err.Error())
return
}

Expand All @@ -75,7 +73,7 @@ func (a *Action) accessKeysCount(c *gin.Context) {
metadata,
conditions,
); err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand Down
40 changes: 22 additions & 18 deletions actions/admin/destinations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/bitcoin-sv/spv-wallet/actions"
"github.com/bitcoin-sv/spv-wallet/engine"
"github.com/bitcoin-sv/spv-wallet/mappings"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/gin-gonic/gin"
)

Expand All @@ -14,19 +16,16 @@ import (
// @Description Search for destinations
// @Tags Admin
// @Produce json
// @Param page query int false "page"
// @Param page_size query int false "page_size"
// @Param order_by_field query string false "order_by_field"
// @Param sort_direction query string false "sort_direction"
// @Param metadata query string false "Metadata filter"
// @Param conditions query string false "Conditions filter"
// @Success 200
// @Param SearchRequestParameters body actions.SearchRequestParameters false "Supports targeted resource searches with filters for metadata and custom conditions, plus options for pagination and sorting to streamline data exploration and analysis"
// @Success 200 {object} []models.Destination "List of destinations"
// @Failure 400 "Bad request - Error while parsing SearchRequestParameters from request body"
// @Failure 500 "Internal server error - Error while searching for destinations"
// @Router /v1/admin/destinations/search [post]
// @Security x-auth-xpub
func (a *Action) destinationsSearch(c *gin.Context) {
queryParams, metadata, conditions, err := actions.GetQueryParameters(c)
queryParams, metadata, conditions, err := actions.GetSearchQueryParameters(c)
if err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusBadRequest, err.Error())
return
}

Expand All @@ -37,11 +36,16 @@ func (a *Action) destinationsSearch(c *gin.Context) {
conditions,
queryParams,
); err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

c.JSON(http.StatusOK, destinations)
destinationContracts := make([]*models.Destination, 0)
for _, destination := range destinations {
destinationContracts = append(destinationContracts, mappings.MapToDestinationContract(destination))
}

c.JSON(http.StatusOK, destinationContracts)
}

// destinationsCount will count all destinations filtered by metadata
Expand All @@ -50,15 +54,15 @@ func (a *Action) destinationsSearch(c *gin.Context) {
// @Description Count destinations
// @Tags Admin
// @Produce json
// @Param metadata query string false "Metadata filter"
// @Param conditions query string false "Conditions filter"
// @Success 200
// @Router /v1/admin/destinations/count [post]
// @Param CountRequestParameters body actions.CountRequestParameters false "Enables precise filtering of resource counts using custom conditions or metadata, catering to specific business or analysis needs"
// @Success 200 {number} int64 "Count of destinations"
// @Failure 400 "Bad request - Error while parsing CountRequestParameters from request body"
// @Failure 500 "Internal Server Error - Error while fetching count of destinations"
// @Security x-auth-xpub
func (a *Action) destinationsCount(c *gin.Context) {
_, metadata, conditions, err := actions.GetQueryParameters(c)
metadata, conditions, err := actions.GetCountQueryParameters(c)
if err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusBadRequest, err.Error())
return
}

Expand All @@ -68,7 +72,7 @@ func (a *Action) destinationsCount(c *gin.Context) {
metadata,
conditions,
); err != nil {
c.JSON(http.StatusExpectationFailed, err.Error())
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand Down
27 changes: 18 additions & 9 deletions actions/admin/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,34 @@ import (

// CreatePaymail is the model for creating a paymail
type CreatePaymail struct {
XpubID string `json:"xpub_id"`
Address string `json:"address"`
PublicName string `json:"public_name"`
Avatar string `json:"avatar"`
Metadata engine.Metadata `json:"metadata"`
// The xpub with which the paymail is associated
Key string `json:"key" example:"xpub661MyMwAqRbcGpZVrSHU..."`
// The paymail address
Address string `json:"address" example:"test@spv-wallet.com"`
// The public name of the paymail
PublicName string `json:"public_name" example:"Test"`
// The avatar of the paymail (url address)
Avatar string `json:"avatar" example:"https://example.com/avatar.png"`
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
}

// PaymailAddress is the model containing only paymail address used for getting and deleting paymail address
type PaymailAddress struct {
Address string `json:"address"`
// The paymail address
Address string `json:"address" example:"test@spv-wallet.com"`
}

// RecordTransaction is the model for recording a transaction
type RecordTransaction struct {
Hex string `json:"hex"`
// The transaction hex
Hex string `json:"hex" example:"0100000002..."`
}

// CreateXpub is the model for creating an xpub
type CreateXpub struct {
Key string `json:"key"`
Metadata engine.Metadata `json:"metadata"`
// The xpub key
Key string `json:"key" example:"xpub661MyMwAqRbcGpZVrSHU..."`
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
}
Loading

0 comments on commit aeedfcb

Please sign in to comment.