Skip to content

Commit

Permalink
Make wallet market withdraw usable with miner addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Oct 23, 2020
1 parent 7d9e8f9 commit b7b6ab7
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cli/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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() {
Expand All @@ -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,
Expand Down

0 comments on commit b7b6ab7

Please sign in to comment.