Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read input commands to rollups-cli #170

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/license-check/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"exclude": [
"offchain/target/**",
"offchain/data/src/schema.rs",
"pkg/contracts/*.go"
"pkg/contracts/*.go",
"pkg/readerclient/generated.go"
],
"license": ".github/license-check/header.txt"
}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +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`

## [1.2.0]

Expand Down
220 changes: 220 additions & 0 deletions api/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
"Data that can be used as proof to validate notices and execute vouchers on the base layer blockchain"
type Proof {
"Validity proof for an output"
validity: OutputValidityProof!
"Data that allows the validity proof to be contextualized within submitted claims, given as a payload in Ethereum hex binary format, starting with '0x'"
context: String!
}

enum CompletionStatus {
UNPROCESSED
ACCEPTED
REJECTED
EXCEPTION
MACHINE_HALTED
CYCLE_LIMIT_EXCEEDED
TIME_LIMIT_EXCEEDED
PAYLOAD_LENGTH_LIMIT_EXCEEDED
}

"Request submitted to the application to advance its state"
type Input {
"Input index starting from genesis"
index: Int!
"Status of the input"
status: CompletionStatus!
"Address responsible for submitting the input"
msgSender: String!
"Timestamp associated with the input submission, as defined by the base layer's block in which it was recorded"
timestamp: BigInt!
"Number of the base layer block in which the input was recorded"
blockNumber: BigInt!
"Input payload in Ethereum hex binary format, starting with '0x'"
payload: String!
"Get a voucher from this particular input given the voucher's index"
voucher(index: Int!): Voucher!
"Get a notice from this particular input given the notice's index"
notice(index: Int!): Notice!
"Get a report from this particular input given the report's index"
report(index: Int!): Report!
"Get vouchers from this particular input with support for pagination"
vouchers(first: Int, last: Int, after: String, before: String): VoucherConnection!
"Get notices from this particular input with support for pagination"
notices(first: Int, last: Int, after: String, before: String): NoticeConnection!
"Get reports from this particular input with support for pagination"
reports(first: Int, last: Int, after: String, before: String): ReportConnection!
}

"Validity proof for an output"
type OutputValidityProof {
"Local input index within the context of the related epoch"
inputIndexWithinEpoch: Int!
"Output index within the context of the input that produced it"
outputIndexWithinInput: Int!
"Merkle root of all output hashes of the related input, given in Ethereum hex binary format (32 bytes), starting with '0x'"
outputHashesRootHash: String!
"Merkle root of all voucher hashes of the related epoch, given in Ethereum hex binary format (32 bytes), starting with '0x'"
vouchersEpochRootHash: String!
"Merkle root of all notice hashes of the related epoch, given in Ethereum hex binary format (32 bytes), starting with '0x'"
noticesEpochRootHash: String!
"Hash of the machine state claimed for the related epoch, given in Ethereum hex binary format (32 bytes), starting with '0x'"
machineStateHash: String!
"Proof that this output hash is in the output-hashes merkle tree. This array of siblings is bottom-up ordered (from the leaf to the root). Each hash is given in Ethereum hex binary format (32 bytes), starting with '0x'."
outputHashInOutputHashesSiblings: [String!]!
"Proof that this output-hashes root hash is in epoch's output merkle tree. This array of siblings is bottom-up ordered (from the leaf to the root). Each hash is given in Ethereum hex binary format (32 bytes), starting with '0x'."
outputHashesInEpochSiblings: [String!]!
}

"Representation of a transaction that can be carried out on the base layer blockchain, such as a transfer of assets"
type Voucher {
"Voucher index within the context of the input that produced it"
index: Int!
"Input whose processing produced the voucher"
input: Input!
"Transaction destination address in Ethereum hex binary format (20 bytes), starting with '0x'"
destination: String!
"Transaction payload in Ethereum hex binary format, starting with '0x'"
payload: String!
"Proof object that allows this voucher to be validated and executed on the base layer blockchain"
proof: Proof
}

"Top level queries"
type Query {
"Get input based on its identifier"
input(index: Int!): Input!
"Get a voucher based on its index"
voucher(voucherIndex: Int!, inputIndex: Int!): Voucher!
"Get a notice based on its index"
notice(noticeIndex: Int!, inputIndex: Int!): Notice!
"Get a report based on its index"
report(reportIndex: Int!, inputIndex: Int!): Report!
"Get inputs with support for pagination"
inputs(first: Int, last: Int, after: String, before: String, where: InputFilter): InputConnection!
"Get vouchers with support for pagination"
vouchers(first: Int, last: Int, after: String, before: String): VoucherConnection!
"Get notices with support for pagination"
notices(first: Int, last: Int, after: String, before: String): NoticeConnection!
"Get reports with support for pagination"
reports(first: Int, last: Int, after: String, before: String): ReportConnection!
}

"Pagination entry"
type NoticeEdge {
"Node instance"
node: Notice!
"Pagination cursor"
cursor: String!
}

"Pagination result"
type InputConnection {
"Total number of entries that match the query"
totalCount: Int!
"Pagination entries returned for the current page"
edges: [InputEdge!]!
"Pagination metadata"
pageInfo: PageInfo!
}

"Pagination result"
type VoucherConnection {
"Total number of entries that match the query"
totalCount: Int!
"Pagination entries returned for the current page"
edges: [VoucherEdge!]!
"Pagination metadata"
pageInfo: PageInfo!
}

"Informational statement that can be validated in the base layer blockchain"
type Notice {
"Notice index within the context of the input that produced it"
index: Int!
"Input whose processing produced the notice"
input: Input!
"Notice data as a payload in Ethereum hex binary format, starting with '0x'"
payload: String!
"Proof object that allows this notice to be validated by the base layer blockchain"
proof: Proof
}

"Pagination entry"
type ReportEdge {
"Node instance"
node: Report!
"Pagination cursor"
cursor: String!
}

"Pagination result"
type ReportConnection {
"Total number of entries that match the query"
totalCount: Int!
"Pagination entries returned for the current page"
edges: [ReportEdge!]!
"Pagination metadata"
pageInfo: PageInfo!
}

"Filter object to restrict results depending on input properties"
input InputFilter {
"Filter only inputs with index lower than a given value"
indexLowerThan: Int
"Filter only inputs with index greater than a given value"
indexGreaterThan: Int
}

scalar BigInt

"Pagination result"
type NoticeConnection {
"Total number of entries that match the query"
totalCount: Int!
"Pagination entries returned for the current page"
edges: [NoticeEdge!]!
"Pagination metadata"
pageInfo: PageInfo!
}

"Pagination entry"
type InputEdge {
"Node instance"
node: Input!
"Pagination cursor"
cursor: String!
}

"Page metadata for the cursor-based Connection pagination pattern"
type PageInfo {
"Cursor pointing to the first entry of the page"
startCursor: String
"Cursor pointing to the last entry of the page"
endCursor: String
"Indicates if there are additional entries after the end curs"
hasNextPage: Boolean!
"Indicates if there are additional entries before the start curs"
hasPreviousPage: Boolean!
}

"Application log or diagnostic information"
type Report {
"Report index within the context of the input that produced it"
index: Int!
"Input whose processing produced the report"
input: Input!
"Report data as a payload in Ethereum hex binary format, starting with '0x'"
payload: String!
}

"Pagination entry"
type VoucherEdge {
"Node instance"
node: Voucher!
"Pagination cursor"
cursor: String!
}

schema {
query: Query
}
51 changes: 51 additions & 0 deletions cmd/cartesi-rollups-cli/root/read/input/input.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

package input

import (
"encoding/json"
"fmt"

"github.com/Khan/genqlient/graphql"
"github.com/cartesi/rollups-node/pkg/readerclient"
torives marked this conversation as resolved.
Show resolved Hide resolved
"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "input",
Short: "Reads an input",
Example: examples,
Run: run,
}

const examples = `# Read specific input from GraphQL:
cartesi-rollups-cli read input --index 5`

var (
index int
graphqlEndpoint string
)

func init() {
Cmd.Flags().IntVar(&index, "index", 0,
"index of the input")

cobra.CheckErr(Cmd.MarkFlagRequired("index"))

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.GetInput(ctx, client, index)
cobra.CheckErr(err)

val, err := json.MarshalIndent(resp, "", " ")
cobra.CheckErr(err)

fmt.Print(string(val))
}
45 changes: 45 additions & 0 deletions cmd/cartesi-rollups-cli/root/read/inputs/inputs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// (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 inputs ordered by index",
Example: examples,
Run: run,
}

const examples = `# Read inputs from GraphQL:
cartesi-rollups-cli read inputs`

var (
graphqlEndpoint string
)

func init() {
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)
cobra.CheckErr(err)

val, err := json.MarshalIndent(resp, "", " ")
cobra.CheckErr(err)

fmt.Print(string(val))
}
20 changes: 20 additions & 0 deletions cmd/cartesi-rollups-cli/root/read/read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

package read

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/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "read",
Short: "Read the node state from the GraphQL API",
}

func init() {
Cmd.AddCommand(input.Cmd)
Cmd.AddCommand(inputs.Cmd)
}
2 changes: 2 additions & 0 deletions cmd/cartesi-rollups-cli/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package root

import (
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/read"
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/send"
"github.com/spf13/cobra"
)
Expand All @@ -17,4 +18,5 @@ Cartesi Rollups node.`,

func init() {
Cmd.AddCommand(send.Cmd)
Cmd.AddCommand(read.Cmd)
}
Loading
Loading