-
Notifications
You must be signed in to change notification settings - Fork 93
/
getBlock.go
41 lines (31 loc) · 943 Bytes
/
getBlock.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
package algod
import (
"context"
"fmt"
"github.com/algorand/go-algorand-sdk/v2/client/v2/common"
"github.com/algorand/go-algorand-sdk/v2/client/v2/common/models"
"github.com/algorand/go-algorand-sdk/v2/types"
)
// BlockParams contains all of the query parameters for url serialization.
type BlockParams struct {
// Format configures whether the response object is JSON or MessagePack encoded. If
// not provided, defaults to JSON.
Format string `url:"format,omitempty"`
}
// Block get the block for the given round.
type Block struct {
c *Client
round uint64
p BlockParams
}
// Do performs the HTTP request
func (s *Block) Do(ctx context.Context, headers ...*common.Header) (result types.Block, err error) {
var response models.BlockResponse
s.p.Format = "msgpack"
err = s.c.getMsgpack(ctx, &response, fmt.Sprintf("/v2/blocks/%d", s.round), s.p, headers)
if err != nil {
return
}
result = response.Block
return
}