Skip to content

Commit

Permalink
try pay user operation request model validator
Browse files Browse the repository at this point in the history
  • Loading branch information
fanhousanbu committed Mar 5, 2024
1 parent 77570db commit 74c8675
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 21 deletions.
16 changes: 16 additions & 0 deletions common/model/api_request.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package model

import "errors"

type TryPayUserOpRequest struct {
ForceStrategyId string `json:"strategy_id"`
ForceNetWork string `json:"force_network"`
Expand All @@ -9,3 +11,17 @@ type TryPayUserOpRequest struct {
Apikey string `json:"apikey"`
Extra interface{} `json:"extra"`
}

func (sender *TryPayUserOpRequest) Validate() error {
if len(sender.Apikey) == 0 {
return errors.New("apikey mustn't empty")
}

if len(sender.ForceStrategyId) == 0 {
if len(sender.ForceNetWork) == 0 || len(sender.ForceTokens) == 0 || len(sender.ForceEntryPointAddress) == 0 {
return errors.New("strategy configuration illegal")
}
}

return nil
}
18 changes: 9 additions & 9 deletions common/model/user_operation.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package model

type UserOperationItem struct {
Sender string `json:"sender"`
Nonce string `json:"nonce"`
InitCode string `json:"init_code"`
CallGasLimit string `json:"call_gas_limit"`
VerificationGasList string `json:"verification_gas_list"`
PerVerificationGas string `json:"per_verification_gas"`
MaxFeePerGas string `json:"max_fee_per_gas"`
MaxPriorityFeePerGas string `json:"max_priority_fee_per_gas"`
Sender string `json:"sender" binding:"required"`
Nonce string `json:"nonce" binding:"required"`
InitCode string `json:"init_code" binding:"required"`
CallGasLimit string `json:"call_gas_limit" binding:"required"`
VerificationGasList string `json:"verification_gas_list" binding:"required"`
PerVerificationGas string `json:"per_verification_gas" binding:"required"`
MaxFeePerGas string `json:"max_fee_per_gas" binding:"required"`
MaxPriorityFeePerGas string `json:"max_priority_fee_per_gas" binding:"required"`
Signature string `json:"signature" binding:"required"`
//paymasterAndData string `json:"paymaster_and_data"`
Signature string `json:"signature"`
}
103 changes: 99 additions & 4 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -35,7 +34,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.ClientCredential"
"$ref": "#/definitions/model.ClientCredential"
}
}
],
Expand All @@ -46,6 +45,22 @@ const docTemplate = `{
}
}
},
"/api/health": {
"get": {
"description": "Get Healthz",
"consumes": [
"application/json"
],
"tags": [
"Healthz"
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/get-support-entrypoint": {
"get": {
"security": [
Expand Down Expand Up @@ -105,6 +120,17 @@ const docTemplate = `{
"tags": [
"Sponsor"
],
"parameters": [
{
"description": "UserOp Request",
"name": "tryPay",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.TryPayUserOpRequest"
}
}
],
"responses": {
"200": {
"description": "OK"
Expand All @@ -114,13 +140,80 @@ const docTemplate = `{
}
},
"definitions": {
"models.ClientCredential": {
"model.ClientCredential": {
"type": "object",
"properties": {
"apiKey": {
"type": "string"
}
}
},
"model.TryPayUserOpRequest": {
"type": "object",
"properties": {
"apikey": {
"type": "string"
},
"extra": {},
"force_entry_point_address": {
"type": "string"
},
"force_network": {
"type": "string"
},
"force_tokens": {
"type": "string"
},
"strategy_id": {
"type": "string"
},
"user_operation": {
"$ref": "#/definitions/model.UserOperationItem"
}
}
},
"model.UserOperationItem": {
"type": "object",
"required": [
"call_gas_limit",
"init_code",
"max_fee_per_gas",
"max_priority_fee_per_gas",
"nonce",
"per_verification_gas",
"sender",
"signature",
"verification_gas_list"
],
"properties": {
"call_gas_limit": {
"type": "string"
},
"init_code": {
"type": "string"
},
"max_fee_per_gas": {
"type": "string"
},
"max_priority_fee_per_gas": {
"type": "string"
},
"nonce": {
"type": "string"
},
"per_verification_gas": {
"type": "string"
},
"sender": {
"type": "string"
},
"signature": {
"type": "string"
},
"verification_gas_list": {
"type": "string"
}
}
}
},
"securityDefinitions": {
Expand All @@ -143,6 +236,8 @@ var SwaggerInfo = &swag.Spec{
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
Expand Down
98 changes: 96 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.ClientCredential"
"$ref": "#/definitions/model.ClientCredential"
}
}
],
Expand All @@ -34,6 +34,22 @@
}
}
},
"/api/health": {
"get": {
"description": "Get Healthz",
"consumes": [
"application/json"
],
"tags": [
"Healthz"
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/get-support-entrypoint": {
"get": {
"security": [
Expand Down Expand Up @@ -93,6 +109,17 @@
"tags": [
"Sponsor"
],
"parameters": [
{
"description": "UserOp Request",
"name": "tryPay",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.TryPayUserOpRequest"
}
}
],
"responses": {
"200": {
"description": "OK"
Expand All @@ -102,13 +129,80 @@
}
},
"definitions": {
"models.ClientCredential": {
"model.ClientCredential": {
"type": "object",
"properties": {
"apiKey": {
"type": "string"
}
}
},
"model.TryPayUserOpRequest": {
"type": "object",
"properties": {
"apikey": {
"type": "string"
},
"extra": {},
"force_entry_point_address": {
"type": "string"
},
"force_network": {
"type": "string"
},
"force_tokens": {
"type": "string"
},
"strategy_id": {
"type": "string"
},
"user_operation": {
"$ref": "#/definitions/model.UserOperationItem"
}
}
},
"model.UserOperationItem": {
"type": "object",
"required": [
"call_gas_limit",
"init_code",
"max_fee_per_gas",
"max_priority_fee_per_gas",
"nonce",
"per_verification_gas",
"sender",
"signature",
"verification_gas_list"
],
"properties": {
"call_gas_limit": {
"type": "string"
},
"init_code": {
"type": "string"
},
"max_fee_per_gas": {
"type": "string"
},
"max_priority_fee_per_gas": {
"type": "string"
},
"nonce": {
"type": "string"
},
"per_verification_gas": {
"type": "string"
},
"sender": {
"type": "string"
},
"signature": {
"type": "string"
},
"verification_gas_list": {
"type": "string"
}
}
}
},
"securityDefinitions": {
Expand Down
Loading

0 comments on commit 74c8675

Please sign in to comment.