-
Notifications
You must be signed in to change notification settings - Fork 67
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
9 changed files
with
686 additions
and
5 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
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,57 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package notices | ||
|
||
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: "notices", | ||
Short: "Reads all notices. If an input is specified, reads all notices from that input", | ||
Example: examples, | ||
Run: run, | ||
} | ||
|
||
const examples = `# Read all notices: | ||
cartesi-rollups-cli read notices` | ||
|
||
var ( | ||
inputIndex int | ||
graphqlEndpoint string | ||
) | ||
|
||
func init() { | ||
Cmd.Flags().IntVar(&inputIndex, "input-index", -1, | ||
"index of the input") | ||
|
||
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) | ||
|
||
var resp []readerclient.Notice | ||
var err error | ||
|
||
if inputIndex != -1 { | ||
resp, err = readerclient.GetInputNotices(ctx, client, inputIndex) | ||
cobra.CheckErr(err) | ||
} else { | ||
resp, err = readerclient.GetNotices(ctx, client) | ||
cobra.CheckErr(err) | ||
} | ||
|
||
val, err := json.MarshalIndent(resp, "", " ") | ||
cobra.CheckErr(err) | ||
|
||
fmt.Print(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
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,26 @@ | ||
query getInputNotices($inputIndex: Int!) { | ||
input(index: $inputIndex) { | ||
index | ||
notices { | ||
edges { | ||
node{ | ||
index | ||
payload | ||
proof { | ||
validity { | ||
inputIndexWithinEpoch | ||
outputIndexWithinInput | ||
outputHashesRootHash | ||
vouchersEpochRootHash | ||
noticesEpochRootHash | ||
machineStateHash | ||
outputHashInOutputHashesSiblings | ||
outputHashesInEpochSiblings | ||
} | ||
context | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,26 @@ | ||
query getNotices { | ||
notices { | ||
edges { | ||
node { | ||
index | ||
payload | ||
proof { | ||
validity { | ||
inputIndexWithinEpoch | ||
outputIndexWithinInput | ||
outputHashesRootHash | ||
vouchersEpochRootHash | ||
noticesEpochRootHash | ||
machineStateHash | ||
outputHashInOutputHashesSiblings | ||
outputHashesInEpochSiblings | ||
} | ||
context | ||
} | ||
input { | ||
index | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.