-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroadcast.go
51 lines (48 loc) · 1.17 KB
/
broadcast.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
46
47
48
49
50
package main
import(
"bytes"
"encoding/json"
"log"
"io/ioutil"
"lurcury/core/transaction"
"lurcury/types"
"net/http"
"time"
)
/*
func main(){
core_arg := &types.CoreStruct{}
cast(core_arg)
}
*/
func Cast(core_arg *types.CoreStruct){
for{
log.Println("check broadcast")
if(len(core_arg.PendingTransaction)>0){
req := core_arg.PendingTransaction[0]
postGo(core_arg.Config.Peers[0]+"/broadcast",
"application/x-www-form-urlencoded",req)
transaction.OrderDeletPendingTransaction(core_arg,0)
}else{
time.Sleep(2 * time.Second)
}
}
}
func postGo(urls string, heads string, bodys interface{}){
req := bodys
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(req)
resp, err := http.Post(urls,
heads,
b,
)
if err != nil {
log.Println(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err!= nil{
// handle error
}
log.Println(string(body))
}