Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions flowkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ import (

// BlockQuery defines possible queries for block.
type BlockQuery struct {
ID *flow.Identifier
Height uint64
Latest bool
ID *flow.Identifier
Height uint64
Latest bool
IsSealed bool
}

// LatestBlockQuery specifies the latest block.
var LatestBlockQuery = BlockQuery{Latest: true}
var LatestBlockQuery = BlockQuery{Latest: true, IsSealed: true}

// NewBlockQuery creates block query based on the passed query value.
//
Expand Down Expand Up @@ -226,7 +227,7 @@ func (f *Flowkit) prepareTransaction(
tx *transactions.Transaction,
account *accounts.Account,
) (*transactions.Transaction, error) {
block, err := f.gateway.GetLatestBlock(ctx)
block, err := f.gateway.GetLatestBlock(ctx, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -455,7 +456,11 @@ func (f *Flowkit) GetBlock(ctx context.Context, query BlockQuery) (*flow.Block,
var err error
var block *flow.Block
if query.Latest {
block, err = f.gateway.GetLatestBlock(ctx)
if query.IsSealed {
block, err = f.gateway.GetLatestBlock(ctx, true)
} else {
block, err = f.gateway.GetLatestBlock(ctx, false)
}
} else if query.ID != nil {
block, err = f.gateway.GetBlockByID(ctx, *query.ID)
} else {
Expand Down Expand Up @@ -929,7 +934,7 @@ func (f *Flowkit) BuildTransaction(
return nil, err
}

latestBlock, err := f.gateway.GetLatestBlock(ctx)
latestBlock, err := f.gateway.GetLatestBlock(ctx, false)
if err != nil {
return nil, fmt.Errorf("failed to get latest sealed block: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions gateway/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ func (g *EmulatorGateway) ExecuteScriptAtID(
return g.executeScriptQuery(ctx, script, arguments, scriptQuery{id: id})
}

func (g *EmulatorGateway) GetLatestBlock(ctx context.Context) (*flow.Block, error) {
block, _, err := g.adapter.GetLatestBlock(ctx, true)
func (g *EmulatorGateway) GetLatestBlock(ctx context.Context, isSealed bool) (*flow.Block, error) {
block, _, err := g.adapter.GetLatestBlock(ctx, isSealed)
if err != nil {
return nil, UnwrapStatusError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Gateway interface {
ExecuteScript(context.Context, []byte, []cadence.Value) (cadence.Value, error)
ExecuteScriptAtHeight(context.Context, []byte, []cadence.Value, uint64) (cadence.Value, error)
ExecuteScriptAtID(context.Context, []byte, []cadence.Value, flow.Identifier) (cadence.Value, error)
GetLatestBlock(context.Context) (*flow.Block, error)
GetLatestBlock(ctx context.Context, isSealed bool) (*flow.Block, error)
GetBlockByHeight(context.Context, uint64) (*flow.Block, error)
GetBlockByID(context.Context, flow.Identifier) (*flow.Block, error)
GetEvents(context.Context, string, uint64, uint64) ([]flow.BlockEvents, error)
Expand Down
4 changes: 2 additions & 2 deletions gateway/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func (g *GrpcGateway) ExecuteScriptAtID(ctx context.Context, script []byte, argu
}

// GetLatestBlock gets the latest block on Flow through the Access API.
func (g *GrpcGateway) GetLatestBlock(ctx context.Context) (*flow.Block, error) {
return g.client.GetLatestBlock(ctx, true)
func (g *GrpcGateway) GetLatestBlock(ctx context.Context, isSealed bool) (*flow.Block, error) {
return g.client.GetLatestBlock(ctx, isSealed)
}

// GetBlockByID get block by ID from the Flow Access API.
Expand Down
24 changes: 12 additions & 12 deletions gateway/mocks/Gateway.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gateway/mocks/gateway_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func DefaultMockGateway() *TestGateway {
),
GetBlockByHeight: m.On(GetBlockByHeightFunc, ctxMock, mock.Anything),
GetBlockByID: m.On(GetBlockByIDFunc, ctxMock, mock.Anything),
GetLatestBlock: m.On(GetLatestBlockFunc, ctxMock),
GetLatestBlock: m.On(GetLatestBlockFunc, ctxMock, mock.AnythingOfType("bool")),
GetSystemTransaction: m.On(
GetSystemTransactionFunc,
ctxMock,
Expand Down
8 changes: 4 additions & 4 deletions mocks/Services.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading