Skip to content

Commit ad004bd

Browse files
committed
Added getSystemTransaction implementation (#1871)
1 parent 38ba3ac commit ad004bd

File tree

6 files changed

+131
-16
lines changed

6 files changed

+131
-16
lines changed

flowkit.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,27 @@ func (f *Flowkit) GetTransactionsByBlockID(
891891
return tx, txRes, nil
892892
}
893893

894+
func (f *Flowkit) GetSystemTransaction(
895+
ctx context.Context,
896+
blockID flow.Identifier,
897+
) (*flow.Transaction, *flow.TransactionResult, error) {
898+
f.logger.StartProgress("Fetching System Transaction...")
899+
defer f.logger.StopProgress()
900+
901+
tx, err := f.gateway.GetSystemTransaction(ctx, blockID)
902+
if err != nil {
903+
return nil, nil, err
904+
}
905+
906+
// Fetch the result so that it can be correctly returned
907+
result, err := f.gateway.GetSystemTransactionResult(ctx, blockID)
908+
if err != nil {
909+
return tx, nil, err
910+
}
911+
912+
return tx, result, nil
913+
}
914+
894915
// BuildTransaction builds a new transaction type for later signing and submitting to the network.
895916
//
896917
// AddressesRoles type defines the address for each role (payer, proposer, authorizers) and the script defines the transaction content.

gateway/emulator.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ func (g *EmulatorGateway) GetTransactionsByBlockID(ctx context.Context, id flow.
151151
return txr, nil
152152
}
153153

154+
func (g *EmulatorGateway) GetSystemTransaction(ctx context.Context, blockID flow.Identifier) (*flow.Transaction, error) {
155+
return nil, errors.New("GetSystemTransaction is not implemented")
156+
}
157+
158+
func (g *EmulatorGateway) GetSystemTransactionResult(ctx context.Context, blockID flow.Identifier) (*flow.TransactionResult, error) {
159+
return nil, errors.New("GetSystemTransactionResult is not implemented")
160+
}
161+
154162
func (g *EmulatorGateway) Ping() error {
155163
ctx := context.Background()
156164
err := g.adapter.Ping(ctx)

gateway/gateway.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type Gateway interface {
3535
GetTransactionResultsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*flow.TransactionResult, error)
3636
GetTransactionResult(context.Context, flow.Identifier, bool) (*flow.TransactionResult, error)
3737
GetTransactionsByBlockID(context.Context, flow.Identifier) ([]*flow.Transaction, error)
38+
GetSystemTransaction(ctx context.Context, blockID flow.Identifier) (*flow.Transaction, error)
39+
GetSystemTransactionResult(ctx context.Context, blockID flow.Identifier) (*flow.TransactionResult, error)
3840
ExecuteScript(context.Context, []byte, []cadence.Value) (cadence.Value, error)
3941
ExecuteScriptAtHeight(context.Context, []byte, []cadence.Value, uint64) (cadence.Value, error)
4042
ExecuteScriptAtID(context.Context, []byte, []cadence.Value, flow.Identifier) (cadence.Value, error)

gateway/grpc.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ type GrpcGateway struct {
4747
func NewGrpcGateway(network config.Network, opts ...grpcAccess.ClientOption) (*GrpcGateway, error) {
4848
options := append(
4949
[]grpcAccess.ClientOption{
50-
grpcAccess.WithGRPCDialOptions(
51-
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxGRPCMessageSize)),
52-
),
50+
grpcAccess.WithGRPCDialOptions(
51+
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxGRPCMessageSize)),
52+
),
5353
},
5454
opts...,
5555
)
@@ -147,6 +147,14 @@ func (g *GrpcGateway) GetTransactionResult(ctx context.Context, ID flow.Identifi
147147
return result, nil
148148
}
149149

150+
func (g *GrpcGateway) GetSystemTransaction(ctx context.Context, blockID flow.Identifier) (*flow.Transaction, error) {
151+
return g.client.GetSystemTransaction(ctx, blockID)
152+
}
153+
154+
func (g *GrpcGateway) GetSystemTransactionResult(ctx context.Context, blockID flow.Identifier) (*flow.TransactionResult, error) {
155+
return g.client.GetSystemTransactionResult(ctx, blockID)
156+
}
157+
150158
// ExecuteScript executes a script on Flow through the Access API.
151159
func (g *GrpcGateway) ExecuteScript(ctx context.Context, script []byte, arguments []cadence.Value) (cadence.Value, error) {
152160
return g.client.ExecuteScriptAtLatestBlock(ctx, script, arguments)

gateway/mocks/Gateway.go

Lines changed: 63 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gateway/mocks/gateway_mock.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ import (
2929
)
3030

3131
const (
32-
GetAccountFunc = "GetAccount"
33-
SendSignedTransactionFunc = "SendSignedTransaction"
34-
GetCollectionFunc = "GetCollection"
35-
GetTransactionResultFunc = "GetTransactionResult"
36-
GetEventsFunc = "GetEvents"
37-
GetLatestBlockFunc = "GetLatestBlock"
38-
GetBlockByHeightFunc = "GetBlockByHeight"
39-
GetBlockByIDFunc = "GetBlockByID"
40-
ExecuteScriptFunc = "ExecuteScript"
41-
GetTransactionFunc = "GetTransaction"
32+
GetAccountFunc = "GetAccount"
33+
SendSignedTransactionFunc = "SendSignedTransaction"
34+
GetCollectionFunc = "GetCollection"
35+
GetTransactionResultFunc = "GetTransactionResult"
36+
GetEventsFunc = "GetEvents"
37+
GetLatestBlockFunc = "GetLatestBlock"
38+
GetBlockByHeightFunc = "GetBlockByHeight"
39+
GetBlockByIDFunc = "GetBlockByID"
40+
ExecuteScriptFunc = "ExecuteScript"
41+
GetTransactionFunc = "GetTransaction"
42+
GetSystemTransactionFunc = "GetSystemTransaction"
43+
GetSystemTransactionResultFunc = "GetSystemTransactionResult"
4244
)
4345

4446
type TestGateway struct {
@@ -55,6 +57,8 @@ type TestGateway struct {
5557
GetTransaction *mock.Call
5658
GetTransactionResultsByBlockID *mock.Call
5759
GetTransactionsByBlockID *mock.Call
60+
GetSystemTransaction *mock.Call
61+
GetSystemTransactionResult *mock.Call
5862
GetLatestProtocolStateSnapshot *mock.Call
5963
Ping *mock.Call
6064
SecureConnection *mock.Call
@@ -107,6 +111,16 @@ func DefaultMockGateway() *TestGateway {
107111
GetBlockByHeight: m.On(GetBlockByHeightFunc, ctxMock, mock.Anything),
108112
GetBlockByID: m.On(GetBlockByIDFunc, ctxMock, mock.Anything),
109113
GetLatestBlock: m.On(GetLatestBlockFunc, ctxMock),
114+
GetSystemTransaction: m.On(
115+
GetSystemTransactionFunc,
116+
ctxMock,
117+
mock.AnythingOfType("flow.Identifier"),
118+
),
119+
GetSystemTransactionResult: m.On(
120+
GetSystemTransactionResultFunc,
121+
ctxMock,
122+
mock.AnythingOfType("flow.Identifier"),
123+
),
110124
}
111125

112126
// default return values
@@ -130,6 +144,8 @@ func DefaultMockGateway() *TestGateway {
130144
t.GetLatestBlock.Return(tests.NewBlock(), nil)
131145
t.GetBlockByHeight.Return(tests.NewBlock(), nil)
132146
t.GetBlockByID.Return(tests.NewBlock(), nil)
147+
t.GetSystemTransaction.Return(tests.NewTransaction(), nil)
148+
t.GetSystemTransactionResult.Return(tests.NewTransactionResult(nil), nil)
133149

134150
return t
135151
}

0 commit comments

Comments
 (0)