diff --git a/common/model/db_model.go b/common/model/db_model.go new file mode 100644 index 00000000..1d2412a8 --- /dev/null +++ b/common/model/db_model.go @@ -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"` +} diff --git a/rpc_server/middlewares/auth.go b/rpc_server/middlewares/auth.go index 40ccf278..e5570230 100644 --- a/rpc_server/middlewares/auth.go +++ b/rpc_server/middlewares/auth.go @@ -46,7 +46,7 @@ func AuthHandler() gin.HandlerFunc { if err != nil { return "", err } - err = CheckAPIKeyAvailable(apiModel) + err = checkAPIKeyAvailable(apiModel) if err != nil { return "", err } @@ -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 @@ -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") } diff --git a/service/dashboard_service/dashboard_service.go b/service/dashboard_service/dashboard_service.go index 459ccde3..b7371f2b 100644 --- a/service/dashboard_service/dashboard_service.go +++ b/service/dashboard_service/dashboard_service.go @@ -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"` @@ -76,6 +77,7 @@ func GetStrategyByCode(strategyCode string, entryPointVersion global_const.Entry if err != nil { return nil, err } + strategy.ProjectSponsor = true return strategy, nil @@ -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, @@ -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"`