-
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
6 changed files
with
466 additions
and
0 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 voucher | ||
|
||
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: "voucher", | ||
Short: "Reads a voucher", | ||
Example: examples, | ||
Run: run, | ||
} | ||
|
||
const examples = `# Read voucher 5 from input 6: | ||
cartesi-rollups-cli read voucher --voucher-index 5 --input-index 6` | ||
|
||
var ( | ||
voucherIndex int | ||
inputIndex int | ||
graphqlEndpoint string | ||
) | ||
|
||
func init() { | ||
Cmd.Flags().IntVar(&voucherIndex, "voucher-index", 0, | ||
"index of the voucher") | ||
|
||
cobra.CheckErr(Cmd.MarkFlagRequired("voucher-index")) | ||
|
||
Cmd.Flags().IntVar(&inputIndex, "input-index", 0, | ||
"index of the input") | ||
|
||
cobra.CheckErr(Cmd.MarkFlagRequired("input-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.GetVoucher(ctx, client, voucherIndex, inputIndex) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
query getVoucher($voucherIndex: Int!, $inputIndex: Int!) { | ||
voucher(voucherIndex: $voucherIndex, inputIndex: $inputIndex) { | ||
index | ||
payload | ||
destination | ||
proof { | ||
validity { | ||
inputIndexWithinEpoch | ||
outputIndexWithinInput | ||
outputHashesRootHash | ||
vouchersEpochRootHash | ||
noticesEpochRootHash | ||
machineStateHash | ||
outputHashInOutputHashesSiblings | ||
outputHashesInEpochSiblings | ||
} | ||
context | ||
} | ||
input { | ||
index | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.