Skip to content

Commit

Permalink
feat: edit register api
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Jan 26, 2022
1 parent 3f5838f commit be4ad75
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestAccountSearch(t *testing.T) {
func TestOrderRegister(t *testing.T) {
req := handle.ReqOrderRegister{
ReqAccountSearch: handle.ReqAccountSearch{
ChainType: common.ChainTypeEth,
ChainType: common.ChainTypeTron,
Address: "0x15a33588908cF8Edb27D1AbE3852Bf287Abd3891",
Account: "1234567885.bit",
AccountCharStr: []tables.AccountCharSet{
Expand Down
4 changes: 2 additions & 2 deletions http_server/handle/account_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (h *HttpHandle) doAccountRegister(req *ReqAccountRegister, apiResp *api_cod
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, "params invalid")
return nil
}
if ok := checkRegisterChainType(req.ChainType); !ok {
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("chain type [%s] invalid", req.ChainType.String()))
if ok := checkRegisterChainTypeAndAddress(req.ChainType, req.Address); !ok {
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("chain type and address [%s-%s] invalid", req.ChainType.String(), req.Address))
return nil
}
req.Address = core.FormatAddressToHex(req.ChainType, req.Address)
Expand Down
4 changes: 2 additions & 2 deletions http_server/handle/order_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (h *HttpHandle) doOrderChange(req *ReqOrderChange, apiResp *api_code.ApiRes
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("pay token id [%s] invalid", req.PayTokenId))
return nil
}
if ok := checkRegisterChainType(req.ChainType); !ok {
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("chain type [%s] invalid", req.ChainType.String()))
if ok := checkRegisterChainTypeAndAddress(req.ChainType, req.Address); !ok {
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("chain type and address [%s-%s] invalid", req.ChainType.String(), req.Address))
return nil
}
req.Address = core.FormatAddressToHex(req.ChainType, req.Address)
Expand Down
17 changes: 12 additions & 5 deletions http_server/handle/order_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/scorpiotzh/toolib"
"github.com/shopspring/decimal"
"net/http"
"strings"
"time"
)

Expand Down Expand Up @@ -96,8 +97,8 @@ func (h *HttpHandle) doOrderRegister(req *ReqOrderRegister, apiResp *api_code.Ap
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("pay token id [%s] invalid", req.PayTokenId))
return nil
}
if ok := checkRegisterChainType(req.ChainType); !ok {
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("chain type [%s] invalid", req.ChainType.String()))
if ok := checkRegisterChainTypeAndAddress(req.ChainType, req.Address); !ok {
apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, fmt.Sprintf("chain type and address [%s-%s] invalid", req.ChainType.String(), req.Address))
return nil
}

Expand Down Expand Up @@ -350,10 +351,16 @@ func (h *HttpHandle) getOrderAmount(account, inviterAccount string, years int, i
return
}

func checkRegisterChainType(chainType common.ChainType) bool {
func checkRegisterChainTypeAndAddress(chainType common.ChainType, address string) bool {
switch chainType {
case common.ChainTypeTron, common.ChainTypeEth:
return true
case common.ChainTypeTron:
if strings.HasPrefix(address, common.TronPreFix) || strings.HasPrefix(address, common.TronBase58PreFix) {
return true
}
case common.ChainTypeEth:
if strings.HasPrefix(address, common.HexPreFix) {
return true
}
}
return false
}

0 comments on commit be4ad75

Please sign in to comment.