From 13c8a235b64697d1e000eb0ee51e9e1bda74869e Mon Sep 17 00:00:00 2001 From: Ingar Shu Date: Thu, 3 Dec 2020 12:47:26 -0800 Subject: [PATCH 1/2] Use FundManager to withdraw funds, add MarketWithdraw to API --- api/api_full.go | 2 ++ api/apistruct/struct.go | 5 +++++ cli/wallet.go | 25 ++++--------------------- node/impl/market/market.go | 7 ++++++- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 1edebc4a644..4cda4716260 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -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 diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index cca498bf528..c6c74a34ee0 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -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"` @@ -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) } diff --git a/cli/wallet.go b/cli/wallet.go index f6368cbfa44..e9b8e6ece3e 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -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" ) @@ -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 }, diff --git a/node/impl/market/market.go b/node/impl/market/market.go index 9e75a4db7ce..e7fccc9ba6e 100644 --- a/node/impl/market/market.go +++ b/node/impl/market/market.go @@ -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 { @@ -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) +} From 65abeb066df9abe99fec6ea75a84475d8f3f6f7f Mon Sep 17 00:00:00 2001 From: Ingar Shu Date: Thu, 3 Dec 2020 13:20:50 -0800 Subject: [PATCH 2/2] docs --- documentation/en/api-methods.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index 04998b27e4d..5ddaddb350e 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -70,6 +70,7 @@ * [Market](#Market) * [MarketReleaseFunds](#MarketReleaseFunds) * [MarketReserveFunds](#MarketReserveFunds) + * [MarketWithdraw](#MarketWithdraw) * [Miner](#Miner) * [MinerCreateBlock](#MinerCreateBlock) * [MinerGetBaseInfo](#MinerGetBaseInfo) @@ -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: