client retrieval logging

This commit is contained in:
Ingar Shu
2020-08-11 13:04:00 -07:00
parent 01af855450
commit 53e06f358a
6 changed files with 116 additions and 39 deletions
+25 -4
View File
@@ -12,6 +12,7 @@ import (
"github.com/docker/go-units"
"github.com/fatih/color"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-cidutil/cidenc"
"github.com/libp2p/go-libp2p-core/peer"
@@ -837,12 +838,32 @@ var clientRetrieveCmd = &cli.Command{
Path: cctx.Args().Get(1),
IsCAR: cctx.Bool("car"),
}
if err := fapi.ClientRetrieve(ctx, offer.Order(payer), ref); err != nil {
return xerrors.Errorf("Retrieval Failed: %w", err)
updates, err := fapi.ClientRetrieve(ctx, offer.Order(payer), ref)
if err != nil {
return xerrors.Errorf("error setting up retrieval: %w", err)
}
fmt.Println("Success")
return nil
for {
select {
case evt, chOpen := <-updates:
fmt.Printf("Retrieval Event: %s, State: %s, BytesReceived: %d, PaymentSent: %s\n",
retrievalmarket.ClientEvents[evt.Event],
retrievalmarket.DealStatuses[evt.Status],
evt.BytesReceived,
evt.FundsSpent.String(),
)
if !chOpen {
fmt.Println("Success")
return nil
}
if evt.Err != nil {
return xerrors.Errorf("Retrieval Failed: %w", err)
}
}
}
},
}