-
Notifications
You must be signed in to change notification settings - Fork 2
/
broadcast.go
45 lines (38 loc) · 992 Bytes
/
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
package tcabcireadgoclient
import (
"bytes"
"encoding/json"
"net/http"
)
type Broadcast struct {
ID string `json:"id"` //Hash of the transaction
Version uint32 `json:"version"`
Type Type `json:"type"`
SenderAddr string `json:"sender_addr"`
RecipientAddr string `json:"recipient_addr"`
Data []byte `json:"data"`
Sign []byte `json:"sign"`
Fee uint64 `json:"fee"`
}
func (b *Broadcast) URI() string {
return "/v1/tx"
}
func (b *Broadcast) ToJSON() ([]byte, error) {
return json.Marshal(b)
}
func (b *Broadcast) ToRequest() (*http.Request, error) {
body, err := b.ToJSON()
if err != nil {
return nil, err
}
return http.NewRequest(http.MethodPost, "", bytes.NewReader(body))
}
type BroadcastResponse struct {
Data struct {
Hash string `json:"hash"`
Code uint32 `json:"code"`
Data []byte `json:"data"`
Log string `json:"log"`
Codespace string `json:"codespace"`
} `json:"data"`
}