-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package inputs | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/Khan/genqlient/graphql" | ||
"github.com/cartesi/rollups-node/internal/logger" | ||
"github.com/cartesi/rollups-node/pkg/readerclient" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "inputs", | ||
Short: "Reads first N inputs from node GraphQL", | ||
Example: examples, | ||
Run: run, | ||
} | ||
|
||
const examples = `# Read inputs from GraphQL: | ||
cartesi-rollups-cli read inputs --first 5 --graphqlEndpoint http://0.0.0.0:4000/graphql` | ||
|
||
var ( | ||
first uint32 | ||
graphqlEndpoint string | ||
) | ||
|
||
func init() { | ||
Cmd.Flags().Uint32Var(&first, "first", 0, | ||
"index used to sign the transaction") | ||
|
||
cobra.CheckErr(Cmd.MarkFlagRequired("first")) | ||
|
||
Cmd.Flags().StringVar(&graphqlEndpoint, "graphql_endpoint", "http://0.0.0.0:4000/graphql", | ||
"address used to connect to graphql") | ||
} | ||
|
||
func run(cmd *cobra.Command, args []string) { | ||
logger.Init("info", true) | ||
|
||
ctx := cmd.Context() | ||
client := graphql.NewClient(graphqlEndpoint, nil) | ||
|
||
resp, err := readerclient.GetInputs(ctx, client, int(first)) | ||
cobra.CheckErr(err) | ||
|
||
val, err := json.MarshalIndent(resp, "", " ") | ||
cobra.CheckErr(err) | ||
|
||
logger.Info.Printf(string(val)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
query getInputs($first: Int!) { | ||
inputs(first: $first) { | ||
edges { | ||
node { | ||
index | ||
status | ||
msgSender | ||
timestamp | ||
blockNumber | ||
payload | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters