-
Notifications
You must be signed in to change notification settings - Fork 64
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
114 additions
and
37 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,49 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package inputs | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/Khan/genqlient/graphql" | ||
"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` | ||
|
||
var ( | ||
first int | ||
graphqlEndpoint string | ||
) | ||
|
||
func init() { | ||
Cmd.Flags().IntVar(&first, "first", 10, | ||
"first N inputs returned, starting at 0") | ||
|
||
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) { | ||
ctx := cmd.Context() | ||
client := graphql.NewClient(graphqlEndpoint, nil) | ||
|
||
resp, err := readerclient.GetInputs(ctx, client, first) | ||
cobra.CheckErr(err) | ||
|
||
val, err := json.MarshalIndent(resp, "", " ") | ||
cobra.CheckErr(err) | ||
|
||
fmt.Print(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