2019-12-10 04:19:59 +00:00
|
|
|
package retrievaladapter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-10 18:21:46 +00:00
|
|
|
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
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"
|
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"
|
2019-12-17 03:17:46 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
2019-12-10 04:19:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type retrievalProviderNode struct {
|
2019-12-17 03:17:46 +00:00
|
|
|
sectorBlocks *sectorblocks.SectorBlocks
|
|
|
|
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
|
2019-12-17 03:17:46 +00:00
|
|
|
func NewRetrievalProviderNode(sectorBlocks *sectorblocks.SectorBlocks, full api.FullNode) retrievalmarket.RetrievalProviderNode {
|
|
|
|
return &retrievalProviderNode{sectorBlocks, full}
|
2019-12-10 04:19:59 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 03:17:46 +00:00
|
|
|
func (rpn *retrievalProviderNode) GetPieceSize(pieceCid []byte) (uint64, error) {
|
|
|
|
asCid, err := cid.Cast(pieceCid)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return rpn.sectorBlocks.GetSize(asCid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rpn *retrievalProviderNode) SealedBlockstore(approveUnseal func() error) blockstore.Blockstore {
|
|
|
|
return rpn.sectorBlocks.SealedBlockstore(approveUnseal)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|