Skip to content

Commit

Permalink
Merge branch 'bitcoin' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Apr 8, 2024
2 parents 8ebb242 + 4f564a9 commit f3423b4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 57 deletions.
35 changes: 17 additions & 18 deletions example/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,24 @@ func TestOrderRegister(t *testing.T) {
req := handle.ReqOrderRegister{
ReqAccountSearch: handle.ReqAccountSearch{
ChainType: common.ChainTypeBitcoin,
Address: "tb1qg56gqsanept494plpa3hdhhmtl2ejyrq5sfw42",
Address: "tb1qumrp5k2es0d0hy5z6044zr2305pyzc978qz0ju",
Account: "2024040801.bit",
//AccountCharStr: []common.AccountCharSet{
// {CharSetName: common.AccountCharTypeDigit, Char: "1"},
// {CharSetName: common.AccountCharTypeDigit, Char: "2"},
// {CharSetName: common.AccountCharTypeDigit, Char: "3"},
// {CharSetName: common.AccountCharTypeDigit, Char: "4"},
// {CharSetName: common.AccountCharTypeDigit, Char: "5"},
// {CharSetName: common.AccountCharTypeDigit, Char: "6"},
// {CharSetName: common.AccountCharTypeDigit, Char: "7"},
// {CharSetName: common.AccountCharTypeDigit, Char: "8"},
// {CharSetName: common.AccountCharTypeDigit, Char: "7"},
// {CharSetName: common.AccountCharTypeDigit, Char: "3"},
// //{CharSetName: common.AccountCharTypeEn, Char: "a"},
// {CharSetName: common.AccountCharTypeEn, Char: "."},
// {CharSetName: common.AccountCharTypeEn, Char: "b"},
// {CharSetName: common.AccountCharTypeEn, Char: "i"},
// {CharSetName: common.AccountCharTypeEn, Char: "t"},
//},
AccountCharStr: []common.AccountCharSet{
{CharSetName: common.AccountCharTypeDigit, Char: "2"},
{CharSetName: common.AccountCharTypeDigit, Char: "0"},
{CharSetName: common.AccountCharTypeDigit, Char: "2"},
{CharSetName: common.AccountCharTypeDigit, Char: "4"},
{CharSetName: common.AccountCharTypeDigit, Char: "0"},
{CharSetName: common.AccountCharTypeDigit, Char: "4"},
{CharSetName: common.AccountCharTypeDigit, Char: "0"},
{CharSetName: common.AccountCharTypeDigit, Char: "8"},
{CharSetName: common.AccountCharTypeDigit, Char: "0"},
{CharSetName: common.AccountCharTypeDigit, Char: "1"},
{CharSetName: common.AccountCharTypeEn, Char: "."},
{CharSetName: common.AccountCharTypeEn, Char: "b"},
{CharSetName: common.AccountCharTypeEn, Char: "i"},
{CharSetName: common.AccountCharTypeEn, Char: "t"},
},
},
ReqOrderRegisterBase: handle.ReqOrderRegisterBase{
RegisterYears: 1,
Expand Down
59 changes: 20 additions & 39 deletions http_server/handle/order_register.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handle

import (
"das_register_server/cache"
"das_register_server/config"
"das_register_server/http_server/compatible"
"das_register_server/internal"
Expand Down Expand Up @@ -180,10 +179,10 @@ func (h *HttpHandle) doOrderRegister(req *ReqOrderRegister, apiResp *api_code.Ap
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, "params is invalid")
return err
}
req.ChainType, req.Address = addressHex.ChainType, addressHex.AddressHex
//req.ChainType, req.Address = addressHex.ChainType, addressHex.AddressHex

if !checkChainType(req.ChainType) {
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("chain type [%d] invalid", req.ChainType))
if !checkChainType(addressHex.ChainType) {
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("chain type [%d] invalid", addressHex.ChainType))
return nil
}

Expand All @@ -196,23 +195,23 @@ func (h *HttpHandle) doOrderRegister(req *ReqOrderRegister, apiResp *api_code.Ap
return fmt.Errorf("sync block number")
}

if err := h.rc.RegisterLimitLockWithRedis(req.ChainType, req.Address, "register", req.Account, time.Second*10); err != nil {
if err == cache.ErrDistributedLockPreemption {
apiResp.ApiRespErr(api_code.ApiCodeOperationFrequent, "the operation is too frequent")
return nil
}
}
//if err := h.rc.RegisterLimitLockWithRedis(addressHex.ChainType, addressHex.AddressHex, "register", req.Account, time.Second*10); err != nil {
// if err == cache.ErrDistributedLockPreemption {
// apiResp.ApiRespErr(api_code.ApiCodeOperationFrequent, "the operation is too frequent")
// return nil
// }
//}

// check un pay
maxUnPayCount := int64(200)
if config.Cfg.Server.Net != common.DasNetTypeMainNet {
maxUnPayCount = 200
}
if unPayCount, err := h.dbDao.GetUnPayOrderCount(req.ChainType, req.Address); err != nil {
if unPayCount, err := h.dbDao.GetUnPayOrderCount(addressHex.ChainType, addressHex.AddressHex); err != nil {
apiResp.ApiRespErr(api_code.ApiCodeDbError, "failed to check order count")
return nil
} else if unPayCount > maxUnPayCount {
log.Info("GetUnPayOrderCount:", req.ChainType, req.Address, unPayCount)
log.Info("GetUnPayOrderCount:", addressHex.ChainType, addressHex.AddressHex, unPayCount)
apiResp.ApiRespErr(api_code.ApiCodeOperationFrequent, "the operation is too frequent")
return nil
}
Expand Down Expand Up @@ -272,9 +271,9 @@ func (h *HttpHandle) doOrderRegister(req *ReqOrderRegister, apiResp *api_code.Ap

// create order
if req.GiftCard != "" {
h.doRegisterCouponOrder(req, apiResp, &resp)
h.doRegisterCouponOrder(addressHex, req, apiResp, &resp)
} else {
h.doRegisterOrder(req, apiResp, &resp)
h.doRegisterOrder(addressHex, req, apiResp, &resp)
}

if apiResp.ErrNo != api_code.ApiCodeSuccess {
Expand Down Expand Up @@ -340,14 +339,8 @@ func (h *HttpHandle) checkOrderInfo(coinType, crossCoinType string, req *ReqOrde
return nil
}

func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.ApiResp, resp *RespOrderRegister) {
func (h *HttpHandle) doRegisterOrder(addrHex core.DasAddressHex, req *ReqOrderRegister, apiResp *api_code.ApiResp, resp *RespOrderRegister) {
// pay amount
addrHex := core.DasAddressHex{
DasAlgorithmId: req.ChainType.ToDasAlgorithmId(true),
AddressHex: req.Address,
IsMulti: false,
ChainType: req.ChainType,
}
args, err := h.dasCore.Daf().HexToArgs(addrHex, addrHex)
if err != nil {
log.Error("HexToArgs err: ", err.Error())
Expand Down Expand Up @@ -421,13 +414,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap
var paymentInfo tables.TableDasOrderPayInfo
// unipay
if config.Cfg.Server.UniPayUrl != "" {
addrNormal, err := h.dasCore.Daf().HexToNormal(core.DasAddressHex{
DasAlgorithmId: req.ChainType.ToDasAlgorithmId(true),
AddressHex: req.Address,
AddressPayload: nil,
IsMulti: false,
ChainType: req.ChainType,
})
addrNormal, err := h.dasCore.Daf().HexToNormal(addrHex)
if err != nil {
apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("HexToNormal err"))
return
Expand Down Expand Up @@ -460,7 +447,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap
PremiumAmount: premiumAmount,
MetaData: map[string]string{
"account": req.Account,
"algorithm_id": req.ChainType.ToString(),
"algorithm_id": addrHex.DasAlgorithmId.ToChainType().ToString(),
"address": addrNormal.AddressNormal,
"action": "register",
},
Expand All @@ -475,7 +462,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap
AccountId: accountId,
Account: req.Account,
Action: common.DasActionApplyRegister,
ChainType: req.ChainType,
ChainType: addrHex.ChainType,
Address: req.Address,
Timestamp: time.Now().UnixNano() / 1e6,
PayTokenId: req.PayTokenId,
Expand Down Expand Up @@ -514,7 +501,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap
AccountId: accountId,
Account: req.Account,
Action: common.DasActionApplyRegister,
ChainType: req.ChainType,
ChainType: addrHex.ChainType,
Address: req.Address,
Timestamp: time.Now().UnixNano() / 1e6,
PayTokenId: req.PayTokenId,
Expand Down Expand Up @@ -566,15 +553,9 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap
return
}

func (h *HttpHandle) doRegisterCouponOrder(req *ReqOrderRegister, apiResp *api_code.ApiResp, resp *RespOrderRegister) {
func (h *HttpHandle) doRegisterCouponOrder(addrHex core.DasAddressHex, req *ReqOrderRegister, apiResp *api_code.ApiResp, resp *RespOrderRegister) {
req.PayTokenId = tables.TokenCoupon
// pay amount
addrHex := core.DasAddressHex{
DasAlgorithmId: req.ChainType.ToDasAlgorithmId(true),
AddressHex: req.Address,
IsMulti: false,
ChainType: req.ChainType,
}
args, err := h.dasCore.Daf().HexToArgs(addrHex, addrHex)
if err != nil {
log.Error("HexToArgs err: ", err.Error())
Expand Down Expand Up @@ -650,7 +631,7 @@ func (h *HttpHandle) doRegisterCouponOrder(req *ReqOrderRegister, apiResp *api_c
AccountId: accountId,
Account: req.Account,
Action: common.DasActionApplyRegister,
ChainType: req.ChainType,
ChainType: addrHex.ChainType,
Address: req.Address,
Timestamp: time.Now().UnixNano() / 1e6,
PayTokenId: req.PayTokenId,
Expand Down

0 comments on commit f3423b4

Please sign in to comment.