Ejemplo n.º 1
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))
}
Ejemplo n.º 2
0
// if the nonce is given, the addr is not needed
func checkCommon(addr, amtS, gasS, priceS string, seq uint64) (from common.Address, nonce uint64, amount, gas, price *big.Int, err error) {
	// resolve the big ints
	if amount, err = stringToBig(amtS); err != nil {
		err = fmt.Errorf("amt %s is bad hex: %v", amtS, err)
		return
	}
	if gas, err = stringToBig(gasS); err != nil {
		err = fmt.Errorf("gas %s is bad hex: %v", gasS, err)
		return
	}
	if price, err = stringToBig(priceS); err != nil {
		err = fmt.Errorf("price %s is bad hex: %v", priceS, err)
		return
	}

	// resolve the address
	if addr == "" {
		err = fmt.Errorf("--addr must be given")
		return
	}
	var addrBytes []byte
	addrBytes, err = hex.DecodeString(utils.StripHex(addr))
	if err != nil {
		err = fmt.Errorf("addr is bad hex: %v", err)
		return
	}
	from = common.BytesToAddress(addrBytes)

	// resolve the nonce (or fetch it)
	if seq == 0 {
		if EthClient.Host == "" {
			// NOTE this error only applies to ethtx, not other possible consumers of ethtx/core
			err = fmt.Errorf("input must specify a nonce with the --nonce flag or use --node-addr (or ETHTX_NODE_ADDR) to fetch the nonce from a node")
			return
		}

		var r interface{}
		// fetch block num
		r, err = EthClient.RequestResponse("eth", "blockNumber")
		if err != nil {
			err = fmt.Errorf("Error fetching block number: %v", err)
			return
		}
		// NOTE: both block num and account nonces are hex. (why?!)
		blockNum := utils.HexToInt(r.(string))

		r, err = EthClient.RequestResponse("eth", "getTransactionCount", addr, blockNum)
		if err != nil {
			err = fmt.Errorf("Error fetching account nonce: %v", err)
			return
		}

		nonce = uint64(utils.HexToInt(r.(string)))
	} else {
		nonce = seq
	}

	return
}
Ejemplo n.º 3
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)
	}
}
Ejemplo n.º 4
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)
}
Ejemplo n.º 5
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))
}