-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
executable file
·45 lines (41 loc) · 980 Bytes
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package broadcast
import (
"io/ioutil"
"net/http"
"net/url"
"strings"
)
//异步
func httpBroadcastAsyncTx(tx, reqUrl string) {
cli := &http.Client{}
data := url.Values{}
data.Set("txByte", tx)
data.Set("proxy", "lb")
req, err := http.NewRequest("POST", reqUrl, strings.NewReader(data.Encode()))
if err != nil {
panic(err)
}
req.Body = ioutil.NopCloser(strings.NewReader(data.Encode()))
// set request content types
req.Header.Set("Content-Type", "x-www-form-urlencoded")
// request
_, _ = cli.Do(req)
}
func SendTransaction(tx string, async bool, isIBC bool, requestURL string) ([]byte, retData, error) {
//
if async == false {
if isIBC == false {
res, err := httpBroadcastTx(tx, requestURL)
if err != nil {
return nil, retData{}, err
}
return res, retData{}, nil
}else {
retData := httpIBCBroadcastTx(tx, requestURL)
return nil, retData, nil
}
}else {
httpBroadcastAsyncTx(tx, requestURL)
return nil, retData{}, nil
}
}