-
Notifications
You must be signed in to change notification settings - Fork 2
/
bhandlers.go
123 lines (108 loc) · 3.49 KB
/
bhandlers.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package bhandlers
import (
"bytes"
"fmt"
"net/http"
//"net/request"
//"encoding/hex"
"encoding/json"
//"log"
"strings"
//"github.com/klyed/hivesmartchain/execution"
//"github.com/klyed/hiverpc-go"
//"github.com/klyed/hiverpc-go/transactions"
types "github.com/klyed/hiverpc-go/types"
//"error"
)
//var (
// response = fmt.Printf("")
// error = nil
//)
// Generated by curl-to-Go: https://mholt.github.io/curl-to-go
// curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582" -d '{"type":"A","name":"www","data":"162.10.66.0","priority":null,"port":null,"weight":null}' "https://api.digitalocean.com/v2/domains/example.com/records"
/*
type Payload struct {
id string `json:"type"`
action string `json:"name"`
method string `json:"method"`
data interface{} `json:"data"`
}
data := Payload{
// fill struct
}
payloadBytes, err := json.Marshal(data)
if err != nil {
// handle err
}
body := bytes.NewReader(payloadBytes)
req, err := http.NewRequest("POST", "https://api.digitalocean.com/v2/domains/example.com/records", body)
if err != nil {
// handle err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer b7d03a6947b217efb6f3ec3bd3504582")
resp, err := http.DefaultClient.Do(req)
if err != nil {
// handle err
}
defer resp.Body.Close()
*/
// Generated by curl-to-Go: https://mholt.github.io/curl-to-go
// curl -X POST -d '{"method": "names", "id": "foo", "params": ["loves"]}' http://0.0.0.0:26658
func Curl(id string, sender string, action string, method string, params map[string]interface{}) (interface{}, error) {
type Payload struct {
//id string `json:"type"`
action string `params:"name"`
method string `params:"method"`
data map[string]interface{} `params:"data"`
}
//data := Payload{
// fill struct
//}
fmt.Printf("\n\n\nparams: %v\n\n\n", params)
payloadBytes, err := json.Marshal(params)
if err != nil {
// handle err
}
body := bytes.NewReader(payloadBytes)
//bodyContent := []interface{string}{id: id, action: action, method: method, params: params}
//body := strings.NewReader(bodyContent)
req, err := http.NewRequest("POST", "http://0.0.0.0:26658", body)
req.Header.Set("Content-Type", "application/json")
if err != nil {
// handle err
return fmt.Printf("ERROR: %v", err)
}
//req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := http.DefaultClient.Do(req)
if err != nil {
// handle err
return fmt.Printf("ERROR: %v", err)
}
fmt.Printf("Response: %v", resp)
defer resp.Body.Close()
return resp, err
}
func CustomJSON(block uint32, tx *types.Transaction, op *types.CustomJSONOperation) string {
//fmt.Printf("\n\nHIVE --(custom_json op)-> HSC: Op: %v", op)
sender := op.RequiredAuths[0]
json := op.JSON
jsonParsed := []interface{}{json}
action := jsonParsed[0]
method := jsonParsed[1]
data := []interface{}{jsonParsed[2]}
return fmt.Sprintf("HIVE --(custom_json)-> HSC: Sender: %v - Action: %X - Method: %X - Data: %X)", sender, action, method, data)
//execution
//return response, error
}
func Transfer(block uint32, tx *types.Transaction, op *types.TransferOperation) string {
sender := op.From
//receiver := op.To
amount := op.Amount
amountsplit := strings.Fields(amount)
value := amountsplit[0]
coin := amountsplit[1]
memo := op.Memo
return fmt.Sprintf("HIVE --(transfer)-> HSC: Sender: %X - Amount: %X %X Memo: %X)", sender, value, coin, memo)
//return response, error
}