Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FundManager to withdraw funds, add MarketWithdraw API #5112

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ type FullNode interface {
MarketReserveFunds(ctx context.Context, wallet address.Address, addr address.Address, amt types.BigInt) (cid.Cid, error)
// MarketReleaseFunds releases funds reserved by MarketReserveFunds
MarketReleaseFunds(ctx context.Context, addr address.Address, amt types.BigInt) error
// MarketWithdraw withdraws unlocked funds from the market actor
MarketWithdraw(ctx context.Context, wallet, addr address.Address, amt types.BigInt) (cid.Cid, error)

// MethodGroup: Paych
// The Paych methods are for interacting with and managing payment channels
Expand Down
5 changes: 5 additions & 0 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ type FullNodeStruct struct {

MarketReserveFunds func(ctx context.Context, wallet address.Address, addr address.Address, amt types.BigInt) (cid.Cid, error) `perm:"sign"`
MarketReleaseFunds func(ctx context.Context, addr address.Address, amt types.BigInt) error `perm:"sign"`
MarketWithdraw func(ctx context.Context, wallet, addr address.Address, amt types.BigInt) (cid.Cid, error) `perm:"sign"`

PaychGet func(ctx context.Context, from, to address.Address, amt types.BigInt) (*api.ChannelInfo, error) `perm:"sign"`
PaychGetWaitReady func(context.Context, cid.Cid) (address.Address, error) `perm:"sign"`
Expand Down Expand Up @@ -1149,6 +1150,10 @@ func (c *FullNodeStruct) MarketReleaseFunds(ctx context.Context, addr address.Ad
return c.Internal.MarketReleaseFunds(ctx, addr, amt)
}

func (c *FullNodeStruct) MarketWithdraw(ctx context.Context, wallet, addr address.Address, amt types.BigInt) (cid.Cid, error) {
return c.Internal.MarketWithdraw(ctx, wallet, addr, amt)
}

func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, amt types.BigInt) (*api.ChannelInfo, error) {
return c.Internal.PaychGet(ctx, from, to, amt)
}
Expand Down
25 changes: 4 additions & 21 deletions cli/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/v2/actors/builtin"

"github.com/filecoin-project/lotus/chain/actors"
types "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/tablewriter"
)

Expand Down Expand Up @@ -585,27 +582,13 @@ var walletMarketWithdraw = &cli.Command{
return xerrors.Errorf("zero unlocked funds available to withdraw")
}

params, err := actors.SerializeParams(&market.WithdrawBalanceParams{
ProviderOrClientAddress: addr,
Amount: amt,
})
if err != nil {
return xerrors.Errorf("serializing params: %w", err)
}

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: from,
Value: types.NewInt(0),
Method: builtin.MethodsMarket.WithdrawBalance,
Params: params,
}, nil)
smsg, err := api.MarketWithdraw(ctx, from, addr, amt)
if err != nil {
return xerrors.Errorf("submitting WithdrawBalance message: %w", err)
return xerrors.Errorf("fund manager withdraw error: %w", err)
}

fmt.Printf("WithdrawBalance message cid: %s\n", smsg.Cid())
fmt.Printf("WithdrawBalance message cid: %s\n", smsg)

return nil
},
Expand Down
23 changes: 23 additions & 0 deletions documentation/en/api-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
* [Market](#Market)
* [MarketReleaseFunds](#MarketReleaseFunds)
* [MarketReserveFunds](#MarketReserveFunds)
* [MarketWithdraw](#MarketWithdraw)
* [Miner](#Miner)
* [MinerCreateBlock](#MinerCreateBlock)
* [MinerGetBaseInfo](#MinerGetBaseInfo)
Expand Down Expand Up @@ -1636,6 +1637,28 @@ Response: `{}`
MarketReserveFunds reserves funds for a deal


Perms: sign

Inputs:
```json
[
"f01234",
"f01234",
"0"
]
```

Response:
```json
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
```

### MarketWithdraw
MarketWithdraw withdraws unlocked funds from the market actor


Perms: sign

Inputs:
Expand Down
7 changes: 6 additions & 1 deletion node/impl/market/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (

"go.uber.org/fx"

"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/market"
"github.com/filecoin-project/lotus/chain/types"
"github.com/ipfs/go-cid"
)

type MarketAPI struct {
Expand All @@ -24,3 +25,7 @@ func (a *MarketAPI) MarketReserveFunds(ctx context.Context, wallet address.Addre
func (a *MarketAPI) MarketReleaseFunds(ctx context.Context, addr address.Address, amt types.BigInt) error {
return a.FMgr.Release(addr, amt)
}

func (a *MarketAPI) MarketWithdraw(ctx context.Context, wallet, addr address.Address, amt types.BigInt) (cid.Cid, error) {
return a.FMgr.Withdraw(ctx, wallet, addr, amt)
}