github.com/algorand/go-algorand-sdk@v1.24.0/client/v2/algod/getBlock.go (about)

     1  package algod
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/algorand/go-algorand-sdk/client/v2/common"
     8  	"github.com/algorand/go-algorand-sdk/client/v2/common/models"
     9  	"github.com/algorand/go-algorand-sdk/types"
    10  )
    11  
    12  // BlockParams contains all of the query parameters for url serialization.
    13  type BlockParams struct {
    14  
    15  	// Format configures whether the response object is JSON or MessagePack encoded.
    16  	Format string `url:"format,omitempty"`
    17  }
    18  
    19  // Block get the block for the given round.
    20  type Block struct {
    21  	c *Client
    22  
    23  	round uint64
    24  
    25  	p BlockParams
    26  }
    27  
    28  // Do performs the HTTP request
    29  func (s *Block) Do(ctx context.Context, headers ...*common.Header) (result types.Block, err error) {
    30  	var response models.BlockResponse
    31  
    32  	s.p.Format = "msgpack"
    33  	err = s.c.getMsgpack(ctx, &response, fmt.Sprintf("/v2/blocks/%d", s.round), s.p, headers)
    34  	if err != nil {
    35  		return
    36  	}
    37  
    38  	result = response.Block
    39  	return
    40  }