@@ -34,17 +34,16 @@ import (
34
34
"github.com/onflow/flow-go-sdk"
35
35
"github.com/onflow/flow-go-sdk/access/grpc"
36
36
"github.com/onflow/flow-go-sdk/crypto"
37
- "github.com/pkg/errors"
38
- "github.com/tyler-smith/go-bip39"
39
- "golang.org/x/exp/maps"
40
- "golang.org/x/exp/slices"
41
-
42
37
"github.com/onflow/flowkit/accounts"
43
38
"github.com/onflow/flowkit/config"
44
39
"github.com/onflow/flowkit/gateway"
45
40
"github.com/onflow/flowkit/output"
46
41
"github.com/onflow/flowkit/project"
47
42
"github.com/onflow/flowkit/transactions"
43
+ "github.com/pkg/errors"
44
+ "github.com/tyler-smith/go-bip39"
45
+ "golang.org/x/exp/maps"
46
+ "golang.org/x/exp/slices"
48
47
)
49
48
50
49
// BlockQuery defines possible queries for block.
@@ -137,16 +136,16 @@ func (f *Flowkit) Ping() error {
137
136
}
138
137
139
138
// GetAccount fetches account on the Flow network.
140
- func (f * Flowkit ) GetAccount (_ context.Context , address flow.Address ) (* flow.Account , error ) {
141
- return f .gateway .GetAccount (address )
139
+ func (f * Flowkit ) GetAccount (ctx context.Context , address flow.Address ) (* flow.Account , error ) {
140
+ return f .gateway .GetAccount (ctx , address )
142
141
}
143
142
144
143
// CreateAccount on the Flow network with the provided keys and using the signer for creation transaction.
145
144
// Returns the newly created account as well as the ID of the transaction that created the account.
146
145
//
147
146
// Keys is a slice but only one can be passed as well. If the transaction fails or there are other issues an error is returned.
148
147
func (f * Flowkit ) CreateAccount (
149
- _ context.Context ,
148
+ ctx context.Context ,
150
149
signer * accounts.Account ,
151
150
keys []accounts.PublicKey ,
152
151
) (* flow.Account , flow.Identifier , error ) {
@@ -176,7 +175,7 @@ func (f *Flowkit) CreateAccount(
176
175
return nil , flow .EmptyID , err
177
176
}
178
177
179
- tx , err = f .prepareTransaction (tx , signer )
178
+ tx , err = f .prepareTransaction (ctx , tx , signer )
180
179
if err != nil {
181
180
return nil , flow .EmptyID , err
182
181
}
@@ -185,15 +184,15 @@ func (f *Flowkit) CreateAccount(
185
184
f .logger .StartProgress ("Creating account..." )
186
185
defer f .logger .StopProgress ()
187
186
188
- sentTx , err := f .gateway .SendSignedTransaction (tx .FlowTransaction ())
187
+ sentTx , err := f .gateway .SendSignedTransaction (ctx , tx .FlowTransaction ())
189
188
if err != nil {
190
189
return nil , flow .EmptyID , errors .Wrap (err , "account creation transaction failed" )
191
190
}
192
191
193
192
f .logger .StartProgress ("Waiting for transaction to be sealed..." )
194
193
defer f .logger .StopProgress ()
195
194
196
- result , err := f .gateway .GetTransactionResult (sentTx .ID (), true )
195
+ result , err := f .gateway .GetTransactionResult (ctx , sentTx .ID (), true )
197
196
if err != nil {
198
197
return nil , flow .EmptyID , err
199
198
}
@@ -208,7 +207,7 @@ func (f *Flowkit) CreateAccount(
208
207
return nil , flow .EmptyID , fmt .Errorf ("new account address couldn't be fetched" )
209
208
}
210
209
211
- account , err := f .gateway .GetAccount (* newAccountAddress [0 ]) // we know it's the only and first event
210
+ account , err := f .gateway .GetAccount (ctx , * newAccountAddress [0 ]) // we know it's the only and first event
212
211
if err != nil {
213
212
return nil , flow .EmptyID , err
214
213
}
@@ -218,15 +217,16 @@ func (f *Flowkit) CreateAccount(
218
217
219
218
// prepareTransaction prepares transaction for sending with data from network
220
219
func (f * Flowkit ) prepareTransaction (
220
+ ctx context.Context ,
221
221
tx * transactions.Transaction ,
222
222
account * accounts.Account ,
223
223
) (* transactions.Transaction , error ) {
224
- block , err := f .gateway .GetLatestBlock ()
224
+ block , err := f .gateway .GetLatestBlock (ctx )
225
225
if err != nil {
226
226
return nil , err
227
227
}
228
228
229
- proposer , err := f .gateway .GetAccount (account .Address )
229
+ proposer , err := f .gateway .GetAccount (ctx , account .Address )
230
230
if err != nil {
231
231
return nil , err
232
232
}
@@ -311,7 +311,7 @@ func (f *Flowkit) AddContract(
311
311
defer f .logger .StopProgress ()
312
312
313
313
// check if contract exists on account
314
- flowAccount , err := f .gateway .GetAccount (account .Address )
314
+ flowAccount , err := f .gateway .GetAccount (ctx , account .Address )
315
315
if err != nil {
316
316
return flow .EmptyID , false , err
317
317
}
@@ -334,13 +334,13 @@ func (f *Flowkit) AddContract(
334
334
}
335
335
}
336
336
337
- tx , err = f .prepareTransaction (tx , account )
337
+ tx , err = f .prepareTransaction (ctx , tx , account )
338
338
if err != nil {
339
339
return flow .EmptyID , false , err
340
340
}
341
341
342
342
// send transaction with contract
343
- sentTx , err := f .gateway .SendSignedTransaction (tx .FlowTransaction ())
343
+ sentTx , err := f .gateway .SendSignedTransaction (ctx , tx .FlowTransaction ())
344
344
if err != nil {
345
345
return tx .FlowTransaction ().ID (), false , fmt .Errorf ("failed to send transaction to deploy a contract: %w" , err )
346
346
}
@@ -352,7 +352,7 @@ func (f *Flowkit) AddContract(
352
352
}
353
353
354
354
// we wait for transaction to be sealed
355
- trx , err := f .gateway .GetTransactionResult (sentTx .ID (), true )
355
+ trx , err := f .gateway .GetTransactionResult (ctx , sentTx .ID (), true )
356
356
if err != nil {
357
357
return tx .FlowTransaction ().ID (), false , err
358
358
}
@@ -391,12 +391,12 @@ func (f *Flowkit) AddContract(
391
391
//
392
392
// If removal is successful transaction ID is returned.
393
393
func (f * Flowkit ) RemoveContract (
394
- _ context.Context ,
394
+ ctx context.Context ,
395
395
account * accounts.Account ,
396
396
contractName string ,
397
397
) (flow.Identifier , error ) {
398
398
// check if contracts exists on the account
399
- flowAcc , err := f .gateway .GetAccount (account .Address )
399
+ flowAcc , err := f .gateway .GetAccount (ctx , account .Address )
400
400
if err != nil {
401
401
return flow .EmptyID , err
402
402
}
@@ -415,7 +415,7 @@ func (f *Flowkit) RemoveContract(
415
415
return flow .EmptyID , err
416
416
}
417
417
418
- tx , err = f .prepareTransaction (tx , account )
418
+ tx , err = f .prepareTransaction (ctx , tx , account )
419
419
if err != nil {
420
420
return flow .EmptyID , err
421
421
}
@@ -425,12 +425,12 @@ func (f *Flowkit) RemoveContract(
425
425
)
426
426
defer f .logger .StopProgress ()
427
427
428
- sentTx , err := f .gateway .SendSignedTransaction (tx .FlowTransaction ())
428
+ sentTx , err := f .gateway .SendSignedTransaction (ctx , tx .FlowTransaction ())
429
429
if err != nil {
430
430
return flow .EmptyID , err
431
431
}
432
432
433
- txr , err := f .gateway .GetTransactionResult (sentTx .ID (), true )
433
+ txr , err := f .gateway .GetTransactionResult (ctx , sentTx .ID (), true )
434
434
if err != nil {
435
435
return flow .EmptyID , err
436
436
}
@@ -444,15 +444,15 @@ func (f *Flowkit) RemoveContract(
444
444
}
445
445
446
446
// GetBlock by the query from Flow blockchain. Query can define a block by ID, block by height or require the latest block.
447
- func (f * Flowkit ) GetBlock (_ context.Context , query BlockQuery ) (* flow.Block , error ) {
447
+ func (f * Flowkit ) GetBlock (ctx context.Context , query BlockQuery ) (* flow.Block , error ) {
448
448
var err error
449
449
var block * flow.Block
450
450
if query .Latest {
451
- block , err = f .gateway .GetLatestBlock ()
451
+ block , err = f .gateway .GetLatestBlock (ctx )
452
452
} else if query .ID != nil {
453
- block , err = f .gateway .GetBlockByID (* query .ID )
453
+ block , err = f .gateway .GetBlockByID (ctx , * query .ID )
454
454
} else {
455
- block , err = f .gateway .GetBlockByHeight (query .Height )
455
+ block , err = f .gateway .GetBlockByHeight (ctx , query .Height )
456
456
}
457
457
458
458
if err != nil {
@@ -467,8 +467,8 @@ func (f *Flowkit) GetBlock(_ context.Context, query BlockQuery) (*flow.Block, er
467
467
}
468
468
469
469
// GetCollection by the ID from Flow network.
470
- func (f * Flowkit ) GetCollection (_ context.Context , ID flow.Identifier ) (* flow.Collection , error ) {
471
- return f .gateway .GetCollection (ID )
470
+ func (f * Flowkit ) GetCollection (ctx context.Context , ID flow.Identifier ) (* flow.Collection , error ) {
471
+ return f .gateway .GetCollection (ctx , ID )
472
472
}
473
473
474
474
// GetEvents from Flow network by their event name in the specified height interval defined by start and end inclusive.
@@ -478,7 +478,7 @@ func (f *Flowkit) GetCollection(_ context.Context, ID flow.Identifier) (*flow.Co
478
478
// Providing worker value will produce faster response as the interval will be scanned concurrently. This parameter is optional,
479
479
// if not provided only a single worker will be used.
480
480
func (f * Flowkit ) GetEvents (
481
- _ context.Context ,
481
+ ctx context.Context ,
482
482
names []string ,
483
483
startHeight uint64 ,
484
484
endHeight uint64 ,
@@ -506,7 +506,7 @@ func (f *Flowkit) GetEvents(
506
506
wg .Add (1 )
507
507
go func () {
508
508
defer wg .Done ()
509
- f .eventWorker (jobChan , results )
509
+ f .eventWorker (ctx , jobChan , results )
510
510
}()
511
511
}
512
512
@@ -536,9 +536,9 @@ func (f *Flowkit) GetEvents(
536
536
return resultEvents , nil
537
537
}
538
538
539
- func (f * Flowkit ) eventWorker (jobChan <- chan grpc.EventRangeQuery , results chan <- eventWorkerResult ) {
539
+ func (f * Flowkit ) eventWorker (ctx context. Context , jobChan <- chan grpc.EventRangeQuery , results chan <- eventWorkerResult ) {
540
540
for q := range jobChan {
541
- blockEvents , err := f .gateway .GetEvents (q .Type , q .StartHeight , q .EndHeight )
541
+ blockEvents , err := f .gateway .GetEvents (ctx , q .Type , q .StartHeight , q .EndHeight )
542
542
if err != nil {
543
543
results <- eventWorkerResult {nil , err }
544
544
}
@@ -800,7 +800,7 @@ type Script struct {
800
800
801
801
// ExecuteScript on the Flow network and return the Cadence value as a result. The script is executed at the
802
802
// block provided as part of the ScriptQuery value.
803
- func (f * Flowkit ) ExecuteScript (_ context.Context , script Script , query ScriptQuery ) (cadence.Value , error ) {
803
+ func (f * Flowkit ) ExecuteScript (ctx context.Context , script Script , query ScriptQuery ) (cadence.Value , error ) {
804
804
state , err := f .State ()
805
805
if err != nil {
806
806
return nil , err
@@ -839,24 +839,24 @@ func (f *Flowkit) ExecuteScript(_ context.Context, script Script, query ScriptQu
839
839
}
840
840
841
841
if query .Latest {
842
- return f .gateway .ExecuteScript (program .Code (), script .Args )
842
+ return f .gateway .ExecuteScript (ctx , program .Code (), script .Args )
843
843
} else if query .ID != flow .EmptyID {
844
- return f .gateway .ExecuteScriptAtID (program .Code (), script .Args , query .ID )
844
+ return f .gateway .ExecuteScriptAtID (ctx , program .Code (), script .Args , query .ID )
845
845
} else {
846
- return f .gateway .ExecuteScriptAtHeight (program .Code (), script .Args , query .Height )
846
+ return f .gateway .ExecuteScriptAtHeight (ctx , program .Code (), script .Args , query .Height )
847
847
}
848
848
}
849
849
850
850
// GetTransactionByID from the Flow network including the transaction result. Using the waitSeal we can wait for the transaction to be sealed.
851
851
func (f * Flowkit ) GetTransactionByID (
852
- _ context.Context ,
852
+ ctx context.Context ,
853
853
ID flow.Identifier ,
854
854
waitSeal bool ,
855
855
) (* flow.Transaction , * flow.TransactionResult , error ) {
856
856
f .logger .StartProgress ("Fetching Transaction..." )
857
857
defer f .logger .StopProgress ()
858
858
859
- tx , err := f .gateway .GetTransaction (ID )
859
+ tx , err := f .gateway .GetTransaction (ctx , ID )
860
860
if err != nil {
861
861
return nil , nil , err
862
862
}
@@ -866,20 +866,20 @@ func (f *Flowkit) GetTransactionByID(
866
866
defer f .logger .StopProgress ()
867
867
}
868
868
869
- result , err := f .gateway .GetTransactionResult (ID , waitSeal )
869
+ result , err := f .gateway .GetTransactionResult (ctx , ID , waitSeal )
870
870
return tx , result , err
871
871
}
872
872
873
873
func (f * Flowkit ) GetTransactionsByBlockID (
874
- _ context.Context ,
874
+ ctx context.Context ,
875
875
blockID flow.Identifier ,
876
876
) ([]* flow.Transaction , []* flow.TransactionResult , error ) {
877
- tx , err := f .gateway .GetTransactionsByBlockID (blockID )
877
+ tx , err := f .gateway .GetTransactionsByBlockID (ctx , blockID )
878
878
if err != nil {
879
879
return nil , nil , err
880
880
}
881
881
882
- txRes , err := f .gateway .GetTransactionResultsByBlockID (blockID )
882
+ txRes , err := f .gateway .GetTransactionResultsByBlockID (ctx , blockID )
883
883
if err != nil {
884
884
return nil , nil , err
885
885
}
@@ -890,7 +890,7 @@ func (f *Flowkit) GetTransactionsByBlockID(
890
890
//
891
891
// AddressesRoles type defines the address for each role (payer, proposer, authorizers) and the script defines the transaction content.
892
892
func (f * Flowkit ) BuildTransaction (
893
- _ context.Context ,
893
+ ctx context.Context ,
894
894
addresses transactions.AddressesRoles ,
895
895
proposerKeyIndex int ,
896
896
script Script ,
@@ -901,12 +901,12 @@ func (f *Flowkit) BuildTransaction(
901
901
return nil , err
902
902
}
903
903
904
- latestBlock , err := f .gateway .GetLatestBlock ()
904
+ latestBlock , err := f .gateway .GetLatestBlock (ctx )
905
905
if err != nil {
906
906
return nil , fmt .Errorf ("failed to get latest sealed block: %w" , err )
907
907
}
908
908
909
- proposerAccount , err := f .gateway .GetAccount (addresses .Proposer )
909
+ proposerAccount , err := f .gateway .GetAccount (ctx , addresses .Proposer )
910
910
if err != nil {
911
911
return nil , err
912
912
}
@@ -986,15 +986,15 @@ func (f *Flowkit) SignTransactionPayload(
986
986
//
987
987
// You can build the transaction using the BuildTransaction method and then sign it using the SignTranscation method.
988
988
func (f * Flowkit ) SendSignedTransaction (
989
- _ context.Context ,
989
+ ctx context.Context ,
990
990
tx * transactions.Transaction ,
991
991
) (* flow.Transaction , * flow.TransactionResult , error ) {
992
- sentTx , err := f .gateway .SendSignedTransaction (tx .FlowTransaction ())
992
+ sentTx , err := f .gateway .SendSignedTransaction (ctx , tx .FlowTransaction ())
993
993
if err != nil {
994
994
return nil , nil , err
995
995
}
996
996
997
- res , err := f .gateway .GetTransactionResult (sentTx .ID (), true )
997
+ res , err := f .gateway .GetTransactionResult (ctx , sentTx .ID (), true )
998
998
if err != nil {
999
999
return nil , nil , err
1000
1000
}
@@ -1037,7 +1037,7 @@ func (f *Flowkit) SendTransaction(
1037
1037
f .logger .StartProgress ("Sending transaction..." )
1038
1038
defer f .logger .StopProgress ()
1039
1039
1040
- sentTx , err := f .gateway .SendSignedTransaction (tx .FlowTransaction ())
1040
+ sentTx , err := f .gateway .SendSignedTransaction (ctx , tx .FlowTransaction ())
1041
1041
if err != nil {
1042
1042
return nil , nil , err
1043
1043
}
@@ -1046,7 +1046,7 @@ func (f *Flowkit) SendTransaction(
1046
1046
f .logger .StartProgress ("Waiting for transaction to be sealed..." )
1047
1047
defer f .logger .StopProgress ()
1048
1048
1049
- res , err := f .gateway .GetTransactionResult (sentTx .ID (), true )
1049
+ res , err := f .gateway .GetTransactionResult (ctx , sentTx .ID (), true )
1050
1050
1051
1051
return sentTx , res , err
1052
1052
}
0 commit comments