-
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.
feat(cli): add read vouchers command
- Loading branch information
Showing
7 changed files
with
587 additions
and
1 deletion.
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
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 vouchers | ||
|
||
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: "vouchers", | ||
Short: "Reads all vouchers. If an input is specified, reads all vouchers from that input", | ||
Example: examples, | ||
Run: run, | ||
} | ||
|
||
const examples = `# Read all vouchers: | ||
cartesi-rollups-cli read vouchers` | ||
|
||
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.Voucher | ||
var err error | ||
|
||
if cmd.Flags().Changed("input-index") { | ||
resp, err = readerclient.GetInputVouchers(ctx, client, inputIndex) | ||
cobra.CheckErr(err) | ||
} else { | ||
resp, err = readerclient.GetVouchers(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
query getInputVouchers($inputIndex: Int!) { | ||
input(index: $inputIndex) { | ||
index | ||
vouchers { | ||
edges { | ||
node{ | ||
index | ||
payload | ||
destination | ||
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,27 @@ | ||
query getVouchers { | ||
vouchers { | ||
edges { | ||
node { | ||
index | ||
payload | ||
destination | ||
proof { | ||
validity { | ||
inputIndexWithinEpoch | ||
outputIndexWithinInput | ||
outputHashesRootHash | ||
vouchersEpochRootHash | ||
noticesEpochRootHash | ||
machineStateHash | ||
outputHashInOutputHashesSiblings | ||
outputHashesInEpochSiblings | ||
} | ||
context | ||
} | ||
input { | ||
index | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.