From 40289848c673829e2261b987bc3da6893db3c191 Mon Sep 17 00:00:00 2001 From: jsign Date: Fri, 13 Dec 2019 16:15:56 -0300 Subject: [PATCH] client: make wallet addr be a param in ClientStartDeal Signed-off-by: jsign --- api/api_full.go | 2 +- api/apistruct/struct.go | 22 +++++++++++----------- api/test/deals.go | 6 +++++- cli/client.go | 6 +++++- node/impl/client/client.go | 12 +++++++----- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index db1ab9a3c..06739ade8 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -73,7 +73,7 @@ type FullNode interface { // ClientImport imports file under the specified path into filestore ClientImport(ctx context.Context, path string) (cid.Cid, error) - ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, epochPrice types.BigInt, blocksDuration uint64) (*cid.Cid, error) + ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Address, miner address.Address, epochPrice types.BigInt, blocksDuration uint64) (*cid.Cid, error) ClientGetDealInfo(context.Context, cid.Cid) (*DealInfo, error) ClientListDeals(ctx context.Context) ([]DealInfo, error) ClientHasLocal(ctx context.Context, root cid.Cid) (bool, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index c8582d986..eb8327d60 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -77,15 +77,15 @@ type FullNodeStruct struct { WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"` WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"` - ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"admin"` - ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"` - ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"` - ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"` - ClientStartDeal func(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) `perm:"admin"` - ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"` - ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"` - ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, path string) error `perm:"admin"` - ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*types.SignedStorageAsk, error) `perm:"read"` + ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"admin"` + ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"` + ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"` + ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"` + ClientStartDeal func(ctx context.Context, data cid.Cid, addr address.Address, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) `perm:"admin"` + ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"` + ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"` + ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, path string) error `perm:"admin"` + ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*types.SignedStorageAsk, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerProvingSet func(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error) `perm:"read"` @@ -208,8 +208,8 @@ func (c *FullNodeStruct) ClientFindData(ctx context.Context, root cid.Cid) ([]ap return c.Internal.ClientFindData(ctx, root) } -func (c *FullNodeStruct) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) { - return c.Internal.ClientStartDeal(ctx, data, miner, price, blocksDuration) +func (c *FullNodeStruct) ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Address, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) { + return c.Internal.ClientStartDeal(ctx, data, addr, miner, price, blocksDuration) } func (c *FullNodeStruct) ClientGetDealInfo(ctx context.Context, deal cid.Cid) (*api.DealInfo, error) { return c.Internal.ClientGetDealInfo(ctx, deal) diff --git a/api/test/deals.go b/api/test/deals.go index 237a8f627..b9ff2611f 100644 --- a/api/test/deals.go +++ b/api/test/deals.go @@ -71,7 +71,11 @@ func TestDealFlow(t *testing.T, b APIBuilder) { } } }() - deal, err := client.ClientStartDeal(ctx, fcid, maddr, types.NewInt(40000000), 100) + addr, err := client.WalletDefaultAddress(ctx) + if err != nil { + t.Fatal(err) + } + deal, err := client.ClientStartDeal(ctx, fcid, addr, maddr, types.NewInt(40000000), 100) if err != nil { t.Fatal(err) } diff --git a/cli/client.go b/cli/client.go index 61848951a..f2ceb60dc 100644 --- a/cli/client.go +++ b/cli/client.go @@ -115,7 +115,11 @@ var clientDealCmd = &cli.Command{ return err } - proposal, err := api.ClientStartDeal(ctx, data, miner, types.BigInt(price), uint64(dur)) + a, err := api.WalletDefaultAddress(ctx) + if err != nil { + return err + } + proposal, err := api.ClientStartDeal(ctx, data, a, miner, types.BigInt(price), uint64(dur)) if err != nil { return err } diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 8f31df6cd..66a9e2473 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -53,11 +53,13 @@ type API struct { Filestore dtypes.ClientFilestore `optional:"true"` } -func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, epochPrice types.BigInt, blocksDuration uint64) (*cid.Cid, error) { - // TODO: make this a param - self, err := a.WalletDefaultAddress(ctx) +func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Address, miner address.Address, epochPrice types.BigInt, blocksDuration uint64) (*cid.Cid, error) { + exist, err := a.WalletHas(ctx, addr) if err != nil { - return nil, xerrors.Errorf("failed to get default address: %w", err) + return nil, xerrors.Errorf("failed getting addr from wallet: %w", addr) + } + if !exist { + return nil, xerrors.Errorf("provided address doesn't exist in wallet") } pid, err := a.StateMinerPeerID(ctx, miner, nil) @@ -75,7 +77,7 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.A PricePerEpoch: epochPrice, ProposalExpiration: math.MaxUint64, // TODO: set something reasonable Duration: blocksDuration, - Client: self, + Client: addr, ProviderAddress: miner, MinerWorker: mw, MinerID: pid,