@@ -10,10 +10,13 @@ import (
1010 "reflect"
1111 "time"
1212
13+ "github.com/filecoin-project/go-address"
14+ "github.com/filecoin-project/lotus/api"
15+ str "github.com/filecoin-project/lotus/chain/store"
16+ "github.com/filecoin-project/lotus/chain/types"
1317 "github.com/ipfs/go-cid"
1418 "github.com/ipfs/go-datastore"
1519 logging "github.com/ipfs/go-log"
16- "github.com/textileio/filecoin/lotus/types"
1720)
1821
1922const (
2831// Module exposes storage, monitoring, and Asks from the market.
2932type Module struct {
3033 api API
31- ds datastore.Datastore
3234 basePathImport string
3335}
3436
@@ -54,35 +56,31 @@ type DealInfo struct {
5456
5557// API interacts with a Filecoin full-node
5658type API interface {
57- ClientStartDeal (ctx context.Context , data cid.Cid , addr string , miner string , epochPrice types.BigInt , blocksDuration uint64 ) (* cid.Cid , error )
59+ ClientStartDeal (ctx context.Context , data cid.Cid , addr address. Address , miner address. Address , price types.BigInt , blocksDuration uint64 ) (* cid.Cid , error )
5860 ClientImport (ctx context.Context , path string ) (cid.Cid , error )
59- ClientGetDealInfo (context.Context , cid.Cid ) (* types .DealInfo , error )
60- ChainNotify (context.Context ) (<- chan []* types .HeadChange , error )
61+ ClientGetDealInfo (context.Context , cid.Cid ) (* api .DealInfo , error )
62+ ChainNotify (ctx context.Context ) (<- chan []* str .HeadChange , error )
6163}
6264
6365// New creates a new deal module
6466func New (ds datastore.Datastore , api API ) * Module {
6567 // can't avoid home base path, ipfs checks: cannot add filestore references outside ipfs root (home folder)
66- home , err := os .UserHomeDir ()
67- if err != nil {
68- panic (err )
69- }
68+ home := os .TempDir ()
69+ os .MkdirAll (filepath .Join (home , "textilefc" ), os .ModePerm )
7070 dm := & Module {
7171 api : api ,
72- ds : ds ,
7372 basePathImport : filepath .Join (home , "textilefc" ),
7473 }
7574 return dm
7675}
7776
7877// Store creates a proposal deal for data using wallet addr to all miners indicated
7978// by dealConfigs for duration epochs
80- func (m * Module ) Store (ctx context.Context , addr string , data io.Reader , dealConfigs []DealConfig , duration uint64 ) ([]cid.Cid , []DealConfig , error ) {
79+ func (m * Module ) Store (ctx context.Context , strAddr string , data io.Reader , dealConfigs []DealConfig , duration uint64 ) ([]cid.Cid , []DealConfig , error ) {
8180 tmpF , err := ioutil .TempFile (m .basePathImport , "import-*" )
8281 if err != nil {
8382 return nil , nil , fmt .Errorf ("error when creating tmpfile: %s" , err )
8483 }
85- defer os .Remove (tmpF .Name ())
8684 defer tmpF .Close ()
8785 if _ , err := io .Copy (tmpF , data ); err != nil {
8886 return nil , nil , fmt .Errorf ("error when copying data to tmpfile: %s" , err )
@@ -91,19 +89,24 @@ func (m *Module) Store(ctx context.Context, addr string, data io.Reader, dealCon
9189 if err != nil {
9290 return nil , nil , fmt .Errorf ("error when importing data: %s" , err )
9391 }
92+ addr , err := address .NewFromString (strAddr )
93+ if err != nil {
94+ return nil , nil , err
95+ }
9496
9597 var proposals []cid.Cid
9698 var failed []DealConfig
97- for _ , dconfig := range dealConfigs {
99+ for _ , c := range dealConfigs {
100+ maddr , err := address .NewFromString (c .Miner )
98101 if err != nil {
99- log .Errorf ("miner addr is invalid %v: %s" , dconfig , err )
100- failed = append (failed , dconfig )
102+ log .Errorf ("invalid miner address %v: %s" , c , err )
103+ failed = append (failed , c )
101104 continue
102105 }
103- proposal , err := m .api .ClientStartDeal (ctx , dataCid , addr , dconfig . Miner , dconfig .EpochPrice , duration )
106+ proposal , err := m .api .ClientStartDeal (ctx , dataCid , addr , maddr , c .EpochPrice , duration )
104107 if err != nil {
105- log .Errorf ("error when starting deal with %v: %s" , dconfig , err )
106- failed = append (failed , dconfig )
108+ log .Errorf ("starting deal with %v: %s" , c , err )
109+ failed = append (failed , c )
107110 continue
108111 }
109112 proposals = append (proposals , * proposal )
@@ -121,7 +124,7 @@ func (m *Module) Watch(ctx context.Context, proposals []cid.Cid) (<-chan DealInf
121124 go func () {
122125 defer close (ch )
123126
124- currentState := make (map [cid.Cid ]types .DealInfo )
127+ currentState := make (map [cid.Cid ]api .DealInfo )
125128 tout := time .After (initialWait )
126129 for {
127130 select {
@@ -141,7 +144,7 @@ func (m *Module) Watch(ctx context.Context, proposals []cid.Cid) (<-chan DealInf
141144 return ch , nil
142145}
143146
144- func (m * Module ) pushNewChanges (ctx context.Context , currState map [cid.Cid ]types .DealInfo , proposals []cid.Cid , ch chan <- DealInfo ) error {
147+ func (m * Module ) pushNewChanges (ctx context.Context , currState map [cid.Cid ]api .DealInfo , proposals []cid.Cid , ch chan <- DealInfo ) error {
145148 for _ , pcid := range proposals {
146149 dinfo , err := m .api .ClientGetDealInfo (ctx , pcid )
147150 if err != nil {
@@ -153,8 +156,8 @@ func (m *Module) pushNewChanges(ctx context.Context, currState map[cid.Cid]types
153156 newState := DealInfo {
154157 ProposalCid : dinfo .ProposalCid ,
155158 StateID : dinfo .State ,
156- StateName : types .DealStates [dinfo .State ],
157- Miner : dinfo .Provider ,
159+ StateName : api .DealStates [dinfo .State ],
160+ Miner : dinfo .Provider . String () ,
158161 PieceRef : dinfo .PieceRef ,
159162 Size : dinfo .Size ,
160163 PricePerEpoch : dinfo .PricePerEpoch ,
0 commit comments