Skip to content

Commit

Permalink
fix deep dup bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed Mar 5, 2024
1 parent 48f83a2 commit f74e300
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 41 deletions.
12 changes: 6 additions & 6 deletions common/model/api_response.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package model

type TryPayUserOpResponse struct {
StrategyId string `json:"strategy_id"`
EntryPointAddress string `json:"entry_point_address"`
PayMasterAddress string `json:"pay_master_address"`
PayMasterSignature string `json:"pay_master_signature"`
PayReceipt interface{} `json:"pay_receipt"`
GasInfo ComputeGasResponse `json:"gaf_info"`
StrategyId string `json:"strategy_id"`
EntryPointAddress string `json:"entry_point_address"`
PayMasterAddress string `json:"pay_master_address"`
PayMasterSignature string `json:"pay_master_signature"`
PayReceipt interface{} `json:"pay_receipt"`
GasInfo *ComputeGasResponse `json:"gaf_info"`
}

type ComputeGasResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion rpc_server/api/v1/get_support_entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetSupportEntrypoint(c *gin.Context) {
}

//2. recall service
result, err := operator.GetSupportEntrypointExecute(request)
result, err := operator.GetSupportEntrypointExecute(&request)
if err != nil {
errStr := fmt.Sprintf("%v", err)
response.SetHttpCode(http.StatusInternalServerError).FailCode(c, http.StatusInternalServerError, errStr)
Expand Down
2 changes: 1 addition & 1 deletion rpc_server/api/v1/try_pay_user_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TryPayUserOperation(c *gin.Context) {
return
}
//2. recall service
result, err := operator.TryPayUserOpExecute(request)
result, err := operator.TryPayUserOpExecute(&request)
if err != nil {
errStr := fmt.Sprintf("TryPayUserOpExecute ERROR [%v]", err)
response.SetHttpCode(http.StatusInternalServerError).FailCode(c, http.StatusInternalServerError, errStr)
Expand Down
2 changes: 1 addition & 1 deletion service/dashboard_service/strategy_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"AAStarCommunity/EthPaymaster_BackService/common/model"
)

func GetSuitableStrategy(entrypoint string, network string, token string) (model.Strategy, error) {
func GetSuitableStrategy(entrypoint *string, network *string, token *string) (model.Strategy, error) {

return model.Strategy{}, nil

Expand Down
6 changes: 3 additions & 3 deletions service/gas_service/gas_compotor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package gas_service

import "AAStarCommunity/EthPaymaster_BackService/common/model"

func ComputeGas(userOp model.UserOperationItem, strategy model.Strategy) (model.ComputeGasResponse, error) {
return model.ComputeGasResponse{}, nil
func ComputeGas(userOp *model.UserOperationItem, strategy *model.Strategy) (*model.ComputeGasResponse, error) {
return &model.ComputeGasResponse{}, nil
}

func ValidateGas(userOp model.UserOperationItem, gasComputeResponse model.ComputeGasResponse) error {
func ValidateGas(userOp *model.UserOperationItem, gasComputeResponse *model.ComputeGasResponse) error {
return nil
}
4 changes: 2 additions & 2 deletions service/operator/get_support_entry_point_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package operator

import "AAStarCommunity/EthPaymaster_BackService/common/model"

func GetSupportEntrypointExecute(request model.GetSupportEntrypointRequest) (model.Result, error) {
return model.Result{}, nil
func GetSupportEntrypointExecute(request *model.GetSupportEntrypointRequest) (*model.Result, error) {
return &model.Result{}, nil
}
4 changes: 2 additions & 2 deletions service/operator/get_support_strategy_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import (
"AAStarCommunity/EthPaymaster_BackService/common/model"
)

func GetSupportStrategyExecute(request model.GetSupportStrategyRequest) (model.Result, error) {
return model.Result{}, nil
func GetSupportStrategyExecute(request *model.GetSupportStrategyRequest) (*model.Result, error) {
return &model.Result{}, nil
}
46 changes: 23 additions & 23 deletions service/operator/try_pay_user_op_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ import (
"golang.org/x/xerrors"
)

func TryPayUserOpExecute(request model.TryPayUserOpRequest) (model.Result, error) {
func TryPayUserOpExecute(request *model.TryPayUserOpRequest) (*model.Result, error) {
//validator
if err := businessParamValidate(request); err != nil {
return model.Result{}, err
return &model.Result{}, err
}
userOp := request.UserOperation
//getStrategy
strategy, err := strategyGenerate(request)
if err != nil {
return model.Result{}, err
return &model.Result{}, err
}
if err := validator_service.ValidateStrategy(strategy, userOp); err != nil {
return model.Result{}, err
if err := validator_service.ValidateStrategy(strategy, &userOp); err != nil {
return &model.Result{}, err
}

//base Strategy and UserOp computeGas
gasResponse, gasComputeError := gas_service.ComputeGas(userOp, strategy)
gasResponse, gasComputeError := gas_service.ComputeGas(&userOp, strategy)
if gasComputeError != nil {
return model.Result{}, gasComputeError
return &model.Result{}, gasComputeError
}

//validate gas
if err := gas_service.ValidateGas(userOp, gasResponse); err != nil {
return model.Result{}, err
if err := gas_service.ValidateGas(&userOp, gasResponse); err != nil {
return &model.Result{}, err
}
//pay
payReceipt, payError := executePay(strategy, request.UserOperation, gasResponse)
payReceipt, payError := executePay(strategy, &userOp, gasResponse)
if payError != nil {
return model.Result{}, payError
return &model.Result{}, payError
}
paymasterSignature := getPayMasterSignature(strategy, request.UserOperation)
paymasterSignature := getPayMasterSignature(strategy, &userOp)
var result = model.TryPayUserOpResponse{
StrategyId: strategy.Id,
EntryPointAddress: strategy.EntryPointAddress,
Expand All @@ -48,44 +48,44 @@ func TryPayUserOpExecute(request model.TryPayUserOpRequest) (model.Result, error
GasInfo: gasResponse,
}

return model.Result{
return &model.Result{
Code: 200,
Data: result,
Message: "message",
Cost: "cost",
}, nil
}
func businessParamValidate(request model.TryPayUserOpRequest) error {
func businessParamValidate(request *model.TryPayUserOpRequest) error {
//UserOp Validate
return nil
}

func executePay(strategy model.Strategy, userOp model.UserOperationItem, gasResponse model.ComputeGasResponse) (interface{}, error) {
func executePay(strategy *model.Strategy, userOp *model.UserOperationItem, gasResponse *model.ComputeGasResponse) (interface{}, error) {
//1.Recharge
//2.record account
//3.return Receipt
return nil, nil
}
func getPayMasterSignature(strategy model.Strategy, userOp model.UserOperationItem) string {
func getPayMasterSignature(strategy *model.Strategy, userOp *model.UserOperationItem) string {
return ""
}

func strategyGenerate(request model.TryPayUserOpRequest) (model.Strategy, error) {
func strategyGenerate(request *model.TryPayUserOpRequest) (*model.Strategy, error) {
if forceStrategyId := request.ForceStrategyId; forceStrategyId != "" {
//force strategy
strategy := dashboard_service.GetStrategyById(forceStrategyId)
if strategy == (model.Strategy{}) {
return model.Strategy{}, xerrors.Errorf("Not Support Strategy ID: [%w]", forceStrategyId)
return &model.Strategy{}, xerrors.Errorf("Not Support Strategy ID: [%w]", forceStrategyId)
}
return strategy, nil
return &strategy, nil
}

suitableStrategy, err := dashboard_service.GetSuitableStrategy(request.ForceEntryPointAddress, request.ForceNetWork, request.ForceTokens) //TODO
suitableStrategy, err := dashboard_service.GetSuitableStrategy(&request.ForceEntryPointAddress, &request.ForceNetWork, &request.ForceTokens) //TODO
if err != nil {
return model.Strategy{}, err
return &model.Strategy{}, err
}
if suitableStrategy == (model.Strategy{}) {
return model.Strategy{}, xerrors.Errorf("Empty Strategies")
return &model.Strategy{}, xerrors.Errorf("Empty Strategies")
}
return suitableStrategy, nil
return &suitableStrategy, nil
}
3 changes: 1 addition & 2 deletions service/validator_service/basic_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package validator_service

import "AAStarCommunity/EthPaymaster_BackService/common/model"

func ValidateStrategy(strategy model.Strategy, userOp model.UserOperationItem) error {

func ValidateStrategy(strategy *model.Strategy, userOp *model.UserOperationItem) error {
return nil
}

0 comments on commit f74e300

Please sign in to comment.