From e339f15f914f4da6aa78b9776dc8cdbcc99ddfeb Mon Sep 17 00:00:00 2001 From: dylanyang Date: Mon, 17 Jun 2024 16:37:17 +0800 Subject: [PATCH] update bug --- common/model/secret_config.go | 16 ++++++++-------- common/price_compoent/price_util.go | 8 +++++++- common/utils/util.go | 2 +- config/secret_config.go | 14 +++++++++----- rpc_server/api/v1/sponsor_test.go | 9 +++++++++ 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/common/model/secret_config.go b/common/model/secret_config.go index f00221c3..4e10c774 100644 --- a/common/model/secret_config.go +++ b/common/model/secret_config.go @@ -19,17 +19,17 @@ type SecretConfig struct { RelayDBConfig DBConfig `json:"relay_db_config"` ApiKeyTableName string `json:"api_key_table_name"` StrategyConfigTableName string `json:"strategy_config_table_name"` - FreeSponsorWhitelist []string `json:"free_sponsor_whitelist"` SponsorConfig SponsorConfig `json:"sponsor_config"` } type SponsorConfig struct { - SponsorDepositAddress string `json:"sponsor_deposit_address"` - SponsorDepositPrivateKey string `json:"sponsor_deposit_private_key"` - DashBoardSignerAddress string `json:"dashboard_signer_address"` - DepositTestNetUrl string `json:"deposit_test_net_url"` - DepositMainNetUrl string `json:"deposit_main_net_url"` - SponsorTestClientUrl string `json:"sponsor_client_rpc_test_net"` - SponsorMainClientUrl string `json:"sponsor_client_rpc_main_net"` + SponsorDepositAddress string `json:"sponsor_deposit_address"` + SponsorDepositPrivateKey string `json:"sponsor_deposit_private_key"` + DashBoardSignerAddress string `json:"dashboard_signer_address"` + DepositTestNetUrl string `json:"deposit_test_net_url"` + DepositMainNetUrl string `json:"deposit_main_net_url"` + SponsorTestClientUrl string `json:"sponsor_client_rpc_test_net"` + SponsorMainClientUrl string `json:"sponsor_client_rpc_main_net"` + FreeSponsorWhitelist []string `json:"free_sponsor_whitelist"` } type NetWorkSecretConfig struct { diff --git a/common/price_compoent/price_util.go b/common/price_compoent/price_util.go index 42a7a52f..55db47ea 100644 --- a/common/price_compoent/price_util.go +++ b/common/price_compoent/price_util.go @@ -4,6 +4,7 @@ import ( "AAStarCommunity/EthPaymaster_BackService/common/global_const" "AAStarCommunity/EthPaymaster_BackService/config" "fmt" + "github.com/sirupsen/logrus" "golang.org/x/xerrors" "io" "io/ioutil" @@ -57,7 +58,12 @@ func GetPriceUsd(tokenType global_const.TokenType) (float64, error) { res, _ := http.DefaultClient.Do(req) - defer res.Body.Close() + defer func(Body io.ReadCloser) { + err := Body.Close() + if err != nil { + logrus.Error("close body error: ", err) + } + }(res.Body) body, _ := io.ReadAll(res.Body) bodystr := string(body) strarr := strings.Split(bodystr, ":") diff --git a/common/utils/util.go b/common/utils/util.go index 1a202652..58418eee 100644 --- a/common/utils/util.go +++ b/common/utils/util.go @@ -59,7 +59,7 @@ func GenerateMockUservOperation() *map[string]any { "maxPriorityFeePerGas": "0x59682f00", "nonce": "0x00", "preVerificationGas": "0xae64", - "sender": "0xffdb071c2b58ccc10ad386f9bb4e8d3d664ce73c", + "sender": "0xFfDB071C2b58CCC10Ad386f9Bb4E8d3d664CE73c", "signature": "0xaa846693598194980f3bf50486be854704534c1622d0c2ee895a5a1ebe1508221909a27cc7971d9f522c8df13b9d8a6ee446d09ea7635f31c59d77d35d1281421c", "verificationGasLimit": "0x05fa35", } diff --git a/config/secret_config.go b/config/secret_config.go index f58309f8..15e7533c 100644 --- a/config/secret_config.go +++ b/config/secret_config.go @@ -6,9 +6,10 @@ import ( "context" "encoding/json" "fmt" + mapset "github.com/deckarep/golang-set/v2" "github.com/ethereum/go-ethereum/ethclient" + "github.com/sirupsen/logrus" "math/big" - mapset "github.com/deckarep/golang-set/v2" "os" "sync" ) @@ -38,6 +39,7 @@ func GetPaymasterSponsorChainId(isTestNet bool) *big.Int { } return sponsorMainNetClientChainId } + var sponsorWhitelist = mapset.NewSet[string]() type SignerConfigMap map[global_const.Network]*global_const.EOA @@ -96,14 +98,16 @@ func secretConfigInit(secretConfigPath string) { sponsorTestNetClient = paymasterSponsorTestNetClient sponsorTestNetClientChainId = paymasterInnerClientChainId }) - if secretConfig.FreeSponsorWhitelist != nil { - sponsorWhitelist.Append(secretConfig.FreeSponsorWhitelist...) + logrus.Debugf("secretConfig [%v]", secretConfig) + if secretConfig.SponsorConfig.FreeSponsorWhitelist != nil { + sponsorWhitelist.Append(secretConfig.SponsorConfig.FreeSponsorWhitelist...) } } func IsSponsorWhitelist(senderAddress string) bool { - //TODO - return true + logrus.Debugf("IsSponsorWhitelist [%s]", senderAddress) + logrus.Debugf("IsSponsorWhitelist [%v]", sponsorWhitelist) + return sponsorWhitelist.Contains(senderAddress) } func GetNetworkSecretConfig(network global_const.Network) model.NetWorkSecretConfig { return secretConfig.NetWorkSecretConfigMap[string(network)] diff --git a/rpc_server/api/v1/sponsor_test.go b/rpc_server/api/v1/sponsor_test.go index 272bbc73..0e98aad4 100644 --- a/rpc_server/api/v1/sponsor_test.go +++ b/rpc_server/api/v1/sponsor_test.go @@ -10,6 +10,7 @@ import ( "encoding/json" "fmt" "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "testing" ) @@ -78,3 +79,11 @@ func TestValidateSignature(t *testing.T) { } t.Logf("ValidateSignature success") } +func TestDemo(t *testing.T) { + t.Logf("Demo") + address := "0xFfDB071C2b58CCC10Ad386f9Bb4E8d3d664CE73c" + commonAddres := common.HexToAddress(address) + commonAddres.Hex() + t.Logf("commonAddres: %v", commonAddres.Hex()) + +}