2019-08-07 23:22:35 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-10-03 18:12:30 +00:00
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-08-07 23:22:35 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var sendCmd = &cli.Command{
|
2019-10-09 20:02:08 +00:00
|
|
|
Name: "send",
|
|
|
|
Usage: "Send funds between accounts",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[targetAddress] [amount]",
|
2019-08-07 23:22:35 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "source",
|
2020-01-21 19:02:51 +00:00
|
|
|
Usage: "optionally specify the account to send funds from",
|
2019-08-07 23:22:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-10-03 18:12:30 +00:00
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
2019-08-07 23:22:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-08-07 23:22:35 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-10-18 12:31:45 +00:00
|
|
|
val, err := types.ParseFIL(cctx.Args().Get(1))
|
2019-08-07 23:22:35 +00:00
|
|
|
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,
|
2019-10-18 12:31:45 +00:00
|
|
|
Value: types.BigInt(val),
|
2019-08-14 04:43:29 +00:00
|
|
|
GasLimit: types.NewInt(1000),
|
|
|
|
GasPrice: types.NewInt(0),
|
2019-08-07 23:22:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-17 08:15:26 +00:00
|
|
|
_, err = api.MpoolPushMessage(ctx, msg)
|
2019-08-07 23:22:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|