diff --git a/marketplace/marketplace.gen.go b/marketplace/marketplace.gen.go index ab3ec5c6..37abb5be 100644 --- a/marketplace/marketplace.gen.go +++ b/marketplace/marketplace.gen.go @@ -1,8 +1,8 @@ -// marketplace-api 8569918d27ddb43b484dbd057b83e8855acfdb05 +// marketplace-api 9c35e97a832f55f3a8b8f25b92c21c6afb23c25a // -- -// Code generated by webrpc-gen@v0.18.3 with golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.1 with golang generator. DO NOT EDIT. // -// webrpc-gen -schema=marketplace.ridl -target=golang -pkg=marketplaceclient -client -out=./clients/marketplace.gen.go +// webrpc-gen -schema=proto/marketplace.ridl -target=golang -pkg=marketplace -client -out=proto/clients/marketplace.gen.go package marketplace import ( @@ -14,11 +14,14 @@ import ( "io" "net/http" "net/url" + "strings" "time" - - "github.com/0xsequence/go-sequence/lib/prototyp" ) +const WebrpcHeader = "Webrpc" + +const WebrpcHeaderValue = "webrpc@v0.22.1;gen-golang@v0.17.0;marketplace-api@v0.0.0-9c35e97a832f55f3a8b8f25b92c21c6afb23c25a" + // WebRPC description and code-gen version func WebRPCVersion() string { return "v1" @@ -31,7 +34,58 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "8569918d27ddb43b484dbd057b83e8855acfdb05" + return "9c35e97a832f55f3a8b8f25b92c21c6afb23c25a" +} + +type WebrpcGenVersions struct { + WebrpcGenVersion string + CodeGenName string + CodeGenVersion string + SchemaName string + SchemaVersion string +} + +func VersionFromHeader(h http.Header) (*WebrpcGenVersions, error) { + if h.Get(WebrpcHeader) == "" { + return nil, fmt.Errorf("header is empty or missing") + } + + versions, err := parseWebrpcGenVersions(h.Get(WebrpcHeader)) + if err != nil { + return nil, fmt.Errorf("webrpc header is invalid: %w", err) + } + + return versions, nil +} + +func parseWebrpcGenVersions(header string) (*WebrpcGenVersions, error) { + versions := strings.Split(header, ";") + if len(versions) < 3 { + return nil, fmt.Errorf("expected at least 3 parts while parsing webrpc header: %v", header) + } + + _, webrpcGenVersion, ok := strings.Cut(versions[0], "@") + if !ok { + return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", versions[0]) + } + + tmplTarget, tmplVersion, ok := strings.Cut(versions[1], "@") + if !ok { + return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", versions[1]) + } + + schemaName, schemaVersion, ok := strings.Cut(versions[2], "@") + if !ok { + return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2]) + } + + return &WebrpcGenVersions{ + WebrpcGenVersion: webrpcGenVersion, + CodeGenName: tmplTarget, + CodeGenVersion: tmplVersion, + SchemaName: schemaName, + SchemaVersion: schemaVersion, + }, nil } // @@ -199,72 +253,42 @@ const ( MarketplaceKind_unknown MarketplaceKind = 0 MarketplaceKind_sequence_marketplace_v1 MarketplaceKind = 1 MarketplaceKind_sequence_marketplace_v2 MarketplaceKind = 2 - MarketplaceKind_opensea MarketplaceKind = 3 - MarketplaceKind_magic_eden MarketplaceKind = 4 - MarketplaceKind_mintify MarketplaceKind = 5 + MarketplaceKind_blur MarketplaceKind = 3 + MarketplaceKind_zerox MarketplaceKind = 4 + MarketplaceKind_opensea MarketplaceKind = 5 MarketplaceKind_looks_rare MarketplaceKind = 6 MarketplaceKind_x2y2 MarketplaceKind = 7 - MarketplaceKind_sudo_swap MarketplaceKind = 8 - MarketplaceKind_coinbase MarketplaceKind = 9 - MarketplaceKind_rarible MarketplaceKind = 10 - MarketplaceKind_nftx MarketplaceKind = 11 - MarketplaceKind_foundation MarketplaceKind = 12 - MarketplaceKind_manifold MarketplaceKind = 13 - MarketplaceKind_zora MarketplaceKind = 14 - MarketplaceKind_blur MarketplaceKind = 15 - MarketplaceKind_super_rare MarketplaceKind = 16 - MarketplaceKind_okx MarketplaceKind = 17 - MarketplaceKind_element MarketplaceKind = 18 - MarketplaceKind_aqua_xyz MarketplaceKind = 19 - MarketplaceKind_auranft_co MarketplaceKind = 20 + MarketplaceKind_alienswap MarketplaceKind = 8 + MarketplaceKind_payment_processor MarketplaceKind = 9 + MarketplaceKind_mintify MarketplaceKind = 10 ) var MarketplaceKind_name = map[uint32]string{ 0: "unknown", 1: "sequence_marketplace_v1", 2: "sequence_marketplace_v2", - 3: "opensea", - 4: "magic_eden", - 5: "mintify", + 3: "blur", + 4: "zerox", + 5: "opensea", 6: "looks_rare", 7: "x2y2", - 8: "sudo_swap", - 9: "coinbase", - 10: "rarible", - 11: "nftx", - 12: "foundation", - 13: "manifold", - 14: "zora", - 15: "blur", - 16: "super_rare", - 17: "okx", - 18: "element", - 19: "aqua_xyz", - 20: "auranft_co", + 8: "alienswap", + 9: "payment_processor", + 10: "mintify", } var MarketplaceKind_value = map[string]uint32{ "unknown": 0, "sequence_marketplace_v1": 1, "sequence_marketplace_v2": 2, - "opensea": 3, - "magic_eden": 4, - "mintify": 5, + "blur": 3, + "zerox": 4, + "opensea": 5, "looks_rare": 6, "x2y2": 7, - "sudo_swap": 8, - "coinbase": 9, - "rarible": 10, - "nftx": 11, - "foundation": 12, - "manifold": 13, - "zora": 14, - "blur": 15, - "super_rare": 16, - "okx": 17, - "element": 18, - "aqua_xyz": 19, - "auranft_co": 20, + "alienswap": 8, + "payment_processor": 9, + "mintify": 10, } func (x MarketplaceKind) String() string { @@ -292,6 +316,66 @@ func (x *MarketplaceKind) Is(values ...MarketplaceKind) bool { return false } +type OrderbookKind uint32 + +const ( + OrderbookKind_unknown OrderbookKind = 0 + OrderbookKind_sequence_marketplace_v1 OrderbookKind = 1 + OrderbookKind_sequence_marketplace_v2 OrderbookKind = 2 + OrderbookKind_blur OrderbookKind = 3 + OrderbookKind_opensea OrderbookKind = 4 + OrderbookKind_looks_rare OrderbookKind = 5 + OrderbookKind_reservoir OrderbookKind = 6 + OrderbookKind_x2y2 OrderbookKind = 7 +) + +var OrderbookKind_name = map[uint32]string{ + 0: "unknown", + 1: "sequence_marketplace_v1", + 2: "sequence_marketplace_v2", + 3: "blur", + 4: "opensea", + 5: "looks_rare", + 6: "reservoir", + 7: "x2y2", +} + +var OrderbookKind_value = map[string]uint32{ + "unknown": 0, + "sequence_marketplace_v1": 1, + "sequence_marketplace_v2": 2, + "blur": 3, + "opensea": 4, + "looks_rare": 5, + "reservoir": 6, + "x2y2": 7, +} + +func (x OrderbookKind) String() string { + return OrderbookKind_name[uint32(x)] +} + +func (x OrderbookKind) MarshalText() ([]byte, error) { + return []byte(OrderbookKind_name[uint32(x)]), nil +} + +func (x *OrderbookKind) UnmarshalText(b []byte) error { + *x = OrderbookKind(OrderbookKind_value[string(b)]) + return nil +} + +func (x *OrderbookKind) Is(values ...OrderbookKind) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false +} + type SourceKind uint32 const ( @@ -401,6 +485,8 @@ const ( OrderStatus_cancelled OrderStatus = 4 // Permanently unfillable, because it's been completely filled OrderStatus_filled OrderStatus = 5 + // Decimals are missing on collectible needs to be synced and order updated + OrderStatus_decimals_missing OrderStatus = 6 ) var OrderStatus_name = map[uint8]string{ @@ -410,15 +496,17 @@ var OrderStatus_name = map[uint8]string{ 3: "expired", 4: "cancelled", 5: "filled", + 6: "decimals_missing", } var OrderStatus_value = map[string]uint8{ - "unknown": 0, - "active": 1, - "inactive": 2, - "expired": 3, - "cancelled": 4, - "filled": 5, + "unknown": 0, + "active": 1, + "inactive": 2, + "expired": 3, + "cancelled": 4, + "filled": 5, + "decimals_missing": 6, } func (x OrderStatus) String() string { @@ -446,39 +534,147 @@ func (x *OrderStatus) Is(values ...OrderStatus) bool { return false } +type ContractType uint16 + +const ( + ContractType_UNKNOWN ContractType = 0 + ContractType_ERC20 ContractType = 1 + ContractType_ERC721 ContractType = 2 + ContractType_ERC1155 ContractType = 3 +) + +var ContractType_name = map[uint16]string{ + 0: "UNKNOWN", + 1: "ERC20", + 2: "ERC721", + 3: "ERC1155", +} + +var ContractType_value = map[string]uint16{ + "UNKNOWN": 0, + "ERC20": 1, + "ERC721": 2, + "ERC1155": 3, +} + +func (x ContractType) String() string { + return ContractType_name[uint16(x)] +} + +func (x ContractType) MarshalText() ([]byte, error) { + return []byte(ContractType_name[uint16(x)]), nil +} + +func (x *ContractType) UnmarshalText(b []byte) error { + *x = ContractType(ContractType_value[string(b)]) + return nil +} + +func (x *ContractType) Is(values ...ContractType) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false +} + +type CollectionPriority uint8 + +const ( + CollectionPriority_low CollectionPriority = 0 + CollectionPriority_normal CollectionPriority = 1 + CollectionPriority_high CollectionPriority = 2 +) + +var CollectionPriority_name = map[uint8]string{ + 0: "low", + 1: "normal", + 2: "high", +} + +var CollectionPriority_value = map[string]uint8{ + "low": 0, + "normal": 1, + "high": 2, +} + +func (x CollectionPriority) String() string { + return CollectionPriority_name[uint8(x)] +} + +func (x CollectionPriority) MarshalText() ([]byte, error) { + return []byte(CollectionPriority_name[uint8(x)]), nil +} + +func (x *CollectionPriority) UnmarshalText(b []byte) error { + *x = CollectionPriority(CollectionPriority_value[string(b)]) + return nil +} + +func (x *CollectionPriority) Is(values ...CollectionPriority) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false +} + type CollectionStatus uint8 const ( - CollectionStatus_unknown CollectionStatus = 0 - CollectionStatus_created CollectionStatus = 1 - CollectionStatus_syncing_tokens CollectionStatus = 2 - CollectionStatus_synced_tokens CollectionStatus = 3 - CollectionStatus_syncing_orders CollectionStatus = 4 - CollectionStatus_active CollectionStatus = 5 - CollectionStatus_failed CollectionStatus = 6 - CollectionStatus_inactive CollectionStatus = 7 + CollectionStatus_unknown CollectionStatus = 0 + CollectionStatus_created CollectionStatus = 1 + CollectionStatus_syncing_contract_metadata CollectionStatus = 2 + CollectionStatus_synced_contract_metadata CollectionStatus = 3 + CollectionStatus_syncing_metadata CollectionStatus = 4 + CollectionStatus_synced_metadata CollectionStatus = 5 + CollectionStatus_syncing_tokens CollectionStatus = 6 + CollectionStatus_synced_tokens CollectionStatus = 7 + CollectionStatus_syncing_orders CollectionStatus = 8 + CollectionStatus_active CollectionStatus = 9 + CollectionStatus_failed CollectionStatus = 10 + CollectionStatus_inactive CollectionStatus = 11 + CollectionStatus_incompatible_type CollectionStatus = 12 ) var CollectionStatus_name = map[uint8]string{ - 0: "unknown", - 1: "created", - 2: "syncing_tokens", - 3: "synced_tokens", - 4: "syncing_orders", - 5: "active", - 6: "failed", - 7: "inactive", + 0: "unknown", + 1: "created", + 2: "syncing_contract_metadata", + 3: "synced_contract_metadata", + 4: "syncing_metadata", + 5: "synced_metadata", + 6: "syncing_tokens", + 7: "synced_tokens", + 8: "syncing_orders", + 9: "active", + 10: "failed", + 11: "inactive", + 12: "incompatible_type", } var CollectionStatus_value = map[string]uint8{ - "unknown": 0, - "created": 1, - "syncing_tokens": 2, - "synced_tokens": 3, - "syncing_orders": 4, - "active": 5, - "failed": 6, - "inactive": 7, + "unknown": 0, + "created": 1, + "syncing_contract_metadata": 2, + "synced_contract_metadata": 3, + "syncing_metadata": 4, + "synced_metadata": 5, + "syncing_tokens": 6, + "synced_tokens": 7, + "syncing_orders": 8, + "active": 9, + "failed": 10, + "inactive": 11, + "incompatible_type": 12, } func (x CollectionStatus) String() string { @@ -596,697 +792,2022 @@ func (x *CollectibleStatus) Is(values ...CollectibleStatus) bool { return false } -// Page represents a results page. This can be used both to request a page and -// to store the state of a page. -type Page struct { - // Numbered pages: Page number, this is multiplied by the value of the parameter. - Page uint32 `json:"page,omitempty"` - // Number of items per page - PageSize uint32 `json:"pageSize,omitempty"` - // Indicates if there are more results available - More *bool `json:"more,omitempty"` - // Sorting filter - Sort []*SortBy `json:"sort,omitempty"` -} +type CurrencyStatus uint8 -type SortBy struct { - Column string `json:"column"` - Order SortOrder `json:"order"` -} +const ( + CurrencyStatus_unknown CurrencyStatus = 0 + CurrencyStatus_created CurrencyStatus = 1 + CurrencyStatus_syncing_metadata CurrencyStatus = 2 + CurrencyStatus_active CurrencyStatus = 3 + CurrencyStatus_failed CurrencyStatus = 4 +) -// copied from metadata filter -// PropertyFilter -// name -> name of the property, eg: hero -// type -> type of the values of the property, eg: Int, string -// min?, max? used if type is int, gives range of values for filtering -// values? -> if string then array of values, eg: ['Ada', 'Ari', 'Axel', 'Banjo' ...] -// NOTE: When Filter has an array of PropertyFilter, the logic used is an 'and' condition -// whereas if the user selects multiple values inside the PropertyFilter, they logic used is the 'or' condition -// this is to achieve the desired effect opensea had on their filters -type Filter struct { - Text *string `json:"text"` - Properties []*PropertyFilter `json:"properties"` +var CurrencyStatus_name = map[uint8]string{ + 0: "unknown", + 1: "created", + 2: "syncing_metadata", + 3: "active", + 4: "failed", } -type PropertyFilter struct { - Name string `json:"name"` - Type PropertyType `json:"type"` - Min *int64 `json:"min"` - Max *int64 `json:"max"` - Values []interface{} `json:"values"` +var CurrencyStatus_value = map[string]uint8{ + "unknown": 0, + "created": 1, + "syncing_metadata": 2, + "active": 3, + "failed": 4, } -type CollectiblesFilter struct { - IncludeEmpty bool `json:"includeEmpty"` - SearchText *string `json:"searchText"` - Properties []*PropertyFilter `json:"properties"` - Marketplaces []*MarketplaceKind `json:"marketplaces"` - // filter collectibles owned by given account addresses - InAccounts []string `json:"inAccounts"` - // filter out collectibles owned by given account addresses - NotInAccounts []string `json:"notInAccounts"` - // filter orders created by given account addresses - OrdersCreatedBy []string `json:"ordersCreatedBy"` - // filter out orders created by given account addresses - OrdersNotCreatedBy []string `json:"ordersNotCreatedBy"` +func (x CurrencyStatus) String() string { + return CurrencyStatus_name[uint8(x)] } -type Order struct { - ID uint64 `json:"-" db:"id,omitempty"` - CollectionID uint64 `json:"-" db:"collection_id,omitempty"` - CollectibleID uint64 `json:"-" db:"collectible_id,omitempty"` - OrderID string `json:"orderId" db:"order_id"` - Marketplace MarketplaceKind `json:"marketplace" db:"marketplace"` - Source SourceKind `json:"-" db:"source"` - Side OrderSide `json:"side" db:"side"` - Status OrderStatus `json:"status" db:"status"` - ChainID uint64 `json:"chainId" db:"chain_id"` - // contract - CollectionContractAddress prototyp.Hash `json:"collectionContractAddress" db:"contract_address"` - TokenID prototyp.BigInt `json:"tokenId" db:"token_id"` - CreatedBy prototyp.Hash `json:"createdBy" db:"created_by"` - PriceAmount prototyp.BigInt `json:"priceAmount" db:"price_amount"` - PriceAmountFormatted string `json:"priceAmountFormatted"` - PriceAmountNet prototyp.BigInt `json:"priceAmountNet" db:"price_amount_net"` - PriceAmountNetFormatted string `json:"priceAmountNetFormatted"` - PriceCurrencyAddress prototyp.Hash `json:"priceCurrencyAddress" db:"price_currency_address"` - PriceDecimals uint64 `json:"priceDecimals" db:"price_decimals"` - PriceUSD float64 `json:"priceUSD" db:"price_usd"` - QuantityInitial prototyp.BigInt `json:"quantityInitial" db:"qty_initial"` - QuantityInitialFormatted string `json:"quantityInitialFormatted"` - QuantityRemaining prototyp.BigInt `json:"quantityRemaining" db:"qty_remaining"` - QuantityRemainingFormatted string `json:"quantityRemainingFormatted"` - QuantityAvailable prototyp.BigInt `json:"quantityAvailable" db:"qty_available"` - QuantityAvailableFormatted string `json:"quantityAvailableFormatted"` - QuantityDecimals uint64 `json:"quantityDecimals" db:"qty_decimals"` - FeeBPS int64 `json:"feeBps" db:"fee_bps"` - FeeBreakdown []*FeeBreakdown `json:"feeBreakdown" db:"fee_breakdown"` - ValidFrom time.Time `json:"validFrom" db:"valid_from"` - // expiration - ValidUntil time.Time `json:"validUntil" db:"valid_until"` - OrderCreatedAt *time.Time `json:"orderCreatedAt" db:"order_created_at"` - OrderUpdatedAt *time.Time `json:"orderUpdatedAt" db:"order_updated_at"` - CreatedAt time.Time `json:"createdAt" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` - DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +func (x CurrencyStatus) MarshalText() ([]byte, error) { + return []byte(CurrencyStatus_name[uint8(x)]), nil } -type FeeBreakdown struct { - Kind string `json:"kind"` - RecipientAddress string `json:"recipientAddress"` - Bps int64 `json:"bps"` +func (x *CurrencyStatus) UnmarshalText(b []byte) error { + *x = CurrencyStatus(CurrencyStatus_value[string(b)]) + return nil } -type CollectibleOrder struct { - Metadata *TokenMetadata `json:"metadata"` - Order *Order `json:"order"` +func (x *CurrencyStatus) Is(values ...CurrencyStatus) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false } -type OrderFilter struct { - CreatedBy []string `json:"createdBy"` - Marketplace []*MarketplaceKind `json:"marketplace"` -} +type WalletKind uint8 -type Activity struct { - Type string `json:"type"` - FromAddress string `json:"fromAddress"` - ToAddress string `json:"toAddress"` - TxHash string `json:"txHash"` - Timestamp int64 `json:"timestamp"` - TokenId string `json:"tokenId"` - TokenImage string `json:"tokenImage"` - TokenName string `json:"tokenName"` - Currency *Currency `json:"currency"` -} +const ( + WalletKind_unknown WalletKind = 0 + WalletKind_sequence WalletKind = 1 +) -type Collection struct { - ID uint64 `json:"-" db:"id,omitempty"` - Status CollectionStatus `json:"status" db:"status"` - ChainID uint64 `json:"chainId" db:"chain_id"` - ContractAddress prototyp.Hash `json:"contractAddress" db:"contract_address"` - TokenQuantityDecimals uint64 `json:"tokenQuantityDecimals" db:"token_qty_decimals"` - Config *CollectionConfig `json:"config" db:"config"` - CreatedAt time.Time `json:"createdAt" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` - DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +var WalletKind_name = map[uint8]string{ + 0: "unknown", + 1: "sequence", } -type CollectionConfig struct { - LastSynced map[string]*CollectionLastSynced `json:"lastSynced"` +var WalletKind_value = map[string]uint8{ + "unknown": 0, + "sequence": 1, } -type CollectionLastSynced struct { - AllOrders time.Time `json:"allOrders"` - NewOrders time.Time `json:"newOrders"` +func (x WalletKind) String() string { + return WalletKind_name[uint8(x)] } -type Project struct { - ID uint64 `json:"-" db:"id,omitempty"` - ProjectID uint64 `json:"projectId" db:"project_id"` - CollectionID uint64 `json:"-" db:"collection_id,omitempty"` - ChainID uint64 `json:"chainId" db:"chain_id"` - ContractAddress prototyp.Hash `json:"contractAddress" db:"contract_address"` - Status ProjectStatus `json:"status" db:"status"` - CreatedAt time.Time `json:"createdAt" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` - DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +func (x WalletKind) MarshalText() ([]byte, error) { + return []byte(WalletKind_name[uint8(x)]), nil } -type Collectible struct { - ID uint64 `json:"-" db:"id,omitempty"` - CollectionID uint64 `json:"-" db:"collection_id,omitempty"` - ChainID uint64 `json:"chainId" db:"chain_id"` - ContractAddress prototyp.Hash `json:"contractAddress" db:"contract_address"` - Status CollectibleStatus `json:"status" db:"status"` - TokenID prototyp.BigInt `json:"tokenId" db:"token_id"` - CreatedAt time.Time `json:"createdAt" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` - DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +func (x *WalletKind) UnmarshalText(b []byte) error { + *x = WalletKind(WalletKind_value[string(b)]) + return nil } -type Currency struct { - ID uint64 `json:"-" db:"id,omitempty"` - ChainID uint64 `json:"chainId" db:"chain_id"` - ContractAddress prototyp.Hash `json:"contractAddress" db:"contract_address"` - Name string `json:"name" db:"name"` - Symbol string `json:"symbol" db:"symbol"` - Decimals uint64 `json:"decimals" db:"decimals"` - ImageURL string `json:"imageUrl" db:"image_url"` - ExchangeRate float64 `json:"exchangeRate" db:"exchange_rate"` - DefaultChainCurrency bool `json:"defaultChainCurrency" db:"default_chain_currency"` - NativeCurrency bool `json:"nativeCurrency" db:"native_currency"` - SardineSupported bool `json:"sardineSupported" db:"sardine_supported"` - TransakSupported bool `json:"transakSupported" db:"transak_supported"` - CreatedAt time.Time `json:"createdAt" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` - DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +func (x *WalletKind) Is(values ...WalletKind) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false } -var WebRPCServices = map[string][]string{ - "Admin": { - "CreateCollection", - "GetCollection", - "ListCollections", - "DeleteCollection", - "SyncCollection", - "CreateCurrency", - "CreateCurrencies", - "UpdateCurrency", - "ListCurrencies", - "DeleteCurrency", - }, - "Marketplace": { - "ListCurrencies", - "GetCollectible", - "GetCollectibleLowestOffer", - "GetCollectibleHighestOffer", - "GetCollectibleLowestListing", - "GetCollectibleHighestListing", - "ListCollectibleListings", - "ListCollectibleOffers", - "ListCollectiblesWithLowestListing", - "ListCollectiblesWithHighestOffer", - "SyncOrder", - "SyncOrders", - }, +type StepType uint8 + +const ( + StepType_unknown StepType = 0 + StepType_tokenApproval StepType = 1 + StepType_buy StepType = 2 + StepType_sell StepType = 3 + StepType_createListing StepType = 4 + StepType_createOffer StepType = 5 + StepType_signEIP712 StepType = 6 + StepType_signEIP191 StepType = 7 + StepType_cancel StepType = 8 +) + +var StepType_name = map[uint8]string{ + 0: "unknown", + 1: "tokenApproval", + 2: "buy", + 3: "sell", + 4: "createListing", + 5: "createOffer", + 6: "signEIP712", + 7: "signEIP191", + 8: "cancel", } -// -// Server types -// +var StepType_value = map[string]uint8{ + "unknown": 0, + "tokenApproval": 1, + "buy": 2, + "sell": 3, + "createListing": 4, + "createOffer": 5, + "signEIP712": 6, + "signEIP191": 7, + "cancel": 8, +} -type Admin interface { - CreateCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) - GetCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) - ListCollections(ctx context.Context, projectId uint64, page *Page) ([]*Collection, *Page, error) - DeleteCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) - SyncCollection(ctx context.Context, projectId uint64, contractAddress string) error - CreateCurrency(ctx context.Context, currency *Currency) (*Currency, error) - CreateCurrencies(ctx context.Context, currencies []*Currency) (map[string]*Currency, error) - UpdateCurrency(ctx context.Context, currency *Currency) (*Currency, error) - ListCurrencies(ctx context.Context) ([]*Currency, error) - DeleteCurrency(ctx context.Context, chainId uint64, contractAddress string) (*Currency, error) +func (x StepType) String() string { + return StepType_name[uint8(x)] } -type Marketplace interface { - ListCurrencies(ctx context.Context) ([]*Currency, error) - GetCollectible(ctx context.Context, contractAddress string, tokenId string) (*TokenMetadata, error) - GetCollectibleLowestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) - GetCollectibleHighestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) - GetCollectibleLowestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) - GetCollectibleHighestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) - ListCollectibleListings(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) - ListCollectibleOffers(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) - ListCollectiblesWithLowestListing(ctx context.Context, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) - ListCollectiblesWithHighestOffer(ctx context.Context, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) - SyncOrder(ctx context.Context, order *Order) error - SyncOrders(ctx context.Context, orders []*Order) error +func (x StepType) MarshalText() ([]byte, error) { + return []byte(StepType_name[uint8(x)]), nil } -// -// Client types -// +func (x *StepType) UnmarshalText(b []byte) error { + *x = StepType(StepType_value[string(b)]) + return nil +} -type AdminClient interface { - CreateCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) - GetCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) - ListCollections(ctx context.Context, projectId uint64, page *Page) ([]*Collection, *Page, error) - DeleteCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) - SyncCollection(ctx context.Context, projectId uint64, contractAddress string) error - CreateCurrency(ctx context.Context, currency *Currency) (*Currency, error) - CreateCurrencies(ctx context.Context, currencies []*Currency) (map[string]*Currency, error) - UpdateCurrency(ctx context.Context, currency *Currency) (*Currency, error) - ListCurrencies(ctx context.Context) ([]*Currency, error) - DeleteCurrency(ctx context.Context, chainId uint64, contractAddress string) (*Currency, error) +func (x *StepType) Is(values ...StepType) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false } -type MarketplaceClient interface { - ListCurrencies(ctx context.Context) ([]*Currency, error) - GetCollectible(ctx context.Context, contractAddress string, tokenId string) (*TokenMetadata, error) - GetCollectibleLowestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) - GetCollectibleHighestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) - GetCollectibleLowestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) - GetCollectibleHighestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) - ListCollectibleListings(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) - ListCollectibleOffers(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) - ListCollectiblesWithLowestListing(ctx context.Context, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) - ListCollectiblesWithHighestOffer(ctx context.Context, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) - SyncOrder(ctx context.Context, order *Order) error - SyncOrders(ctx context.Context, orders []*Order) error +type TransactionCrypto uint32 + +const ( + TransactionCrypto_none TransactionCrypto = 0 + TransactionCrypto_partially TransactionCrypto = 1 + TransactionCrypto_all TransactionCrypto = 2 +) + +var TransactionCrypto_name = map[uint32]string{ + 0: "none", + 1: "partially", + 2: "all", } -// -// Client -// +var TransactionCrypto_value = map[string]uint32{ + "none": 0, + "partially": 1, + "all": 2, +} + +func (x TransactionCrypto) String() string { + return TransactionCrypto_name[uint32(x)] +} + +func (x TransactionCrypto) MarshalText() ([]byte, error) { + return []byte(TransactionCrypto_name[uint32(x)]), nil +} + +func (x *TransactionCrypto) UnmarshalText(b []byte) error { + *x = TransactionCrypto(TransactionCrypto_value[string(b)]) + return nil +} + +func (x *TransactionCrypto) Is(values ...TransactionCrypto) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false +} + +type TransactionNFTCheckoutProvider uint32 const ( - AdminPathPrefix = "/rpc/Admin/" - MarketplacePathPrefix = "/rpc/Marketplace/" + TransactionNFTCheckoutProvider_unknown TransactionNFTCheckoutProvider = 0 + TransactionNFTCheckoutProvider_sardine TransactionNFTCheckoutProvider = 1 + TransactionNFTCheckoutProvider_transak TransactionNFTCheckoutProvider = 2 ) -type adminClient struct { - client HTTPClient - urls [10]string +var TransactionNFTCheckoutProvider_name = map[uint32]string{ + 0: "unknown", + 1: "sardine", + 2: "transak", } -func NewAdminClient(addr string, client HTTPClient) AdminClient { - prefix := urlBase(addr) + AdminPathPrefix - urls := [10]string{ - prefix + "CreateCollection", - prefix + "GetCollection", - prefix + "ListCollections", - prefix + "DeleteCollection", - prefix + "SyncCollection", - prefix + "CreateCurrency", - prefix + "CreateCurrencies", - prefix + "UpdateCurrency", - prefix + "ListCurrencies", - prefix + "DeleteCurrency", +var TransactionNFTCheckoutProvider_value = map[string]uint32{ + "unknown": 0, + "sardine": 1, + "transak": 2, +} + +func (x TransactionNFTCheckoutProvider) String() string { + return TransactionNFTCheckoutProvider_name[uint32(x)] +} + +func (x TransactionNFTCheckoutProvider) MarshalText() ([]byte, error) { + return []byte(TransactionNFTCheckoutProvider_name[uint32(x)]), nil +} + +func (x *TransactionNFTCheckoutProvider) UnmarshalText(b []byte) error { + *x = TransactionNFTCheckoutProvider(TransactionNFTCheckoutProvider_value[string(b)]) + return nil +} + +func (x *TransactionNFTCheckoutProvider) Is(values ...TransactionNFTCheckoutProvider) bool { + if x == nil { + return false } - return &adminClient{ - client: client, - urls: urls, + for _, v := range values { + if *x == v { + return true + } + } + return false +} + +type TransactionOnRampProvider uint32 + +const ( + TransactionOnRampProvider_unknown TransactionOnRampProvider = 0 + TransactionOnRampProvider_sardine TransactionOnRampProvider = 1 + TransactionOnRampProvider_transak TransactionOnRampProvider = 2 +) + +var TransactionOnRampProvider_name = map[uint32]string{ + 0: "unknown", + 1: "sardine", + 2: "transak", +} + +var TransactionOnRampProvider_value = map[string]uint32{ + "unknown": 0, + "sardine": 1, + "transak": 2, +} + +func (x TransactionOnRampProvider) String() string { + return TransactionOnRampProvider_name[uint32(x)] +} + +func (x TransactionOnRampProvider) MarshalText() ([]byte, error) { + return []byte(TransactionOnRampProvider_name[uint32(x)]), nil +} + +func (x *TransactionOnRampProvider) UnmarshalText(b []byte) error { + *x = TransactionOnRampProvider(TransactionOnRampProvider_value[string(b)]) + return nil +} + +func (x *TransactionOnRampProvider) Is(values ...TransactionOnRampProvider) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false +} + +type TransactionSwapProvider uint32 + +const ( + TransactionSwapProvider_unknown TransactionSwapProvider = 0 + TransactionSwapProvider_zerox TransactionSwapProvider = 1 +) + +var TransactionSwapProvider_name = map[uint32]string{ + 0: "unknown", + 1: "zerox", +} + +var TransactionSwapProvider_value = map[string]uint32{ + "unknown": 0, + "zerox": 1, +} + +func (x TransactionSwapProvider) String() string { + return TransactionSwapProvider_name[uint32(x)] +} + +func (x TransactionSwapProvider) MarshalText() ([]byte, error) { + return []byte(TransactionSwapProvider_name[uint32(x)]), nil +} + +func (x *TransactionSwapProvider) UnmarshalText(b []byte) error { + *x = TransactionSwapProvider(TransactionSwapProvider_value[string(b)]) + return nil +} + +func (x *TransactionSwapProvider) Is(values ...TransactionSwapProvider) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false +} + +type ExecuteType uint32 + +const ( + ExecuteType_unknown ExecuteType = 0 + ExecuteType_order ExecuteType = 1 +) + +var ExecuteType_name = map[uint32]string{ + 0: "unknown", + 1: "order", +} + +var ExecuteType_value = map[string]uint32{ + "unknown": 0, + "order": 1, +} + +func (x ExecuteType) String() string { + return ExecuteType_name[uint32(x)] +} + +func (x ExecuteType) MarshalText() ([]byte, error) { + return []byte(ExecuteType_name[uint32(x)]), nil +} + +func (x *ExecuteType) UnmarshalText(b []byte) error { + *x = ExecuteType(ExecuteType_value[string(b)]) + return nil +} + +func (x *ExecuteType) Is(values ...ExecuteType) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } } + return false +} + +type ActivityAction uint8 + +const ( + ActivityAction_unknown ActivityAction = 0 + ActivityAction_listing ActivityAction = 1 + ActivityAction_offer ActivityAction = 2 + ActivityAction_mint ActivityAction = 3 + ActivityAction_sale ActivityAction = 4 + ActivityAction_listingCancel ActivityAction = 5 + ActivityAction_offerCancel ActivityAction = 6 + ActivityAction_transfer ActivityAction = 7 +) + +var ActivityAction_name = map[uint8]string{ + 0: "unknown", + 1: "listing", + 2: "offer", + 3: "mint", + 4: "sale", + 5: "listingCancel", + 6: "offerCancel", + 7: "transfer", +} + +var ActivityAction_value = map[string]uint8{ + "unknown": 0, + "listing": 1, + "offer": 2, + "mint": 3, + "sale": 4, + "listingCancel": 5, + "offerCancel": 6, + "transfer": 7, +} + +func (x ActivityAction) String() string { + return ActivityAction_name[uint8(x)] +} + +func (x ActivityAction) MarshalText() ([]byte, error) { + return []byte(ActivityAction_name[uint8(x)]), nil +} + +func (x *ActivityAction) UnmarshalText(b []byte) error { + *x = ActivityAction(ActivityAction_value[string(b)]) + return nil +} + +func (x *ActivityAction) Is(values ...ActivityAction) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false +} + +// Page represents a results page. This can be used both to request a page and +// to store the state of a page. +type Page struct { + // Numbered pages: Page number, this is multiplied by the value of the parameter. + Page uint32 `json:"page,omitempty"` + // Number of items per page + PageSize uint32 `json:"pageSize,omitempty"` + // Indicates if there are more results available + More *bool `json:"more,omitempty"` + // Sorting filter + Sort []*SortBy `json:"sort,omitempty"` +} + +type SortBy struct { + Column string `json:"column"` + Order SortOrder `json:"order"` +} + +// copied from metadata filter +// PropertyFilter +// name -> name of the property, eg: hero +// type -> type of the values of the property, eg: Int, string +// min?, max? used if type is int, gives range of values for filtering +// values? -> if string then array of values, eg: ['Ada', 'Ari', 'Axel', 'Banjo' ...] +// NOTE: When Filter has an array of PropertyFilter, the logic used is an 'and' condition +// whereas if the user selects multiple values inside the PropertyFilter, they logic used is the 'or' condition +// this is to achieve the desired effect opensea had on their filters +type Filter struct { + Text *string `json:"text"` + Properties []*PropertyFilter `json:"properties"` +} + +type PropertyFilter struct { + Name string `json:"name"` + Type PropertyType `json:"type"` + Min *int64 `json:"min"` + Max *int64 `json:"max"` + Values []interface{} `json:"values"` +} + +type CollectiblesFilter struct { + IncludeEmpty bool `json:"includeEmpty"` + SearchText *string `json:"searchText"` + Properties []*PropertyFilter `json:"properties"` + Marketplaces []MarketplaceKind `json:"marketplaces"` + // filter collectibles owned by given account addresses + InAccounts []string `json:"inAccounts"` + // filter out collectibles owned by given account addresses + NotInAccounts []string `json:"notInAccounts"` + // filter orders created by given account addresses + OrdersCreatedBy []string `json:"ordersCreatedBy"` + // filter out orders created by given account addresses + OrdersNotCreatedBy []string `json:"ordersNotCreatedBy"` +} + +type Order struct { + ID uint64 `json:"-" db:"id,omitempty"` + CollectionID uint64 `json:"-" db:"collection_id,omitempty"` + CollectibleID uint64 `json:"-" db:"collectible_id,omitempty"` + OrderID string `json:"orderId" db:"order_id"` + Marketplace MarketplaceKind `json:"marketplace" db:"marketplace"` + Source SourceKind `json:"-" db:"source"` + Side OrderSide `json:"side" db:"side"` + Status OrderStatus `json:"status" db:"status"` + ChainID uint64 `json:"chainId" db:"chain_id"` + OriginName string `json:"originName,omitempty" db:"origin_name"` + // contract + CollectionContractAddress prototyp.Hash `json:"collectionContractAddress" db:"contract_address"` + TokenID prototyp.BigInt `json:"tokenId" db:"token_id"` + CreatedBy prototyp.Hash `json:"createdBy" db:"created_by"` + PriceAmount prototyp.BigInt `json:"priceAmount" db:"price_amount"` + PriceAmountFormatted string `json:"priceAmountFormatted"` + PriceAmountNet prototyp.BigInt `json:"priceAmountNet" db:"price_amount_net"` + PriceAmountNetFormatted string `json:"priceAmountNetFormatted"` + PriceCurrencyAddress prototyp.Hash `json:"priceCurrencyAddress" db:"price_currency_address"` + PriceDecimals uint64 `json:"priceDecimals" db:"price_decimals"` + PriceUSD float64 `json:"priceUSD" db:"price_usd"` + PriceUSDFormatted string `json:"priceUSDFormatted"` + QuantityInitial prototyp.BigInt `json:"quantityInitial" db:"qty_initial"` + QuantityInitialFormatted string `json:"quantityInitialFormatted"` + QuantityRemaining prototyp.BigInt `json:"quantityRemaining" db:"qty_remaining"` + QuantityRemainingFormatted string `json:"quantityRemainingFormatted"` + QuantityAvailable prototyp.BigInt `json:"quantityAvailable" db:"qty_available"` + QuantityAvailableFormatted string `json:"quantityAvailableFormatted"` + QuantityDecimals uint64 `json:"quantityDecimals" db:"qty_decimals"` + FeeBPS int64 `json:"feeBps" db:"fee_bps"` + FeeBreakdown []*FeeBreakdown `json:"feeBreakdown" db:"fee_breakdown"` + ValidFrom time.Time `json:"validFrom" db:"valid_from"` + // expiration + ValidUntil time.Time `json:"validUntil" db:"valid_until"` + BlockNumber uint64 `json:"blockNumber" db:"block_number"` + OrderCreatedAt *time.Time `json:"orderCreatedAt" db:"order_created_at"` + OrderUpdatedAt *time.Time `json:"orderUpdatedAt" db:"order_updated_at"` + CreatedAt time.Time `json:"createdAt" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` + DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +} + +type FeeBreakdown struct { + Kind string `json:"kind"` + RecipientAddress string `json:"recipientAddress"` + Bps int64 `json:"bps"` +} + +type CollectibleOrder struct { + Metadata *TokenMetadata `json:"metadata"` + Order *Order `json:"order"` +} + +type OrderFilter struct { + CreatedBy []string `json:"createdBy"` + Marketplace []MarketplaceKind `json:"marketplace"` + Currencies []string `json:"currencies"` +} + +type Collection struct { + ID uint64 `json:"-" db:"id,omitempty"` + Status CollectionStatus `json:"status" db:"status"` + ChainID uint64 `json:"chainId" db:"chain_id"` + ContractAddress prototyp.Hash `json:"contractAddress" db:"contract_address"` + ContractType ContractType `json:"contractType" db:"contract_type"` + Priority CollectionPriority `json:"priority" db:"priority"` + TokenQuantityDecimals uint64 `json:"tokenQuantityDecimals" db:"token_qty_decimals"` + Config *CollectionConfig `json:"config" db:"config"` + SyncContractMetadataJob uint64 `json:"-" db:"sync_contract_metadata_job"` + RefreshMetadataJob uint64 `json:"-" db:"refresh_metadata_job"` + RefreshMetadataTimestamp time.Time `json:"-" db:"refresh_metadata_timestamp"` + CreatedAt time.Time `json:"createdAt" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` + DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +} + +type CollectionConfig struct { + LastSynced map[string]*CollectionLastSynced `json:"lastSynced"` + CollectiblesSynced time.Time `json:"collectiblesSynced"` + ActivitiesSynced time.Time `json:"activitiesSynced"` + ActivitiesSyncedContinuity string `json:"activitiesSyncedContinuity"` +} + +type CollectionLastSynced struct { + AllOrders time.Time `json:"allOrders"` + NewOrders time.Time `json:"newOrders"` +} + +type Project struct { + ID uint64 `json:"-" db:"id,omitempty"` + ProjectID uint64 `json:"projectId" db:"project_id"` + CollectionID uint64 `json:"-" db:"collection_id,omitempty"` + ChainID uint64 `json:"chainId" db:"chain_id"` + ContractAddress prototyp.Hash `json:"contractAddress" db:"contract_address"` + Status ProjectStatus `json:"status" db:"status"` + CreatedAt time.Time `json:"createdAt" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` + DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +} + +type Collectible struct { + ID uint64 `json:"-" db:"id,omitempty"` + CollectionID uint64 `json:"-" db:"collection_id,omitempty"` + ChainID uint64 `json:"chainId" db:"chain_id"` + ContractAddress prototyp.Hash `json:"contractAddress" db:"contract_address"` + Status CollectibleStatus `json:"status" db:"status"` + TokenID prototyp.BigInt `json:"tokenId" db:"token_id"` + Decimals uint64 `json:"decimals" db:"decimals"` + CreatedAt time.Time `json:"createdAt" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` + DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +} + +type Currency struct { + ID uint64 `json:"-" db:"id,omitempty"` + ChainID uint64 `json:"chainId" db:"chain_id"` + ContractAddress prototyp.Hash `json:"contractAddress,omitempty" db:"contract_address"` + Status CurrencyStatus `json:"status" db:"status"` + Name string `json:"name" db:"name"` + Symbol string `json:"symbol" db:"symbol"` + Decimals uint64 `json:"decimals" db:"decimals"` + ImageURL string `json:"imageUrl" db:"image_url"` + ExchangeRate float64 `json:"exchangeRate" db:"exchange_rate"` + DefaultChainCurrency bool `json:"defaultChainCurrency" db:"default_chain_currency"` + NativeCurrency bool `json:"nativeCurrency" db:"native_currency"` + CreatedAt time.Time `json:"createdAt" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` + DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` + RefreshMetadataJob uint64 `json:"-" db:"refresh_metadata_job"` +} + +type OrderData struct { + OrderID string `json:"orderId"` + Quantity string `json:"quantity"` +} + +type AdditionalFee struct { + Amount string `json:"amount"` + Receiver string `json:"receiver"` +} + +type Step struct { + ID StepType `json:"id"` + Data string `json:"data"` + To string `json:"to"` + Value string `json:"value"` + Signature *Signature `json:"signature"` + Post *PostRequest `json:"post"` + ExecuteType *ExecuteType `json:"executeType"` +} + +type PostRequest struct { + Endpoint string `json:"endpoint"` + Method string `json:"method"` + Body interface{} `json:"body"` +} + +type CreateReq struct { + TokenID string `json:"tokenId"` + Quantity string `json:"quantity"` + Expiry string `json:"expiry"` + CurrencyAddress string `json:"currencyAddress"` + PricePerToken string `json:"pricePerToken"` +} + +type GetOrdersInput struct { + ContractAddress prototyp.Hash `json:"contractAddress"` + OrderID string `json:"orderId"` + Marketplace MarketplaceKind `json:"marketplace"` +} + +type Signature struct { + Domain *Domain `json:"domain"` + Types interface{} `json:"types"` + PrimaryType string `json:"primaryType"` + Value interface{} `json:"value"` +} + +type Domain struct { + Name string `json:"name"` + Version string `json:"version"` + ChainID uint64 `json:"chainId"` + VerifyingContract string `json:"verifyingContract"` +} + +type CheckoutOptionsMarketplaceOrder struct { + ContractAddress prototyp.Hash `json:"contractAddress"` + OrderID string `json:"orderId"` + Marketplace MarketplaceKind `json:"marketplace"` +} + +type CheckoutOptionsItem struct { + TokenID string `json:"tokenId"` + Quantity prototyp.BigInt `json:"quantity"` +} + +type CheckoutOptions struct { + Crypto TransactionCrypto `json:"crypto"` + Swap []TransactionSwapProvider `json:"swap"` + NFTCheckout []TransactionNFTCheckoutProvider `json:"nftCheckout"` + OnRamp []TransactionOnRampProvider `json:"onRamp"` +} + +type Activity struct { + ID uint64 `json:"-" db:"id,omitempty"` + CollectionID uint64 `json:"-" db:"collection_id,omitempty"` + CollectibleID uint64 `json:"-" db:"collectible_id,omitempty"` + ChainID uint64 `json:"chainId" db:"chain_id"` + ContractAddress prototyp.Hash `json:"contractAddress" db:"contract_address"` + TokenID prototyp.BigInt `json:"tokenId" db:"token_id"` + Action ActivityAction `json:"action" db:"action"` + TxHash prototyp.Hash `json:"txHash" db:"tx_hash"` + Source SourceKind `json:"-" db:"source"` + From prototyp.Hash `json:"from" db:"from_address"` + To prototyp.Hash `json:"to" db:"to_address"` + Quantity prototyp.BigInt `json:"quantity" db:"qty"` + QuantityDecimals uint64 `json:"quantityDecimals" db:"qty_decimals"` + PriceAmount prototyp.BigInt `json:"priceAmount" db:"price_amount"` + PriceAmountFormatted *string `json:"priceAmountFormatted"` + PriceCurrencyAddress prototyp.Hash `json:"priceCurrencyAddress" db:"price_currency_address"` + PriceDecimals *uint64 `json:"priceDecimals" db:"price_decimals"` + ActivityCreatedAt time.Time `json:"activityCreatedAt" db:"activity_created_at"` + LogIndex uint64 `json:"-" db:"log_index"` + UniqueHash prototyp.Hash `json:"uniqueHash" db:"unique_hash"` + CreatedAt time.Time `json:"createdAt" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` + DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"` +} + +var methods = map[string]method{ + "/rpc/Admin/CreateCollection": { + Name: "CreateCollection", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/GetCollection": { + Name: "GetCollection", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/ListCollections": { + Name: "ListCollections", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/DeleteCollection": { + Name: "DeleteCollection", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/SyncCollection": { + Name: "SyncCollection", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/CreateCurrency": { + Name: "CreateCurrency", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/CreateCurrencies": { + Name: "CreateCurrencies", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/UpdateCurrency": { + Name: "UpdateCurrency", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/ListCurrencies": { + Name: "ListCurrencies", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Admin/DeleteCurrency": { + Name: "DeleteCurrency", + Service: "Admin", + Annotations: map[string]string{"auth": "AccessKey"}, + }, + "/rpc/Marketplace/ListCurrencies": { + Name: "ListCurrencies", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetCollectible": { + Name: "GetCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetLowestPriceOfferForCollectible": { + Name: "GetLowestPriceOfferForCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetHighestPriceOfferForCollectible": { + Name: "GetHighestPriceOfferForCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetLowestPriceListingForCollectible": { + Name: "GetLowestPriceListingForCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetHighestPriceListingForCollectible": { + Name: "GetHighestPriceListingForCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/ListListingsForCollectible": { + Name: "ListListingsForCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/ListOffersForCollectible": { + Name: "ListOffersForCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetCountOfListingsForCollectible": { + Name: "GetCountOfListingsForCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetCountOfOffersForCollectible": { + Name: "GetCountOfOffersForCollectible", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetCollectibleLowestOffer": { + Name: "GetCollectibleLowestOffer", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "deprecated": "GetLowestPriceOfferForCollectible"}, + }, + "/rpc/Marketplace/GetCollectibleHighestOffer": { + Name: "GetCollectibleHighestOffer", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "deprecated": "GetHighestPriceOfferForCollectible"}, + }, + "/rpc/Marketplace/GetCollectibleLowestListing": { + Name: "GetCollectibleLowestListing", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "deprecated": "GetLowestPriceListingForCollectible"}, + }, + "/rpc/Marketplace/GetCollectibleHighestListing": { + Name: "GetCollectibleHighestListing", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "deprecated": "GetHighestPriceListingForCollectible"}, + }, + "/rpc/Marketplace/ListCollectibleListings": { + Name: "ListCollectibleListings", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "deprecated": "ListListingsForCollectible"}, + }, + "/rpc/Marketplace/ListCollectibleOffers": { + Name: "ListCollectibleOffers", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "deprecated": "ListOffersForCollectible"}, + }, + "/rpc/Marketplace/GenerateBuyTransaction": { + Name: "GenerateBuyTransaction", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GenerateSellTransaction": { + Name: "GenerateSellTransaction", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GenerateListingTransaction": { + Name: "GenerateListingTransaction", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GenerateOfferTransaction": { + Name: "GenerateOfferTransaction", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GenerateCancelTransaction": { + Name: "GenerateCancelTransaction", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/Execute": { + Name: "Execute", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/ListCollectibles": { + Name: "ListCollectibles", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetCountOfAllCollectibles": { + Name: "GetCountOfAllCollectibles", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetCountOfFilteredCollectibles": { + Name: "GetCountOfFilteredCollectibles", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/GetFloorOrder": { + Name: "GetFloorOrder", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/ListCollectionActivities": { + Name: "ListCollectionActivities", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/ListCollectibleActivities": { + Name: "ListCollectibleActivities", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/ListCollectiblesWithLowestListing": { + Name: "ListCollectiblesWithLowestListing", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "deprecated": "ListCollectibles"}, + }, + "/rpc/Marketplace/ListCollectiblesWithHighestOffer": { + Name: "ListCollectiblesWithHighestOffer", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "deprecated": "ListCollectibles"}, + }, + "/rpc/Marketplace/SyncOrder": { + Name: "SyncOrder", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "internal": ""}, + }, + "/rpc/Marketplace/SyncOrders": { + Name: "SyncOrders", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public", "internal": ""}, + }, + "/rpc/Marketplace/GetOrders": { + Name: "GetOrders", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/CheckoutOptionsMarketplace": { + Name: "CheckoutOptionsMarketplace", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, + "/rpc/Marketplace/CheckoutOptionsSalesContract": { + Name: "CheckoutOptionsSalesContract", + Service: "Marketplace", + Annotations: map[string]string{"auth": "Public"}, + }, +} + +func WebrpcMethods() map[string]method { + res := make(map[string]method, len(methods)) + for k, v := range methods { + res[k] = v + } + + return res +} + +var WebRPCServices = map[string][]string{ + "Admin": { + "CreateCollection", + "GetCollection", + "ListCollections", + "DeleteCollection", + "SyncCollection", + "CreateCurrency", + "CreateCurrencies", + "UpdateCurrency", + "ListCurrencies", + "DeleteCurrency", + }, + "Marketplace": { + "ListCurrencies", + "GetCollectible", + "GetLowestPriceOfferForCollectible", + "GetHighestPriceOfferForCollectible", + "GetLowestPriceListingForCollectible", + "GetHighestPriceListingForCollectible", + "ListListingsForCollectible", + "ListOffersForCollectible", + "GetCountOfListingsForCollectible", + "GetCountOfOffersForCollectible", + "GetCollectibleLowestOffer", + "GetCollectibleHighestOffer", + "GetCollectibleLowestListing", + "GetCollectibleHighestListing", + "ListCollectibleListings", + "ListCollectibleOffers", + "GenerateBuyTransaction", + "GenerateSellTransaction", + "GenerateListingTransaction", + "GenerateOfferTransaction", + "GenerateCancelTransaction", + "Execute", + "ListCollectibles", + "GetCountOfAllCollectibles", + "GetCountOfFilteredCollectibles", + "GetFloorOrder", + "ListCollectionActivities", + "ListCollectibleActivities", + "ListCollectiblesWithLowestListing", + "ListCollectiblesWithHighestOffer", + "SyncOrder", + "SyncOrders", + "GetOrders", + "CheckoutOptionsMarketplace", + "CheckoutOptionsSalesContract", + }, +} + +// +// Server types +// + +type Admin interface { + CreateCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) + GetCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) + ListCollections(ctx context.Context, projectId uint64, page *Page) ([]*Collection, *Page, error) + DeleteCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) + // determine what should happen here + SyncCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) + CreateCurrency(ctx context.Context, currency *Currency) (*Currency, error) + CreateCurrencies(ctx context.Context, currencies []*Currency) (map[string]*Currency, error) + UpdateCurrency(ctx context.Context, currency *Currency) (*Currency, error) + ListCurrencies(ctx context.Context) ([]*Currency, error) + DeleteCurrency(ctx context.Context, chainId uint64, contractAddress string) (*Currency, error) +} + +type Marketplace interface { + ListCurrencies(ctx context.Context) ([]*Currency, error) + GetCollectible(ctx context.Context, contractAddress string, tokenId string) (*TokenMetadata, error) + GetLowestPriceOfferForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + GetHighestPriceOfferForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + GetLowestPriceListingForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + GetHighestPriceListingForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + ListListingsForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, skipRealtimeSync bool, page *Page) ([]*Order, *Page, error) + ListOffersForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, skipRealtimeSync bool, page *Page) ([]*Order, *Page, error) + GetCountOfListingsForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (uint64, error) + GetCountOfOffersForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (uint64, error) + // Deprecated: + GetCollectibleLowestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + // Deprecated: + GetCollectibleHighestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + // Deprecated: + GetCollectibleLowestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + // Deprecated: + GetCollectibleHighestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + // Deprecated: + ListCollectibleListings(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) + // Deprecated: + ListCollectibleOffers(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) + // checkout process + GenerateBuyTransaction(ctx context.Context, collectionAddress string, buyer string, marketplace MarketplaceKind, ordersData []*OrderData, additionalFees []*AdditionalFee, walletType *WalletKind) ([]*Step, error) + GenerateSellTransaction(ctx context.Context, collectionAddress string, seller string, marketplace MarketplaceKind, ordersData []*OrderData, additionalFees []*AdditionalFee, walletType *WalletKind) ([]*Step, error) + GenerateListingTransaction(ctx context.Context, collectionAddress string, owner string, contractType ContractType, orderbook OrderbookKind, listing *CreateReq, walletType *WalletKind) ([]*Step, error) + GenerateOfferTransaction(ctx context.Context, collectionAddress string, maker string, contractType ContractType, orderbook OrderbookKind, offer *CreateReq, walletType *WalletKind) ([]*Step, error) + GenerateCancelTransaction(ctx context.Context, collectionAddress string, maker string, marketplace MarketplaceKind, orderId string) ([]*Step, error) + // only used in a case of external transactions ( when we create off-chain transactions ) for instance opensea market + Execute(ctx context.Context, signature string, executeType ExecuteType, body interface{}) (string, error) + ListCollectibles(ctx context.Context, side OrderSide, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) + GetCountOfAllCollectibles(ctx context.Context, contractAddress string) (uint64, error) + GetCountOfFilteredCollectibles(ctx context.Context, side OrderSide, contractAddress string, filter *CollectiblesFilter) (uint64, error) + GetFloorOrder(ctx context.Context, contractAddress string, filter *CollectiblesFilter) (*CollectibleOrder, error) + ListCollectionActivities(ctx context.Context, contractAddress string, page *Page) ([]*Activity, *Page, error) + ListCollectibleActivities(ctx context.Context, contractAddress string, tokenId string, page *Page) ([]*Activity, *Page, error) + // Deprecated: + ListCollectiblesWithLowestListing(ctx context.Context, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) + // Deprecated: + ListCollectiblesWithHighestOffer(ctx context.Context, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) + SyncOrder(ctx context.Context, order *Order) error + SyncOrders(ctx context.Context, orders []*Order) error + GetOrders(ctx context.Context, input []*GetOrdersInput, page *Page) ([]*Order, *Page, error) + CheckoutOptionsMarketplace(ctx context.Context, wallet string, orders []*CheckoutOptionsMarketplaceOrder, additionalFee int) (*CheckoutOptions, error) + CheckoutOptionsSalesContract(ctx context.Context, wallet string, contractAddress string, collectionAddress string, items []*CheckoutOptionsItem) (*CheckoutOptions, error) +} + +// +// Client types +// + +type AdminClient interface { + CreateCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) + GetCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) + ListCollections(ctx context.Context, projectId uint64, page *Page) ([]*Collection, *Page, error) + DeleteCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) + // determine what should happen here + SyncCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) + CreateCurrency(ctx context.Context, currency *Currency) (*Currency, error) + CreateCurrencies(ctx context.Context, currencies []*Currency) (map[string]*Currency, error) + UpdateCurrency(ctx context.Context, currency *Currency) (*Currency, error) + ListCurrencies(ctx context.Context) ([]*Currency, error) + DeleteCurrency(ctx context.Context, chainId uint64, contractAddress string) (*Currency, error) +} + +type MarketplaceClient interface { + ListCurrencies(ctx context.Context) ([]*Currency, error) + GetCollectible(ctx context.Context, contractAddress string, tokenId string) (*TokenMetadata, error) + GetLowestPriceOfferForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + GetHighestPriceOfferForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + GetLowestPriceListingForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + GetHighestPriceListingForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + ListListingsForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, skipRealtimeSync bool, page *Page) ([]*Order, *Page, error) + ListOffersForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, skipRealtimeSync bool, page *Page) ([]*Order, *Page, error) + GetCountOfListingsForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (uint64, error) + GetCountOfOffersForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (uint64, error) + // Deprecated: + GetCollectibleLowestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + // Deprecated: + GetCollectibleHighestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + // Deprecated: + GetCollectibleLowestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + // Deprecated: + GetCollectibleHighestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) + // Deprecated: + ListCollectibleListings(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) + // Deprecated: + ListCollectibleOffers(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) + // checkout process + GenerateBuyTransaction(ctx context.Context, collectionAddress string, buyer string, marketplace MarketplaceKind, ordersData []*OrderData, additionalFees []*AdditionalFee, walletType *WalletKind) ([]*Step, error) + GenerateSellTransaction(ctx context.Context, collectionAddress string, seller string, marketplace MarketplaceKind, ordersData []*OrderData, additionalFees []*AdditionalFee, walletType *WalletKind) ([]*Step, error) + GenerateListingTransaction(ctx context.Context, collectionAddress string, owner string, contractType ContractType, orderbook OrderbookKind, listing *CreateReq, walletType *WalletKind) ([]*Step, error) + GenerateOfferTransaction(ctx context.Context, collectionAddress string, maker string, contractType ContractType, orderbook OrderbookKind, offer *CreateReq, walletType *WalletKind) ([]*Step, error) + GenerateCancelTransaction(ctx context.Context, collectionAddress string, maker string, marketplace MarketplaceKind, orderId string) ([]*Step, error) + // only used in a case of external transactions ( when we create off-chain transactions ) for instance opensea market + Execute(ctx context.Context, signature string, executeType ExecuteType, body interface{}) (string, error) + ListCollectibles(ctx context.Context, side OrderSide, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) + GetCountOfAllCollectibles(ctx context.Context, contractAddress string) (uint64, error) + GetCountOfFilteredCollectibles(ctx context.Context, side OrderSide, contractAddress string, filter *CollectiblesFilter) (uint64, error) + GetFloorOrder(ctx context.Context, contractAddress string, filter *CollectiblesFilter) (*CollectibleOrder, error) + ListCollectionActivities(ctx context.Context, contractAddress string, page *Page) ([]*Activity, *Page, error) + ListCollectibleActivities(ctx context.Context, contractAddress string, tokenId string, page *Page) ([]*Activity, *Page, error) + // Deprecated: + ListCollectiblesWithLowestListing(ctx context.Context, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) + // Deprecated: + ListCollectiblesWithHighestOffer(ctx context.Context, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) + SyncOrder(ctx context.Context, order *Order) error + SyncOrders(ctx context.Context, orders []*Order) error + GetOrders(ctx context.Context, input []*GetOrdersInput, page *Page) ([]*Order, *Page, error) + CheckoutOptionsMarketplace(ctx context.Context, wallet string, orders []*CheckoutOptionsMarketplaceOrder, additionalFee int) (*CheckoutOptions, error) + CheckoutOptionsSalesContract(ctx context.Context, wallet string, contractAddress string, collectionAddress string, items []*CheckoutOptionsItem) (*CheckoutOptions, error) +} + +// +// Client +// + +const AdminPathPrefix = "/rpc/Admin/" +const MarketplacePathPrefix = "/rpc/Marketplace/" + +type adminClient struct { + client HTTPClient + urls [10]string +} + +func NewAdminClient(addr string, client HTTPClient) AdminClient { + prefix := urlBase(addr) + AdminPathPrefix + urls := [10]string{ + prefix + "CreateCollection", + prefix + "GetCollection", + prefix + "ListCollections", + prefix + "DeleteCollection", + prefix + "SyncCollection", + prefix + "CreateCurrency", + prefix + "CreateCurrencies", + prefix + "UpdateCurrency", + prefix + "ListCurrencies", + prefix + "DeleteCurrency", + } + return &adminClient{ + client: client, + urls: urls, + } +} + +func (c *adminClient) CreateCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) { + in := struct { + Arg0 uint64 `json:"projectId"` + Arg1 string `json:"contractAddress"` + }{projectId, contractAddress} + out := struct { + Ret0 *Collection `json:"collection"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[0], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *adminClient) GetCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) { + in := struct { + Arg0 uint64 `json:"projectId"` + Arg1 string `json:"contractAddress"` + }{projectId, contractAddress} + out := struct { + Ret0 *Collection `json:"collection"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[1], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *adminClient) ListCollections(ctx context.Context, projectId uint64, page *Page) ([]*Collection, *Page, error) { + in := struct { + Arg0 uint64 `json:"projectId"` + Arg1 *Page `json:"page"` + }{projectId, page} + out := struct { + Ret0 []*Collection `json:"collections"` + Ret1 *Page `json:"page"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[2], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, out.Ret1, err +} + +func (c *adminClient) DeleteCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) { + in := struct { + Arg0 uint64 `json:"projectId"` + Arg1 string `json:"contractAddress"` + }{projectId, contractAddress} + out := struct { + Ret0 *Collection `json:"collection"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[3], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *adminClient) SyncCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) { + in := struct { + Arg0 uint64 `json:"projectId"` + Arg1 string `json:"contractAddress"` + }{projectId, contractAddress} + out := struct { + Ret0 *Collection `json:"collection"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[4], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *adminClient) CreateCurrency(ctx context.Context, currency *Currency) (*Currency, error) { + in := struct { + Arg0 *Currency `json:"currency"` + }{currency} + out := struct { + Ret0 *Currency `json:"currency"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[5], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *adminClient) CreateCurrencies(ctx context.Context, currencies []*Currency) (map[string]*Currency, error) { + in := struct { + Arg0 []*Currency `json:"currencies"` + }{currencies} + out := struct { + Ret0 map[string]*Currency `json:"currency"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[6], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *adminClient) UpdateCurrency(ctx context.Context, currency *Currency) (*Currency, error) { + in := struct { + Arg0 *Currency `json:"currency"` + }{currency} + out := struct { + Ret0 *Currency `json:"currency"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[7], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *adminClient) ListCurrencies(ctx context.Context) ([]*Currency, error) { + out := struct { + Ret0 []*Currency `json:"currencies"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[8], nil, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *adminClient) DeleteCurrency(ctx context.Context, chainId uint64, contractAddress string) (*Currency, error) { + in := struct { + Arg0 uint64 `json:"chainId"` + Arg1 string `json:"contractAddress"` + }{chainId, contractAddress} + out := struct { + Ret0 *Currency `json:"currency"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[9], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +type marketplaceClient struct { + client HTTPClient + urls [35]string +} + +func NewMarketplaceClient(addr string, client HTTPClient) MarketplaceClient { + prefix := urlBase(addr) + MarketplacePathPrefix + urls := [35]string{ + prefix + "ListCurrencies", + prefix + "GetCollectible", + prefix + "GetLowestPriceOfferForCollectible", + prefix + "GetHighestPriceOfferForCollectible", + prefix + "GetLowestPriceListingForCollectible", + prefix + "GetHighestPriceListingForCollectible", + prefix + "ListListingsForCollectible", + prefix + "ListOffersForCollectible", + prefix + "GetCountOfListingsForCollectible", + prefix + "GetCountOfOffersForCollectible", + prefix + "GetCollectibleLowestOffer", + prefix + "GetCollectibleHighestOffer", + prefix + "GetCollectibleLowestListing", + prefix + "GetCollectibleHighestListing", + prefix + "ListCollectibleListings", + prefix + "ListCollectibleOffers", + prefix + "GenerateBuyTransaction", + prefix + "GenerateSellTransaction", + prefix + "GenerateListingTransaction", + prefix + "GenerateOfferTransaction", + prefix + "GenerateCancelTransaction", + prefix + "Execute", + prefix + "ListCollectibles", + prefix + "GetCountOfAllCollectibles", + prefix + "GetCountOfFilteredCollectibles", + prefix + "GetFloorOrder", + prefix + "ListCollectionActivities", + prefix + "ListCollectibleActivities", + prefix + "ListCollectiblesWithLowestListing", + prefix + "ListCollectiblesWithHighestOffer", + prefix + "SyncOrder", + prefix + "SyncOrders", + prefix + "GetOrders", + prefix + "CheckoutOptionsMarketplace", + prefix + "CheckoutOptionsSalesContract", + } + return &marketplaceClient{ + client: client, + urls: urls, + } +} + +func (c *marketplaceClient) ListCurrencies(ctx context.Context) ([]*Currency, error) { + out := struct { + Ret0 []*Currency `json:"currencies"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[0], nil, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *marketplaceClient) GetCollectible(ctx context.Context, contractAddress string, tokenId string) (*TokenMetadata, error) { + in := struct { + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + }{contractAddress, tokenId} + out := struct { + Ret0 *TokenMetadata `json:"metadata"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[1], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *marketplaceClient) GetLowestPriceOfferForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { + in := struct { + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} + out := struct { + Ret0 *Order `json:"order"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[2], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *marketplaceClient) GetHighestPriceOfferForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { + in := struct { + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} + out := struct { + Ret0 *Order `json:"order"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[3], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *marketplaceClient) GetLowestPriceListingForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { + in := struct { + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} + out := struct { + Ret0 *Order `json:"order"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[4], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *marketplaceClient) GetHighestPriceListingForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { + in := struct { + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} + out := struct { + Ret0 *Order `json:"order"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[5], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *marketplaceClient) ListListingsForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, skipRealtimeSync bool, page *Page) ([]*Order, *Page, error) { + in := struct { + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + Arg3 bool `json:"skipRealtimeSync"` + Arg4 *Page `json:"page"` + }{contractAddress, tokenId, filter, skipRealtimeSync, page} + out := struct { + Ret0 []*Order `json:"listings"` + Ret1 *Page `json:"page"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[6], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, out.Ret1, err +} + +func (c *marketplaceClient) ListOffersForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, skipRealtimeSync bool, page *Page) ([]*Order, *Page, error) { + in := struct { + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + Arg3 bool `json:"skipRealtimeSync"` + Arg4 *Page `json:"page"` + }{contractAddress, tokenId, filter, skipRealtimeSync, page} + out := struct { + Ret0 []*Order `json:"offers"` + Ret1 *Page `json:"page"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[7], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, out.Ret1, err +} + +func (c *marketplaceClient) GetCountOfListingsForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (uint64, error) { + in := struct { + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} + out := struct { + Ret0 uint64 `json:"count"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[8], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err } -func (c *adminClient) CreateCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) { +func (c *marketplaceClient) GetCountOfOffersForCollectible(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (uint64, error) { in := struct { - Arg0 uint64 `json:"projectId"` - Arg1 string `json:"contractAddress"` - }{projectId, contractAddress} + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} out := struct { - Ret0 *Collection `json:"collection"` + Ret0 uint64 `json:"count"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[0], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[9], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *adminClient) GetCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) { +func (c *marketplaceClient) GetCollectibleLowestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { in := struct { - Arg0 uint64 `json:"projectId"` - Arg1 string `json:"contractAddress"` - }{projectId, contractAddress} + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} out := struct { - Ret0 *Collection `json:"collection"` + Ret0 *Order `json:"order"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[1], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[10], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *adminClient) ListCollections(ctx context.Context, projectId uint64, page *Page) ([]*Collection, *Page, error) { +func (c *marketplaceClient) GetCollectibleHighestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { in := struct { - Arg0 uint64 `json:"projectId"` - Arg1 *Page `json:"page"` - }{projectId, page} + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} out := struct { - Ret0 []*Collection `json:"collections"` - Ret1 *Page `json:"page"` + Ret0 *Order `json:"order"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[2], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[11], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } - return out.Ret0, out.Ret1, err + return out.Ret0, err } -func (c *adminClient) DeleteCollection(ctx context.Context, projectId uint64, contractAddress string) (*Collection, error) { +func (c *marketplaceClient) GetCollectibleLowestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { in := struct { - Arg0 uint64 `json:"projectId"` - Arg1 string `json:"contractAddress"` - }{projectId, contractAddress} + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} out := struct { - Ret0 *Collection `json:"collection"` + Ret0 *Order `json:"order"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[3], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[12], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *adminClient) SyncCollection(ctx context.Context, projectId uint64, contractAddress string) error { +func (c *marketplaceClient) GetCollectibleHighestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { in := struct { - Arg0 uint64 `json:"projectId"` - Arg1 string `json:"contractAddress"` - }{projectId, contractAddress} + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + }{contractAddress, tokenId, filter} + out := struct { + Ret0 *Order `json:"order"` + }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[4], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[13], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } - return err + return out.Ret0, err } -func (c *adminClient) CreateCurrency(ctx context.Context, currency *Currency) (*Currency, error) { +func (c *marketplaceClient) ListCollectibleListings(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) { in := struct { - Arg0 *Currency `json:"currency"` - }{currency} + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + Arg3 *Page `json:"page"` + }{contractAddress, tokenId, filter, page} out := struct { - Ret0 *Currency `json:"currency"` + Ret0 []*Order `json:"listings"` + Ret1 *Page `json:"page"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[5], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[14], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } - return out.Ret0, err + return out.Ret0, out.Ret1, err } -func (c *adminClient) CreateCurrencies(ctx context.Context, currencies []*Currency) (map[string]*Currency, error) { +func (c *marketplaceClient) ListCollectibleOffers(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) { in := struct { - Arg0 []*Currency `json:"currencies"` - }{currencies} + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *OrderFilter `json:"filter"` + Arg3 *Page `json:"page"` + }{contractAddress, tokenId, filter, page} out := struct { - Ret0 map[string]*Currency `json:"currency"` + Ret0 []*Order `json:"offers"` + Ret1 *Page `json:"page"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[6], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[15], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } - return out.Ret0, err + return out.Ret0, out.Ret1, err } -func (c *adminClient) UpdateCurrency(ctx context.Context, currency *Currency) (*Currency, error) { +func (c *marketplaceClient) GenerateBuyTransaction(ctx context.Context, collectionAddress string, buyer string, marketplace MarketplaceKind, ordersData []*OrderData, additionalFees []*AdditionalFee, walletType *WalletKind) ([]*Step, error) { in := struct { - Arg0 *Currency `json:"currency"` - }{currency} + Arg0 string `json:"collectionAddress"` + Arg1 string `json:"buyer"` + Arg2 MarketplaceKind `json:"marketplace"` + Arg3 []*OrderData `json:"ordersData"` + Arg4 []*AdditionalFee `json:"additionalFees"` + Arg5 *WalletKind `json:"walletType"` + }{collectionAddress, buyer, marketplace, ordersData, additionalFees, walletType} out := struct { - Ret0 *Currency `json:"currency"` + Ret0 []*Step `json:"steps"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[7], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[16], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *adminClient) ListCurrencies(ctx context.Context) ([]*Currency, error) { +func (c *marketplaceClient) GenerateSellTransaction(ctx context.Context, collectionAddress string, seller string, marketplace MarketplaceKind, ordersData []*OrderData, additionalFees []*AdditionalFee, walletType *WalletKind) ([]*Step, error) { + in := struct { + Arg0 string `json:"collectionAddress"` + Arg1 string `json:"seller"` + Arg2 MarketplaceKind `json:"marketplace"` + Arg3 []*OrderData `json:"ordersData"` + Arg4 []*AdditionalFee `json:"additionalFees"` + Arg5 *WalletKind `json:"walletType"` + }{collectionAddress, seller, marketplace, ordersData, additionalFees, walletType} out := struct { - Ret0 []*Currency `json:"currencies"` + Ret0 []*Step `json:"steps"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[8], nil, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[17], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *adminClient) DeleteCurrency(ctx context.Context, chainId uint64, contractAddress string) (*Currency, error) { +func (c *marketplaceClient) GenerateListingTransaction(ctx context.Context, collectionAddress string, owner string, contractType ContractType, orderbook OrderbookKind, listing *CreateReq, walletType *WalletKind) ([]*Step, error) { in := struct { - Arg0 uint64 `json:"chainId"` - Arg1 string `json:"contractAddress"` - }{chainId, contractAddress} + Arg0 string `json:"collectionAddress"` + Arg1 string `json:"owner"` + Arg2 ContractType `json:"contractType"` + Arg3 OrderbookKind `json:"orderbook"` + Arg4 *CreateReq `json:"listing"` + Arg5 *WalletKind `json:"walletType"` + }{collectionAddress, owner, contractType, orderbook, listing, walletType} out := struct { - Ret0 *Currency `json:"currency"` + Ret0 []*Step `json:"steps"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[9], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[18], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -type marketplaceClient struct { - client HTTPClient - urls [12]string -} +func (c *marketplaceClient) GenerateOfferTransaction(ctx context.Context, collectionAddress string, maker string, contractType ContractType, orderbook OrderbookKind, offer *CreateReq, walletType *WalletKind) ([]*Step, error) { + in := struct { + Arg0 string `json:"collectionAddress"` + Arg1 string `json:"maker"` + Arg2 ContractType `json:"contractType"` + Arg3 OrderbookKind `json:"orderbook"` + Arg4 *CreateReq `json:"offer"` + Arg5 *WalletKind `json:"walletType"` + }{collectionAddress, maker, contractType, orderbook, offer, walletType} + out := struct { + Ret0 []*Step `json:"steps"` + }{} -func NewMarketplaceClient(addr string, client HTTPClient) MarketplaceClient { - prefix := urlBase(addr) + MarketplacePathPrefix - urls := [12]string{ - prefix + "ListCurrencies", - prefix + "GetCollectible", - prefix + "GetCollectibleLowestOffer", - prefix + "GetCollectibleHighestOffer", - prefix + "GetCollectibleLowestListing", - prefix + "GetCollectibleHighestListing", - prefix + "ListCollectibleListings", - prefix + "ListCollectibleOffers", - prefix + "ListCollectiblesWithLowestListing", - prefix + "ListCollectiblesWithHighestOffer", - prefix + "SyncOrder", - prefix + "SyncOrders", - } - return &marketplaceClient{ - client: client, - urls: urls, + resp, err := doHTTPRequest(ctx, c.client, c.urls[19], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } } + + return out.Ret0, err } -func (c *marketplaceClient) ListCurrencies(ctx context.Context) ([]*Currency, error) { +func (c *marketplaceClient) GenerateCancelTransaction(ctx context.Context, collectionAddress string, maker string, marketplace MarketplaceKind, orderId string) ([]*Step, error) { + in := struct { + Arg0 string `json:"collectionAddress"` + Arg1 string `json:"maker"` + Arg2 MarketplaceKind `json:"marketplace"` + Arg3 string `json:"orderId"` + }{collectionAddress, maker, marketplace, orderId} out := struct { - Ret0 []*Currency `json:"currencies"` + Ret0 []*Step `json:"steps"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[0], nil, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[20], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *marketplaceClient) GetCollectible(ctx context.Context, contractAddress string, tokenId string) (*TokenMetadata, error) { +func (c *marketplaceClient) Execute(ctx context.Context, signature string, executeType ExecuteType, body interface{}) (string, error) { in := struct { - Arg0 string `json:"contractAddress"` - Arg1 string `json:"tokenId"` - }{contractAddress, tokenId} + Arg0 string `json:"signature"` + Arg1 ExecuteType `json:"executeType"` + Arg2 interface{} `json:"body"` + }{signature, executeType, body} out := struct { - Ret0 *TokenMetadata `json:"metadata"` + Ret0 string `json:"orderId"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[1], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[21], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *marketplaceClient) GetCollectibleLowestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { +func (c *marketplaceClient) ListCollectibles(ctx context.Context, side OrderSide, contractAddress string, filter *CollectiblesFilter, page *Page) ([]*CollectibleOrder, *Page, error) { in := struct { - Arg0 string `json:"contractAddress"` - Arg1 string `json:"tokenId"` - Arg2 *OrderFilter `json:"filter"` - }{contractAddress, tokenId, filter} + Arg0 OrderSide `json:"side"` + Arg1 string `json:"contractAddress"` + Arg2 *CollectiblesFilter `json:"filter"` + Arg3 *Page `json:"page"` + }{side, contractAddress, filter, page} out := struct { - Ret0 *Order `json:"order"` + Ret0 []*CollectibleOrder `json:"collectibles"` + Ret1 *Page `json:"page"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[2], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[22], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } - return out.Ret0, err + return out.Ret0, out.Ret1, err } -func (c *marketplaceClient) GetCollectibleHighestOffer(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { +func (c *marketplaceClient) GetCountOfAllCollectibles(ctx context.Context, contractAddress string) (uint64, error) { in := struct { - Arg0 string `json:"contractAddress"` - Arg1 string `json:"tokenId"` - Arg2 *OrderFilter `json:"filter"` - }{contractAddress, tokenId, filter} + Arg0 string `json:"contractAddress"` + }{contractAddress} out := struct { - Ret0 *Order `json:"order"` + Ret0 uint64 `json:"count"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[3], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[23], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *marketplaceClient) GetCollectibleLowestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { +func (c *marketplaceClient) GetCountOfFilteredCollectibles(ctx context.Context, side OrderSide, contractAddress string, filter *CollectiblesFilter) (uint64, error) { in := struct { - Arg0 string `json:"contractAddress"` - Arg1 string `json:"tokenId"` - Arg2 *OrderFilter `json:"filter"` - }{contractAddress, tokenId, filter} + Arg0 OrderSide `json:"side"` + Arg1 string `json:"contractAddress"` + Arg2 *CollectiblesFilter `json:"filter"` + }{side, contractAddress, filter} out := struct { - Ret0 *Order `json:"order"` + Ret0 uint64 `json:"count"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[4], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[24], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *marketplaceClient) GetCollectibleHighestListing(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter) (*Order, error) { +func (c *marketplaceClient) GetFloorOrder(ctx context.Context, contractAddress string, filter *CollectiblesFilter) (*CollectibleOrder, error) { in := struct { - Arg0 string `json:"contractAddress"` - Arg1 string `json:"tokenId"` - Arg2 *OrderFilter `json:"filter"` - }{contractAddress, tokenId, filter} + Arg0 string `json:"contractAddress"` + Arg1 *CollectiblesFilter `json:"filter"` + }{contractAddress, filter} out := struct { - Ret0 *Order `json:"order"` + Ret0 *CollectibleOrder `json:"collectible"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[5], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[25], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *marketplaceClient) ListCollectibleListings(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) { +func (c *marketplaceClient) ListCollectionActivities(ctx context.Context, contractAddress string, page *Page) ([]*Activity, *Page, error) { in := struct { - Arg0 string `json:"contractAddress"` - Arg1 string `json:"tokenId"` - Arg2 *OrderFilter `json:"filter"` - Arg3 *Page `json:"page"` - }{contractAddress, tokenId, filter, page} + Arg0 string `json:"contractAddress"` + Arg1 *Page `json:"page"` + }{contractAddress, page} out := struct { - Ret0 []*Order `json:"listings"` - Ret1 *Page `json:"page"` + Ret0 []*Activity `json:"activities"` + Ret1 *Page `json:"page"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[6], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[26], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, out.Ret1, err } -func (c *marketplaceClient) ListCollectibleOffers(ctx context.Context, contractAddress string, tokenId string, filter *OrderFilter, page *Page) ([]*Order, *Page, error) { +func (c *marketplaceClient) ListCollectibleActivities(ctx context.Context, contractAddress string, tokenId string, page *Page) ([]*Activity, *Page, error) { in := struct { - Arg0 string `json:"contractAddress"` - Arg1 string `json:"tokenId"` - Arg2 *OrderFilter `json:"filter"` - Arg3 *Page `json:"page"` - }{contractAddress, tokenId, filter, page} + Arg0 string `json:"contractAddress"` + Arg1 string `json:"tokenId"` + Arg2 *Page `json:"page"` + }{contractAddress, tokenId, page} out := struct { - Ret0 []*Order `json:"offers"` - Ret1 *Page `json:"page"` + Ret0 []*Activity `json:"activities"` + Ret1 *Page `json:"page"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[7], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[27], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1304,11 +2825,11 @@ func (c *marketplaceClient) ListCollectiblesWithLowestListing(ctx context.Contex Ret1 *Page `json:"page"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[8], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[28], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1326,11 +2847,11 @@ func (c *marketplaceClient) ListCollectiblesWithHighestOffer(ctx context.Context Ret1 *Page `json:"page"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[9], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[29], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1342,11 +2863,11 @@ func (c *marketplaceClient) SyncOrder(ctx context.Context, order *Order) error { Arg0 *Order `json:"order"` }{order} - resp, err := doHTTPRequest(ctx, c.client, c.urls[10], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[30], in, nil) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1358,17 +2879,81 @@ func (c *marketplaceClient) SyncOrders(ctx context.Context, orders []*Order) err Arg0 []*Order `json:"orders"` }{orders} - resp, err := doHTTPRequest(ctx, c.client, c.urls[11], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[31], in, nil) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return err } +func (c *marketplaceClient) GetOrders(ctx context.Context, input []*GetOrdersInput, page *Page) ([]*Order, *Page, error) { + in := struct { + Arg0 []*GetOrdersInput `json:"input"` + Arg1 *Page `json:"page"` + }{input, page} + out := struct { + Ret0 []*Order `json:"orders"` + Ret1 *Page `json:"page"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[32], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, out.Ret1, err +} + +func (c *marketplaceClient) CheckoutOptionsMarketplace(ctx context.Context, wallet string, orders []*CheckoutOptionsMarketplaceOrder, additionalFee int) (*CheckoutOptions, error) { + in := struct { + Arg0 string `json:"wallet"` + Arg1 []*CheckoutOptionsMarketplaceOrder `json:"orders"` + Arg2 int `json:"additionalFee"` + }{wallet, orders, additionalFee} + out := struct { + Ret0 *CheckoutOptions `json:"options"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[33], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + +func (c *marketplaceClient) CheckoutOptionsSalesContract(ctx context.Context, wallet string, contractAddress string, collectionAddress string, items []*CheckoutOptionsItem) (*CheckoutOptions, error) { + in := struct { + Arg0 string `json:"wallet"` + Arg1 string `json:"contractAddress"` + Arg2 string `json:"collectionAddress"` + Arg3 []*CheckoutOptionsItem `json:"items"` + }{wallet, contractAddress, collectionAddress, items} + out := struct { + Ret0 *CheckoutOptions `json:"options"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[34], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + // HTTPClient is the interface used by generated clients to send HTTP requests. // It is fulfilled by *(net/http).Client, which is sufficient for most users. // Users can provide their own implementation for special retry policies. @@ -1399,6 +2984,7 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType } req.Header.Set("Accept", contentType) req.Header.Set("Content-Type", contentType) + req.Header.Set(WebrpcHeader, WebrpcHeaderValue) if headers, ok := HTTPRequestHeaders(ctx); ok { for k := range headers { for _, v := range headers[k] { @@ -1413,15 +2999,15 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out interface{}) (*http.Response, error) { reqBody, err := json.Marshal(in) if err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to marshal JSON body: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("failed to marshal JSON body: %w", err) } if err = ctx.Err(); err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("aborted because context was done: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("aborted because context was done: %w", err) } req, err := newRequest(ctx, url, bytes.NewBuffer(reqBody), "application/json") if err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("could not build request: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("could not build request: %w", err) } resp, err := client.Do(req) @@ -1432,12 +3018,12 @@ func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out i if resp.StatusCode != 200 { respBody, err := io.ReadAll(resp.Body) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to read server error response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to read server error response body: %w", err) } var rpcErr WebRPCError if err := json.Unmarshal(respBody, &rpcErr); err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to unmarshal server error: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to unmarshal server error: %w", err) } if rpcErr.Cause != "" { rpcErr.cause = errors.New(rpcErr.Cause) @@ -1448,12 +3034,12 @@ func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out i if out != nil { respBody, err := io.ReadAll(resp.Body) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to read response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to read response body: %w", err) } err = json.Unmarshal(respBody, &out) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to unmarshal JSON response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to unmarshal JSON response body: %w", err) } } @@ -1490,6 +3076,12 @@ func HTTPRequestHeaders(ctx context.Context) (http.Header, bool) { // Helpers // +type method struct { + Name string + Service string + Annotations map[string]string +} + type contextKey struct { name string } @@ -1522,6 +3114,20 @@ func RequestFromContext(ctx context.Context) *http.Request { return r } +func MethodCtx(ctx context.Context) (method, bool) { + req := RequestFromContext(ctx) + if req == nil { + return method{}, false + } + + m, ok := methods[req.URL.Path] + if !ok { + return method{}, false + } + + return m, true +} + // // Errors //