From fd0f4038f808bb324967360c233cde3c154b95a9 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sat, 27 Jan 2024 12:15:05 +0800 Subject: [PATCH 1/9] feat: update renew sldid --- http_server/handle/auto_account_search.go | 38 +++++++++++++----- http_server/handle/auto_order_create.go | 44 ++++++++++++++------- txtool/update_sub_account.go | 48 +++++++++++++---------- 3 files changed, 85 insertions(+), 45 deletions(-) diff --git a/http_server/handle/auto_account_search.go b/http_server/handle/auto_account_search.go index efdf3706..8cfe33ee 100644 --- a/http_server/handle/auto_account_search.go +++ b/http_server/handle/auto_account_search.go @@ -34,6 +34,7 @@ type RespAutoAccountSearch struct { ExpiredAt uint64 `json:"expired_at"` PremiumPercentage decimal.Decimal `json:"premium_percentage"` PremiumBase decimal.Decimal `json:"premium_base"` + DefaultRenewRule bool `json:"default_renew_rule"` } type AccStatus int @@ -98,7 +99,7 @@ func (h *HttpHandle) doAutoAccountSearch(req *ReqAutoAccountSearch, apiResp *api } // check switch - err = h.checkSwitch(parentAccountId, apiResp) + err = h.checkSwitch(parentAccountId, req.ActionType, apiResp) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { @@ -108,19 +109,20 @@ func (h *HttpHandle) doAutoAccountSearch(req *ReqAutoAccountSearch, apiResp *api // get max years resp.MaxYear = h.getMaxYears(parentAccount) - // get rule price - resp.Price, err = h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp) - if err != nil { - return err - } else if apiResp.ErrNo != api_code.ApiCodeSuccess { - return nil - } // check min price 0.99$ builder, err := h.DasCore.ConfigCellDataBuilderByTypeArgsList(common.ConfigCellTypeArgsSubAccount) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to get config info") return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error()) } + // get rule price + resp.Price, resp.DefaultRenewRule, err = h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder) + if err != nil { + return err + } else if apiResp.ErrNo != api_code.ApiCodeSuccess { + return nil + } + newSubAccountPrice, _ := molecule.Bytes2GoU64(builder.ConfigCellSubAccount.NewSubAccountPrice().RawData()) minPrice := decimal.NewFromInt(int64(newSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2) if req.ActionType == tables.ActionTypeRenew { @@ -304,7 +306,10 @@ func (h *HttpHandle) checkSubAccount(actionType tables.ActionType, apiResp *api_ return } -func (h *HttpHandle) checkSwitch(parentAccountId string, apiResp *api_code.ApiResp) error { +func (h *HttpHandle) checkSwitch(parentAccountId string, actionType tables.ActionType, apiResp *api_code.ApiResp) error { + if actionType == tables.ActionTypeRenew { + return nil + } subAccCell, err := h.DasCore.GetSubAccountCell(parentAccountId) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, err.Error()) @@ -339,12 +344,19 @@ func (h *HttpHandle) getMaxYears(parentAccount *tables.TableAccountInfo) uint64 return maxYear } -func (h *HttpHandle) getRulePrice(parentAcc, parentAccountId, subAccount string, apiResp *api_code.ApiResp) (price decimal.Decimal, e error) { +func (h *HttpHandle) getRulePrice(parentAcc, parentAccountId, subAccount string, apiResp *api_code.ApiResp, actionType tables.ActionType, priceBuilder *witness.ConfigCellDataBuilder) (price decimal.Decimal, defaultRenewRule bool, e error) { ruleConfig, err := h.DbDao.GetRuleConfigByAccountId(parentAccountId) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeDbError, "Failed to search rule config") e = fmt.Errorf("GetRuleConfigByAccountId err: %s", err.Error()) return + } else if ruleConfig.TxHash == "" { + if actionType == tables.ActionTypeRenew { + defaultRenewRule = true + renewSubAccountPrice, _ := molecule.Bytes2GoU64(priceBuilder.ConfigCellSubAccount.RenewSubAccountPrice().RawData()) + price = decimal.NewFromInt(int64(renewSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2) + return + } } ruleTx, err := h.DasCore.Client().GetTransaction(h.Ctx, types.HexToHash(ruleConfig.TxHash)) if err != nil { @@ -380,6 +392,12 @@ func (h *HttpHandle) getRulePrice(parentAcc, parentAccountId, subAccount string, e = fmt.Errorf("rulePrice.Hit err: %s", err.Error()) return } else if !hit { + if actionType == tables.ActionTypeRenew { + defaultRenewRule = true + renewSubAccountPrice, _ := molecule.Bytes2GoU64(priceBuilder.ConfigCellSubAccount.RenewSubAccountPrice().RawData()) + price = decimal.NewFromInt(int64(renewSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2) + return + } apiResp.ApiRespErr(api_code.ApiCodeNoTSetRules, "not set price rules") return } diff --git a/http_server/handle/auto_order_create.go b/http_server/handle/auto_order_create.go index a0ba64e8..227a5117 100644 --- a/http_server/handle/auto_order_create.go +++ b/http_server/handle/auto_order_create.go @@ -110,7 +110,7 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod } // check switch - err = h.checkSwitch(parentAccountId, apiResp) + err = h.checkSwitch(parentAccountId, req.ActionType, apiResp) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { @@ -123,8 +123,14 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod return nil } + // check min price 0.99$ + builder, err := h.DasCore.ConfigCellDataBuilderByTypeArgsList(common.ConfigCellTypeArgsSubAccount) + if err != nil { + apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to get config info") + return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error()) + } // get rule price - usdAmount, err := h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp) + usdAmount, defaultRenewRule, err := h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { @@ -207,21 +213,29 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod // usd price -> token price if actualUsdPrice.GreaterThan(decimal.Zero) { // check user payment config - userConfig, err := h.DbDao.GetUserPaymentConfig(parentAccountId) - if err != nil { - apiResp.ApiRespErr(api_code.ApiCodeDbError, "Failed to search payment config") - return fmt.Errorf("GetUserPaymentConfig err: %s", err.Error()) - } else if cfg, ok := userConfig.CfgMap[string(req.TokenId)]; !ok || !cfg.Enable { - apiResp.ApiRespErr(api_code.ApiCodeTokenIdNotSupported, "payment method not supported") - return nil + if defaultRenewRule { + find := false + for _, v := range config.Cfg.Das.AutoMint.SupportPaymentToken { + if v == string(req.TokenId) { + find = true + break + } + } + if !find { + apiResp.ApiRespErr(api_code.ApiCodeNoSupportPaymentToken, "payment method not supported") + return nil + } + } else { + userConfig, err := h.DbDao.GetUserPaymentConfig(parentAccountId) + if err != nil { + apiResp.ApiRespErr(api_code.ApiCodeDbError, "Failed to search payment config") + return fmt.Errorf("GetUserPaymentConfig err: %s", err.Error()) + } else if cfg, ok := userConfig.CfgMap[string(req.TokenId)]; !ok || !cfg.Enable { + apiResp.ApiRespErr(api_code.ApiCodeTokenIdNotSupported, "payment method not supported") + return nil + } } - // check min price 0.99$ - builder, err := h.DasCore.ConfigCellDataBuilderByTypeArgsList(common.ConfigCellTypeArgsSubAccount) - if err != nil { - apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to get config info") - return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error()) - } newSubAccountPrice, _ := molecule.Bytes2GoU64(builder.ConfigCellSubAccount.NewSubAccountPrice().RawData()) minPrice := decimal.NewFromInt(int64(newSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2) if req.ActionType == tables.ActionTypeRenew { diff --git a/txtool/update_sub_account.go b/txtool/update_sub_account.go index d414b537..4021bfdc 100644 --- a/txtool/update_sub_account.go +++ b/txtool/update_sub_account.go @@ -250,28 +250,36 @@ func (s *SubAccountTxTool) getAccountPrice(p *ParamBuildUpdateSubAccountTx) (*Ac ruleConfig, err := s.DbDao.GetRuleConfigByAccountId(v.ParentAccountId) if err != nil { return nil, err - } - ruleTx, err := s.DasCore.Client().GetTransaction(s.Ctx, types.HexToHash(ruleConfig.TxHash)) - if err != nil { - return nil, err - } + } else if ruleConfig.TxHash == "" && v.SubAction == common.SubActionRenew { + yearlyPrice = p.RenewSubAccountPrice + } else { + ruleTx, err := s.DasCore.Client().GetTransaction(s.Ctx, types.HexToHash(ruleConfig.TxHash)) + if err != nil { + return nil, err + } - parentAccountInfo, err := s.DbDao.GetAccountInfoByAccountId(v.ParentAccountId) - if err != nil { - return nil, err - } - subAccountRule := witness.NewSubAccountRuleEntity(parentAccountInfo.Account) - if err := subAccountRule.ParseFromTx(ruleTx.Transaction, common.ActionDataTypeSubAccountPriceRules); err != nil { - return nil, err - } - hit, idx, err := subAccountRule.Hit(v.Account) - if err != nil { - return nil, err - } - if !hit { - return nil, fmt.Errorf("%s not hit any price rule", v.Account) + parentAccountInfo, err := s.DbDao.GetAccountInfoByAccountId(v.ParentAccountId) + if err != nil { + return nil, err + } + subAccountRule := witness.NewSubAccountRuleEntity(parentAccountInfo.Account) + if err := subAccountRule.ParseFromTx(ruleTx.Transaction, common.ActionDataTypeSubAccountPriceRules); err != nil { + return nil, err + } + hit, idx, err := subAccountRule.Hit(v.Account) + if err != nil { + return nil, err + } + if !hit { + if v.SubAction == common.SubActionRenew { + yearlyPrice = p.RenewSubAccountPrice + } else { + return nil, fmt.Errorf("%s not hit any price rule", v.Account) + } + } else { + yearlyPrice = uint64(subAccountRule.Rules[idx].Price) + } } - yearlyPrice = uint64(subAccountRule.Rules[idx].Price) } subAccCapacity := config.PriceToCKB(yearlyPrice, quote, v.RegisterYears+v.RenewYears) From a8e48fea17bd82c79640d0b31b212a35c804791a Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sat, 27 Jan 2024 12:21:17 +0800 Subject: [PATCH 2/9] feat: update renew sldid --- txtool/update_sub_account.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/txtool/update_sub_account.go b/txtool/update_sub_account.go index 4021bfdc..5bb35b2b 100644 --- a/txtool/update_sub_account.go +++ b/txtool/update_sub_account.go @@ -281,7 +281,7 @@ func (s *SubAccountTxTool) getAccountPrice(p *ParamBuildUpdateSubAccountTx) (*Ac } } } - + log.Info("yearlyPrice:", yearlyPrice) subAccCapacity := config.PriceToCKB(yearlyPrice, quote, v.RegisterYears+v.RenewYears) switch v.MintType { From 8d35a62a47b8352d247f369cebda05dd1e8a7514 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sat, 27 Jan 2024 20:37:05 +0800 Subject: [PATCH 3/9] feat: fix renew status check --- http_server/handle/auto_account_search.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/http_server/handle/auto_account_search.go b/http_server/handle/auto_account_search.go index 8cfe33ee..e8d42434 100644 --- a/http_server/handle/auto_account_search.go +++ b/http_server/handle/auto_account_search.go @@ -300,8 +300,13 @@ func (h *HttpHandle) checkSubAccount(actionType tables.ActionType, apiResp *api_ e = fmt.Errorf("GetMintOrderInProgressByAccountIdWithAddr err: %s %s", err.Error(), subAccountId) return } - if orderInfo.Id > 0 { - accStatus = AccStatusMinting + if orderInfo.Id > 0 && orderInfo.OrderStatus == tables.OrderStatusDefault { + switch actionType { + case tables.ActionTypeMint: + accStatus = AccStatusMinting + case tables.ActionTypeRenew: + accStatus = AccStatusRenewing + } } return } From f2b221bc858fc2fc7a5333f85bea398d59abae37 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sat, 27 Jan 2024 21:12:56 +0800 Subject: [PATCH 4/9] feat: update check renew rule --- http_server/handle/auto_account_search.go | 24 +++++++++++++---------- http_server/handle/auto_order_create.go | 8 ++++++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/http_server/handle/auto_account_search.go b/http_server/handle/auto_account_search.go index e8d42434..7d9c56c0 100644 --- a/http_server/handle/auto_account_search.go +++ b/http_server/handle/auto_account_search.go @@ -99,7 +99,7 @@ func (h *HttpHandle) doAutoAccountSearch(req *ReqAutoAccountSearch, apiResp *api } // check switch - err = h.checkSwitch(parentAccountId, req.ActionType, apiResp) + resp.DefaultRenewRule, err = h.checkSwitch(parentAccountId, req.ActionType, apiResp) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { @@ -116,12 +116,16 @@ func (h *HttpHandle) doAutoAccountSearch(req *ReqAutoAccountSearch, apiResp *api return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error()) } // get rule price - resp.Price, resp.DefaultRenewRule, err = h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder) + defaultRenewRule := false + resp.Price, defaultRenewRule, err = h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { return nil } + if !resp.DefaultRenewRule { + resp.DefaultRenewRule = defaultRenewRule + } newSubAccountPrice, _ := molecule.Bytes2GoU64(builder.ConfigCellSubAccount.NewSubAccountPrice().RawData()) minPrice := decimal.NewFromInt(int64(newSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2) @@ -311,26 +315,26 @@ func (h *HttpHandle) checkSubAccount(actionType tables.ActionType, apiResp *api_ return } -func (h *HttpHandle) checkSwitch(parentAccountId string, actionType tables.ActionType, apiResp *api_code.ApiResp) error { - if actionType == tables.ActionTypeRenew { - return nil - } +func (h *HttpHandle) checkSwitch(parentAccountId string, actionType tables.ActionType, apiResp *api_code.ApiResp) (bool, error) { subAccCell, err := h.DasCore.GetSubAccountCell(parentAccountId) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, err.Error()) - return fmt.Errorf("GetSubAccountCell err: %s", err.Error()) + return false, fmt.Errorf("GetSubAccountCell err: %s", err.Error()) } subAccTx, err := h.DasCore.Client().GetTransaction(h.Ctx, subAccCell.OutPoint.TxHash) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, err.Error()) - return fmt.Errorf("GetTransaction err: %s", err.Error()) + return false, fmt.Errorf("GetTransaction err: %s", err.Error()) } subAccData := witness.ConvertSubAccountCellOutputData(subAccTx.Transaction.OutputsData[subAccCell.OutPoint.Index]) if subAccData.AutoDistribution == witness.AutoDistributionDefault { + if actionType == tables.ActionTypeRenew { + return true, nil + } apiResp.ApiRespErr(api_code.ApiCodeAutoDistributionClosed, "Automatic allocation is not turned on") - return nil + return false, nil } - return nil + return false, nil } func (h *HttpHandle) getMaxYears(parentAccount *tables.TableAccountInfo) uint64 { diff --git a/http_server/handle/auto_order_create.go b/http_server/handle/auto_order_create.go index 227a5117..f0ff2478 100644 --- a/http_server/handle/auto_order_create.go +++ b/http_server/handle/auto_order_create.go @@ -110,7 +110,7 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod } // check switch - err = h.checkSwitch(parentAccountId, req.ActionType, apiResp) + defaultRenewRule, err := h.checkSwitch(parentAccountId, req.ActionType, apiResp) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { @@ -130,13 +130,17 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error()) } // get rule price - usdAmount, defaultRenewRule, err := h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder) + usdAmount, defaultRenewRule2, err := h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { return nil } + if !defaultRenewRule { + defaultRenewRule = defaultRenewRule2 + } + log.Info("usdAmount:", usdAmount.String(), req.Years) // total usd price usdAmount = usdAmount.Mul(decimal.NewFromInt(int64(req.Years))) From d1b8e41aa75957245141decf10d7c0dbbfa611a8 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sat, 27 Jan 2024 22:05:00 +0800 Subject: [PATCH 5/9] feat: fix renew tx price --- http_server/handle/auto_account_search.go | 2 +- txtool/update_sub_account.go | 53 +++++++++++++---------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/http_server/handle/auto_account_search.go b/http_server/handle/auto_account_search.go index 7d9c56c0..fbb79f88 100644 --- a/http_server/handle/auto_account_search.go +++ b/http_server/handle/auto_account_search.go @@ -281,7 +281,7 @@ func (h *HttpHandle) checkSubAccount(actionType tables.ActionType, apiResp *api_ return } if orderInfo.Id > 0 { - if smtRecord.OrderID == orderInfo.OrderId { + if smtRecord.OrderID == orderInfo.OrderId && orderInfo.OrderStatus != tables.OrderStatusDefault { accStatus = AccStatusDefault return } diff --git a/txtool/update_sub_account.go b/txtool/update_sub_account.go index 5bb35b2b..2e233bbe 100644 --- a/txtool/update_sub_account.go +++ b/txtool/update_sub_account.go @@ -247,37 +247,42 @@ func (s *SubAccountTxTool) getAccountPrice(p *ParamBuildUpdateSubAccountTx) (*Ac yearlyPrice = p.RenewSubAccountPrice } case tables.MintTypeAutoMint: - ruleConfig, err := s.DbDao.GetRuleConfigByAccountId(v.ParentAccountId) - if err != nil { - return nil, err - } else if ruleConfig.TxHash == "" && v.SubAction == common.SubActionRenew { + subDataDetail := witness.ConvertSubAccountCellOutputData(p.SubAccountOutputsData) + if subDataDetail.AutoDistribution == witness.AutoDistributionDefault && v.SubAction == common.SubActionRenew { yearlyPrice = p.RenewSubAccountPrice } else { - ruleTx, err := s.DasCore.Client().GetTransaction(s.Ctx, types.HexToHash(ruleConfig.TxHash)) + ruleConfig, err := s.DbDao.GetRuleConfigByAccountId(v.ParentAccountId) if err != nil { return nil, err - } + } else if ruleConfig.TxHash == "" && v.SubAction == common.SubActionRenew { + yearlyPrice = p.RenewSubAccountPrice + } else { + ruleTx, err := s.DasCore.Client().GetTransaction(s.Ctx, types.HexToHash(ruleConfig.TxHash)) + if err != nil { + return nil, err + } - parentAccountInfo, err := s.DbDao.GetAccountInfoByAccountId(v.ParentAccountId) - if err != nil { - return nil, err - } - subAccountRule := witness.NewSubAccountRuleEntity(parentAccountInfo.Account) - if err := subAccountRule.ParseFromTx(ruleTx.Transaction, common.ActionDataTypeSubAccountPriceRules); err != nil { - return nil, err - } - hit, idx, err := subAccountRule.Hit(v.Account) - if err != nil { - return nil, err - } - if !hit { - if v.SubAction == common.SubActionRenew { - yearlyPrice = p.RenewSubAccountPrice + parentAccountInfo, err := s.DbDao.GetAccountInfoByAccountId(v.ParentAccountId) + if err != nil { + return nil, err + } + subAccountRule := witness.NewSubAccountRuleEntity(parentAccountInfo.Account) + if err := subAccountRule.ParseFromTx(ruleTx.Transaction, common.ActionDataTypeSubAccountPriceRules); err != nil { + return nil, err + } + hit, idx, err := subAccountRule.Hit(v.Account) + if err != nil { + return nil, err + } + if !hit { + if v.SubAction == common.SubActionRenew { + yearlyPrice = p.RenewSubAccountPrice + } else { + return nil, fmt.Errorf("%s not hit any price rule", v.Account) + } } else { - return nil, fmt.Errorf("%s not hit any price rule", v.Account) + yearlyPrice = uint64(subAccountRule.Rules[idx].Price) } - } else { - yearlyPrice = uint64(subAccountRule.Rules[idx].Price) } } } From fa474cb83d902e0ef965fb76365df0d44df12b90 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sat, 27 Jan 2024 22:16:52 +0800 Subject: [PATCH 6/9] feat: fix order status --- http_server/handle/auto_order_info.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/http_server/handle/auto_order_info.go b/http_server/handle/auto_order_info.go index bdd445a0..b9b51848 100644 --- a/http_server/handle/auto_order_info.go +++ b/http_server/handle/auto_order_info.go @@ -118,6 +118,9 @@ func (h *HttpHandle) doAutoOrderInfo(req *ReqAutoOrderInfo, apiResp *api_code.Ap resp.OrderStatus = OrderStatusMintFail case tables.RecordTypeChain: resp.OrderStatus = OrderStatusMintOK + if order.OrderStatus == tables.OrderStatusDefault { + resp.OrderStatus = OrderStatusMinting + } } } From d3be20aebb3fe3689d1e55acbc8877b32f5e752b Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sat, 27 Jan 2024 22:26:33 +0800 Subject: [PATCH 7/9] feat: update check order time --- unipay/order_check.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unipay/order_check.go b/unipay/order_check.go index 8b695df6..d933937e 100644 --- a/unipay/order_check.go +++ b/unipay/order_check.go @@ -9,7 +9,7 @@ import ( ) func (t *ToolUniPay) RunOrderCheck() { - tickerOrder := time.NewTicker(time.Minute * 5) + tickerOrder := time.NewTicker(time.Minute) t.Wg.Add(1) go func() { defer http_api.RecoverPanic() From 9944d3eb9a03e234c20436d0ef7965cec7f0f5d8 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sat, 27 Jan 2024 22:39:07 +0800 Subject: [PATCH 8/9] feat: fix renew price --- http_server/handle/auto_account_search.go | 28 ++++++++++++----------- http_server/handle/auto_order_create.go | 8 ++----- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/http_server/handle/auto_account_search.go b/http_server/handle/auto_account_search.go index fbb79f88..6a6472e9 100644 --- a/http_server/handle/auto_account_search.go +++ b/http_server/handle/auto_account_search.go @@ -99,7 +99,7 @@ func (h *HttpHandle) doAutoAccountSearch(req *ReqAutoAccountSearch, apiResp *api } // check switch - resp.DefaultRenewRule, err = h.checkSwitch(parentAccountId, req.ActionType, apiResp) + autoDistribution, err := h.checkSwitch(parentAccountId, req.ActionType, apiResp) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { @@ -116,16 +116,12 @@ func (h *HttpHandle) doAutoAccountSearch(req *ReqAutoAccountSearch, apiResp *api return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error()) } // get rule price - defaultRenewRule := false - resp.Price, defaultRenewRule, err = h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder) + resp.Price, resp.DefaultRenewRule, err = h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder, autoDistribution) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { return nil } - if !resp.DefaultRenewRule { - resp.DefaultRenewRule = defaultRenewRule - } newSubAccountPrice, _ := molecule.Bytes2GoU64(builder.ConfigCellSubAccount.NewSubAccountPrice().RawData()) minPrice := decimal.NewFromInt(int64(newSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2) @@ -315,26 +311,26 @@ func (h *HttpHandle) checkSubAccount(actionType tables.ActionType, apiResp *api_ return } -func (h *HttpHandle) checkSwitch(parentAccountId string, actionType tables.ActionType, apiResp *api_code.ApiResp) (bool, error) { +func (h *HttpHandle) checkSwitch(parentAccountId string, actionType tables.ActionType, apiResp *api_code.ApiResp) (witness.AutoDistribution, error) { subAccCell, err := h.DasCore.GetSubAccountCell(parentAccountId) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, err.Error()) - return false, fmt.Errorf("GetSubAccountCell err: %s", err.Error()) + return witness.AutoDistributionDefault, fmt.Errorf("GetSubAccountCell err: %s", err.Error()) } subAccTx, err := h.DasCore.Client().GetTransaction(h.Ctx, subAccCell.OutPoint.TxHash) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, err.Error()) - return false, fmt.Errorf("GetTransaction err: %s", err.Error()) + return witness.AutoDistributionDefault, fmt.Errorf("GetTransaction err: %s", err.Error()) } subAccData := witness.ConvertSubAccountCellOutputData(subAccTx.Transaction.OutputsData[subAccCell.OutPoint.Index]) if subAccData.AutoDistribution == witness.AutoDistributionDefault { if actionType == tables.ActionTypeRenew { - return true, nil + return witness.AutoDistributionDefault, nil } apiResp.ApiRespErr(api_code.ApiCodeAutoDistributionClosed, "Automatic allocation is not turned on") - return false, nil + return witness.AutoDistributionDefault, nil } - return false, nil + return witness.AutoDistributionEnable, nil } func (h *HttpHandle) getMaxYears(parentAccount *tables.TableAccountInfo) uint64 { @@ -353,7 +349,13 @@ func (h *HttpHandle) getMaxYears(parentAccount *tables.TableAccountInfo) uint64 return maxYear } -func (h *HttpHandle) getRulePrice(parentAcc, parentAccountId, subAccount string, apiResp *api_code.ApiResp, actionType tables.ActionType, priceBuilder *witness.ConfigCellDataBuilder) (price decimal.Decimal, defaultRenewRule bool, e error) { +func (h *HttpHandle) getRulePrice(parentAcc, parentAccountId, subAccount string, apiResp *api_code.ApiResp, actionType tables.ActionType, priceBuilder *witness.ConfigCellDataBuilder, autoDistribution witness.AutoDistribution) (price decimal.Decimal, defaultRenewRule bool, e error) { + if autoDistribution == witness.AutoDistributionDefault && actionType == tables.ActionTypeRenew { + defaultRenewRule = true + renewSubAccountPrice, _ := molecule.Bytes2GoU64(priceBuilder.ConfigCellSubAccount.RenewSubAccountPrice().RawData()) + price = decimal.NewFromInt(int64(renewSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2) + return + } ruleConfig, err := h.DbDao.GetRuleConfigByAccountId(parentAccountId) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeDbError, "Failed to search rule config") diff --git a/http_server/handle/auto_order_create.go b/http_server/handle/auto_order_create.go index f0ff2478..507df9d5 100644 --- a/http_server/handle/auto_order_create.go +++ b/http_server/handle/auto_order_create.go @@ -110,7 +110,7 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod } // check switch - defaultRenewRule, err := h.checkSwitch(parentAccountId, req.ActionType, apiResp) + autoDistribution, err := h.checkSwitch(parentAccountId, req.ActionType, apiResp) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { @@ -130,17 +130,13 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error()) } // get rule price - usdAmount, defaultRenewRule2, err := h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder) + usdAmount, defaultRenewRule, err := h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp, req.ActionType, builder, autoDistribution) if err != nil { return err } else if apiResp.ErrNo != api_code.ApiCodeSuccess { return nil } - if !defaultRenewRule { - defaultRenewRule = defaultRenewRule2 - } - log.Info("usdAmount:", usdAmount.String(), req.Years) // total usd price usdAmount = usdAmount.Mul(decimal.NewFromInt(int64(req.Years))) From 90849e661989465950409ae12238d20569dac6c8 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Sun, 28 Jan 2024 21:17:01 +0800 Subject: [PATCH 9/9] feat: fix renew for check flag --- http_server/handle/auto_account_search.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/http_server/handle/auto_account_search.go b/http_server/handle/auto_account_search.go index 6a6472e9..5fdbbb0c 100644 --- a/http_server/handle/auto_account_search.go +++ b/http_server/handle/auto_account_search.go @@ -323,8 +323,9 @@ func (h *HttpHandle) checkSwitch(parentAccountId string, actionType tables.Actio return witness.AutoDistributionDefault, fmt.Errorf("GetTransaction err: %s", err.Error()) } subAccData := witness.ConvertSubAccountCellOutputData(subAccTx.Transaction.OutputsData[subAccCell.OutPoint.Index]) + log.Info("checkSwitch:", subAccData.AutoDistribution, subAccData.Flag) if subAccData.AutoDistribution == witness.AutoDistributionDefault { - if actionType == tables.ActionTypeRenew { + if subAccData.Flag == witness.FlagTypeCustomRule && actionType == tables.ActionTypeRenew { return witness.AutoDistributionDefault, nil } apiResp.ApiRespErr(api_code.ApiCodeAutoDistributionClosed, "Automatic allocation is not turned on")