New Transaction.GetInterchain and Block.GetInterchain call the prime-node
/api/v1/{transaction,block}/{id}/interchain endpoints, returning an
InterchainTrace {blockId, validatorBlocks, interchainTransactions}. Adds local
VerificationBlock / InterchainTransaction / InterchainTrace model types.
41 lines
1.0 KiB
Go
Executable File
41 lines
1.0 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.
|
|
func (bc *BlockClient) GetInterchain(ctx context.Context, blockID string) (*models.InterchainTrace, error) {
|
|
var resp models.InterchainTrace
|
|
path := fmt.Sprintf("/api/v1/block/%s/interchain", blockID)
|
|
err := bc.client.Get(ctx, path, &resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|