Exemple #1
0
func cliStorage(cmd *cobra.Command, args []string) {
	if len(args) == 0 {
		common.Exit(fmt.Errorf("must specify an account"))
	}

	addr := args[0]
	var storageKey string
	if len(args) > 1 {
		storageKey = args[1]
	}

	r, err := client.RequestResponse("eth", "blockNumber")
	common.IfExit(err)
	blockNum := utils.HexToInt(r.(string))

	if storageKey == "" {
		// get all the storage
		r, err = client.RequestResponse("eth", "getStorage", addr, blockNum)
		common.IfExit(err)
		sortPrintMap(r.(map[string]interface{}))
	} else {
		// only grab one storage entry
		r, err = client.RequestResponse("eth", "getStorageAt", addr, storageKey, blockNum)
		common.IfExit(err)
		fmt.Println(r)
	}
}
Exemple #2
0
func cliAccount(cmd *cobra.Command, args []string) {
	if len(args) == 0 {
		common.Exit(fmt.Errorf("must specify an account"))
	}

	addr := args[0]
	acc := new(Account)
	acc.Address = addr

	r, err := client.RequestResponse("eth", "blockNumber")
	common.IfExit(err)
	blockNum := utils.HexToInt(r.(string))

	r, err = client.RequestResponse("eth", "getBalance", addr, blockNum)
	common.IfExit(err)
	acc.Balance = r.(string)

	r, err = client.RequestResponse("eth", "getTransactionCount", addr, blockNum)
	common.IfExit(err)
	acc.Nonce = uint64(utils.HexToInt(r.(string)))

	r, err = client.RequestResponse("eth", "getCode", addr, blockNum)
	common.IfExit(err)
	acc.Code = r.(string)

	b, err := json.MarshalIndent(acc, "", "\t")
	common.IfExit(err)
	fmt.Println(string(b))
}
Exemple #3
0
func cliCall(cmd *cobra.Command, args []string) {
	r, err := client.RequestResponse("eth", "blockNumber")
	common.IfExit(err)
	blockNum := utils.HexToInt(r.(string))

	callArgs := callData{FromFlag, ToFlag, AmtFlag, GasFlag, PriceFlag, DataFlag}

	r, err = client.RequestResponse("eth", "call", callArgs, blockNum)
	common.IfExit(err)
	fmt.Println(r)
}
Exemple #4
0
func cliCall(cmd *cobra.Command, args []string) {
	tx, err := core.Call(AddressFlag, ToFlag, AmtFlag, GasFlag, GasPriceFlag, DataFlag, NonceFlag)
	common.IfExit(err)
	logger.Infoln(tx)
	r, err := core.SignAndBroadcast(SignAddrFlag, tx, SignFlag, BroadcastFlag, WaitFlag)
	common.IfExit(err)
	if BinaryFlag {
		logger.Printf("%X\n", tx.Bytes())
	}
	if SignFlag {
		logger.Infof("Signature: %X\n", tx.Signature())
	}
	if BroadcastFlag {
		logger.Println("TxID:", r)
	}
}
Exemple #5
0
// TODO: this should be able to read off stdin too
func cliBroadcast(cmd *cobra.Command, args []string) {
	if len(args) == 0 {
		common.Exit(fmt.Errorf("must pass some transaction bytes"))
	}

	txHex := args[0]
	r, err := client.RequestResponse("eth", "sendRawTransaction", txHex)
	common.IfExit(err)
	fmt.Println(r)
}
Exemple #6
0
func cliReceipt(cmd *cobra.Command, args []string) {
	if len(args) == 0 {
		common.Exit(fmt.Errorf("must specify tx hash"))
	}

	txHash := args[0]

	r, err := client.RequestResponse("eth", "getTransactionReceipt", txHash)
	common.IfExit(err)
	sortPrintMap(r.(map[string]interface{}))

}
Exemple #7
0
// eth: blockNumber, protocolVersion, coinbase, mining, gasPrice
// net: peerCount, listening, version
func cliStatus(cmd *cobra.Command, args []string) {
	var status Status

	r, err := client.RequestResponse("eth", "blockNumber")
	common.IfExit(err)
	status.ChainStatus.BlockNumber = utils.HexToInt(r.(string))

	r, err = client.RequestResponse("eth", "protocolVersion")
	common.IfExit(err)
	status.ChainStatus.ProtocolVersion = r.(string)

	r, err = client.RequestResponse("net", "peerCount")
	common.IfExit(err)
	status.NetStatus.Version = r.(string)

	r, err = client.RequestResponse("net", "listening")
	common.IfExit(err)
	status.NetStatus.Listening = r.(bool)

	r, err = client.RequestResponse("net", "version")
	common.IfExit(err)
	status.NetStatus.Version = r.(string)

	r, err = client.RequestResponse("eth", "coinbase")
	common.IfExit(err)
	status.MiningStatus.Coinbase = r.(string)

	r, err = client.RequestResponse("eth", "mining")
	common.IfExit(err)
	status.MiningStatus.Mining = r.(bool)

	r, err = client.RequestResponse("eth", "gasPrice")
	common.IfExit(err)
	status.MiningStatus.Price = r.(string)

	b, err := json.MarshalIndent(status, "", "\t")
	common.IfExit(err)
	fmt.Println(string(b))
}