Skip to content

Commit

Permalink
feat(cli): add read input command
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Nov 27, 2023
1 parent 788440c commit 15c4d25
Show file tree
Hide file tree
Showing 11 changed files with 677 additions and 3 deletions.
218 changes: 218 additions & 0 deletions api/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
"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 voucher from this particular input given the voucher's index"
voucher(index: Int!): Voucher!
"Get notice from this particular input given the notice's index"
notice(index: Int!): Notice!
"Get 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 voucher based on its index"
voucher(voucherIndex: Int!, inputIndex: Int!): Voucher!
"Get notice based on its index"
notice(noticeIndex: Int!, inputIndex: Int!): Notice!
"Get 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
}
53 changes: 53 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,53 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

package input

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: "input",
Short: "Reads input from node GraphQL",
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) {
logger.Init("info", true)

ctx := cmd.Context()
client := graphql.NewClient(graphqlEndpoint, nil)

resp, err := readerclient.GetInput(ctx, client, int(index))
cobra.CheckErr(err)

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

logger.Info.Printf(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)
}
12 changes: 9 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.1

require (
github.com/ethereum/go-ethereum v1.13.5
github.com/spf13/cobra v1.7.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.26.0
github.com/tyler-smith/go-bip32 v1.0.0
Expand All @@ -16,9 +16,13 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/Khan/genqlient v0.6.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/alexflint/go-arg v1.4.2 // indirect
github.com/alexflint/go-scalar v1.0.0 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
Expand All @@ -27,7 +31,7 @@ require (
github.com/containerd/containerd v1.7.7 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
Expand All @@ -43,7 +47,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
Expand All @@ -69,6 +73,7 @@ require (
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/vektah/gqlparser/v2 v2.5.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
Expand All @@ -80,6 +85,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit 15c4d25

Please sign in to comment.