filclient

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2022 License: Apache-2.0, MIT Imports: 65 Imported by: 17

README

filclient

A standalone client library that enables users to interact with the Filecoin storage network. The types of interactions available are listed below, under "Features".

This functionality is accomplished by allowing users to interact with the API of any Lotus Node on the Filecoin storage network. One such node is api.chain.love, which is a node hosted by the Outercore Engineering team.

Features

  • Make storage deals with miners
    • Query storage ask prices
    • Construct and sign deal proposals
    • Send deal proposals over the network to miners
    • Send data to miners via data transfer and graphsync
    • Check status of a deal with a miner
  • Make retrieval deals with miners
    • Query retrieval ask prices
    • Run retrieval protocol, get data
  • Data transfer management
    • Ability to query data transfer (in or out) status
  • Market funds management
    • Check and add to market escrow balance
  • Local message signing capabilities and wallet management

Roadmap

  • Cleanup and organization of functions
  • Godocs on main methods
  • Direct mempool integration (to avoid relying on a lotus gateway node)
  • Cleanup of dependency tree
    • Remove dependency on filecoin-ffi
    • Remove dependency on go-fil-markets
    • Remove dependency on main lotus repo
  • Good usage examples
    • Sample application using filclient
  • Integration testing

License

MIT

Documentation

Index

Constants

View Source
const DealProtocolv110 = "/fil/storage/mk/1.1.0"
View Source
const DealProtocolv120 = "/fil/storage/mk/1.2.0"
View Source
const DealStatusProtocolv110 = "/fil/storage/status/1.1.0"
View Source
const DealStatusProtocolv120 = "/fil/storage/status/1.2.0"
View Source
const QueryAskProtocol = "/fil/storage/ask/1.1.0"
View Source
const RetrievalQueryProtocol = "/fil/retrieval/qry/1.0.0"

Variables

View Source
var ErrNoTransferFound = fmt.Errorf("no transfer found")
View Source
var Tracer trace.Tracer = otel.Tracer("filclient")

Functions

func ChannelIDFromString

func ChannelIDFromString(id string) (*datatransfer.ChannelID, error)

func ComputePrice

func ComputePrice(askPrice types.BigInt, size abi.PaddedPieceSize, duration abi.ChainEpoch) (*abi.TokenAmount, error)

func GeneratePieceCommitment

func GeneratePieceCommitment(ctx context.Context, payloadCid cid.Cid, bstore blockstore.Blockstore) (cid.Cid, uint64, abi.UnpaddedPieceSize, error)

func GeneratePieceCommitmentFFI

func GeneratePieceCommitmentFFI(ctx context.Context, payloadCid cid.Cid, bstore blockstore.Blockstore) (cid.Cid, uint64, abi.UnpaddedPieceSize, error)

func NewErrLotusError

func NewErrLotusError(err error) error

func NewErrMinerConnectionFailed

func NewErrMinerConnectionFailed(err error) error

func NewErrUnknown

func NewErrUnknown(err error) error

func ZeroPadPieceCommitment

func ZeroPadPieceCommitment(c cid.Cid, curSize abi.UnpaddedPieceSize, toSize abi.UnpaddedPieceSize) (cid.Cid, error)

Types

type Balance

type Balance struct {
	Account         address.Address `json:"account"`
	Balance         types.FIL       `json:"balance"`
	MarketEscrow    types.FIL       `json:"marketEscrow"`
	MarketLocked    types.FIL       `json:"marketLocked"`
	MarketAvailable types.FIL       `json:"marketAvailable"`

	VerifiedClientBalance *abi.StoragePower `json:"verifiedClientBalance"`
}

type ChannelState

type ChannelState struct {

	// SelfPeer returns the peer this channel belongs to
	SelfPeer   peer.ID `json:"selfPeer"`
	RemotePeer peer.ID `json:"remotePeer"`

	// Status is the current status of this channel
	Status    datatransfer.Status `json:"status"`
	StatusStr string              `json:"statusMessage"`

	// Sent returns the number of bytes sent
	Sent uint64 `json:"sent"`

	// Received returns the number of bytes received
	Received uint64 `json:"received"`

	// Message offers additional information about the current status
	Message string `json:"message"`

	BaseCid string `json:"baseCid"`

	ChannelID datatransfer.ChannelID `json:"channelId"`

	TransferID string `json:"transferId"`

	Stages *datatransfer.ChannelStages

	TransferType TransferType
}

func ChannelStateConv

func ChannelStateConv(st datatransfer.ChannelState) *ChannelState

type Config

type Config struct {
	DataDir                    string
	GraphsyncOpts              []gsimpl.Option
	Api                        api.Gateway
	Wallet                     *wallet.LocalWallet
	Addr                       address.Address
	Blockstore                 blockstore.Blockstore
	Datastore                  datastore.Batching
	Host                       host.Host
	ChannelMonitorConfig       channelmonitor.Config
	RetrievalConfigurer        datatransfer.TransportConfigurer
	LogRetrievalProgressEvents bool
	Lp2pDTConfig               Lp2pDTConfig
}

type Error

type Error struct {
	Code  ErrorCode
	Inner error
}

func NewError

func NewError(code ErrorCode, err error) *Error

func (*Error) Error

func (err *Error) Error() string

func (*Error) Unwrap

func (err *Error) Unwrap() error

type ErrorCode

type ErrorCode int
const (
	ErrUnknown ErrorCode = iota

	// Failed to connect to a miner.
	ErrMinerConnectionFailed

	// There was an issue related to the Lotus API.
	ErrLotusError
)

func (ErrorCode) String

func (code ErrorCode) String() string

type FilClient

type FilClient struct {
	ClientAddr address.Address

	Libp2pTransferMgr *libp2pTransferManager
	// contains filtered or unexported fields
}

func NewClient

func NewClient(h host.Host, api api.Gateway, w *wallet.LocalWallet, addr address.Address, bs blockstore.Blockstore, ds datastore.Batching, ddir string, opts ...func(*Config)) (*FilClient, error)

func NewClientWithConfig

func NewClientWithConfig(cfg *Config) (*FilClient, error)

func (*FilClient) Balance

func (fc *FilClient) Balance(ctx context.Context) (*Balance, error)

func (*FilClient) CheckChainDeal

func (fc *FilClient) CheckChainDeal(ctx context.Context, dealid abi.DealID) (bool, *api.MarketDeal, error)

func (*FilClient) CheckOngoingTransfer

func (fc *FilClient) CheckOngoingTransfer(ctx context.Context, miner address.Address, st *ChannelState) (outerr error)

func (*FilClient) ConnectToMiner

func (fc *FilClient) ConnectToMiner(ctx context.Context, maddr address.Address) (peer.ID, error)

Errors - ErrMinerConnectionFailed, ErrLotusError

func (*FilClient) DealProtocolForMiner

func (fc *FilClient) DealProtocolForMiner(ctx context.Context, miner address.Address) (protocol.ID, error)

func (*FilClient) DealStatus

func (fc *FilClient) DealStatus(ctx context.Context, miner address.Address, propCid cid.Cid, dealUUID *uuid.UUID) (*storagemarket.ProviderDealState, error)

func (*FilClient) GetAsk

func (fc *FilClient) GetAsk(ctx context.Context, maddr address.Address) (*network.AskResponse, error)

func (*FilClient) GetDtMgr added in v0.3.0

func (fc *FilClient) GetDtMgr() datatransfer.Manager

func (*FilClient) GetMinerVersion

func (fc *FilClient) GetMinerVersion(ctx context.Context, maddr address.Address) (string, error)

func (*FilClient) GraphSyncStats

func (fc *FilClient) GraphSyncStats() graphsync.Stats

func (*FilClient) LockMarketFunds

func (fc *FilClient) LockMarketFunds(ctx context.Context, amt types.FIL) (*LockFundsResp, error)

func (*FilClient) MakeDeal

func (fc *FilClient) MakeDeal(ctx context.Context, miner address.Address, data cid.Cid, price types.BigInt, minSize abi.PaddedPieceSize, duration abi.ChainEpoch, verified bool) (*network.Proposal, error)

func (*FilClient) MinerPeer

func (fc *FilClient) MinerPeer(ctx context.Context, miner address.Address) (peer.AddrInfo, error)

func (*FilClient) MinerTransferDiagnostics

func (fc *FilClient) MinerTransferDiagnostics(ctx context.Context, miner address.Address) (*MinerTransferDiagnostics, error)

MinerTransferDiagnostics provides in depth current information on the state of transfers for a given miner, covering running graphsync requests and related data transfers, etc

func (*FilClient) OnRetrievalEvent

func (fc *FilClient) OnRetrievalEvent(event rep.RetrievalEvent)

Implement RetrievalSubscriber

func (*FilClient) RestartTransfer

func (fc *FilClient) RestartTransfer(ctx context.Context, chanid *datatransfer.ChannelID) error

func (*FilClient) RetrievalQuery

func (fc *FilClient) RetrievalQuery(ctx context.Context, maddr address.Address, pcid cid.Cid) (*retrievalmarket.QueryResponse, error)

func (*FilClient) RetrievalQueryToPeer

func (fc *FilClient) RetrievalQueryToPeer(ctx context.Context, minerPeer peer.AddrInfo, pcid cid.Cid) (*retrievalmarket.QueryResponse, error)

func (*FilClient) RetrieveContent

func (fc *FilClient) RetrieveContent(
	ctx context.Context,
	miner address.Address,
	proposal *retrievalmarket.DealProposal,
) (*RetrievalStats, error)

func (*FilClient) RetrieveContentFromPeerAsync added in v0.4.0

func (fc *FilClient) RetrieveContentFromPeerAsync(
	ctx context.Context,
	peerID peer.ID,
	minerWallet address.Address,
	proposal *retrievalmarket.DealProposal,
) (result <-chan RetrievalResult, onProgress <-chan uint64, gracefulShutdown func())

func (*FilClient) RetrieveContentFromPeerWithProgressCallback

func (fc *FilClient) RetrieveContentFromPeerWithProgressCallback(
	ctx context.Context,
	peerID peer.ID,
	minerWallet address.Address,
	proposal *retrievalmarket.DealProposal,
	progressCallback func(bytesReceived uint64),
) (*RetrievalStats, error)

func (*FilClient) RetrieveContentWithProgressCallback

func (fc *FilClient) RetrieveContentWithProgressCallback(
	ctx context.Context,
	miner address.Address,
	proposal *retrievalmarket.DealProposal,
	progressCallback func(bytesReceived uint64),
) (*RetrievalStats, error)

func (*FilClient) SendProposalV110

func (fc *FilClient) SendProposalV110(ctx context.Context, netprop network.Proposal, propCid cid.Cid) (bool, error)

func (*FilClient) SendProposalV120

func (fc *FilClient) SendProposalV120(ctx context.Context, dbid uint, netprop network.Proposal, dealUUID uuid.UUID, announce multiaddr.Multiaddr, authToken string) (bool, error)

func (*FilClient) SetPieceCommFunc

func (fc *FilClient) SetPieceCommFunc(pcf GetPieceCommFunc)

func (*FilClient) StartDataTransfer

func (fc *FilClient) StartDataTransfer(ctx context.Context, miner address.Address, propCid cid.Cid, dataCid cid.Cid) (*datatransfer.ChannelID, error)

func (*FilClient) SubscribeToDataTransferEvents

func (fc *FilClient) SubscribeToDataTransferEvents(f datatransfer.Subscriber) func()

func (*FilClient) SubscribeToRetrievalEvents

func (fc *FilClient) SubscribeToRetrievalEvents(subscriber rep.RetrievalSubscriber)

func (*FilClient) TransferStatus

func (fc *FilClient) TransferStatus(ctx context.Context, chanid *datatransfer.ChannelID) (*ChannelState, error)

func (*FilClient) TransferStatusByID

func (fc *FilClient) TransferStatusByID(ctx context.Context, id string) (*ChannelState, error)

func (*FilClient) TransferStatusForContent

func (fc *FilClient) TransferStatusForContent(ctx context.Context, content cid.Cid, miner address.Address) (*ChannelState, error)

func (*FilClient) TransfersInProgress

func (fc *FilClient) TransfersInProgress(ctx context.Context) (map[string]*ChannelState, error)

func (*FilClient) V110TransfersInProgress

func (fc *FilClient) V110TransfersInProgress(ctx context.Context) (map[datatransfer.ChannelID]datatransfer.ChannelState, error)

type GetPieceCommFunc

type GetPieceCommFunc func(ctx context.Context, payloadCid cid.Cid, bstore blockstore.Blockstore) (cid.Cid, uint64, abi.UnpaddedPieceSize, error)

type GraphSyncDataTransfer

type GraphSyncDataTransfer struct {
	// GraphSync request id for this transfer
	RequestID graphsync.RequestID `json:"requestID"`
	// Graphsync state for this transfer
	RequestState string `json:"requestState"`
	// If a channel ID is present, indicates whether this is the current graphsync request for this channel
	// (could have changed in a restart)
	IsCurrentChannelRequest bool `json:"isCurrentChannelRequest"`
	// Data transfer channel ID for this transfer
	ChannelID *datatransfer.ChannelID `json:"channelID"`
	// Data transfer state for this transfer
	ChannelState *ChannelState `json:"channelState"`
	// Diagnostic information about this request -- and unexpected inconsistencies in
	// request state
	Diagnostics []string `json:"diagnostics"`
}

type LockFundsResp

type LockFundsResp struct {
	MsgCid cid.Cid
}

type Lp2pDTConfig

type Lp2pDTConfig struct {
	Server          httptransport.ServerConfig
	TransferTimeout time.Duration
}

type MinerTransferDiagnostics

type MinerTransferDiagnostics struct {
	ReceivingTransfers []*GraphSyncDataTransfer `json:"sendingTransfers"`
	SendingTransfers   []*GraphSyncDataTransfer `json:"receivingTransfers"`
}

type MsgPusher

type MsgPusher struct {
	// contains filtered or unexported fields
}

a simple nonce tracking message pusher that assumes it is the only thing with access to the given key

func NewMsgPusher

func NewMsgPusher(gapi api.Gateway, w *wallet.LocalWallet) *MsgPusher

func (*MsgPusher) MpoolPushMessage

func (mp *MsgPusher) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee *api.MessageSendSpec) (*types.SignedMessage, error)

type RetrievalResult added in v0.4.0

type RetrievalResult struct {
	*RetrievalStats
	Err error
}

type RetrievalStats

type RetrievalStats struct {
	Peer         peer.ID
	Size         uint64
	Duration     time.Duration
	AverageSpeed uint64
	TotalPayment abi.TokenAmount
	NumPayments  int
	AskPrice     abi.TokenAmount
}

type TransferType

type TransferType string
const (
	BoostTransfer     TransferType = "boost"
	GraphsyncTransfer TransferType = "graphsync"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL