@@ -6,18 +6,16 @@ import (
66 "io"
77 "io/ioutil"
88 "os"
9+ "path/filepath"
910 "reflect"
1011 "sync"
1112 "time"
1213
13- "github.com/filecoin-project/lotus/api"
14- "github.com/filecoin-project/lotus/chain/address"
15- "github.com/filecoin-project/lotus/chain/store"
16- "github.com/filecoin-project/lotus/chain/types"
1714 "github.com/ipfs/go-cid"
1815 "github.com/ipfs/go-datastore"
1916 logging "github.com/ipfs/go-log"
2017 peer "github.com/libp2p/go-libp2p-core/peer"
18+ "github.com/textileio/filecoin/lotus/types"
2119)
2220
2321const (
@@ -34,19 +32,20 @@ var (
3432
3533// DealerAPI interacts with a Filecoin full-node
3634type DealerAPI interface {
37- ClientStartDeal (ctx context.Context , data cid.Cid , addr address. Address , miner address. Address , epochPrice types.BigInt , blocksDuration uint64 ) (* cid.Cid , error )
35+ ClientStartDeal (ctx context.Context , data cid.Cid , addr string , miner string , epochPrice types.BigInt , blocksDuration uint64 ) (* cid.Cid , error )
3836 ClientImport (ctx context.Context , path string ) (cid.Cid , error )
39- ClientGetDealInfo (context.Context , cid.Cid ) (* api .DealInfo , error )
40- ChainNotify (context.Context ) (<- chan [] * store. HeadChange , error )
41- StateListMiners (context.Context , * types.TipSet ) ([]address. Address , error )
42- ClientQueryAsk (ctx context.Context , p peer.ID , miner address. Address ) (* types.SignedStorageAsk , error )
43- StateMinerPeerID (ctx context.Context , m address. Address , ts * types.TipSet ) (peer.ID , error )
37+ ClientGetDealInfo (context.Context , cid.Cid ) (* types .DealInfo , error )
38+ ChainNotify (context.Context ) (<- chan struct {} , error )
39+ StateListMiners (context.Context , * types.TipSet ) ([]string , error )
40+ ClientQueryAsk (ctx context.Context , p peer.ID , miner string ) (* types.SignedStorageAsk , error )
41+ StateMinerPeerID (ctx context.Context , m string , ts * types.TipSet ) (peer.ID , error )
4442}
4543
4644// DealModule exposes storage, monitoring, and Asks from the market.
4745type DealModule struct {
48- api DealerAPI
49- ds datastore.Datastore
46+ api DealerAPI
47+ ds datastore.Datastore
48+ basePathImport string
5049
5150 askCacheLock sync.RWMutex
5251 askCache []* types.StorageAsk
@@ -79,11 +78,17 @@ type DealInfo struct {
7978
8079// New creates a new deal module
8180func New (api DealerAPI , ds datastore.Datastore ) * DealModule {
81+ // can't avoid home base path, ipfs checks: cannot add filestore references outside ipfs root (home folder)
82+ home , err := os .UserHomeDir ()
83+ if err != nil {
84+ panic (err )
85+ }
8286 dm := & DealModule {
83- api : api ,
84- ds : ds ,
85- close : make (chan struct {}),
86- closed : make (chan struct {}),
87+ api : api ,
88+ ds : ds ,
89+ basePathImport : filepath .Join (home , "textilefc" ),
90+ close : make (chan struct {}),
91+ closed : make (chan struct {}),
8792 }
8893 go dm .runBackgroundAskCache ()
8994 return dm
@@ -104,7 +109,7 @@ func (d *DealModule) Close() {
104109// Store creates a proposal deal for data using wallet addr to all miners indicated
105110// by dealConfigs for duration epochs
106111func (d * DealModule ) Store (ctx context.Context , addr string , data io.Reader , dealConfigs []DealConfig , duration uint64 ) ([]cid.Cid , []DealConfig , error ) {
107- tmpF , err := ioutil .TempFile ("" , "import-*" )
112+ tmpF , err := ioutil .TempFile (d . basePathImport , "import-*" )
108113 if err != nil {
109114 return nil , nil , fmt .Errorf ("error when creating tmpfile: %s" , err )
110115 }
@@ -118,20 +123,15 @@ func (d *DealModule) Store(ctx context.Context, addr string, data io.Reader, dea
118123 return nil , nil , fmt .Errorf ("error when importing data: %s" , err )
119124 }
120125
121- myAddr , err := address .NewFromString (addr )
122- if err != nil {
123- return nil , nil , fmt .Errorf ("wallet addr is invalid: %s" , err )
124- }
125126 var proposals []cid.Cid
126127 var failed []DealConfig
127128 for _ , dconfig := range dealConfigs {
128- minerAddr , err := address .NewFromString (dconfig .Miner )
129129 if err != nil {
130130 log .Errorf ("miner addr is invalid %v: %s" , dconfig , err )
131131 failed = append (failed , dconfig )
132132 continue
133133 }
134- proposal , err := d .api .ClientStartDeal (ctx , dataCid , myAddr , minerAddr , dconfig .EpochPrice , duration )
134+ proposal , err := d .api .ClientStartDeal (ctx , dataCid , addr , dconfig . Miner , dconfig .EpochPrice , duration )
135135 if err != nil {
136136 log .Errorf ("error when starting deal with %v: %s" , dconfig , err )
137137 failed = append (failed , dconfig )
@@ -152,7 +152,7 @@ func (d *DealModule) Watch(ctx context.Context, proposals []cid.Cid) (<-chan Dea
152152 go func () {
153153 defer close (ch )
154154
155- currentState := make (map [cid.Cid ]api .DealInfo )
155+ currentState := make (map [cid.Cid ]types .DealInfo )
156156 tout := time .After (initialWait )
157157 for {
158158 select {
@@ -172,7 +172,7 @@ func (d *DealModule) Watch(ctx context.Context, proposals []cid.Cid) (<-chan Dea
172172 return ch , nil
173173}
174174
175- func (d * DealModule ) pushNewChanges (ctx context.Context , currState map [cid.Cid ]api .DealInfo , proposals []cid.Cid , ch chan <- DealInfo ) error {
175+ func (d * DealModule ) pushNewChanges (ctx context.Context , currState map [cid.Cid ]types .DealInfo , proposals []cid.Cid , ch chan <- DealInfo ) error {
176176 for _ , pcid := range proposals {
177177 dinfo , err := d .api .ClientGetDealInfo (ctx , pcid )
178178 if err != nil {
@@ -184,8 +184,8 @@ func (d *DealModule) pushNewChanges(ctx context.Context, currState map[cid.Cid]a
184184 newState := DealInfo {
185185 ProposalCid : dinfo .ProposalCid ,
186186 StateID : dinfo .State ,
187- StateName : api .DealStates [dinfo .State ],
188- Miner : dinfo .Provider . String () ,
187+ StateName : types .DealStates [dinfo .State ],
188+ Miner : dinfo .Provider ,
189189 PieceRef : dinfo .PieceRef ,
190190 Size : dinfo .Size ,
191191 PricePerEpoch : dinfo .PricePerEpoch ,
0 commit comments