|
|
@@ -0,0 +1,64 @@
|
|
|
+package api
|
|
|
+
|
|
|
+import (
|
|
|
+ "bytes"
|
|
|
+ "fmt"
|
|
|
+ "io"
|
|
|
+ "net/http"
|
|
|
+)
|
|
|
+
|
|
|
+type BlockchainApi struct {
|
|
|
+ baseUrl string
|
|
|
+}
|
|
|
+
|
|
|
+func NewBlockchainApi() *BlockchainApi {
|
|
|
+ return &BlockchainApi{
|
|
|
+ baseUrl: "http://web.410eth.com:8888",
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func HttpPost(url string, jsonDataStr string) (string, error) {
|
|
|
+ jsonData := []byte(jsonDataStr)
|
|
|
+
|
|
|
+ resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ body, err := io.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+
|
|
|
+ return string(body), nil
|
|
|
+}
|
|
|
+
|
|
|
+func (a *BlockchainApi) HelloWorld() (string, error) {
|
|
|
+ url := a.baseUrl
|
|
|
+ jsonDataStr := `
|
|
|
+{
|
|
|
+ "auth": {
|
|
|
+ "auth": "9d8b7074bf189dcad17189c8f264c0cb",
|
|
|
+ "timestamp": "123123"
|
|
|
+ }
|
|
|
+}
|
|
|
+`
|
|
|
+ return HttpPost(url, jsonDataStr)
|
|
|
+}
|
|
|
+
|
|
|
+func (a *BlockchainApi) V2LpCountByChainId(chainId int64) (string, error) {
|
|
|
+ url := a.baseUrl + "/v2-lp/countByChainId"
|
|
|
+ jsonDataStr := `
|
|
|
+{
|
|
|
+ "chainId": %d,
|
|
|
+ "auth": {
|
|
|
+ "auth": "9d8b7074bf189dcad17189c8f264c0cb",
|
|
|
+ "timestamp": "123123"
|
|
|
+ }
|
|
|
+}
|
|
|
+`
|
|
|
+ jsonDataStr = fmt.Sprintf(jsonDataStr, chainId)
|
|
|
+
|
|
|
+ return HttpPost(url, jsonDataStr)
|
|
|
+}
|