2019-08-07 23:22:35 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/address"
|
2019-09-17 08:15:26 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/chain/types"
|
2019-08-07 23:22:35 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var sendCmd = &cli.Command{
|
|
|
|
Name: "send",
|
|
|
|
Usage: "send funds between accounts",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "source",
|
|
|
|
Usage: "optinally specifiy the account to send funds from",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-08-08 03:30:50 +00:00
|
|
|
api, err := GetFullNodeAPI(cctx)
|
2019-08-07 23:22:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
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.BigFromString(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: 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
|
|
|
|
},
|
|
|
|
}
|