Procházet zdrojové kódy

规范返回数据结构体

skyfffire před 2 roky
rodič
revize
c38b9740ab

+ 7 - 0
arbitrage/api/base_structs.go

@@ -13,3 +13,10 @@ type V2LpCountByChainIdRequest struct {
 	ChainId uint64 `json:"chainId"`
 	AuthObj Auth   `json:"auth"`
 }
+
+type V2LpCountByChainIdResult struct {
+	State  bool   `json:"state"`
+	Msg    string `json:"msg"`
+	Data   int    `json:"data"`
+	Origin string
+}

+ 12 - 2
arbitrage/api/blockchain_api.go

@@ -39,9 +39,19 @@ func (a *BlockchainApi) HelloWorld(request HelloWorldRequest) (string, error) {
 	return HttpPost(url, jsonData)
 }
 
-func (a *BlockchainApi) V2LpCountByChainId(request V2LpCountByChainIdRequest) (string, error) {
+func (a *BlockchainApi) V2LpCountByChainId(request V2LpCountByChainIdRequest) (V2LpCountByChainIdResult, error) {
 	url := a.baseUrl + "/v2-lp/countByChainId"
 	jsonData, _ := json.Marshal(request)
 
-	return HttpPost(url, jsonData)
+	rstStr, err := HttpPost(url, jsonData)
+	if err != nil {
+		return V2LpCountByChainIdResult{}, err
+	}
+
+	result := V2LpCountByChainIdResult{
+		Origin: rstStr,
+	}
+	json.Unmarshal([]byte(rstStr), &result)
+
+	return result, err
 }

+ 2 - 1
arbitrage/api/blockchain_api_test.go

@@ -1,6 +1,7 @@
 package api
 
 import (
+	"fmt"
 	"testing"
 )
 
@@ -29,5 +30,5 @@ func TestV2LpCountByChainId(t *testing.T) {
 		t.Fatalf("err, %v.\n", err)
 	}
 
-	t.Logf(rst)
+	t.Logf(fmt.Sprintf("data is %d, origin is %s.", rst.Data, rst.Origin))
 }