ether

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BalanceCommand = &cobra.Command{
	Use:    "balance [address]",
	Short:  "gets the balance of the [address]",
	PreRun: cli.Connect,
	Args:   cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		var addr common.Address
		var err error

		if len(args) == 0 {
			s := viper.GetString("keystoreAddress")
			addr = common.HexToAddress(s)
			if !common.IsHexAddress(s) {
				err = errors.New("No [address] provided, and no valid 'keystoreAddress' address found")
			}
		} else if common.IsHexAddress(args[0]) {
			addr, err = cli.GetArgAddress(0, args)
		} else {
			addr, _, _, err = cli.AddressForKeystoreAlias(args[0])
		}
		cli.CheckErr(cmd, err)

		// Get the block flag, if set
		var block *big.Int
		i, err := cmd.Flags().GetInt64("block")
		cli.CheckErr(cmd, err)
		if i > -1 {
			block = big.NewInt(i)
		}
		balance, err := cli.Conn.BalanceAt(context.Background(), addr, block)
		cli.CheckErr(cmd, err)

		ether := units.ConvertInt(balance, units.Wei, units.Ether)
		cmd.Printf("Ξ %s\n", ether.Text('f', 4))
		usd, btc, sat, err := getExchangePrice(ether)
		if err == nil {
			cmd.Printf("\n(%s)\n", exchange)
			cmd.Printf("₿ %s (%s SAT)\n", btc.Text('f', 4), sat.Text('f', 0))
			cmd.Printf("$ %s\n", usd.Text('f', 4))
		}
	},
}
View Source
var Command = &cobra.Command{
	Use:   "ether",
	Short: "Ether utilities",
}
View Source
var SendCommand = &cobra.Command{
	Use:    "send <address> <ether> [message]",
	Short:  "sends an <address> <ether> [message]",
	PreRun: cli.ConnectWithKeyStore,
	Args:   cli.ChainArgs(cobra.RangeArgs(2, 3), cli.AddressArgFunc("address", 0), cli.BigFloatArgFunc("ether", 1)),
	Run: func(cmd *cobra.Command, args []string) {
		to := common.HexToAddress(args[0])
		wei := getAmount(args[1])
		gasPrice, err := gas.GetPrice(cmd, args)
		cli.CheckErr(cmd, err)

		var data []byte
		if len(args) == 3 {
			data = []byte(args[2])
		}

		n, err := nonce.Get()
		cli.CheckErr(cmd, err)

		gas, err := cli.Conn.EstimateGas(context.Background(), ethereum.CallMsg{
			From:     cli.Conn.Opts.From,
			To:       &to,
			Data:     data,
			Value:    wei,
			GasPrice: gasPrice,
		})
		cli.CheckErr(cmd, err)

		tx := types.NewTransaction(n, to, wei, gas, gasPrice, data)
		signedTx, err := cli.Conn.Opts.Signer(types.HomesteadSigner{}, cli.Conn.Opts.From, tx)
		cli.CheckErr(cmd, err)

		err = cli.Conn.SendTransaction(context.Background(), signedTx)
		cli.PrintTransactionFn(cmd)(signedTx, err)
	},
}

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