|
| 1 | +/* |
| 2 | + * Flow CLI |
| 3 | + * |
| 4 | + * Copyright Flow Foundation |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package transactions |
| 20 | + |
| 21 | +import ( |
| 22 | + "context" |
| 23 | + |
| 24 | + "github.com/spf13/cobra" |
| 25 | + |
| 26 | + "github.com/onflow/flowkit/v2" |
| 27 | + "github.com/onflow/flowkit/v2/output" |
| 28 | + |
| 29 | + "github.com/onflow/flow-cli/internal/command" |
| 30 | +) |
| 31 | + |
| 32 | +type flagsGetSystem struct { |
| 33 | + Include []string `default:"" flag:"include" info:"Fields to include in the output. Valid values: signatures, code, payload, fee-events."` |
| 34 | + Exclude []string `default:"" flag:"exclude" info:"Fields to exclude from the output. Valid values: events."` |
| 35 | +} |
| 36 | + |
| 37 | +var getSystemFlags = flagsGetSystem{} |
| 38 | + |
| 39 | +var getSystemCommand = &command.Command{ |
| 40 | + Cmd: &cobra.Command{ |
| 41 | + Use: "get-system <block_id|latest|block_height>", |
| 42 | + Short: "Get the system transaction by block info", |
| 43 | + Example: "flow transactions get-system a1b2c3...", |
| 44 | + Args: cobra.ExactArgs(1), |
| 45 | + }, |
| 46 | + Flags: &getSystemFlags, |
| 47 | + Run: getSystemTransaction, |
| 48 | +} |
| 49 | + |
| 50 | +func getSystemTransaction( |
| 51 | + args []string, |
| 52 | + _ command.GlobalFlags, |
| 53 | + logger output.Logger, |
| 54 | + _ flowkit.ReaderWriter, |
| 55 | + flow flowkit.Services, |
| 56 | +) (command.Result, error) { |
| 57 | + query, err := flowkit.NewBlockQuery(args[0]) |
| 58 | + if err != nil { |
| 59 | + return nil, err |
| 60 | + } |
| 61 | + |
| 62 | + logger.StartProgress("Fetching Block...") |
| 63 | + defer logger.StopProgress() |
| 64 | + block, err := flow.GetBlock(context.Background(), query) |
| 65 | + if err != nil { |
| 66 | + return nil, err |
| 67 | + } |
| 68 | + |
| 69 | + tx, result, err := flow.GetSystemTransaction(context.Background(), block.ID) |
| 70 | + if err != nil { |
| 71 | + return nil, err |
| 72 | + } |
| 73 | + |
| 74 | + return &transactionResult{ |
| 75 | + result: result, |
| 76 | + tx: tx, |
| 77 | + include: getSystemFlags.Include, |
| 78 | + exclude: getSystemFlags.Exclude, |
| 79 | + }, nil |
| 80 | +} |
0 commit comments