Skip to content

Commit

Permalink
add White List
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed Sep 4, 2024
1 parent a805e83 commit 843195b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/model/secret_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type SponsorConfig struct {
SponsorTestClientUrl string `json:"sponsor_client_rpc_test_net"`
SponsorMainClientUrl string `json:"sponsor_client_rpc_main_net"`
FreeSponsorWhitelist []string `json:"free_sponsor_whitelist"`
FreeSponsorAPIList []string `json:"free_sponsor_white_api_list"`
}

type NetWorkSecretConfig struct {
Expand Down
7 changes: 7 additions & 0 deletions config/secret_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func GetPaymasterSponsorChainId(isTestNet bool) *big.Int {
}

var sponsorWhitelist = mapset.NewSet[string]()
var sponsorWhiteApiList = mapset.NewSet[string]()

type SignerConfigMap map[global_const.Network]*global_const.EOA

Expand Down Expand Up @@ -107,11 +108,17 @@ func secretConfigInit(secretConfigPath string) {
if secretConfig.SponsorConfig.FreeSponsorWhitelist != nil {
sponsorWhitelist.Append(secretConfig.SponsorConfig.FreeSponsorWhitelist...)
}
if secretConfig.SponsorConfig.FreeSponsorAPIList != nil {
sponsorWhiteApiList.Append(secretConfig.SponsorConfig.FreeSponsorAPIList...)
}
}

func IsSponsorWhitelist(senderAddress string) bool {
return sponsorWhitelist.Contains(senderAddress)
}
func IsSponsorWhiteApiList(apiKey string) bool {
return sponsorWhiteApiList.Contains(apiKey)
}
func GetNetworkSecretConfig(network global_const.Network) model.NetWorkSecretConfig {
return secretConfig.NetWorkSecretConfigMap[string(network)]
}
Expand Down
7 changes: 7 additions & 0 deletions service/operator/try_pay_user_op_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func executePay(input *ExecutePayInput) (*model.PayResponse, error) {
logrus.Debugf("Not Need ExecutePay In SponsorWhitelist [%s]", input.UserOpSender)
return nil, nil
}
if config.IsSponsorWhiteApiList(input.ApiKey) {
logrus.Debugf("Not Need ExecutePay In SponsorWhiteKeylist [%s]", input.ApiKey)
return nil, nil
}

// TODO
//if config.IsTestNet(input.Network) {
// logrus.Debugf("Not Need ExecutePay In TestNet [%s]", input.Network)
Expand Down Expand Up @@ -141,6 +146,7 @@ func executePay(input *ExecutePayInput) (*model.PayResponse, error) {
}

type ExecutePayInput struct {
ApiKey string
ProjectUserId string
PayType global_const.PayType
ProjectSponsor bool
Expand All @@ -161,6 +167,7 @@ func postExecute(apiKeyModel *model.ApiKeyModel, userOp *user_op.UserOpInput, st
logrus.Debug("postExecute paymasterData:", paymasterData)

_, err = executePay(&ExecutePayInput{
ApiKey: apiKeyModel.ApiKey,
ProjectUserId: strconv.FormatInt(apiKeyModel.UserId, 10),
PayType: strategy.GetPayType(),
ProjectSponsor: strategy.ProjectSponsor,
Expand Down

0 comments on commit 843195b

Please sign in to comment.