Skip to content

Commit

Permalink
update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed Jun 17, 2024
1 parent 216eb98 commit e339f15
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
16 changes: 8 additions & 8 deletions common/model/secret_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion common/price_compoent/price_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, ":")
Expand Down
2 changes: 1 addition & 1 deletion common/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GenerateMockUservOperation() *map[string]any {
"maxPriorityFeePerGas": "0x59682f00",
"nonce": "0x00",
"preVerificationGas": "0xae64",
"sender": "0xffdb071c2b58ccc10ad386f9bb4e8d3d664ce73c",
"sender": "0xFfDB071C2b58CCC10Ad386f9Bb4E8d3d664CE73c",
"signature": "0xaa846693598194980f3bf50486be854704534c1622d0c2ee895a5a1ebe1508221909a27cc7971d9f522c8df13b9d8a6ee446d09ea7635f31c59d77d35d1281421c",
"verificationGasLimit": "0x05fa35",
}
Expand Down
14 changes: 9 additions & 5 deletions config/secret_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down
9 changes: 9 additions & 0 deletions rpc_server/api/v1/sponsor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())

}

0 comments on commit e339f15

Please sign in to comment.