Skip to content

Commit

Permalink
feat(cli): add read notices command
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Dec 6, 2023
1 parent 6a83ab1 commit bdb0739
Show file tree
Hide file tree
Showing 9 changed files with 686 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `cartesi-rollups-node` Go binary as a single entrypoint to execute all Cartesi Node services
- Added unified configuration for the Node with a new set of environment variables.
- Added `cartesi-rollups-cli` binary to help develop and debug the Cartesi Rollups node
- Added read input to `cartesi-rollups-cli`
- Added read input and read notice to `cartesi-rollups-cli`

### Changed

Expand Down
57 changes: 57 additions & 0 deletions cmd/cartesi-rollups-cli/root/read/notices/notices.go
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))
}
2 changes: 2 additions & 0 deletions cmd/cartesi-rollups-cli/root/read/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/read/input"
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/read/inputs"
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/read/notice"
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/read/notices"
"github.com/spf13/cobra"
)

Expand All @@ -19,4 +20,5 @@ func init() {
Cmd.AddCommand(input.Cmd)
Cmd.AddCommand(inputs.Cmd)
Cmd.AddCommand(notice.Cmd)
Cmd.AddCommand(notices.Cmd)
}
26 changes: 26 additions & 0 deletions pkg/readerclient/generate/input_notices.graphql
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
}
}
}
}
}
}
26 changes: 26 additions & 0 deletions pkg/readerclient/generate/notices.graphql
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
}
}
}
}
}
Loading

0 comments on commit bdb0739

Please sign in to comment.