Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 91 additions & 84 deletions docs/package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/spec/components/schemas/RegistrationRequest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: object
x-go-is-request: true
required:
- data
properties:
data:
$ref: '#/components/schemas/RegistrationRequestData'
20 changes: 20 additions & 0 deletions docs/spec/components/schemas/RegistrationRequestData.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type: object
required:
- tx_data
- no_send
properties:
meta:
type: object
description: "Metadata if it is required"
example: {"source": "web", "user_id": 123}
tx_data:
type: string
no_send:
type: bool
description: Flag indicates whether transaction should be sent on-chain
example: true
destination:
type: string
example: "0xC0B09085Fa2ad3A8BbF96494B8d5cd10702FE20d"
description: Address of registration smart contract

Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,7 @@ post:
content:
application/json:
schema:
type: object
required:
- data
properties:
data:
type: object
required:
- tx_data
properties:
tx_data:
type: string
no_send:
type: bool
description: Flag indicates whether transaction should be sent on-chain
example: true
destination:
type: string
example: "0xC0B09085Fa2ad3A8BbF96494B8d5cd10702FE20d"
description: Address of registration smart contract
$ref: '#/components/schemas/RegistrationRequest'
responses:
'200':
description: Success
Expand Down
10 changes: 7 additions & 3 deletions internal/service/handlers/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ func Registration(w http.ResponseWriter, r *http.Request) {
ape.RenderErr(w, problems.BadRequest(err)...)
return
}

log := Log(r).WithFields(logan.F{
logF := logan.F{
"user-agent": r.Header.Get("User-Agent"),
"calldata": req.Data.TxData,
})
}
if req.Data.Meta != nil {
logF = logF.Merge(*req.Data.Meta)
}

log := Log(r).WithFields(logF)
log.Debug("registration request")

// `RelayerConfig(r).RegistrationAddress` is default value for target contract
Expand Down
13 changes: 2 additions & 11 deletions internal/service/requests/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/rarimo/registration-relayer/resources"
"gitlab.com/distributed_lab/logan/v3/errors"
)

Expand All @@ -15,17 +16,7 @@ var (
addressRegexp = regexp.MustCompile("^0x[0-9a-fA-F]{40}")
)

type RegistrationRequestData struct {
TxData string `json:"tx_data"`
NoSend bool `json:"no_send"`
Destination *string `json:"destination,omitempty"`
}

type RegistrationRequest struct {
Data RegistrationRequestData `json:"data"`
}

func NewRegistrationRequest(r *http.Request) (req RegistrationRequest, err error) {
func NewRegistrationRequest(r *http.Request) (req resources.RegistrationRequest, err error) {
err = json.NewDecoder(r.Body).Decode(&req)
if err != nil {
return req, errors.Wrap(err, "failed to unmarshal")
Expand Down
9 changes: 9 additions & 0 deletions resources/model_registration_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* GENERATED. Do not modify. Your changes might be overwritten!
*/

package resources

type RegistrationRequest struct {
Data RegistrationRequestData `json:"data"`
}
15 changes: 15 additions & 0 deletions resources/model_registration_request_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* GENERATED. Do not modify. Your changes might be overwritten!
*/

package resources

type RegistrationRequestData struct {
// Address of registration smart contract
Destination *string `json:"destination,omitempty"`
// Metadata if it is required
Meta *map[string]interface{} `json:"meta,omitempty"`
// Flag indicates whether transaction should be sent on-chain
NoSend bool `json:"no_send"`
TxData string `json:"tx_data"`
}