-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsummary.go
54 lines (43 loc) · 1.01 KB
/
summary.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
package tcabcireadgoclient
import (
"bytes"
"encoding/json"
"net/http"
)
type Summary struct {
RecipientAddresses []string `json:"recipient_addrs,omitempty"`
SenderAddresses []string `json:"sender_addrs,omitempty"`
Type Type `json:"typ,omitempty"`
}
func (s *Summary) URI() string {
return "/v1/tx_summary"
}
func (s *Summary) IsValid() bool {
if len(s.RecipientAddresses) > 251 {
return false
}
if len(s.SenderAddresses) > 251 {
return false
}
if s.Type != "" && !s.Type.IsValid() {
return false
}
return true
}
func (s *Summary) ToJSON() ([]byte, error) {
return json.Marshal(s)
}
func (s *Summary) ToRequest() (*http.Request, error) {
b, err := s.ToJSON()
if err != nil {
return nil, err
}
return http.NewRequest(http.MethodPost, "", bytes.NewReader(b))
}
type SummaryResponse struct {
Data struct {
LastBlockHeight uint64 `json:"last_block_height"`
LastTransaction *Transaction `json:"last_transaction"`
} `json:"data"`
TotalCount uint64 `json:"total_count"`
}