Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into gas_tank_v1
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/model/api_key_info.go
#	common/model/secret_config.go
#	common/model/strategy.go
#	rpc_server/middlewares/auth.go
#	rpc_server/middlewares/rate_limit.go
#	service/dashboard_service/dashboard_service.go
  • Loading branch information
cherry-yl-sh committed May 21, 2024
2 parents 7b1c01d + ac28d11 commit 37e82f1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
14 changes: 14 additions & 0 deletions common/model/db_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package model

import (
"gorm.io/gorm"
"time"
)

type BaseData struct {
// ID
ID int64 `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"softDelete:flag" json:"deleted_at"`
}
8 changes: 3 additions & 5 deletions rpc_server/middlewares/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func AuthHandler() gin.HandlerFunc {
if err != nil {
return "", err
}
err = CheckAPIKeyAvailable(apiModel)
err = checkAPIKeyAvailable(apiModel)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func AuthHandler() gin.HandlerFunc {
c.Set("ERROR_REASON", "API Key is not found")
return false
}
err = CheckAPIKeyAvailable(apiModel)
err = checkAPIKeyAvailable(apiModel)
if err != nil {
c.Set("ERROR_REASON", err.Error())
return false
Expand All @@ -98,12 +98,10 @@ func AuthHandler() gin.HandlerFunc {
return "401 Unauthorized"
},
})

jwtMiddleware = m

return m.MiddlewareFunc()
}
func CheckAPIKeyAvailable(apiModel *model.ApiKeyModel) error {
func checkAPIKeyAvailable(apiModel *model.ApiKeyModel) error {
if apiModel.Disable {
return xerrors.Errorf("API Key is disabled")
}
Expand Down
39 changes: 39 additions & 0 deletions service/dashboard_service/dashboard_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func Init() {
}

type StrategyDBModel struct {
model.BaseData
DeletedAt gorm.DeletedAt `gorm:"softDelete:flag" json:"deleted_at"`
Description string `gorm:"type:varchar(500)" json:"description"`
StrategyCode string `gorm:"type:varchar(255)" json:"strategy_code"`
Expand Down Expand Up @@ -76,6 +77,7 @@ func GetStrategyByCode(strategyCode string, entryPointVersion global_const.Entry
if err != nil {
return nil, err
}

strategy.ProjectSponsor = true

return strategy, nil
Expand Down Expand Up @@ -166,6 +168,41 @@ type StrategyExecuteRestrictionJson struct {
ChainIdWhiteList []string `json:"chain_id_whitelist"`
}

// GetSuitableStrategy get suitable strategy by entryPointVersion, chain,
//
// For Offical StrategyConfig,
func GetSuitableStrategy(entryPointVersion global_const.EntrypointVersion, chain global_const.Network, gasUseToken global_const.TokenType) (*model.Strategy, error) {
if entryPointVersion == "" {
entryPointVersion = global_const.EntrypointV06
}
gasToken := config.GetGasToken(chain)
entryPointAddress := config.GetEntrypointAddress(chain, entryPointVersion)
paymasterAddress := config.GetPaymasterAddress(chain, entryPointVersion)
payType := global_const.PayTypeVerifying
isPerc20Enable := false
if gasUseToken != "" {
payType = global_const.PayTypeERC20
if config.IsPErc20Token(gasUseToken) {
isPerc20Enable = true
}
}

strategy := &model.Strategy{
NetWorkInfo: &model.NetWorkInfo{
NetWork: chain,
GasToken: gasToken,
},
EntryPointInfo: &model.EntryPointInfo{
EntryPointVersion: entryPointVersion,
EntryPointAddress: entryPointAddress,
},
PaymasterInfo: &model.PaymasterInfo{
PayMasterAddress: paymasterAddress,
PayType: payType,
IsProjectErc20PayEnable: isPerc20Enable,
},
Erc20TokenType: gasUseToken,
}
// GetSuitableStrategy get suitable strategy by entryPointVersion, chain,
//
// For Offical StrategyConfig,
Expand Down Expand Up @@ -224,6 +261,8 @@ func IsPayMasterSupport(address string, chain global_const.Network) bool {
}

type ApiKeyDbModel struct {

model.BaseData
UserId int64 `gorm:"column:user_id;type:integer" json:"user_id"`
Disable bool `gorm:"column:disable;type:bool" json:"disable"`
ApiKey string `gorm:"column:api_key;type:varchar(255)" json:"api_key"`
Expand Down

0 comments on commit 37e82f1

Please sign in to comment.