Plug in InteractiveSend to all adopted commands

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2021-04-02 15:43:28 +02:00
parent 7535c5bb53
commit 3d8f641310
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
6 changed files with 57 additions and 55 deletions

View File

@ -31,6 +31,7 @@ import (
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/v0api"
"github.com/filecoin-project/lotus/build"
@ -1116,11 +1117,12 @@ var SlashConsensusFault = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
srv, err := GetFullNodeServices(cctx)
if err != nil {
return err
}
defer closer()
defer srv.Close()
a := srv.FullNodeAPI()
ctx := ReqContext(cctx)
c1, err := cid.Parse(cctx.Args().Get(0))
@ -1128,7 +1130,7 @@ var SlashConsensusFault = &cli.Command{
return xerrors.Errorf("parsing cid 1: %w", err)
}
b1, err := api.ChainGetBlock(ctx, c1)
b1, err := a.ChainGetBlock(ctx, c1)
if err != nil {
return xerrors.Errorf("getting block 1: %w", err)
}
@ -1138,7 +1140,7 @@ var SlashConsensusFault = &cli.Command{
return xerrors.Errorf("parsing cid 2: %w", err)
}
b2, err := api.ChainGetBlock(ctx, c2)
b2, err := a.ChainGetBlock(ctx, c2)
if err != nil {
return xerrors.Errorf("getting block 2: %w", err)
}
@ -1149,7 +1151,7 @@ var SlashConsensusFault = &cli.Command{
var fromAddr address.Address
if from := cctx.String("from"); from == "" {
defaddr, err := api.WalletDefaultAddress(ctx)
defaddr, err := a.WalletDefaultAddress(ctx)
if err != nil {
return err
}
@ -1185,7 +1187,7 @@ var SlashConsensusFault = &cli.Command{
return xerrors.Errorf("parsing cid extra: %w", err)
}
bExtra, err := api.ChainGetBlock(ctx, cExtra)
bExtra, err := a.ChainGetBlock(ctx, cExtra)
if err != nil {
return xerrors.Errorf("getting block extra: %w", err)
}
@ -1203,15 +1205,17 @@ var SlashConsensusFault = &cli.Command{
return err
}
msg := &types.Message{
To: b2.Miner,
From: fromAddr,
Value: types.NewInt(0),
Method: builtin.MethodsMiner.ReportConsensusFault,
Params: enc,
proto := &api.MessagePrototype{
Message: types.Message{
To: b2.Miner,
From: fromAddr,
Value: types.NewInt(0),
Method: builtin.MethodsMiner.ReportConsensusFault,
Params: enc,
},
}
smsg, err := api.MpoolPushMessage(ctx, msg, nil)
smsg, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}

View File

@ -25,10 +25,14 @@ var mpoolManage = &cli.Command{
if err != nil {
return err
}
defer srv.Close()
defer srv.Close() //nolint:errcheck
ctx := ReqContext(cctx)
_, localAddr, err := srv.LocalAddresses(ctx)
if err != nil {
return xerrors.Errorf("getting local addresses: %w", err)
}
msgs, err := srv.MpoolPendingFilter(ctx, func(sm *types.SignedMessage) bool {
if sm.Message.From.Empty() {

View File

@ -153,7 +153,7 @@ var msigCreateCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -161,7 +161,7 @@ var msigCreateCmd = &cli.Command{
msgCid := sm.Cid()
// wait for it to get mined into a block
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -442,7 +442,7 @@ var msigProposeCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -451,7 +451,7 @@ var msigProposeCmd = &cli.Command{
fmt.Println("send proposal in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -540,7 +540,7 @@ var msigApproveCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -590,7 +590,7 @@ var msigApproveCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -600,7 +600,7 @@ var msigApproveCmd = &cli.Command{
fmt.Println("sent approval in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -671,7 +671,7 @@ var msigRemoveProposeCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -680,7 +680,7 @@ var msigRemoveProposeCmd = &cli.Command{
fmt.Println("sent remove proposal in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -758,7 +758,7 @@ var msigAddProposeCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -767,7 +767,7 @@ var msigAddProposeCmd = &cli.Command{
fmt.Fprintln(cctx.App.Writer, "sent add proposal in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -849,7 +849,7 @@ var msigAddApproveCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -858,7 +858,7 @@ var msigAddApproveCmd = &cli.Command{
fmt.Println("sent add approval in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -935,7 +935,7 @@ var msigAddCancelCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -944,7 +944,7 @@ var msigAddCancelCmd = &cli.Command{
fmt.Println("sent add cancellation in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -1016,7 +1016,7 @@ var msigSwapProposeCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -1025,7 +1025,7 @@ var msigSwapProposeCmd = &cli.Command{
fmt.Println("sent swap proposal in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -1107,7 +1107,7 @@ var msigSwapApproveCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -1116,7 +1116,7 @@ var msigSwapApproveCmd = &cli.Command{
fmt.Println("sent swap approval in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -1193,7 +1193,7 @@ var msigSwapCancelCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -1202,7 +1202,7 @@ var msigSwapCancelCmd = &cli.Command{
fmt.Println("sent swap cancellation in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -1289,7 +1289,7 @@ var msigLockProposeCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -1298,7 +1298,7 @@ var msigLockProposeCmd = &cli.Command{
fmt.Println("sent lock proposal in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -1395,7 +1395,7 @@ var msigLockApproveCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -1404,7 +1404,7 @@ var msigLockApproveCmd = &cli.Command{
fmt.Println("sent lock approval in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -1496,7 +1496,7 @@ var msigLockCancelCmd = &cli.Command{
return err
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -1505,7 +1505,7 @@ var msigLockCancelCmd = &cli.Command{
fmt.Println("sent lock cancellation in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
@ -1642,7 +1642,7 @@ var msigProposeThresholdCmd = &cli.Command{
return fmt.Errorf("failed to propose change of threshold: %w", err)
}
sm, _, err := srv.PublishMessage(ctx, proto, true)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
@ -1651,7 +1651,7 @@ var msigProposeThresholdCmd = &cli.Command{
fmt.Println("sent change threshold proposal in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}

View File

@ -150,12 +150,12 @@ var sendCmd = &cli.Command{
return xerrors.Errorf("creating message prototype: %w", err)
}
c, err := InteractiveSend(ctx, cctx, srv, proto)
sm, err := InteractiveSend(ctx, cctx, srv, proto)
if err != nil {
return err
}
fmt.Fprintf(cctx.App.Writer, "%s\n", c)
fmt.Fprintf(cctx.App.Writer, "%s\n", sm.Cid())
return nil
},
}

View File

@ -13,12 +13,6 @@ import (
ucli "github.com/urfave/cli/v2"
)
var arbtCid = (&types.Message{
From: mustAddr(address.NewIDAddress(2)),
To: mustAddr(address.NewIDAddress(1)),
Value: types.NewInt(1000),
}).Cid()
func mustAddr(a address.Address, err error) address.Address {
if err != nil {
panic(err)

View File

@ -19,7 +19,7 @@ import (
)
func InteractiveSend(ctx context.Context, cctx *cli.Context, srv ServicesAPI,
proto *api.MessagePrototype) (cid.Cid, error) {
proto *api.MessagePrototype) (*types.SignedMessage, error) {
msg, checks, err := srv.PublishMessage(ctx, proto, cctx.Bool("force") || cctx.Bool("force-send"))
printer := cctx.App.Writer
@ -30,17 +30,17 @@ func InteractiveSend(ctx context.Context, cctx *cli.Context, srv ServicesAPI,
} else {
proto, err = resolveChecks(ctx, srv, cctx.App.Writer, proto, checks)
if err != nil {
return cid.Undef, xerrors.Errorf("from UI: %w", err)
return nil, xerrors.Errorf("from UI: %w", err)
}
msg, _, err = srv.PublishMessage(ctx, proto, true)
}
}
if err != nil {
return cid.Undef, xerrors.Errorf("publishing message: %w", err)
return nil, xerrors.Errorf("publishing message: %w", err)
}
return msg.Cid(), nil
return msg, nil
}
var interactiveSolves = map[api.CheckStatusCode]bool{