Documentation
¶
Overview ¶
Package objects contains the type definitions and encodingfunctions for the shop schema
Index ¶
- Constants
- func DefaultValidator() *validator.Validate
- func HAMTValidation(sl validator.StructLevel)
- func OrderValidation(sl validator.StructLevel)
- type Account
- type Accounts
- type AddressDetails
- type ChainAddress
- type ChainAddresses
- type ErrBytesTooShort
- type EthereumAddress
- type Hash
- type Inventory
- type Listing
- type ListingMetadata
- type ListingOption
- type ListingOptions
- type ListingStockStatus
- type ListingVariation
- type ListingVariations
- type ListingViewState
- type Listings
- type Manifest
- type ModificationAbsolute
- type ObjectID
- type Order
- type OrderPaid
- type OrderState
- type OrderedItem
- type OrderedItems
- type Orders
- type Payee
- type PayeeMetadata
- type Payees
- type PaymentDetails
- type PriceModifier
- type PublicKey
- type ShippingRegion
- type ShippingRegions
- type Shop
- type Signature
- type Tag
- type Tags
- type Uint256
Constants ¶
const EthereumAddressSize = common.AddressLength
EthereumAddressSize is the size of an Ethereum address
const HashSize = 32
HashSize is the size of a hash
const PublicKeySize = 33
PublicKeySize is the size of a public key
const SignatureSize = crypto.SignatureLength
SignatureSize is the size of a signature
Variables ¶
This section is empty.
Functions ¶
func DefaultValidator ¶
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 Accounts ¶
Accounts is a HAMT of accounts
func (Accounts) MarshalJSON ¶
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 ¶
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 ¶
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 ¶
Hash represents a cryptographic hash
func (Hash) MarshalJSON ¶
MarshalJSON encodes a Hash as a base64 encoded string
func (*Hash) UnmarshalBinary ¶
UnmarshalBinary unmarshals a hash from a byte slice
type Inventory ¶
Inventory is a HAMT of inventory
func (Inventory) MarshalJSON ¶
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 ¶
Listings is a HAMT of listings
func (Listings) MarshalJSON ¶
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 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 ¶
OrderPaid represents the details of a payment for an order
func (*OrderPaid) UnmarshalCBOR ¶
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 Orders ¶
Orders is a HAMT of orders
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
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 ¶
MarshalJSON encodes a PublicKey as a base64 encoded string
func (*PublicKey) UnmarshalBinary ¶
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 (Shop) MarshalJSON ¶
MarshalJSON encodes a Shop object as a JSON object
type Signature ¶
type Signature [SignatureSize]byte
Signature represents a cryptographic signature
func (Signature) MarshalJSON ¶
MarshalJSON encodes a signature as a base64 encoded string
func (*Signature) UnmarshalBinary ¶
UnmarshalBinary unmarshals a signature from a byte slice