rpc

package
v0.1.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright © 2022 Polygon <engineering@polygon.technology>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

View Source
var RpcCmd = &cobra.Command{
	Use:   "rpc URL method param_0 param_1 ... param_n",
	Short: "A simple wrapper for making RPC requests",
	Long: `
Use this function to make JSON-RPC calls.

## ETH Examples
rpc http://127.0.0.1:8541 eth_getBlockByNumber 0x10E true

rpc http://127.0.0.1:8541 eth_getBlockByHash 0x15206ab0a5b408214127f5c445a86b7cfe6ae48fdcd9172b14e013dae7a7f470 true

rpc http://127.0.0.1:8541 eth_getTransactionByHash 0x97c070cb07bfac783ca73f08fb5999ae1ab509bf644197ef4a2c4e4f4a3c1516
`,
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx := cmd.Context()
		ec, err := ethrpc.DialContext(ctx, args[0])
		if err != nil {
			return err
		}

		params := toGenericParams(args[2:])
		var res = new(json.RawMessage)
		err = ec.Call(res, args[1], params...)
		if err != nil {
			return err
		}
		body, err := res.MarshalJSON()
		if err != nil {
			fmt.Println("gyahhhhhhhh1")
			return err
		}
		fmt.Println(string(body))
		return nil
	},
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) < 2 {
			return fmt.Errorf("rpc needs at least two arguments. A URL and a method")
		}

		_, err := url.Parse(args[0])
		if err != nil {
			return err
		}

		return nil
	},
}

rpcCmd represents the rpc command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL