deals: Show proposal cid in cli

This commit is contained in:
Łukasz Magiera 2019-08-07 22:06:10 +02:00 committed by whyrusleeping
parent 821e03bcd7
commit 2114e8f555
4 changed files with 31 additions and 21 deletions

View File

@ -116,8 +116,7 @@ type FullNode interface {
// ClientImport imports file under the specified path into filestore // ClientImport imports file under the specified path into filestore
ClientImport(ctx context.Context, path string) (cid.Cid, error) ClientImport(ctx context.Context, path string) (cid.Cid, error)
ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error)
ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, blocksDuration uint64) error
// ClientUnimport removes references to the specified file from filestore // ClientUnimport removes references to the specified file from filestore
//ClientUnimport(path string) //ClientUnimport(path string)

View File

@ -62,9 +62,9 @@ type FullNodeStruct struct {
WalletDefaultAddress func(context.Context) (address.Address, error) `perm:"write"` WalletDefaultAddress func(context.Context) (address.Address, error) `perm:"write"`
MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"` MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"`
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"write"` ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"write"`
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"` ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"`
ClientStartDeal func(ctx context.Context, data cid.Cid, miner address.Address, blocksDuration uint64) error `perm:"admin"` ClientStartDeal func(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) `perm:"admin"`
StateMinerSectors func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"` StateMinerProvingSet func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
@ -129,8 +129,8 @@ func (c *FullNodeStruct) ClientImport(ctx context.Context, path string) (cid.Cid
return c.Internal.ClientImport(ctx, path) return c.Internal.ClientImport(ctx, path)
} }
func (c *FullNodeStruct) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, blocksDuration uint64) error { 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, blocksDuration) return c.Internal.ClientStartDeal(ctx, data, miner, price, blocksDuration)
} }
func (c *FullNodeStruct) MpoolPending(ctx context.Context, ts *types.TipSet) ([]*types.SignedMessage, error) { func (c *FullNodeStruct) MpoolPending(ctx context.Context, ts *types.TipSet) ([]*types.SignedMessage, error) {

View File

@ -9,6 +9,7 @@ import (
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/types"
) )
var clientCmd = &cli.Command{ var clientCmd = &cli.Command{
@ -71,8 +72,8 @@ var clientDealCmd = &cli.Command{
} }
ctx := ReqContext(cctx) ctx := ReqContext(cctx)
if cctx.NArg() != 3 { if cctx.NArg() != 4 {
return xerrors.New("expected 3 args: dataCid, miner, duration") return xerrors.New("expected 4 args: dataCid, miner, price, duration")
} }
// [data, miner, dur] // [data, miner, dur]
@ -87,11 +88,23 @@ var clientDealCmd = &cli.Command{
return err return err
} }
dur, err := strconv.ParseInt(cctx.Args().Get(2), 10, 32) // TODO: parse bigint
price, err := strconv.ParseInt(cctx.Args().Get(2), 10, 32)
if err != nil { if err != nil {
return err return err
} }
return api.ClientStartDeal(ctx, data, miner, uint64(dur)) dur, err := strconv.ParseInt(cctx.Args().Get(3), 10, 32)
if err != nil {
return err
}
proposal, err := api.ClientStartDeal(ctx, data, miner, types.NewInt(uint64(price)), uint64(dur))
if err != nil {
return err
}
fmt.Println(proposal)
return nil
}, },
} }

View File

@ -5,8 +5,6 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain" "github.com/filecoin-project/go-lotus/chain"
"github.com/filecoin-project/go-lotus/chain/actors" "github.com/filecoin-project/go-lotus/chain/actors"
@ -27,6 +25,7 @@ import (
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
"golang.org/x/xerrors"
) )
var log = logging.Logger("node") var log = logging.Logger("node")
@ -43,10 +42,10 @@ type FullNodeAPI struct {
Wallet *wallet.Wallet Wallet *wallet.Wallet
} }
func (a *FullNodeAPI) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, blocksDuration uint64) error { func (a *FullNodeAPI) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) {
self, err := a.WalletDefaultAddress(ctx) self, err := a.WalletDefaultAddress(ctx)
if err != nil { if err != nil {
return err return nil, err
} }
msg := &types.Message{ msg := &types.Message{
@ -57,17 +56,16 @@ func (a *FullNodeAPI) ClientStartDeal(ctx context.Context, data cid.Cid, miner a
r, err := a.ChainCall(ctx, msg, nil) r, err := a.ChainCall(ctx, msg, nil)
if err != nil { if err != nil {
return err return nil, err
} }
pid, err := peer.IDFromBytes(r.Return) pid, err := peer.IDFromBytes(r.Return)
if err != nil { if err != nil {
return err return nil, err
} }
price := types.NewInt(10 * blocksDuration) // TODO: allow to actually specify this total := types.BigMul(price, types.NewInt(blocksDuration))
c, err := a.DealClient.Start(ctx, data, total, self, miner, pid, blocksDuration)
_, err = a.DealClient.Start(ctx, data, price, self, miner, pid, blocksDuration) return &c, err
return err
} }
func (a *FullNodeAPI) ChainNotify(ctx context.Context) (<-chan *store.HeadChange, error) { func (a *FullNodeAPI) ChainNotify(ctx context.Context) (<-chan *store.HeadChange, error) {