2019-12-10 04:19:59 +00:00
|
|
|
package retrievaladapter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-24 20:19:52 +00:00
|
|
|
"io"
|
2019-12-10 04:19:59 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
2020-01-10 17:13:12 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
|
|
|
retrievaltoken "github.com/filecoin-project/go-fil-markets/shared/tokenamount"
|
|
|
|
retrievaltypes "github.com/filecoin-project/go-fil-markets/shared/types"
|
2020-02-09 06:06:32 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
|
2020-01-24 20:19:52 +00:00
|
|
|
"github.com/filecoin-project/go-sectorbuilder"
|
2019-11-04 19:57:54 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-01-10 18:21:46 +00:00
|
|
|
"github.com/filecoin-project/lotus/markets/utils"
|
2020-01-24 20:19:52 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage"
|
2019-12-10 04:19:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type retrievalProviderNode struct {
|
2020-01-24 20:19:52 +00:00
|
|
|
miner *storage.Miner
|
|
|
|
sb sectorbuilder.Interface
|
|
|
|
full api.FullNode
|
2019-12-10 04:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRetrievalProviderNode returns a new node adapter for a retrieval provider that talks to the
|
|
|
|
// Lotus Node
|
2020-01-24 20:19:52 +00:00
|
|
|
func NewRetrievalProviderNode(miner *storage.Miner, sb sectorbuilder.Interface, full api.FullNode) retrievalmarket.RetrievalProviderNode {
|
|
|
|
return &retrievalProviderNode{miner, sb, full}
|
2019-12-10 04:19:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 06:06:32 +00:00
|
|
|
func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID abi.SectorNumber, offset uint64, length uint64) (io.ReadCloser, error) {
|
2020-01-24 20:19:52 +00:00
|
|
|
si, err := rpn.miner.GetSectorInfo(sectorID)
|
2019-12-17 03:17:46 +00:00
|
|
|
if err != nil {
|
2020-01-24 20:19:52 +00:00
|
|
|
return nil, err
|
2019-12-17 03:17:46 +00:00
|
|
|
}
|
2020-02-11 01:10:50 +00:00
|
|
|
return rpn.sb.ReadPieceFromSealedSector(ctx, sectorID, sectorbuilder.UnpaddedByteIndex(offset), abi.UnpaddedPieceSize(length), si.Ticket.TicketBytes, si.CommD)
|
2019-12-17 03:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *retrievaltypes.SignedVoucher, proof []byte, expectedAmount retrievaltoken.TokenAmount) (retrievaltoken.TokenAmount, error) {
|
2020-01-10 18:21:46 +00:00
|
|
|
localVoucher, err := utils.FromSharedSignedVoucher(voucher)
|
2019-12-17 03:17:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return retrievaltoken.FromInt(0), err
|
|
|
|
}
|
2020-01-10 18:21:46 +00:00
|
|
|
added, err := rpn.full.PaychVoucherAdd(ctx, paymentChannel, localVoucher, proof, utils.FromSharedTokenAmount(expectedAmount))
|
|
|
|
return utils.ToSharedTokenAmount(added), err
|
2019-12-10 04:19:59 +00:00
|
|
|
}
|