lotus/cli/send.go

77 lines
1.4 KiB
Go
Raw Normal View History

package cli
import (
"fmt"
2019-10-03 18:12:30 +00:00
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"gopkg.in/urfave/cli.v2"
)
var sendCmd = &cli.Command{
Name: "send",
Usage: "Send funds between accounts",
ArgsUsage: "[targetAddress] [amount]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "source",
2020-01-21 19:02:51 +00:00
Usage: "optionally specify the account to send funds from",
},
},
Action: func(cctx *cli.Context) error {
2019-10-03 18:12:30 +00:00
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
2019-10-03 18:12:30 +00:00
defer closer()
ctx := ReqContext(cctx)
if cctx.Args().Len() != 2 {
return fmt.Errorf("'send' expects two arguments, target and amount")
}
toAddr, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
val, err := types.ParseFIL(cctx.Args().Get(1))
if err != nil {
return err
}
var fromAddr address.Address
if from := cctx.String("source"); from == "" {
defaddr, err := api.WalletDefaultAddress(ctx)
if err != nil {
return err
}
fromAddr = defaddr
} else {
addr, err := address.NewFromString(from)
if err != nil {
return err
}
fromAddr = addr
}
msg := &types.Message{
From: fromAddr,
To: toAddr,
Value: types.BigInt(val),
GasLimit: 10000,
2019-08-14 04:43:29 +00:00
GasPrice: types.NewInt(0),
}
2019-09-17 08:15:26 +00:00
_, err = api.MpoolPushMessage(ctx, msg)
if err != nil {
return err
}
return nil
},
}