|
|
@@ -2,7 +2,7 @@ package api
|
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
- "fmt"
|
|
|
+ "encoding/json"
|
|
|
"io"
|
|
|
"net/http"
|
|
|
)
|
|
|
@@ -17,9 +17,7 @@ func NewBlockchainApi() *BlockchainApi {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func HttpPost(url string, jsonDataStr string) (string, error) {
|
|
|
- jsonData := []byte(jsonDataStr)
|
|
|
-
|
|
|
+func HttpPost(url string, jsonData []byte) (string, error) {
|
|
|
resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
@@ -34,31 +32,16 @@ func HttpPost(url string, jsonDataStr string) (string, error) {
|
|
|
return string(body), nil
|
|
|
}
|
|
|
|
|
|
-func (a *BlockchainApi) HelloWorld() (string, error) {
|
|
|
+func (a *BlockchainApi) HelloWorld(request HelloWorldRequest) (string, error) {
|
|
|
url := a.baseUrl
|
|
|
- jsonDataStr := `
|
|
|
-{
|
|
|
- "auth": {
|
|
|
- "auth": "9d8b7074bf189dcad17189c8f264c0cb",
|
|
|
- "timestamp": "123123"
|
|
|
- }
|
|
|
-}
|
|
|
-`
|
|
|
- return HttpPost(url, jsonDataStr)
|
|
|
+ jsonData, _ := json.Marshal(request)
|
|
|
+
|
|
|
+ return HttpPost(url, jsonData)
|
|
|
}
|
|
|
|
|
|
-func (a *BlockchainApi) V2LpCountByChainId(chainId int64) (string, error) {
|
|
|
+func (a *BlockchainApi) V2LpCountByChainId(request V2LpCountByChainIdRequest) (string, error) {
|
|
|
url := a.baseUrl + "/v2-lp/countByChainId"
|
|
|
- jsonDataStr := `
|
|
|
-{
|
|
|
- "chainId": %d,
|
|
|
- "auth": {
|
|
|
- "auth": "9d8b7074bf189dcad17189c8f264c0cb",
|
|
|
- "timestamp": "123123"
|
|
|
- }
|
|
|
-}
|
|
|
-`
|
|
|
- jsonDataStr = fmt.Sprintf(jsonDataStr, chainId)
|
|
|
+ jsonData, _ := json.Marshal(request)
|
|
|
|
|
|
- return HttpPost(url, jsonDataStr)
|
|
|
+ return HttpPost(url, jsonData)
|
|
|
}
|