From c2148ba106d7491f145c793f1c9fd9a20654e33c Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 15 Sep 2020 19:27:36 -0400 Subject: [PATCH 1/5] Multisig: Add a CLI command to propose locking some balance --- cli/multisig.go | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/cli/multisig.go b/cli/multisig.go index 4596628f4..01e922a07 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -11,6 +11,10 @@ import ( "strconv" "text/tabwriter" + "github.com/filecoin-project/lotus/chain/actors" + + "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -43,6 +47,9 @@ var multisigCmd = &cli.Command{ msigSwapProposeCmd, msigSwapApproveCmd, msigSwapCancelCmd, + msigLockProposeCmd, + msigLockApproveCmd, + msigLockCancelCmd, msigVestedCmd, }, } @@ -971,6 +978,93 @@ var msigSwapCancelCmd = &cli.Command{ }, } +var msigLockProposeCmd = &cli.Command{ + Name: "lock-propose", + Usage: "Propose to lock up some balance", + ArgsUsage: "[multisigAddress startEpoch unlockDuration amount]", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "from", + Usage: "account to send the approve message from", + }, + }, + Action: func(cctx *cli.Context) error { + if cctx.Args().Len() != 4 { + return ShowHelp(cctx, fmt.Errorf("must pass multisig address, start epoch, unlock duration, and amount")) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + msig, err := address.NewFromString(cctx.Args().Get(0)) + if err != nil { + return err + } + + start, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64) + if err != nil { + return err + } + + duration, err := strconv.ParseUint(cctx.Args().Get(2), 10, 64) + if err != nil { + return err + } + + amount, err := types.ParseFIL(cctx.Args().Get(3)) + if err != nil { + return err + } + + var from address.Address + if cctx.IsSet("from") { + f, err := address.NewFromString(cctx.String("from")) + if err != nil { + return err + } + from = f + } else { + defaddr, err := api.WalletDefaultAddress(ctx) + if err != nil { + return err + } + from = defaddr + } + + params, actErr := actors.SerializeParams(&samsig.LockBalanceParams{ + StartEpoch: abi.ChainEpoch(start), + UnlockDuration: abi.ChainEpoch(duration), + Amount: abi.NewTokenAmount(amount.Int64()), + }) + + if actErr != nil { + return actErr + } + + msgCid, err := api.MsigPropose(ctx, msig, msig, big.Zero(), from, uint64(builtin.MethodsMultisig.LockBalance), params) + if err != nil { + return err + } + + fmt.Println("sent lock proposal in message: ", msgCid) + + wait, err := api.StateWaitMsg(ctx, msgCid, build.MessageConfidence) + if err != nil { + return err + } + + if wait.Receipt.ExitCode != 0 { + return fmt.Errorf("lock proposal returned exit %d", wait.Receipt.ExitCode) + } + + return nil + }, +} + var msigVestedCmd = &cli.Command{ Name: "vested", Usage: "Gets the amount vested in an msig between two epochs", From b20f558abba6790322ec6d206bd20ff6ded0e548 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 15 Sep 2020 19:51:18 -0400 Subject: [PATCH 2/5] Multisig: Add a CLI command to approve locking some balance --- cli/multisig.go | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/cli/multisig.go b/cli/multisig.go index 01e922a07..9ff1ad18e 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -1065,6 +1065,106 @@ var msigLockProposeCmd = &cli.Command{ }, } +var msigLockApproveCmd = &cli.Command{ + Name: "lock-approve", + Usage: "Approve a message to lock up some balance", + ArgsUsage: "[multisigAddress proposerAddress txId startEpoch unlockDuration amount]", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "from", + Usage: "account to send the approve message from", + }, + }, + Action: func(cctx *cli.Context) error { + if cctx.Args().Len() != 6 { + return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, tx id, start epoch, unlock duration, and amount")) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + msig, err := address.NewFromString(cctx.Args().Get(0)) + if err != nil { + return err + } + + prop, err := address.NewFromString(cctx.Args().Get(1)) + if err != nil { + return err + } + + txid, err := strconv.ParseUint(cctx.Args().Get(2), 10, 64) + if err != nil { + return err + } + + start, err := strconv.ParseUint(cctx.Args().Get(3), 10, 64) + if err != nil { + return err + } + + duration, err := strconv.ParseUint(cctx.Args().Get(4), 10, 64) + if err != nil { + return err + } + + amount, err := types.ParseFIL(cctx.Args().Get(5)) + if err != nil { + return err + } + + var from address.Address + if cctx.IsSet("from") { + f, err := address.NewFromString(cctx.String("from")) + if err != nil { + return err + } + from = f + } else { + defaddr, err := api.WalletDefaultAddress(ctx) + if err != nil { + return err + } + from = defaddr + } + + params, actErr := actors.SerializeParams(&samsig.LockBalanceParams{ + StartEpoch: abi.ChainEpoch(start), + UnlockDuration: abi.ChainEpoch(duration), + Amount: abi.NewTokenAmount(amount.Int64()), + }) + + if actErr != nil { + return actErr + } + + // It takes the following params: , , , , , + // , , + + msgCid, err := api.MsigApprove(ctx, msig, txid, prop, msig, big.Zero(), from, uint64(builtin.MethodsMultisig.LockBalance), params) + if err != nil { + return err + } + + fmt.Println("sent lock approval in message: ", msgCid) + + wait, err := api.StateWaitMsg(ctx, msgCid, build.MessageConfidence) + if err != nil { + return err + } + + if wait.Receipt.ExitCode != 0 { + return fmt.Errorf("lock approval returned exit %d", wait.Receipt.ExitCode) + } + + return nil + }, +} + var msigVestedCmd = &cli.Command{ Name: "vested", Usage: "Gets the amount vested in an msig between two epochs", From 2ca1d111c53b7dbab5da50adc0b6176b3dfed9f2 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 15 Sep 2020 19:52:58 -0400 Subject: [PATCH 3/5] Multisig: Add a CLI command to cancel locking some balance --- cli/multisig.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/cli/multisig.go b/cli/multisig.go index 9ff1ad18e..1f626ae7f 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -1142,9 +1142,6 @@ var msigLockApproveCmd = &cli.Command{ return actErr } - // It takes the following params: , , , , , - // , , - msgCid, err := api.MsigApprove(ctx, msig, txid, prop, msig, big.Zero(), from, uint64(builtin.MethodsMultisig.LockBalance), params) if err != nil { return err @@ -1165,6 +1162,98 @@ var msigLockApproveCmd = &cli.Command{ }, } +var msigLockCancelCmd = &cli.Command{ + Name: "lock-cancel", + Usage: "Cancel a message to lock up some balance", + ArgsUsage: "[multisigAddress txId startEpoch unlockDuration amount]", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "from", + Usage: "account to send the approve message from", + }, + }, + Action: func(cctx *cli.Context) error { + if cctx.Args().Len() != 6 { + return ShowHelp(cctx, fmt.Errorf("must pass multisig address, tx id, start epoch, unlock duration, and amount")) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + msig, err := address.NewFromString(cctx.Args().Get(0)) + if err != nil { + return err + } + + txid, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64) + if err != nil { + return err + } + + start, err := strconv.ParseUint(cctx.Args().Get(2), 10, 64) + if err != nil { + return err + } + + duration, err := strconv.ParseUint(cctx.Args().Get(3), 10, 64) + if err != nil { + return err + } + + amount, err := types.ParseFIL(cctx.Args().Get(4)) + if err != nil { + return err + } + + var from address.Address + if cctx.IsSet("from") { + f, err := address.NewFromString(cctx.String("from")) + if err != nil { + return err + } + from = f + } else { + defaddr, err := api.WalletDefaultAddress(ctx) + if err != nil { + return err + } + from = defaddr + } + + params, actErr := actors.SerializeParams(&samsig.LockBalanceParams{ + StartEpoch: abi.ChainEpoch(start), + UnlockDuration: abi.ChainEpoch(duration), + Amount: abi.NewTokenAmount(amount.Int64()), + }) + + if actErr != nil { + return actErr + } + + msgCid, err := api.MsigCancel(ctx, msig, txid, msig, big.Zero(), from, uint64(builtin.MethodsMultisig.LockBalance), params) + if err != nil { + return err + } + + fmt.Println("sent lock cancellation in message: ", msgCid) + + wait, err := api.StateWaitMsg(ctx, msgCid, build.MessageConfidence) + if err != nil { + return err + } + + if wait.Receipt.ExitCode != 0 { + return fmt.Errorf("lock cancellation returned exit %d", wait.Receipt.ExitCode) + } + + return nil + }, +} + var msigVestedCmd = &cli.Command{ Name: "vested", Usage: "Gets the amount vested in an msig between two epochs", From 130ae3ccb34fad93454faa2061129915fd1b6192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 24 Sep 2020 18:46:21 +0200 Subject: [PATCH 4/5] Multisig: Fix from flag descriptions --- cli/multisig.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/multisig.go b/cli/multisig.go index 944f67b2e..145f5ac41 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -968,7 +968,7 @@ var msigLockProposeCmd = &cli.Command{ Flags: []cli.Flag{ &cli.StringFlag{ Name: "from", - Usage: "account to send the approve message from", + Usage: "account to send the propose message from", }, }, Action: func(cctx *cli.Context) error { @@ -1152,7 +1152,7 @@ var msigLockCancelCmd = &cli.Command{ Flags: []cli.Flag{ &cli.StringFlag{ Name: "from", - Usage: "account to send the approve message from", + Usage: "account to send the cancel message from", }, }, Action: func(cctx *cli.Context) error { From cf9dfdb972f97251f604e9286f34450b2254085d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 24 Sep 2020 19:01:12 +0200 Subject: [PATCH 5/5] Multisig: fix build --- cli/multisig.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/multisig.go b/cli/multisig.go index 145f5ac41..5b0977382 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -20,6 +20,7 @@ import ( "github.com/urfave/cli/v2" "golang.org/x/xerrors" + "github.com/filecoin-project/specs-actors/actors/builtin" init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" @@ -1018,7 +1019,7 @@ var msigLockProposeCmd = &cli.Command{ from = defaddr } - params, actErr := actors.SerializeParams(&samsig.LockBalanceParams{ + params, actErr := actors.SerializeParams(&msig0.LockBalanceParams{ StartEpoch: abi.ChainEpoch(start), UnlockDuration: abi.ChainEpoch(duration), Amount: abi.NewTokenAmount(amount.Int64()), @@ -1115,7 +1116,7 @@ var msigLockApproveCmd = &cli.Command{ from = defaddr } - params, actErr := actors.SerializeParams(&samsig.LockBalanceParams{ + params, actErr := actors.SerializeParams(&msig0.LockBalanceParams{ StartEpoch: abi.ChainEpoch(start), UnlockDuration: abi.ChainEpoch(duration), Amount: abi.NewTokenAmount(amount.Int64()), @@ -1207,7 +1208,7 @@ var msigLockCancelCmd = &cli.Command{ from = defaddr } - params, actErr := actors.SerializeParams(&samsig.LockBalanceParams{ + params, actErr := actors.SerializeParams(&msig0.LockBalanceParams{ StartEpoch: abi.ChainEpoch(start), UnlockDuration: abi.ChainEpoch(duration), Amount: abi.NewTokenAmount(amount.Int64()),