deal

package
v0.5.14 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultHandler added in v0.4.0

type DefaultHandler struct{}

func (DefaultHandler) ListHandler added in v0.4.0

func (DefaultHandler) ListHandler(ctx context.Context, db *gorm.DB, request ListDealRequest) ([]model.Deal, error)

ListHandler retrieves a list of deals from the database based on the specified filtering criteria in ListDealRequest.

The function takes advantage of the conditional nature of the ListDealRequest to construct the final query. It filters deals based on various conditions such as preparations, storages, schedules, providers, and states as specified in the request.

The function begins by associating the provided context with the database connection. It then successively builds upon a GORM statement by appending where clauses based on the parameters in the request.

It's important to note that there aren't indexes for all the query fields in the current database setup. This might be sufficient for smaller datasets but could affect performance on larger datasets or under heavy query loads.

Parameters:

  • ctx: The context for the operation which provides facilities for timeouts and cancellations.
  • db: The database connection for performing CRUD operations related to deals.
  • request: The request object which contains the filtering criteria for the deals retrieval.

Returns:

  • A slice of model.Deal objects matching the filtering criteria.
  • An error indicating any issues that occurred during the database operation.

func (DefaultHandler) SendManualHandler added in v0.4.0

func (DefaultHandler) SendManualHandler(
	ctx context.Context,
	db *gorm.DB,
	dealMaker replication.DealMaker,
	request Proposal,
) (*model.Deal, error)

SendManualHandler creates a deal proposal manually based on the information provided in the Proposal.

The function searches for the client's wallet using the provided address, validates various input fields such as the pieceCID, rootCID, piece size, etc., and then uses the dealMaker to create a deal. The result is a model.Deal that represents the proposal. Any issues during these operations result in an appropriate error response.

Parameters:

  • ctx: The context for the operation which can be used for timeouts and cancellations.
  • db: The database connection for accessing and storing related data.
  • dealMaker: An interface responsible for creating deals based on the given configuration.
  • request: The request object containing all the necessary information for creating a deal proposal.

Returns:

  • A pointer to a model.Deal object representing the created deal.
  • An error indicating any issues that occurred during the process.

type Handler added in v0.4.0

type Handler interface {
	ListHandler(ctx context.Context, db *gorm.DB, request ListDealRequest) ([]model.Deal, error)
	SendManualHandler(
		ctx context.Context,
		db *gorm.DB,
		dealMaker replication.DealMaker,
		request Proposal,
	) (*model.Deal, error)
}
var Default Handler = &DefaultHandler{}

type ListDealRequest

type ListDealRequest struct {
	Preparations []string          `json:"preparations"` // preparation ID or name filter
	Sources      []string          `json:"sources"`      // source ID or name filter
	Schedules    []uint32          `json:"schedules"`    // schedule id filter
	Providers    []string          `json:"providers"`    // provider filter
	States       []model.DealState `json:"states"`       // state filter
}

type MockDeal added in v0.5.0

type MockDeal struct {
	mock.Mock
}

func (*MockDeal) ListHandler added in v0.5.0

func (m *MockDeal) ListHandler(ctx context.Context, db *gorm.DB, request ListDealRequest) ([]model.Deal, error)

func (*MockDeal) SendManualHandler added in v0.5.0

func (m *MockDeal) SendManualHandler(ctx context.Context, db *gorm.DB, dealMaker replication.DealMaker, request Proposal) (*model.Deal, error)

type Proposal

type Proposal struct {
	HTTPHeaders     []string `json:"httpHeaders"`                          // http headers to be passed with the request (i.e. key=value)
	URLTemplate     string   `json:"urlTemplate"`                          // URL template with PIECE_CID placeholder for boost to fetch the CAR file, i.e. http://127.0.0.1/piece/{PIECE_CID}.car
	PricePerGBEpoch float64  `default:"0"          json:"pricePerGbEpoch"` // Price in FIL per GiB per epoch
	PricePerGB      float64  `default:"0"          json:"pricePerGb"`      // Price in FIL  per GiB
	PricePerDeal    float64  `default:"0"          json:"pricePerDeal"`    // Price in FIL per deal
	RootCID         string   `default:"bafkqaaa"   json:"rootCid"`         // Root CID that is required as part of the deal proposal, if empty, will be set to empty CID
	Verified        bool     `default:"true"       json:"verified"`        // Whether the deal should be verified
	IPNI            bool     `default:"true"       json:"ipni"`            // Whether the deal should be IPNI
	KeepUnsealed    bool     `default:"true"       json:"keepUnsealed"`    // Whether the deal should be kept unsealed
	StartDelay      string   `default:"72h"        json:"startDelay"`      // Deal start delay in epoch or in duration format, i.e. 1000, 72h
	Duration        string   `default:"12740h"     json:"duration"`        // Duration in epoch or in duration format, i.e. 1500000, 2400h
	ClientAddress   string   `json:"clientAddress"`                        // Client address
	ProviderID      string   `json:"providerId"`                           // Provider ID
	PieceCID        string   `json:"pieceCid"`                             // Piece CID
	PieceSize       string   `json:"pieceSize"`                            // Piece size
	FileSize        uint64   `json:"fileSize"`                             // File size in bytes for boost to fetch the CAR file
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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