core

package
v0.0.0-...-8d0bd56 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 63 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RatingMin - min raring
	RatingMin = 1
	// RatingMax - max rating
	RatingMax = 5
	// ReviewMaxCharacters - max size for review
	ReviewMaxCharacters = 3000
)
View Source
const (
	// VERSION - current version
	VERSION = "0.14.0"
	// USERAGENT - user-agent header string
	USERAGENT = "/openbazaar-go:" + VERSION + "/"
)
View Source
const (
	// ChatMessageMaxCharacters - limit for chat msg
	ChatMessageMaxCharacters = 20000
	// ChatSubjectMaxCharacters - limit for chat subject
	ChatSubjectMaxCharacters = 500
	// DefaultPointerPrefixLength - default ipfs pointer prefix
	DefaultPointerPrefixLength = 14
)
View Source
const (

	// EscrowReleaseSize - size in bytes for escrow op
	EscrowReleaseSize = 337
	// CryptocurrencyPurchasePaymentAddressMaxLength - max permissible length for an address
	CryptocurrencyPurchasePaymentAddressMaxLength = 512
)
View Source
const (
	// PostStatusMaxCharacters - Maximum length of the status field of a post
	PostStatusMaxCharacters = 280
	// PostLongFormMaxCharacters - Maximum length of the longForm field of a post
	PostLongFormMaxCharacters = 50000
	// PostMaximumTotalTags - Maximum number of tags a post can have
	PostMaximumTotalTags = 50
	// PostMaximumTotalChannels - Maximum number of channels a post can be addressed to
	PostMaximumTotalChannels = 30
	// PostTagsMaxCharacters - Maximum character length of a tag
	PostTagsMaxCharacters = 256
	// PostChannelsMaxCharacters - Maximum character length of a channel
	PostChannelsMaxCharacters = 256
	// PostReferenceMaxCharacters - Maximum character length of a reference
	PostReferenceMaxCharacters = 256
)

Constants for validation

View Source
const DefaultCurrencyDivisibility uint = 8

DefaultCurrencyDivisibility is the Divisibility of the Currency if not defined otherwise

Variables

View Source
var (
	// EscrowTimeLockedError - custom err for time locked escrow
	EscrowTimeLockedError error
	// ErrPrematureReleaseOfTimedoutEscrowFunds - custom err for premature escrow funds release
	ErrPrematureReleaseOfTimedoutEscrowFunds = fmt.Errorf("escrow can only be released when in dispute for %s days", (time.Duration(repo.DisputeTotalDurationHours) * time.Hour).String())
)
View Source
var (
	// ErrPurchaseUnknownListing - unavailable listing err
	ErrPurchaseUnknownListing = errors.New("order contains a hash of a listing that is not currently for sale")

	// ErrPriceCalculationRequiresExchangeRates - exchange rates dependency err
	ErrPriceCalculationRequiresExchangeRates = errors.New("can't calculate price with exchange rates disabled")

	// ErrCryptocurrencyListingCoinTypeRequired - missing coinType err
	ErrCryptocurrencyListingCoinTypeRequired = errors.New("cryptocurrency listings require a coinType")
	// ErrCryptocurrencyPurchasePaymentAddressRequired - missing payment address err
	ErrCryptocurrencyPurchasePaymentAddressRequired = errors.New("paymentAddress required for cryptocurrency items")
	// ErrCryptocurrencyPurchasePaymentAddressTooLong - invalid payment address
	ErrCryptocurrencyPurchasePaymentAddressTooLong = errors.New("paymentAddress required is too long")

	// ErrFulfillIncorrectDeliveryType - incorrect delivery type err
	ErrFulfillIncorrectDeliveryType = errors.New("incorrect delivery type for order")
	// ErrFulfillCryptocurrencyTXIDNotFound - missing txn id err
	ErrFulfillCryptocurrencyTXIDNotFound = errors.New("a transactionID is required to fulfill crypto listings")
	// ErrFulfillCryptocurrencyTXIDTooLong - invalid txn id err
	ErrFulfillCryptocurrencyTXIDTooLong = errors.New("transactionID should be no longer than " + strconv.Itoa(MaxTXIDSize))

	// ErrUnknownWallet is returned when a wallet is not present on the node
	ErrUnknownWallet = errors.New("Unknown wallet type")

	// ErrInvalidSpendAddress is returned when the wallet is unable to decode the string address into a valid destination to send funds to
	ErrInvalidSpendAddress = errors.New("ERROR_INVALID_ADDRESS")

	// ErrInsufficientFunds is returned when the wallet is unable to send the amount specified due to the balance being too low
	ErrInsufficientFunds = errors.New("ERROR_INSUFFICIENT_FUNDS")

	// ErrInvalidAmount is returned when the string representation of the amount to spend is not an integer
	ErrInvalidAmount = errors.New("Spend amount is invalid or empty")

	// ErrSpendAmountIsDust is returned when the requested amount to spend out of the wallet would be considered "dust" by the network. This means the value is too low for the network to bother sending the amount and has a high likelihood of not being accepted or being outright rejected.
	ErrSpendAmountIsDust = errors.New("ERROR_DUST_AMOUNT")

	// ErrUnknownOrder is returned when the requested amount to spend is unable to be associated with the appropriate order
	ErrOrderNotFound = errors.New("ERROR_ORDER_NOT_FOUND")
)
View Source
var (
	// ErrPostUnknownValidationPanic - post has an unknown panic error
	ErrPostUnknownValidationPanic = errors.New("unexpected validation panic")

	// ErrPostSlugNotEmpty - post slug is empty error
	ErrPostSlugNotEmpty = errors.New("slug must not be empty")

	// ErrPostSlugTooLong - post slug longer than max characters error
	ErrPostSlugTooLong = fmt.Errorf("slug is longer than the max of %d", repo.SentenceMaxCharacters)

	// ErrPostSlugContainsSpaces - post slug has spaces error
	ErrPostSlugContainsSpaces = errors.New("slugs cannot contain spaces")

	// ErrPostSlugContainsSlashes - post slug has file separators
	ErrPostSlugContainsSlashes = errors.New("slugs cannot contain file separators")

	// ErrPostInvalidType - post type is invalid error
	ErrPostInvalidType = errors.New("invalid post type")

	// ErrPostStatusTooLong - post 'status' is longer than max characters error
	ErrPostStatusTooLong = fmt.Errorf("status is longer than the max of %d", PostStatusMaxCharacters)

	// ErrPostBodyTooLong - post 'longForm' is longer than max characters error
	ErrPostBodyTooLong = fmt.Errorf("post is longer than the max of %d characters", PostLongFormMaxCharacters)

	// ErrPostTagsTooMany - post tags longer than max length error
	ErrPostTagsTooMany = fmt.Errorf("tags in the post is longer than the max of %d", PostMaximumTotalTags)

	// ErrPostTagsEmpty - post has empty tags error
	ErrPostTagsEmpty = errors.New("tags must not be empty")

	// ErrPostTagTooLong - post tag has characters longer than max length error
	ErrPostTagTooLong = fmt.Errorf("tags must be less than max of %d characters", PostTagsMaxCharacters)

	// ErrPostChannelsTooMany - post channels longer than max length error
	ErrPostChannelsTooMany = fmt.Errorf("channels in the post is longer than the max of %d", PostMaximumTotalChannels)

	// ErrPostChannelTooLong - post channel has characters longer than max length error
	ErrPostChannelTooLong = fmt.Errorf("channels must be less than max of %d characters", PostChannelsMaxCharacters)

	// ErrPostReferenceEmpty - post has an empty reference error
	ErrPostReferenceEmpty = errors.New("reference must not be empty")

	// ErrPostReferenceTooLong - post reference has characters longer than max length error
	ErrPostReferenceTooLong = fmt.Errorf("reference is longer than the max of %d", PostReferenceMaxCharacters)

	// ErrPostReferenceContainsSpaces - post reference has spaces error
	ErrPostReferenceContainsSpaces = errors.New("reference cannot contain spaces")

	// ErrPostImagesTooMany - post images longer than max error
	ErrPostImagesTooMany = fmt.Errorf("number of post images is greater than the max of %d", repo.MaxListItems)

	// ErrPostImageTinyFormatInvalid - post tiny image hash incorrectly formatted error
	ErrPostImageTinyFormatInvalid = errors.New("tiny image hashes must be properly formatted CID")

	// ErrPostImageSmallFormatInvalid - post small image hash incorrectly formatted error
	ErrPostImageSmallFormatInvalid = errors.New("small image hashes must be properly formatted CID")

	// ErrPostImageMediumFormatInvalid - post medium image hash incorrectly formatted error
	ErrPostImageMediumFormatInvalid = errors.New("medium image hashes must be properly formatted CID")

	// ErrPostImageLargeFInvalidormat - post large image hash incorrectly formatted error
	ErrPostImageLargeFormatInvalid = errors.New("large image hashes must be properly formatted CID")

	// ErrPostImageOriginalFormatInvalid - post original image hash incorrectly formatted error
	ErrPostImageOriginalFormatInvalid = errors.New("original image hashes must be properly formatted CID")

	// ErrPostImageFilenameNil - post image filename is nil error
	ErrPostImageFilenameNil = errors.New("image file names must not be nil")

	// ErrPostImageFilenameTooLong - post image filename length longer than max
	ErrPostImageFilenameTooLong = fmt.Errorf("image filename length must be less than the max of %d", repo.FilenameMaxCharacters)
)

Errors

View Source
var DisputeWg = new(sync.WaitGroup)

DisputeWg - waitgroup for disputes

View Source
var ErrCaseNotFound = errors.New("case not found")

ErrCaseNotFound - case not found err

View Source
var ErrCloseFailureCaseExpired = errors.New("unable to close expired case")

ErrCloseFailureCaseExpired - tried closing expired case err

View Source
var ErrCloseFailureNoOutpoints = errors.New("unable to close case with missing outpoints")

ErrCloseFailureNoOutpoints indicates when a dispute cannot be closed due to neither party including outpoints with their dispute

View Source
var ErrInvalidKey = errors.New("invalid key")
View Source
var (

	// ErrInventoryNotFoundForSlug - inventory not found error
	ErrInventoryNotFoundForSlug = errors.New("could not find slug in inventory")
)
View Source
var ErrNoListings = errors.New("no listings to set moderators on")

ErrNoListings - no listing error FIXME : This is not used anywhere

View Source
var ErrOpenFailureOrderExpired = errors.New("unable to open case because order is too old to dispute")

ErrOpenFailureOrderExpired - tried disputing expired order err

View Source
var ErrorProfileNotFound = errors.New("profile not found")

ErrorProfileNotFound - profile not found error

View Source
var (
	// MaxTXIDSize - max length for order txnID
	MaxTXIDSize = 512
)
View Source
var ModeratorPointerID multihash.Multihash

ModeratorPointerID moderator ipfs multihash

View Source
var Node *developertaskNode

Node - ob node

View Source
var OfflineMessageWaitGroup sync.WaitGroup

OfflineMessageWaitGroup - used for offline msgs

Functions

func CheckAndSetUlimit

func CheckAndSetUlimit() error

CheckAndSetUlimit raises the file descriptor limit

func FormatRFC3339PB

func FormatRFC3339PB(ts google_protobuf.Timestamp) string

FormatRFC3339PB returns the given `google_protobuf.Timestamp` as a RFC3339 formatted string

func GetOrderQuantity

func GetOrderQuantity(l *pb.Listing, item *pb.Order_Item) *big.Int

GetOrderQuantity - return the specified item quantity

func GetSelectedSku

func GetSelectedSku(listing *pb.Listing, itemOptions []*pb.Order_Item_Option) (int, error)

GetSelectedSku - return the specified item SKU

func GetSignedListingFromPath

func GetSignedListingFromPath(p string) (*pb.SignedListing, error)

func ParseContractForListing

func ParseContractForListing(hash string, contract *pb.RicardianContract) (*pb.Listing, error)

ParseContractForListing - return the listing identified by the hash from the contract

func SameSku

func SameSku(selectedVariants []int, sku *pb.Listing_Item_Sku) bool

SameSku - check if the variants have the same SKU

func SignPayload

func SignPayload(payload []byte, privKey crypto.PrivKey) ([]byte, []byte, error)

SignPayload produces a signature for the given private key and payload and returns it and the public key or an error

func ValidateProfile

func ValidateProfile(profile *pb.Profile) error

ValidateProfile - validate fetched profile

func ValidateRating

func ValidateRating(rating *pb.Rating) (bool, error)

ValidateRating - validates rating for API GET and Post/Update

func VerifyPayload

func VerifyPayload(payload, sig, pubKey []byte) (string, error)

VerifyPayload proves the payload and signature are authentic for the provided public key and returns the peer ID for that pubkey with no error on success

Types

type CodedError

type CodedError struct {
	Reason string `json:"reason,omitempty"`
	Code   string `json:"code,omitempty"`
}

CodedError is an error that is machine readable

func (CodedError) Error

func (err CodedError) Error() string

type ErrOutOfInventory

type ErrOutOfInventory struct {
	CodedError
	RemainingInventory string `json:"remainingInventory"`
}

ErrOutOfInventory is a codedError returned from vendor nodes when buyers try purchasing too many of an item

func NewErrOutOfInventory

func NewErrOutOfInventory(inventoryRemaining *big.Int) ErrOutOfInventory

NewErrOutOfInventory - return out of inventory err with available inventory

func (ErrOutOfInventory) Error

func (err ErrOutOfInventory) Error() string

type Inventory

type Inventory map[string]*InventoryListing

Inventory is the complete inventory representation stored on IPFS It maps slug -> quantity information

type InventoryListing

type InventoryListing struct {
	Inventory   string `json:"inventory"`
	LastUpdated string `json:"lastUpdated"`
}

InventoryListing is the listing representation stored on IPFS

type OrderRatings

type OrderRatings struct {
	OrderID string       `json:"orderId"`
	Ratings []RatingData `json:"ratings"`
}

OrderRatings - record ratings for an order

type RatingData

type RatingData struct {
	Slug            string `json:"slug"`
	Overall         int    `json:"overall"`
	Quality         int    `json:"quality"`
	Description     int    `json:"description"`
	DeliverySpeed   int    `json:"deliverySpeed"`
	CustomerService int    `json:"customerService"`
	Review          string `json:"review"`
	Anonymous       bool   `json:"anonymous"`
}

RatingData - record rating in detail

type SavedRating

type SavedRating struct {
	Slug    string   `json:"slug"`
	Count   int      `json:"count"`
	Average float32  `json:"average"`
	Ratings []string `json:"ratings"`
}

SavedRating - represent saved rating

type SpendRequest

type SpendRequest struct {
	Amount                 string                   `json:"amount"`
	Currency               *repo.CurrencyDefinition `json:"currency"`
	CurrencyCode           string                   `json:"currencyCode"`
	Address                string                   `json:"address"`
	FeeLevel               string                   `json:"feeLevel"`
	Memo                   string                   `json:"memo"`
	OrderID                string                   `json:"orderId"`
	RequireAssociatedOrder bool                     `json:"requireOrder"`
	SpendAll               bool                     `json:"spendAll"`
	// contains filtered or unexported fields
}

type SpendResponse

type SpendResponse struct {
	Amount             string                   `json:"amount"`
	ConfirmedBalance   string                   `json:"confirmedBalance"`
	UnconfirmedBalance string                   `json:"unconfirmedBalance"`
	Currency           *repo.CurrencyDefinition `json:"currency"`
	Memo               string                   `json:"memo"`
	OrderID            string                   `json:"orderId"`
	Timestamp          time.Time                `json:"timestamp"`
	Txid               string                   `json:"txid"`
	PeerID             string                   `json:"-"`
	ConsumedInput      bool                     `json:"-"`
}

Jump to

Keyboard shortcuts

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