Skip to content

Commit 9369af2

Browse files
authored
Merge pull request #99 from onflow/mfbz/add-get-system-transaction
Add getSystemTransaction function
2 parents 38ba3ac + 426fa51 commit 9369af2

12 files changed

+212
-23
lines changed

flowkit.go

+21
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.

flowkit_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,31 @@ func TestTransactions(t *testing.T) {
15541554
gw.Mock.AssertNumberOfCalls(t, mocks.SendSignedTransactionFunc, 1)
15551555
gw.Mock.AssertNumberOfCalls(t, mocks.GetTransactionResultFunc, 1)
15561556
})
1557+
1558+
t.Run("Get System Transaction", func(t *testing.T) {
1559+
t.Parallel()
1560+
_, flowkit, gw := setup()
1561+
1562+
blockID := flow.HexToID("a310685082f0b09f2a148b2e8905f08ea458ed873596b53b200699e8e1f6536f")
1563+
1564+
gw.GetSystemTransaction.Run(func(args mock.Arguments) {
1565+
assert.Equal(t, blockID, args.Get(1).(flow.Identifier))
1566+
gw.GetSystemTransaction.Return(tests.NewTransaction(), nil)
1567+
})
1568+
1569+
gw.GetSystemTransactionResult.Run(func(args mock.Arguments) {
1570+
assert.Equal(t, blockID, args.Get(1).(flow.Identifier))
1571+
gw.GetSystemTransactionResult.Return(tests.NewTransactionResult(nil), nil)
1572+
})
1573+
1574+
_, _, err := flowkit.GetSystemTransaction(ctx, blockID)
1575+
1576+
assert.NoError(t, err)
1577+
gw.Mock.AssertCalled(t, mocks.GetSystemTransactionFunc, ctx, blockID)
1578+
gw.Mock.AssertCalled(t, mocks.GetSystemTransactionResultFunc, ctx, blockID)
1579+
gw.Mock.AssertNumberOfCalls(t, mocks.GetSystemTransactionFunc, 1)
1580+
gw.Mock.AssertNumberOfCalls(t, mocks.GetSystemTransactionResultFunc, 1)
1581+
})
15571582
}
15581583

15591584
func setupAccounts(state *State, flowkit Flowkit) {

gateway/emulator.go

+8
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

+2
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

+11-3
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

+63-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gateway/mocks/gateway_mock.go

+26-10
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
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/onflow/flow-go v0.38.0-util.0.20250130182921-c8d283b60d12
1616
github.com/onflow/flow-go-sdk v1.3.1
1717
github.com/onflow/flow/protobuf/go/flow v0.4.7
18-
github.com/onflow/go-ethereum v1.14.8
18+
github.com/onflow/go-ethereum v1.14.7
1919
github.com/pkg/errors v0.9.1
2020
github.com/rs/zerolog v1.34.0
2121
github.com/spf13/afero v1.10.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyi
607607
github.com/onflow/flow-nft/lib/go/templates v1.2.1/go.mod h1:W6hOWU0xltPqNpv9gQX8Pj8Jtf0OmRxc1XX2V0kzJaI=
608608
github.com/onflow/flow/protobuf/go/flow v0.4.7 h1:iP6DFx4wZ3ETORsyeqzHu7neFT3d1CXF6wdK+AOOjmc=
609609
github.com/onflow/flow/protobuf/go/flow v0.4.7/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
610-
github.com/onflow/go-ethereum v1.14.8 h1:PnSeWun1oiavZ+RWKsSsl6Lq2VFeaw3kFvBB/Jqpfow=
611-
github.com/onflow/go-ethereum v1.14.8/go.mod h1:FDpxDaSZWa4OaYKeHqbY0wMyGNQYkVwC3wo8WCVCqhk=
610+
github.com/onflow/go-ethereum v1.14.7 h1:gg3awYqI02e3AypRdpJKEvNTJ6kz/OhAqRti0h54Wlc=
611+
github.com/onflow/go-ethereum v1.14.7/go.mod h1:zV14QLrXyYu5ucvcwHUA0r6UaqveqbXaehAVQJlSW+I=
612612
github.com/onflow/nft-storefront/lib/go/contracts v1.0.0 h1:sxyWLqGm/p4EKT6DUlQESDG1ZNMN9GjPCm1gTq7NGfc=
613613
github.com/onflow/nft-storefront/lib/go/contracts v1.0.0/go.mod h1:kMeq9zUwCrgrSojEbTUTTJpZ4WwacVm2pA7LVFr+glk=
614614
github.com/onflow/sdks v0.6.0-preview.1 h1:mb/cUezuqWEP1gFZNAgUI4boBltudv4nlfxke1KBp9k=

mocks/Services.go

+43-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)