Files
prime-sdk-go/block/block.go
Andrew Miller 17057ad1f2 GetInterchain: perChain + chains options (default first anchor per chain)
Transaction.GetInterchain and Block.GetInterchain take variadic options
(client.WithPerChain / client.WithChains, re-exported as sdk.WithPerChain /
sdk.WithChains) that map to the new prime-node ?perChain=&chains= query params.
Backward compatible: existing no-option calls get the default (one anchor per
chain). client.InterchainQuery builds the suffix; unit-tested.
2026-06-05 10:54:45 -04:00

46 lines
1.3 KiB
Go
Executable File

package block
import (
"context"
"fmt"
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
)
type BlockClient struct {
client *client.Client
}
func NewBlockClient(c *client.Client) *BlockClient {
return &BlockClient{client: c}
}
func (bc *BlockClient) Get(ctx context.Context, blockID string) (*models.Block, error) {
var resp models.Block
path := fmt.Sprintf("/api/v1/block/%s", blockID)
err := bc.client.Get(ctx, path, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
// GetInterchain traces a block to the validator (verification) blocks that
// validated it and the public-chain interchain anchors those validator blocks
// were bundled into.
//
// By default it returns the first anchor per public chain (anchor proofs are
// chained, so the earliest per chain is the meaningful one). Use
// client.WithPerChain / client.WithChains to return more anchors per chain or
// restrict to specific chains.
func (bc *BlockClient) GetInterchain(ctx context.Context, blockID string, opts ...client.InterchainOption) (*models.InterchainTrace, error) {
var resp models.InterchainTrace
path := fmt.Sprintf("/api/v1/block/%s/interchain%s", blockID, client.InterchainQuery(opts...))
err := bc.client.Get(ctx, path, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}