-
Notifications
You must be signed in to change notification settings - Fork 113
/
message.go
59 lines (47 loc) · 1.29 KB
/
message.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
package client
import (
"net/http"
"github.com/iotaledger/goshimmer/packages/app/jsonmodels"
"github.com/iotaledger/goshimmer/packages/app/retainer"
)
const (
routeBlock = "blocks/"
routeBlockMetadata = "/metadata"
routeSendPayload = "blocks/payload"
)
// GetBlock is the handler for the /blocks/:blockID endpoint.
func (api *GoShimmerAPI) GetBlock(base58EncodedID string) (*jsonmodels.Block, error) {
res := &jsonmodels.Block{}
if err := api.do(
http.MethodGet,
routeBlock+base58EncodedID,
nil,
res,
); err != nil {
return nil, err
}
return res, nil
}
// GetBlockMetadata is the handler for the /blocks/:blockID/metadata endpoint.
func (api *GoShimmerAPI) GetBlockMetadata(base58EncodedID string) (*retainer.BlockMetadata, error) {
res := retainer.NewBlockMetadata()
if err := api.do(
http.MethodGet,
routeBlock+base58EncodedID+routeBlockMetadata,
nil,
res,
); err != nil {
return nil, err
}
res.SetID(res.M.ID)
return res, nil
}
// SendPayload send a block with the given payload.
func (api *GoShimmerAPI) SendPayload(payload []byte) (string, error) {
res := &jsonmodels.PostPayloadResponse{}
if err := api.do(http.MethodPost, routeSendPayload,
&jsonmodels.PostPayloadRequest{Payload: payload}, res); err != nil {
return "", err
}
return res.ID, nil
}