Skip to content

Commit

Permalink
Add comments. Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaptoss committed Jun 25, 2024
1 parent 8852a24 commit b074920
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ empty, otherwise only `Build and Publish` job will be passed.
private_key: "" # (hex without 0x) ECDSA secp256k1 private key for sign transactions
vault_address: "http://127.0.0.1:8200" # (url) vault address
vault_mount_path: "secret_data" # (string)
whitelist: # (list of hex addresses) specifie which contracts can be passed in `destination` field in request
whitelist: # (list of hex addresses) specify which contracts can be passed in `destination` field in request
- "0x123...123"
- "0x123...123"
```
ENV
```
VAULT_TOKEN (will be cleared after start service)
```
### Order private key getting:
1. private_key
2. vault
There must be specified or private key, or vault address and path. If specified both, then will be used private_key from config.

## Running from docker

Make sure that docker installed.
Expand Down
4 changes: 4 additions & 0 deletions internal/service/handlers/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func Registration(w http.ResponseWriter, r *http.Request) {
})
log.Debug("registration request")

// `RelayerConfig(r).RegistrationAddress` is default value for target contract
// if destination not specified this value will be used
// this value is required in config
registrationAddress := RelayerConfig(r).RegistrationAddress
if req.Data.Destination != nil {
if !RelayerConfig(r).WhiteList.IsPresent(*req.Data.Destination) {
Expand All @@ -49,6 +52,7 @@ func Registration(w http.ResponseWriter, r *http.Request) {
})...)
}

// destination is valid hex address because of request validation
registrationAddress = common.HexToAddress(*req.Data.Destination)
}

Expand Down
9 changes: 7 additions & 2 deletions internal/service/requests/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"gitlab.com/distributed_lab/logan/v3/errors"
)

var (
calldataRegexp = regexp.MustCompile("^0x[0-9a-fA-F]+$")
addressRegexp = regexp.MustCompile("^0x[0-9a-fA-F]{40}")
)

type RegistrationRequestData struct {
TxData string `json:"tx_data"`
Destination *string `json:"destination,omitempty"`
Expand All @@ -30,7 +35,7 @@ func NewRegistrationRequest(r *http.Request) (req RegistrationRequest, err error
}

return req, validation.Errors{
"data/tx_data": validation.Validate(req.Data.TxData, validation.Match(regexp.MustCompile("^0x[0-9a-fA-F]+$"))),
"data/destination": validation.Validate(req.Data.Destination, validation.When(req.Data.Destination != nil, validation.Required, validation.Match(regexp.MustCompile("^0x[0-9a-fA-F]{40}")))),
"data/tx_data": validation.Validate(req.Data.TxData, validation.Match(calldataRegexp)),
"data/destination": validation.Validate(req.Data.Destination, validation.When(req.Data.Destination != nil, validation.Required, validation.Match(addressRegexp))),
}.Filter()
}

0 comments on commit b074920

Please sign in to comment.