-
Notifications
You must be signed in to change notification settings - Fork 71
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 command to send inputs
- Loading branch information
Showing
14 changed files
with
262 additions
and
85 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
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,20 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package root | ||
|
||
import ( | ||
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/send" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "cartesi-rollups-cli", | ||
Short: "Command line interface for Cartesi Rollups", | ||
Long: `This command line interface provides functionality to help develop and debug the | ||
Cartesi Rollups node.`, | ||
} | ||
|
||
func init() { | ||
Cmd.AddCommand(send.Cmd) | ||
} |
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,79 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package send | ||
|
||
import ( | ||
"github.com/cartesi/rollups-node/internal/logger" | ||
"github.com/cartesi/rollups-node/pkg/addresses" | ||
"github.com/cartesi/rollups-node/pkg/ethutil" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "send", | ||
Short: "Send a rollups input to the Ethereum node", | ||
Example: examples, | ||
Run: run, | ||
} | ||
|
||
const examples = `# Send the string "hi" encoded as hex: | ||
cartesi-rollups-cli send --payload 0x$(printf "hi" | xxd -p)` | ||
|
||
var ( | ||
ethEndpoint string | ||
mnemonic string | ||
account uint32 | ||
hexPayload string | ||
addressBookFile string | ||
) | ||
|
||
func init() { | ||
Cmd.Flags().StringVar(ðEndpoint, "eth-endpoint", "http://localhost:8545", | ||
"ethereum node JSON-RPC endpoint") | ||
|
||
Cmd.Flags().StringVar(&mnemonic, "mnemonic", ethutil.FoundryMnemonic, | ||
"mnemonic used to sign the transaction") | ||
|
||
Cmd.Flags().Uint32Var(&account, "account", 0, | ||
"account index used to sign the transaction (default: 0)") | ||
|
||
Cmd.Flags().StringVar(&hexPayload, "payload", "", | ||
"input payload hex-encoded starting with 0x") | ||
|
||
cobra.CheckErr(Cmd.MarkFlagRequired("payload")) | ||
|
||
Cmd.Flags().StringVar(&addressBookFile, "address-book", "", | ||
"if set, load the address book from the given file; else, use test addresses") | ||
} | ||
|
||
func run(cmd *cobra.Command, args []string) { | ||
logger.Init("info", true) | ||
|
||
payload, err := hexutil.Decode(hexPayload) | ||
cobra.CheckErr(err) | ||
|
||
ctx := cmd.Context() | ||
client, err := ethclient.DialContext(ctx, ethEndpoint) | ||
cobra.CheckErr(err) | ||
logger.Info.Printf("connected to %v", ethEndpoint) | ||
|
||
signer, err := ethutil.NewMnemonicSigner(ctx, client, mnemonic, account) | ||
cobra.CheckErr(err) | ||
|
||
var book *addresses.Book | ||
if addressBookFile != "" { | ||
book, err = addresses.GetBookFromFile(addressBookFile) | ||
cobra.CheckErr(err) | ||
} else { | ||
book = addresses.GetTestBook() | ||
} | ||
|
||
logger.Info.Printf("sending input to %x", book.CartesiDApp) | ||
inputIndex, err := ethutil.AddInput(ctx, client, book, signer, payload) | ||
cobra.CheckErr(err) | ||
|
||
logger.Info.Printf("added input with index %v", inputIndex) | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
// This binary generates part of the node documentation automatically. | ||
// It should be executed from the project root dir with: `go run ./cmd/gen-docs`. | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root" | ||
"github.com/spf13/cobra/doc" | ||
) | ||
|
||
func main() { | ||
generateCartesiRollupsCliDocs() | ||
} | ||
|
||
func generateCartesiRollupsCliDocs() { | ||
err := doc.GenMarkdownTree(root.Cmd, "./docs") | ||
if err != nil { | ||
log.Fatalf("failed to gen cartesi-rollups-cli docs: %v", err) | ||
} | ||
log.Print("generated docs for cartesi-rollups-cli") | ||
} |
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,20 @@ | ||
## cartesi-rollups-cli | ||
|
||
Command line interface for Cartesi Rollups | ||
|
||
### Synopsis | ||
|
||
This command line interface provides functionality to help develop and debug the | ||
Cartesi Rollups node. | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for cartesi-rollups-cli | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [cartesi-rollups-cli send](cartesi-rollups-cli_send.md) - Send a rollups input to the Ethereum node | ||
|
||
###### Auto generated by spf13/cobra on 19-Nov-2023 |
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,31 @@ | ||
## cartesi-rollups-cli send | ||
|
||
Send a rollups input to the Ethereum node | ||
|
||
``` | ||
cartesi-rollups-cli send [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Send the string "hi" encoded as hex: | ||
cartesi-rollups-cli send --payload 0x$(printf "hi" | xxd -p) | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--account uint32 account index used to sign the transaction (default: 0) | ||
--address-book string if set, load the address book from the given file; else, use test addresses | ||
--eth-endpoint string ethereum node JSON-RPC endpoint (default "http://localhost:8545") | ||
-h, --help help for send | ||
--mnemonic string mnemonic used to sign the transaction (default "test test test test test test test test test test test junk") | ||
--payload string input payload hex-encoded starting with 0x | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [cartesi-rollups-cli](cartesi-rollups-cli.md) - Command line interface for Cartesi Rollups | ||
|
||
###### Auto generated by spf13/cobra on 19-Nov-2023 |
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,60 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
// This package manages the contract addresses. | ||
// | ||
// The addresses depend on the deployment of the contracts and should be provided by the node user. | ||
// This module offers an option to load these addresses from a config file, compatible with the | ||
// output of `sunodo address-book --json`. | ||
// This package also contain the addresses for the test environment as hard-coded values. | ||
package addresses | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// List of contract addresses. | ||
type Book struct { | ||
CartesiDAppFactory common.Address | ||
DAppAddressRelay common.Address | ||
ERC1155BatchPortal common.Address | ||
ERC1155SinglePortal common.Address | ||
ERC20Portal common.Address | ||
ERC721Portal common.Address | ||
EtherPortal common.Address | ||
InputBox common.Address | ||
CartesiDApp common.Address | ||
} | ||
|
||
// Get the addresses for the test environment. | ||
func GetTestBook() *Book { | ||
return &Book{ | ||
CartesiDAppFactory: common.HexToAddress("0x7122cd1221C20892234186facfE8615e6743Ab02"), | ||
DAppAddressRelay: common.HexToAddress("0xF5DE34d6BbC0446E2a45719E718efEbaaE179daE"), | ||
ERC1155BatchPortal: common.HexToAddress("0xedB53860A6B52bbb7561Ad596416ee9965B055Aa"), | ||
ERC1155SinglePortal: common.HexToAddress("0x7CFB0193Ca87eB6e48056885E026552c3A941FC4"), | ||
ERC20Portal: common.HexToAddress("0x9C21AEb2093C32DDbC53eEF24B873BDCd1aDa1DB"), | ||
ERC721Portal: common.HexToAddress("0x237F8DD094C0e47f4236f12b4Fa01d6Dae89fb87"), | ||
EtherPortal: common.HexToAddress("0xFfdbe43d4c855BF7e0f105c400A50857f53AB044"), | ||
InputBox: common.HexToAddress("0x59b22D57D4f067708AB0c00552767405926dc768"), | ||
CartesiDApp: common.HexToAddress("0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C"), | ||
} | ||
} | ||
|
||
// Get the address book from json File. | ||
func GetBookFromFile(path string) (*Book, error) { | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("read address book file: %v", err) | ||
} | ||
var book Book | ||
err = json.Unmarshal(data, &book) | ||
if err != nil { | ||
return nil, fmt.Errorf("parse address book json: %v", err) | ||
} | ||
return &book, nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.