Merge pull request #4556 from filecoin-project/fix/marketwithdraw-miner
Make wallet market withdraw usable with miner addresses
This commit is contained in:
commit
74bf4c5e71
@ -525,6 +525,11 @@ var walletMarketWithdraw = &cli.Command{
|
|||||||
Usage: "Specify address to withdraw funds from, otherwise it will use the default wallet address",
|
Usage: "Specify address to withdraw funds from, otherwise it will use the default wallet address",
|
||||||
Aliases: []string{"f"},
|
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 {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
@ -534,19 +539,27 @@ var walletMarketWithdraw = &cli.Command{
|
|||||||
defer closer()
|
defer closer()
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
var addr address.Address
|
var from address.Address
|
||||||
if cctx.String("from") != "" {
|
if cctx.String("from") != "" {
|
||||||
addr, err = address.NewFromString(cctx.String("from"))
|
from, err = address.NewFromString(cctx.String("from"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("parsing from address: %w", err)
|
return xerrors.Errorf("parsing from address: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addr, err = api.WalletDefaultAddress(ctx)
|
from, err = api.WalletDefaultAddress(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("getting default wallet address: %w", err)
|
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)
|
bal, err := api.StateMarketBalance(ctx, addr, types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("getting market balance for address %s: %w", addr.String(), err)
|
return xerrors.Errorf("getting market balance for address %s: %w", addr.String(), err)
|
||||||
@ -565,7 +578,7 @@ var walletMarketWithdraw = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if amt.GreaterThan(avail) {
|
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() {
|
if avail.IsZero() {
|
||||||
@ -580,10 +593,10 @@ var walletMarketWithdraw = &cli.Command{
|
|||||||
return xerrors.Errorf("serializing params: %w", err)
|
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{
|
smsg, err := api.MpoolPushMessage(ctx, &types.Message{
|
||||||
To: builtin.StorageMarketActorAddr,
|
To: builtin.StorageMarketActorAddr,
|
||||||
From: addr,
|
From: from,
|
||||||
Value: types.NewInt(0),
|
Value: types.NewInt(0),
|
||||||
Method: builtin.MethodsMarket.WithdrawBalance,
|
Method: builtin.MethodsMarket.WithdrawBalance,
|
||||||
Params: params,
|
Params: params,
|
||||||
|
Loading…
Reference in New Issue
Block a user