diff --git a/example/order_test.go b/example/order_test.go index 25507334..32190fae 100644 --- a/example/order_test.go +++ b/example/order_test.go @@ -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{ diff --git a/http_server/handle/account_register.go b/http_server/handle/account_register.go index b4b22cec..4500d613 100644 --- a/http_server/handle/account_register.go +++ b/http_server/handle/account_register.go @@ -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) diff --git a/http_server/handle/order_change.go b/http_server/handle/order_change.go index 473ff8e8..ec8ecdac 100644 --- a/http_server/handle/order_change.go +++ b/http_server/handle/order_change.go @@ -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) diff --git a/http_server/handle/order_register.go b/http_server/handle/order_register.go index 73e03293..1a92af7f 100644 --- a/http_server/handle/order_register.go +++ b/http_server/handle/order_register.go @@ -15,6 +15,7 @@ import ( "github.com/scorpiotzh/toolib" "github.com/shopspring/decimal" "net/http" + "strings" "time" ) @@ -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 } @@ -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 }