From b7b6ab779ae5607a0a9b398b82652510b7ff0e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 23 Oct 2020 14:54:52 +0200 Subject: [PATCH] Make wallet market withdraw usable with miner addresses --- cli/wallet.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/cli/wallet.go b/cli/wallet.go index f231f345406..2501618f844 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -495,6 +495,11 @@ var walletMarketWithdraw = &cli.Command{ Usage: "Specify address to withdraw funds from, otherwise it will use the default wallet address", Aliases: []string{"f"}, }, + &cli.StringFlag{ + Name: "address", + Usage: "Market address to withdraw from (account or miner actor address, defaults to --from address)", + Aliases: []string{"a"}, + }, }, Action: func(cctx *cli.Context) error { api, closer, err := GetFullNodeAPI(cctx) @@ -504,19 +509,27 @@ var walletMarketWithdraw = &cli.Command{ defer closer() ctx := ReqContext(cctx) - var addr address.Address + var from address.Address if cctx.String("from") != "" { - addr, err = address.NewFromString(cctx.String("from")) + from, err = address.NewFromString(cctx.String("from")) if err != nil { return xerrors.Errorf("parsing from address: %w", err) } } else { - addr, err = api.WalletDefaultAddress(ctx) + from, err = api.WalletDefaultAddress(ctx) if err != nil { return xerrors.Errorf("getting default wallet address: %w", err) } } + addr := from + if cctx.String("address") != "" { + addr, err = address.NewFromString(cctx.String("address")) + if err != nil { + return xerrors.Errorf("parsing market address: %w", err) + } + } + bal, err := api.StateMarketBalance(ctx, addr, types.EmptyTSK) if err != nil { return xerrors.Errorf("getting market balance for address %s: %w", addr.String(), err) @@ -535,7 +548,7 @@ var walletMarketWithdraw = &cli.Command{ } if amt.GreaterThan(avail) { - return xerrors.Errorf("can't withdraw more funds than available; requested: %s; available: %s", amt, avail) + return xerrors.Errorf("can't withdraw more funds than available; requested: %s; available: %s", types.FIL(amt), types.FIL(avail)) } if avail.IsZero() { @@ -550,10 +563,10 @@ var walletMarketWithdraw = &cli.Command{ return xerrors.Errorf("serializing params: %w", err) } - fmt.Printf("Submitting WithdrawBalance message for amount %s for address %s\n", types.FIL(amt), addr.String()) + fmt.Printf("Submitting WithdrawBalance message for amount %s for address %s\n", types.FIL(amt), from.String()) smsg, err := api.MpoolPushMessage(ctx, &types.Message{ To: builtin.StorageMarketActorAddr, - From: addr, + From: from, Value: types.NewInt(0), Method: builtin.MethodsMarket.WithdrawBalance, Params: params,