Merge pull request #5150 from filecoin-project/feat/list-deals-xfer-id
show data transfer ID in list-deals
This commit is contained in:
+66
-46
@@ -184,55 +184,57 @@ func (a *API) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get a map of transfer ID => DataTransfer
|
||||
dataTransfersByID, err := a.transfersByID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := make([]api.DealInfo, len(deals))
|
||||
for k, v := range deals {
|
||||
out[k] = api.DealInfo{
|
||||
ProposalCid: v.ProposalCid,
|
||||
DataRef: v.DataRef,
|
||||
State: v.State,
|
||||
Message: v.Message,
|
||||
Provider: v.Proposal.Provider,
|
||||
|
||||
PieceCID: v.Proposal.PieceCID,
|
||||
Size: uint64(v.Proposal.PieceSize.Unpadded()),
|
||||
|
||||
PricePerEpoch: v.Proposal.StoragePricePerEpoch,
|
||||
Duration: uint64(v.Proposal.Duration()),
|
||||
DealID: v.DealID,
|
||||
CreationTime: v.CreationTime.Time(),
|
||||
Verified: v.Proposal.VerifiedDeal,
|
||||
// Find the data transfer associated with this deal
|
||||
var transferCh *api.DataTransferChannel
|
||||
if v.TransferChannelID != nil {
|
||||
if ch, ok := dataTransfersByID[*v.TransferChannelID]; ok {
|
||||
transferCh = &ch
|
||||
}
|
||||
}
|
||||
|
||||
out[k] = a.newDealInfoWithTransfer(transferCh, v)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (a *API) transfersByID(ctx context.Context) (map[datatransfer.ChannelID]api.DataTransferChannel, error) {
|
||||
inProgressChannels, err := a.DataTransfer.InProgressChannels(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dataTransfersByID := make(map[datatransfer.ChannelID]api.DataTransferChannel, len(inProgressChannels))
|
||||
for id, channelState := range inProgressChannels {
|
||||
ch := api.NewDataTransferChannel(a.Host.ID(), channelState)
|
||||
dataTransfersByID[id] = ch
|
||||
}
|
||||
return dataTransfersByID, nil
|
||||
}
|
||||
|
||||
func (a *API) ClientGetDealInfo(ctx context.Context, d cid.Cid) (*api.DealInfo, error) {
|
||||
v, err := a.SMDealClient.GetLocalDeal(ctx, d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &api.DealInfo{
|
||||
ProposalCid: v.ProposalCid,
|
||||
State: v.State,
|
||||
Message: v.Message,
|
||||
Provider: v.Proposal.Provider,
|
||||
PieceCID: v.Proposal.PieceCID,
|
||||
Size: uint64(v.Proposal.PieceSize.Unpadded()),
|
||||
PricePerEpoch: v.Proposal.StoragePricePerEpoch,
|
||||
Duration: uint64(v.Proposal.Duration()),
|
||||
DealID: v.DealID,
|
||||
CreationTime: v.CreationTime.Time(),
|
||||
Verified: v.Proposal.VerifiedDeal,
|
||||
}, nil
|
||||
di := a.newDealInfo(ctx, v)
|
||||
return &di, nil
|
||||
}
|
||||
|
||||
func (a *API) ClientGetDealUpdates(ctx context.Context) (<-chan api.DealInfo, error) {
|
||||
updates := make(chan api.DealInfo)
|
||||
|
||||
unsub := a.SMDealClient.SubscribeToEvents(func(_ storagemarket.ClientEvent, deal storagemarket.ClientDeal) {
|
||||
updates <- newDealInfo(deal)
|
||||
updates <- a.newDealInfo(ctx, deal)
|
||||
})
|
||||
|
||||
go func() {
|
||||
@@ -243,6 +245,41 @@ func (a *API) ClientGetDealUpdates(ctx context.Context) (<-chan api.DealInfo, er
|
||||
return updates, nil
|
||||
}
|
||||
|
||||
func (a *API) newDealInfo(ctx context.Context, v storagemarket.ClientDeal) api.DealInfo {
|
||||
// Find the data transfer associated with this deal
|
||||
var transferCh *api.DataTransferChannel
|
||||
if v.TransferChannelID != nil {
|
||||
state, err := a.DataTransfer.ChannelState(ctx, *v.TransferChannelID)
|
||||
|
||||
// Note: If there was an error just ignore it, as the data transfer may
|
||||
// be not found if it's no longer active
|
||||
if err == nil {
|
||||
ch := api.NewDataTransferChannel(a.Host.ID(), state)
|
||||
transferCh = &ch
|
||||
}
|
||||
}
|
||||
return a.newDealInfoWithTransfer(transferCh, v)
|
||||
}
|
||||
|
||||
func (a *API) newDealInfoWithTransfer(transferCh *api.DataTransferChannel, v storagemarket.ClientDeal) api.DealInfo {
|
||||
return api.DealInfo{
|
||||
ProposalCid: v.ProposalCid,
|
||||
DataRef: v.DataRef,
|
||||
State: v.State,
|
||||
Message: v.Message,
|
||||
Provider: v.Proposal.Provider,
|
||||
PieceCID: v.Proposal.PieceCID,
|
||||
Size: uint64(v.Proposal.PieceSize.Unpadded()),
|
||||
PricePerEpoch: v.Proposal.StoragePricePerEpoch,
|
||||
Duration: uint64(v.Proposal.Duration()),
|
||||
DealID: v.DealID,
|
||||
CreationTime: v.CreationTime.Time(),
|
||||
Verified: v.Proposal.VerifiedDeal,
|
||||
TransferChannelID: v.TransferChannelID,
|
||||
DataTransfer: transferCh,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) ClientHasLocal(ctx context.Context, root cid.Cid) (bool, error) {
|
||||
// TODO: check if we have the ENTIRE dag
|
||||
|
||||
@@ -876,23 +913,6 @@ func (a *API) ClientCancelDataTransfer(ctx context.Context, transferID datatrans
|
||||
return a.DataTransfer.CloseDataTransferChannel(ctx, datatransfer.ChannelID{Initiator: otherPeer, Responder: selfPeer, ID: transferID})
|
||||
}
|
||||
|
||||
func newDealInfo(v storagemarket.ClientDeal) api.DealInfo {
|
||||
return api.DealInfo{
|
||||
ProposalCid: v.ProposalCid,
|
||||
DataRef: v.DataRef,
|
||||
State: v.State,
|
||||
Message: v.Message,
|
||||
Provider: v.Proposal.Provider,
|
||||
PieceCID: v.Proposal.PieceCID,
|
||||
Size: uint64(v.Proposal.PieceSize.Unpadded()),
|
||||
PricePerEpoch: v.Proposal.StoragePricePerEpoch,
|
||||
Duration: uint64(v.Proposal.Duration()),
|
||||
DealID: v.DealID,
|
||||
CreationTime: v.CreationTime.Time(),
|
||||
Verified: v.Proposal.VerifiedDeal,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) ClientRetrieveTryRestartInsufficientFunds(ctx context.Context, paymentChannel address.Address) error {
|
||||
return a.Retrieval.TryRestartInsufficientFunds(paymentChannel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user