objects

package
v0.0.0-...-4b30682 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 19 Imported by: 1

Documentation

Overview

Package objects contains the type definitions and encodingfunctions for the shop schema

Index

Constants

View Source
const EthereumAddressSize = common.AddressLength

EthereumAddressSize is the size of an Ethereum address

View Source
const HashSize = 32

HashSize is the size of a hash

View Source
const PublicKeySize = 33

PublicKeySize is the size of a public key

View Source
const SignatureSize = crypto.SignatureLength

SignatureSize is the size of a signature

Variables

This section is empty.

Functions

func DefaultValidator

func DefaultValidator() *validator.Validate

DefaultValidator returns a new validator

func HAMTValidation

func HAMTValidation(sl validator.StructLevel)

HAMTValidation validates the HAMT types

func OrderValidation

func OrderValidation(sl validator.StructLevel)

OrderValidation validates the state-dependent fields of an order

Types

type Account

type Account struct {
	KeyCards []PublicKey
	Guest    bool
}

Account represents an account

type Accounts

type Accounts struct {
	*hamt.Trie[Account]
}

Accounts is a HAMT of accounts

func (Accounts) MarshalJSON

func (accs Accounts) MarshalJSON() ([]byte, error)

MarshalJSON encodes an Accounts object as a JSON object

type AddressDetails

type AddressDetails struct {
	Name         string  `validate:"required,notblank"`
	Address1     string  `validate:"required,notblank"`
	Address2     string  `cbor:",omitempty"`
	City         string  `validate:"required,notblank"`
	PostalCode   string  `cbor:",omitempty" validate:"required,notblank"`
	Country      string  `validate:"required,notblank"`
	EmailAddress string  `validate:"required,email"`
	PhoneNumber  *string `cbor:",omitempty" validate:"omitempty,e164"`
}

AddressDetails represents shipping or billing address information

type ChainAddress

type ChainAddress struct {
	ChainID uint64 `validate:"required,gt=0"`
	// when representing an ERC20 the zero address is used for the native currency
	EthereumAddress
}

ChainAddress is an Ethereum address with a chain ID attached

func AddrFromHex

func AddrFromHex(chain uint64, hexAddr string) (ChainAddress, error)

AddrFromHex creates a ChainAddress from a hex string

func MustAddrFromHex

func MustAddrFromHex(chain uint64, hexAddr string) ChainAddress

MustAddrFromHex creates a ChainAddress from a hex string, panics on error

func (ChainAddress) Equal

func (ca ChainAddress) Equal(other ChainAddress) bool

Equal checks if two ChainAddresses are equal

func (ChainAddress) MarshalJSON

func (addr ChainAddress) MarshalJSON() ([]byte, error)

MarshalJSON encodes a ChainAddress as a JSON object

func (*ChainAddress) String

func (ca *ChainAddress) String() string

String returns a string representation of a ChainAddress

type ChainAddresses

type ChainAddresses map[uint64]map[common.Address]struct{}

ChainAddresses maps from chain id to a map of addresses to a boolean

type ErrBytesTooShort

type ErrBytesTooShort struct {
	Want, Got uint
}

ErrBytesTooShort is an error that occurs when a byte slice is too short

func (ErrBytesTooShort) Error

func (err ErrBytesTooShort) Error() string

Error returns a string representation of the error

type EthereumAddress

type EthereumAddress struct {
	common.Address
}

EthereumAddress represents an Ethereum address

func (EthereumAddress) MarshalJSON

func (addr EthereumAddress) MarshalJSON() ([]byte, error)

MarshalJSON encodes an Ethereum address as a JSON string

func (*EthereumAddress) UnmarshalBinary

func (val *EthereumAddress) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals an Ethereum address from a byte slice

type Hash

type Hash [HashSize]byte

Hash represents a cryptographic hash

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

MarshalJSON encodes a Hash as a base64 encoded string

func (*Hash) UnmarshalBinary

func (val *Hash) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a hash from a byte slice

type Inventory

type Inventory struct {
	*hamt.Trie[uint64]
}

Inventory is a HAMT of inventory

func (*Inventory) Delete

func (l *Inventory) Delete(id ObjectID, variations []string) error

Delete deletes an inventory item from the HAMT

func (*Inventory) Get

func (l *Inventory) Get(id ObjectID, variations []string) (uint64, bool)

Get gets an inventory item from the HAMT

func (*Inventory) Insert

func (l *Inventory) Insert(id ObjectID, variations []string, val uint64) error

Insert inserts an inventory item into the HAMT

func (Inventory) MarshalJSON

func (inv Inventory) MarshalJSON() ([]byte, error)

MarshalJSON encodes an Inventory object as a JSON object

type Listing

type Listing struct {
	ID        ObjectID        `validate:"required,gt=0"`
	Price     Uint256         `validate:"required"`
	Metadata  ListingMetadata `validate:"required"`
	ViewState ListingViewState
	Options   ListingOptions `cbor:",omitempty" validate:"nonEmptyMapKeys" json:",omitempty"`

	// one for each combination of variations
	StockStatuses []ListingStockStatus `cbor:",omitempty" json:",omitempty"`
}

Listing represents a listed item in a shop

type ListingMetadata

type ListingMetadata struct {
	Title       string   `validate:"required,notblank"`
	Description string   `validate:"required,notblank"`
	Images      []string `cbor:",omitempty" json:",omitempty"`
}

ListingMetadata represents information about a listing

type ListingOption

type ListingOption struct {
	// the title of the option (like Color, Size, etc.)
	Title      string            `validate:"required,notblank"`
	Variations ListingVariations `cbor:",omitempty" validate:"nonEmptyMapKeys" json:",omitempty"`
}

ListingOption represents a product option

type ListingOptions

type ListingOptions map[string]ListingOption

ListingOptions maps from a variation title to a listing option

type ListingStockStatus

type ListingStockStatus listingStockStatusHack

ListingStockStatus represents the stock status of a listing

func (*ListingStockStatus) UnmarshalCBOR

func (ls *ListingStockStatus) UnmarshalCBOR(data []byte) error

UnmarshalCBOR implements the cbor.Unmarshaler interface

type ListingVariation

type ListingVariation struct {
	// VariationInfo is the metadata of the variation: for example if the option is Color
	// then the title might be "Red"
	VariationInfo ListingMetadata `validate:"required"`
	PriceModifier *PriceModifier  `cbor:",omitempty" json:",omitempty"`
	SKU           string          `cbor:",omitempty" json:",omitempty"`
}

ListingVariation represents a variation of a product option It's ID is the map key it's associated with

type ListingVariations

type ListingVariations map[string]ListingVariation

ListingVariations maps from a variation title to a listing variation

type ListingViewState

type ListingViewState uint

ListingViewState represents the publication state of a listing

const (
	// ListingViewStateUnspecified is the default state of a listing
	ListingViewStateUnspecified ListingViewState = iota
	// ListingViewStatePublished is the state of a listing that is published
	ListingViewStatePublished
	// ListingViewStateDeleted is the state of a listing that is deleted
	ListingViewStateDeleted
)

func (*ListingViewState) UnmarshalCBOR

func (s *ListingViewState) UnmarshalCBOR(data []byte) error

UnmarshalCBOR unmarshals a ListingViewState from a byte slice

type Listings

type Listings struct {
	*hamt.Trie[Listing]
}

Listings is a HAMT of listings

func (*Listings) Delete

func (l *Listings) Delete(id ObjectID) error

Delete deletes a listing from the HAMT

func (*Listings) Get

func (l *Listings) Get(id ObjectID) (Listing, bool)

Get gets a listing from the HAMT

func (*Listings) Has

func (l *Listings) Has(id ObjectID) bool

Has checks if a listing exists in the HAMT

func (*Listings) Insert

func (l *Listings) Insert(id ObjectID, lis Listing) error

Insert inserts a listing into the HAMT

func (Listings) MarshalJSON

func (lis Listings) MarshalJSON() ([]byte, error)

MarshalJSON encodes a Listings object as a JSON object

type Manifest

type Manifest struct {
	// shop metadata lives in the NFT
	ShopID             Uint256 `validate:"required"`
	Payees             Payees
	AcceptedCurrencies ChainAddresses
	PricingCurrency    ChainAddress    // the currency listings are priced in
	ShippingRegions    ShippingRegions `json:",omitempty"`
}

Manifest defines metadata needed to operate a shop

type ModificationAbsolute

type ModificationAbsolute struct {
	Amount Uint256 `validate:"required"`
	Plus   bool    // false means subtract
}

ModificationAbsolute represents an absolute price modification

type ObjectID

type ObjectID = uint64

ObjectID is the unique identifier for an object

type Order

type Order struct {
	ID              ObjectID        `validate:"required,gt=0"`
	Items           OrderedItems    `validate:"required"`
	State           OrderState      `validate:"required"`
	InvoiceAddress  *AddressDetails `cbor:",omitempty"`
	ShippingAddress *AddressDetails `cbor:",omitempty"`
	CanceledAt      *time.Time      `cbor:",omitempty"`
	ChosenPayee     *Payee          `cbor:",omitempty"`
	ChosenCurrency  *ChainAddress   `cbor:",omitempty"`
	PaymentDetails  *PaymentDetails `cbor:",omitempty"`
	TxDetails       *OrderPaid      `cbor:",omitempty"`
}

Order represents an order placed by a user

type OrderPaid

type OrderPaid struct {
	TxHash    *Hash `cbor:",omitempty"`
	BlockHash Hash  `cbor:",omitempty"`
}

OrderPaid represents the details of a payment for an order

func (*OrderPaid) UnmarshalCBOR

func (op *OrderPaid) UnmarshalCBOR(data []byte) error

UnmarshalCBOR implements the cbor.Unmarshaler interface

type OrderState

type OrderState uint

OrderState represents the possible states an order can be in

const (
	// OrderStateUnspecified is the default and invalid state of an order
	OrderStateUnspecified OrderState = iota
	// OrderStateOpen is the state of an order which is open to being changed
	OrderStateOpen
	// OrderStateCanceled is the state of an order which has been canceled
	OrderStateCanceled
	// OrderStateCommitted is the state of an order which items have been frozen
	OrderStateCommitted
	// OrderStatePaymentChosen is the state of an order which has chosen a payment channel
	OrderStatePaymentChosen
	// OrderStateUnpaid is the state of an order which has not been paid for
	OrderStateUnpaid
	// OrderStatePaid is the state of an order which has been paid for
	OrderStatePaid
)

func (*OrderState) UnmarshalCBOR

func (s *OrderState) UnmarshalCBOR(data []byte) error

UnmarshalCBOR implements the cbor.Unmarshaler interface

type OrderedItem

type OrderedItem struct {
	ListingID    ObjectID `validate:"required,gt=0"`
	VariationIDs []string `cbor:",omitempty"`
	Quantity     uint32   `validate:"required,gt=0"`
}

OrderedItem represents an item in an order

type OrderedItems

type OrderedItems []OrderedItem

OrderedItems is a list of items in an order

type Orders

type Orders struct {
	*hamt.Trie[Order]
}

Orders is a HAMT of orders

func (*Orders) Delete

func (l *Orders) Delete(id ObjectID) error

Delete deletes an order from the HAMT

func (*Orders) Get

func (l *Orders) Get(id ObjectID) (Order, bool)

Get gets an order from the HAMT

func (*Orders) Insert

func (l *Orders) Insert(id ObjectID, val Order) error

Insert inserts an order into the HAMT

type Payee

type Payee struct {
	Address ChainAddress

	// controls how the payment is reaches the payee.
	// true:  forwarded via pay() method
	// false: normal transfer
	// See also:
	// https://github.com/masslbs/contracts/
	// commit: 377aba24796e029945696350db581ec1f65da657
	// file: src/IPayments.sol#L90-L95.
	CallAsContract bool
}

Payee represents a payment recipient

func (*Payee) String

func (p *Payee) String() string

type PayeeMetadata

type PayeeMetadata struct {
	CallAsContract bool
}

PayeeMetadata stores additional metadata about a payee

type Payees

type Payees map[uint64]map[common.Address]PayeeMetadata

Payees maps from chain id to a map of addresses to payee metadata

type PaymentDetails

type PaymentDetails struct {
	PaymentID     Hash
	Total         Uint256
	ListingHashes [][]byte `validate:"required,gt=0"`
	TTL           uint64   `validate:"required,gt=0"` // The time to live in block
	ShopSignature Signature
}

PaymentDetails represents the details needed to pay for an order

type PriceModifier

type PriceModifier priceModifierHack

PriceModifier represents a price modification

func (*PriceModifier) UnmarshalCBOR

func (pm *PriceModifier) UnmarshalCBOR(data []byte) error

UnmarshalCBOR unmarshals a PriceModifier from a byte slice

type PublicKey

type PublicKey [PublicKeySize]byte

PublicKey represents a (compressed) ecdsa public key

func (PublicKey) MarshalJSON

func (pub PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON encodes a PublicKey as a base64 encoded string

func (*PublicKey) UnmarshalBinary

func (val *PublicKey) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a public key from a byte slice

type ShippingRegion

type ShippingRegion struct {
	Country        string
	PostalCode     string
	City           string
	PriceModifiers map[string]PriceModifier `cbor:",omitempty"`
}

ShippingRegion represents a shipping region

type ShippingRegions

type ShippingRegions map[string]ShippingRegion

ShippingRegions maps from a nickname to a shipping region

type Shop

type Shop struct {
	// SchemaVersion is the version of the shop schema. Can only be increased.
	SchemaVersion uint64 `validate:"required,gt=0"`
	Tags          Tags
	Orders        Orders
	Accounts      Accounts
	Listings      Listings
	Manifest      Manifest `validate:"required"`
	Inventory     Inventory
}

Shop represents a shop and all its contents

func NewShop

func NewShop(version uint64) Shop

NewShop creates a new shop

func (*Shop) Hash

func (s *Shop) Hash() (Hash, error)

Hash hashes the shop

func (Shop) MarshalJSON

func (s Shop) MarshalJSON() ([]byte, error)

MarshalJSON encodes a Shop object as a JSON object

type Signature

type Signature [SignatureSize]byte

Signature represents a cryptographic signature

func (Signature) MarshalJSON

func (sig Signature) MarshalJSON() ([]byte, error)

MarshalJSON encodes a signature as a base64 encoded string

func (*Signature) UnmarshalBinary

func (val *Signature) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a signature from a byte slice

type Tag

type Tag struct {
	Name       string `validate:"required,notblank"`
	ListingIDs []ObjectID
}

Tag represents a tag

type Tags

type Tags struct {
	*hamt.Trie[Tag]
}

Tags is a HAMT of tags

func (*Tags) Delete

func (t *Tags) Delete(name string) error

Delete deletes a tag from the HAMT

func (*Tags) Get

func (t *Tags) Get(name string) (Tag, bool)

Get gets a tag from the HAMT

func (*Tags) Has

func (t *Tags) Has(name string) bool

Has checks if a tag exists in the HAMT

func (*Tags) Insert

func (t *Tags) Insert(name string, tag Tag) error

Insert inserts a tag into the HAMT

type Uint256

type Uint256 = big.Int

Uint256 represents a 256-bit unsigned integer

Jump to

Keyboard shortcuts

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