-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebabc9f
commit 77570db
Showing
34 changed files
with
288 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package model | ||
|
||
type TryPayUserOpRequest struct { | ||
ForceStrategyId string `json:"strategy_id"` | ||
ForceNetWork string `json:"force_network"` | ||
ForceTokens string `json:"force_tokens"` | ||
ForceEntryPointAddress string `json:"force_entry_point_address"` | ||
UserOperation UserOperationItem `json:"user_operation"` | ||
Apikey string `json:"apikey"` | ||
Extra interface{} `json:"extra"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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"` | ||
} | ||
|
||
type ComputeGasResponse struct { | ||
StrategyId string | ||
tokenCost string | ||
network string | ||
token string | ||
UsdCost string | ||
} |
2 changes: 1 addition & 1 deletion
2
rpc_server/models/client_credential.go → common/model/client_credential.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package models | ||
package model | ||
|
||
type ClientCredential struct { | ||
ApiKey string `json:"apiKey"` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package models | ||
package model | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package model | ||
|
||
type Strategy struct { | ||
Id string | ||
EntryPointAddress string | ||
PayMasterAddress string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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"` | ||
//paymasterAndData string `json:"paymaster_and_data"` | ||
Signature string `json:"signature"` | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
jwt: | ||
security: hello-eth-paymaster | ||
security: hello-ethereum-paymaster | ||
realm: aastar | ||
idkey: id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dashboard_service | ||
|
||
import "AAStarCommunity/EthPaymaster_BackService/common/model" | ||
|
||
func GetStrategyById(strategyId string) model.Strategy { | ||
return model.Strategy{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dashboard_service | ||
|
||
import ( | ||
"AAStarCommunity/EthPaymaster_BackService/common/model" | ||
) | ||
|
||
func GetSuitableStrategy(entrypoint string, network string, token string) (model.Strategy, error) { | ||
|
||
return model.Strategy{}, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package executor | ||
|
||
import ( | ||
"AAStarCommunity/EthPaymaster_BackService/common/model" | ||
) | ||
|
||
func GetSupportEntrypointExecute() (model.Result, error) { | ||
return model.Result{}, nil | ||
} | ||
func GetSupportStrategyExecute() (model.Result, error) { | ||
return model.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package executor | ||
|
||
import ( | ||
"AAStarCommunity/EthPaymaster_BackService/common/model" | ||
"AAStarCommunity/EthPaymaster_BackService/service/dashboard_service" | ||
"AAStarCommunity/EthPaymaster_BackService/service/gas_service" | ||
"AAStarCommunity/EthPaymaster_BackService/service/validator_service" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
func TryPayUserOpExecute(request model.TryPayUserOpRequest) (model.Result, error) { | ||
//validator | ||
if err := paramValidate(request); err != nil { | ||
return model.Result{}, err | ||
} | ||
userOp := request.UserOperation | ||
//getStrategy | ||
strategy, err := strategyGenerate(request) | ||
if 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) | ||
if gasComputeError != nil { | ||
return model.Result{}, gasComputeError | ||
} | ||
|
||
//validate gas | ||
if err := gas_service.ValidateGas(userOp, gasResponse); err != nil { | ||
return model.Result{}, err | ||
} | ||
//pay | ||
payReceipt, payError := executePay(strategy, request.UserOperation, gasResponse) | ||
if payError != nil { | ||
return model.Result{}, payError | ||
} | ||
paymasterSignature := getPayMasterSignature(strategy, request.UserOperation) | ||
var result = model.TryPayUserOpResponse{ | ||
StrategyId: strategy.Id, | ||
EntryPointAddress: strategy.EntryPointAddress, | ||
PayMasterAddress: strategy.EntryPointAddress, | ||
PayReceipt: payReceipt, | ||
PayMasterSignature: paymasterSignature, | ||
GasInfo: gasResponse, | ||
} | ||
|
||
return model.Result{ | ||
Code: 0, | ||
Data: result, | ||
Message: "message", | ||
Cost: "cost", | ||
}, nil | ||
} | ||
func paramValidate(request model.TryPayUserOpRequest) error { | ||
return nil | ||
} | ||
|
||
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 { | ||
return "" | ||
} | ||
|
||
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 strategy, nil | ||
} | ||
|
||
suitableStrategy, err := dashboard_service.GetSuitableStrategy(request.ForceEntryPointAddress, request.ForceNetWork, request.ForceTokens) //TODO | ||
if err != nil { | ||
return model.Strategy{}, err | ||
} | ||
if suitableStrategy == (model.Strategy{}) { | ||
return model.Strategy{}, xerrors.Errorf("Empty Strategies") | ||
} | ||
return suitableStrategy, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package executor | ||
|
||
import ( | ||
"AAStarCommunity/EthPaymaster_BackService/common/model" | ||
|
||
"testing" | ||
) | ||
|
||
func TestTryPayUserOpExecute(t *testing.T) { | ||
request := getMockTryPayUserOpRequest() | ||
TryPayUserOpExecute(request) | ||
|
||
} | ||
|
||
func getMockTryPayUserOpRequest() model.TryPayUserOpRequest { | ||
return model.TryPayUserOpRequest{ | ||
ForceStrategyId: "1", | ||
UserOperation: model.UserOperationItem{ | ||
Sender: "0x123", | ||
Nonce: "", | ||
CallGasLimit: "", | ||
VerificationGasList: "", | ||
PerVerificationGas: "", | ||
MaxFeePerGas: "", | ||
MaxPriorityFeePerGas: "", | ||
}, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package gas_service |
Oops, something went wrong.