diff --git a/indexer/indexer.gen.go b/indexer/indexer.gen.go index 3a577f6..2e4d2e9 100644 --- a/indexer/indexer.gen.go +++ b/indexer/indexer.gen.go @@ -1,6 +1,6 @@ -// sequence-indexer v0.4.0 604761d36d9ef082fa97d028f8315ccdedf19838 +// sequence-indexer v0.4.0 42a988bcb0871f1249450f0d92967db5b47ff33e // -- -// Code generated by webrpc-gen@v0.18.6 with golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.20.0 with golang generator. DO NOT EDIT. // // webrpc-gen -schema=indexer.ridl -target=golang -pkg=indexer -client -out=./clients/indexer.gen.go package indexer @@ -33,7 +33,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "604761d36d9ef082fa97d028f8315ccdedf19838" + return "42a988bcb0871f1249450f0d92967db5b47ff33e" } // @@ -246,21 +246,22 @@ func (x *EventLogType) Is(values ...EventLogType) bool { type EventLogDataType uint8 const ( - EventLogDataType_UNKNOWN EventLogDataType = 0 + // aka, generic / unknown event type + EventLogDataType_EVENT EventLogDataType = 0 EventLogDataType_TOKEN_TRANSFER EventLogDataType = 1 EventLogDataType_NATIVE_TOKEN_TRANSFER EventLogDataType = 2 EventLogDataType_SEQUENCE_TXN EventLogDataType = 3 ) var EventLogDataType_name = map[uint8]string{ - 0: "UNKNOWN", + 0: "EVENT", 1: "TOKEN_TRANSFER", 2: "NATIVE_TOKEN_TRANSFER", 3: "SEQUENCE_TXN", } var EventLogDataType_value = map[string]uint8{ - "UNKNOWN": 0, + "EVENT": 0, "TOKEN_TRANSFER": 1, "NATIVE_TOKEN_TRANSFER": 2, "SEQUENCE_TXN": 3, @@ -510,6 +511,35 @@ func (x *SortOrder) Is(values ...SortOrder) bool { return false } +type ContractVerificationStatus string + +const ( + ContractVerificationStatus_VERIFIED ContractVerificationStatus = "VERIFIED" + ContractVerificationStatus_UNVERIFIED ContractVerificationStatus = "UNVERIFIED" + ContractVerificationStatus_ALL ContractVerificationStatus = "ALL" +) + +func (x ContractVerificationStatus) MarshalText() ([]byte, error) { + return []byte(x), nil +} + +func (x *ContractVerificationStatus) UnmarshalText(b []byte) error { + *x = ContractVerificationStatus(string(b)) + return nil +} + +func (x *ContractVerificationStatus) Is(values ...ContractVerificationStatus) bool { + if x == nil { + return false + } + for _, v := range values { + if *x == v { + return true + } + } + return false +} + type Version struct { WebrpcVersion string `json:"webrpcVersion"` SchemaVersion string `json:"schemaVersion"` @@ -589,6 +619,11 @@ type EtherBalance struct { BalanceWei prototyp.BigInt `json:"balanceWei" cbor:"-"` } +type NativeTokenBalance struct { + AccountAddress prototyp.Hash `json:"accountAddress" cbor:"-"` + Balance prototyp.BigInt `json:"balance" cbor:"-"` +} + type IndexState struct { ChainID prototyp.BigInt `json:"chainId" cbor:"chain_id,extension"` LastBlockNum uint64 `json:"lastBlockNum" cbor:"last_block_num"` @@ -600,27 +635,46 @@ type IndexedBlock struct { BlockShortHash prototyp.Hash `json:"blockShortHash" cbor:"2,extension"` } -type TxnData struct { +type TxnInfo struct { From prototyp.Hash `json:"from" cbor:"from"` To prototyp.Hash `json:"to" cbor:"to"` Value prototyp.BigInt `json:"value" cbor:"value"` } type EventLog struct { - ID uint64 `json:"id" cbor:"id,omitempty"` + ID uint64 `json:"id,omitempty" cbor:"id,omitempty"` + UID prototyp.Hash `json:"uid,omitempty" cbor:"uid,omitempty"` Type EventLogType `json:"type" cbor:"type"` BlockNumber uint64 `json:"blockNumber" cbor:"block_num"` BlockHash prototyp.Hash `json:"blockHash" cbor:"block_hash,extension"` - ParentBlockHash prototyp.Hash `json:"parentBlockHash" cbor:"parent_block_hash,extension" db:"parent_block_hash"` + ParentBlockHash prototyp.Hash `json:"parentBlockHash,omitempty" cbor:"parent_block_hash,extension" db:"parent_block_hash"` ContractAddress prototyp.Hash `json:"contractAddress" cbor:"contract_address,extension"` ContractType ContractType `json:"contractType" cbor:"contract_type"` TxnHash prototyp.Hash `json:"txnHash" cbor:"txn_hash,extension"` TxnIndex uint `json:"txnIndex" cbor:"txn_index"` - TxnData TxnData `json:"txnData" cbor:"txn_data"` TxnLogIndex uint `json:"txnLogIndex" cbor:"txn_log_index"` LogDataType EventLogDataType `json:"logDataType" cbor:"log_data_type"` TS time.Time `json:"ts" cbor:"ts"` - LogData string `json:"logData" cbor:"log_data"` + TxnInfo *TxnInfo `json:"txnInfo,omitempty" cbor:"txn_info"` + // optional rawLog data returns for json responses + // such as for streaming events to SubscribeEvents(..), + // for webhooks this is left empty + RawLog map[string]interface{} `json:"rawLog,omitempty" cbor:"-"` + // optional decoded event data passed to streams + // and webhooks. + Event *EventDecoded `json:"event,omitempty" cbor:"-"` +} + +type EventDecoded struct { + TopicHash string `json:"topicHash"` + // ie. 'Move(address indexed from, uint256 amount)' + EventSig string `json:"eventSig,omitempty"` + // ie. ['address', 'uint256'] + Types []string `json:"types,omitempty"` + // ie. ['from', 'amount'] + Names []string `json:"names,omitempty"` + // ie. ['0xabc..def', '0x000000....001234'] + Values []string `json:"values,omitempty"` } // Token Balances @@ -633,10 +687,11 @@ type TokenBalance struct { BlockHash prototyp.Hash `json:"blockHash,omitempty" cbor:"6,extension"` BlockNumber uint64 `json:"blockNumber,omitempty" cbor:"7"` // included to remind the receiver of network source - ChainID uint64 `json:"chainId" cbor:"-"` - IsNFTSummary bool `json:"-" cbor:"9"` - ContractInfo *ContractInfo `json:"contractInfo,omitempty" cbor:"-"` - TokenMetadata *TokenMetadata `json:"tokenMetadata,omitempty" cbor:"-"` + ChainID uint64 `json:"chainId" cbor:"-"` + UniqueCollectibles *prototyp.BigInt `json:"uniqueCollectibles,omitempty" cbor:"-"` + IsSummary bool `json:"isSummary,omitempty" cbor:"9"` + ContractInfo *ContractInfo `json:"contractInfo,omitempty" cbor:"-"` + TokenMetadata *TokenMetadata `json:"tokenMetadata,omitempty" cbor:"-"` } type OrderbookOrder struct { @@ -651,15 +706,19 @@ type OrderbookOrder struct { Expiry prototyp.BigInt `json:"expiry" cbor:"9,extension"` OrderStatus OrderStatus `json:"orderStatus" cbor:"10,extension"` CreatedBy prototyp.Hash `json:"createdBy" cbor:"11,extension"` - CreatedAt uint64 `json:"createdAt" cbor:"12,extension"` + BlockNumber uint64 `json:"blockNumber" cbor:"12,extension"` OrderbookContractAddress prototyp.Hash `json:"orderbookContractAddress" cbor:"13,extension"` + CreatedAt uint64 `json:"createdAt" cbor:"14,extension"` } type OrderbookOrderFilter struct { - IsListing *bool `json:"isListing" cbor:"1,extension"` - UserAddress *string `json:"userAddress" cbor:"2,extension"` - TokenIDs []string `json:"tokenIds" cbor:"3,extension"` - ExcludeUserAddress *string `json:"excludeUserAddress" cbor:"4,extension"` + IsListing *bool `json:"isListing" cbor:"1,extension"` + UserAddresses []string `json:"userAddresses" cbor:"2,extension"` + TokenIDs []string `json:"tokenIds" cbor:"3,extension"` + ExcludeUserAddresses []string `json:"excludeUserAddresses" cbor:"4,extension"` + AfterBlockNumber uint64 `json:"afterBlockNumber" cbor:"5,extension"` + AfterCreatedAt int64 `json:"afterCreatedAt" cbor:"6,extension"` + BeforeExpiry int64 `json:"beforeExpiry" cbor:"7,extension"` } // Token History @@ -735,9 +794,8 @@ type TransactionFilter struct { From *prototyp.Hash `json:"from"` To *prototyp.Hash `json:"to"` ContractAddress *prototyp.Hash `json:"contractAddress"` - // NOTE: event will convert to topicHash, its a sugar - Event *string `json:"event"` - TopicHash *prototyp.Hash `json:"topicHash"` + // event signature, ie. Transfer(address indexed,address indexed,uint256) + Event *string `json:"event"` } type TransactionReceipt struct { @@ -789,7 +847,7 @@ type SortBy struct { } type WebhookListener struct { - Id uint64 `json:"id" db:"id"` + ID uint64 `json:"id" db:"id"` ProjectID uint64 `json:"projectID" db:"project_id"` Url string `json:"url" db:"url"` Filters *EventFilter `json:"filters" db:"filters"` @@ -801,18 +859,19 @@ type WebhookListener struct { type EventFilter struct { // event is the event name to filter, for example // 'Transfer(address indexed from, address indexed to, uint256 value)' - // - // essentially the event is converted to a topic hash, and so - // this filter option is a sugar to topicHashes Events []string `json:"events"` - // explicit event topic hashes. See related `events` filter option. - TopicHashes []prototyp.Hash `json:"topicHashes"` // contract addresses + // TODO: maybe rename to just `contracts` ..? ContractAddresses []prototyp.Hash `json:"contractAddresses"` - // token ids for events which have token ids - TokenIDs []prototyp.BigInt `json:"tokenIDs"` // wallet addresses + // NOTE: for EOA's, this checks a transactions from/to, in addition + // to 'Transfer' events From/To. For Smart wallets it checks the 'Transfer + // events From/To. For any generic event, this is unreliable method because + // the event could be emitted from any address (for example for a smart wallet), + // or some other kind of relayer. Accounts []prototyp.Hash `json:"accounts"` + // token ids for events which have token ids + TokenIDs []prototyp.BigInt `json:"tokenIDs"` } type TokenBalanceFilter struct { @@ -826,6 +885,174 @@ type MetadataOptions struct { IncludeContracts []prototyp.Hash `json:"includeContracts"` } +type TokenBalancesFilter struct { + AccountAddresses []prototyp.Hash `json:"accountAddresses"` + ContractStatus ContractVerificationStatus `json:"contractStatus"` + ContractWhitelist []prototyp.Hash `json:"contractWhitelist"` + ContractBlacklist []prototyp.Hash `json:"contractBlacklist"` +} + +type TokenBalancesByContractFilter struct { + ContractAddresses []prototyp.Hash `json:"contractAddresses"` + AccountAddresses []prototyp.Hash `json:"accountAddresses"` + ContractStatus ContractVerificationStatus `json:"contractStatus"` +} + +var ( + methods = map[string]method{ + "/rpc/Indexer/Ping": { + Name: "Ping", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/Version": { + Name: "Version", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/RuntimeStatus": { + Name: "RuntimeStatus", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetChainID": { + Name: "GetChainID", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetEtherBalance": { + Name: "GetEtherBalance", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetNativeTokenBalance": { + Name: "GetNativeTokenBalance", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetTokenBalancesSummary": { + Name: "GetTokenBalancesSummary", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetTokenBalancesDetails": { + Name: "GetTokenBalancesDetails", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetTokenBalancesByContract": { + Name: "GetTokenBalancesByContract", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetTokenBalances": { + Name: "GetTokenBalances", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetTokenSupplies": { + Name: "GetTokenSupplies", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetTokenSuppliesMap": { + Name: "GetTokenSuppliesMap", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetBalanceUpdates": { + Name: "GetBalanceUpdates", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetTransactionHistory": { + Name: "GetTransactionHistory", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/SyncBalance": { + Name: "SyncBalance", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/FetchTransactionReceipt": { + Name: "FetchTransactionReceipt", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetOrderbookOrders": { + Name: "GetOrderbookOrders", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetTopOrders": { + Name: "GetTopOrders", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/FetchTransactionReceiptWithFilter": { + Name: "FetchTransactionReceiptWithFilter", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetAllWebhookListeners": { + Name: "GetAllWebhookListeners", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/GetWebhookListener": { + Name: "GetWebhookListener", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/AddWebhookListener": { + Name: "AddWebhookListener", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/UpdateWebhookListener": { + Name: "UpdateWebhookListener", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/RemoveWebhookListener": { + Name: "RemoveWebhookListener", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/ToggleWebhookListener": { + Name: "ToggleWebhookListener", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/PauseAllWebhookListeners": { + Name: "PauseAllWebhookListeners", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/ResumeAllWebhookListeners": { + Name: "ResumeAllWebhookListeners", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/SubscribeReceipts": { + Name: "SubscribeReceipts", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/SubscribeEvents": { + Name: "SubscribeEvents", + Service: "Indexer", + Annotations: map[string]string{}, + }, + "/rpc/Indexer/SubscribeBalanceUpdates": { + Name: "SubscribeBalanceUpdates", + Service: "Indexer", + Annotations: map[string]string{}, + }, + } +) + var WebRPCServices = map[string][]string{ "Indexer": { "Ping", @@ -833,6 +1060,10 @@ var WebRPCServices = map[string][]string{ "RuntimeStatus", "GetChainID", "GetEtherBalance", + "GetNativeTokenBalance", + "GetTokenBalancesSummary", + "GetTokenBalancesDetails", + "GetTokenBalancesByContract", "GetTokenBalances", "GetTokenSupplies", "GetTokenSuppliesMap", @@ -871,7 +1102,42 @@ type Indexer interface { // Get the chain ID of the indexer GetChainID(ctx context.Context) (uint64, error) // Queries an ethereum node for the latest and confirm ETH balances + // DEPRECATED: use GetNativeTokenBalance instead GetEtherBalance(ctx context.Context, accountAddress *string) (*EtherBalance, error) + // GetNativeTokenBalance queries an ethereum node for the latest native token account balance. + // The native token is the token of the chain the indexer is connected to, for example, ETH on Ethereum + // and POL on Polygon. + GetNativeTokenBalance(ctx context.Context, accountAddress *string) (*NativeTokenBalance, error) + // GetTokenBalancesSummary returns a summary of token balances for a specific + // accounts. The collection ERC721 & ERC1155 tokens are represented as a + // single aggregated balance. + // + // If `filter` is not provided, it will use the filter with account from the + // jwt session. + // + // If `filter.contractStatus` is not provided, it will include verified only + // tokens. + GetTokenBalancesSummary(ctx context.Context, filter *TokenBalancesFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) + // GetTokenBalancesDetails returns a detailed balance summary for a specific + // accounts. The collection ERC721 & ERC1155 tokens are represented as + // individual balances. + // + // If `filter` is not provided, it will use the filter with account from the + // jwt session. + // + // If `filter.contractStatus` is not provided, it will include verified only + // tokens. + GetTokenBalancesDetails(ctx context.Context, filter *TokenBalancesFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) + // GetTokenBalancesByContract returns a balances for a specific accounts and + // contracts. The collection ERC721 & ERC1155 tokens are represented as + // individual balances. + // + // If `filter` is not provided, it will error out as it requires at least + // contract address. + // + // If `filter.contractStatus` is not provided, it will include verified only + // tokens. + GetTokenBalancesByContract(ctx context.Context, filter *TokenBalancesByContractFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) // GetTokenBalances returns a balance summary/details for a specific account. By default // if accountAddress is left empty, it will use the account from the jwt session. // @@ -898,7 +1164,7 @@ type Indexer interface { // Fetches a single receipt and then will stop the subscription FetchTransactionReceipt(ctx context.Context, txnHash string, maxBlockWait *int) (*TransactionReceipt, error) // Fetch orderbook orders - GetOrderbookOrders(ctx context.Context, page *Page, orderbookContractAddress string, collectionAddress string, currencyAddresses []string, filters []*OrderbookOrderFilter, orderStatuses []*OrderStatus, beforeExpiryTimestamp int64) (*Page, []*OrderbookOrder, error) + GetOrderbookOrders(ctx context.Context, page *Page, orderbookContractAddress string, collectionAddress string, currencyAddresses []string, filter *OrderbookOrderFilter, orderStatuses []OrderStatus) (*Page, []*OrderbookOrder, error) GetTopOrders(ctx context.Context, orderbookContractAddress string, collectionAddress string, currencyAddresses []string, tokenIDs []string, isListing bool, priceSort SortOrder, excludeUser *string) ([]*OrderbookOrder, error) // Fetches a single receipt with filter and then will stop the subscription FetchTransactionReceiptWithFilter(ctx context.Context, filter *TransactionFilter, maxBlockWait *int) (*TransactionReceipt, error) @@ -1029,7 +1295,42 @@ type IndexerClient interface { // Get the chain ID of the indexer GetChainID(ctx context.Context) (uint64, error) // Queries an ethereum node for the latest and confirm ETH balances + // DEPRECATED: use GetNativeTokenBalance instead GetEtherBalance(ctx context.Context, accountAddress *string) (*EtherBalance, error) + // GetNativeTokenBalance queries an ethereum node for the latest native token account balance. + // The native token is the token of the chain the indexer is connected to, for example, ETH on Ethereum + // and POL on Polygon. + GetNativeTokenBalance(ctx context.Context, accountAddress *string) (*NativeTokenBalance, error) + // GetTokenBalancesSummary returns a summary of token balances for a specific + // accounts. The collection ERC721 & ERC1155 tokens are represented as a + // single aggregated balance. + // + // If `filter` is not provided, it will use the filter with account from the + // jwt session. + // + // If `filter.contractStatus` is not provided, it will include verified only + // tokens. + GetTokenBalancesSummary(ctx context.Context, filter *TokenBalancesFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) + // GetTokenBalancesDetails returns a detailed balance summary for a specific + // accounts. The collection ERC721 & ERC1155 tokens are represented as + // individual balances. + // + // If `filter` is not provided, it will use the filter with account from the + // jwt session. + // + // If `filter.contractStatus` is not provided, it will include verified only + // tokens. + GetTokenBalancesDetails(ctx context.Context, filter *TokenBalancesFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) + // GetTokenBalancesByContract returns a balances for a specific accounts and + // contracts. The collection ERC721 & ERC1155 tokens are represented as + // individual balances. + // + // If `filter` is not provided, it will error out as it requires at least + // contract address. + // + // If `filter.contractStatus` is not provided, it will include verified only + // tokens. + GetTokenBalancesByContract(ctx context.Context, filter *TokenBalancesByContractFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) // GetTokenBalances returns a balance summary/details for a specific account. By default // if accountAddress is left empty, it will use the account from the jwt session. // @@ -1056,7 +1357,7 @@ type IndexerClient interface { // Fetches a single receipt and then will stop the subscription FetchTransactionReceipt(ctx context.Context, txnHash string, maxBlockWait *int) (*TransactionReceipt, error) // Fetch orderbook orders - GetOrderbookOrders(ctx context.Context, page *Page, orderbookContractAddress string, collectionAddress string, currencyAddresses []string, filters []*OrderbookOrderFilter, orderStatuses []*OrderStatus, beforeExpiryTimestamp int64) (*Page, []*OrderbookOrder, error) + GetOrderbookOrders(ctx context.Context, page *Page, orderbookContractAddress string, collectionAddress string, currencyAddresses []string, filter *OrderbookOrderFilter, orderStatuses []OrderStatus) (*Page, []*OrderbookOrder, error) GetTopOrders(ctx context.Context, orderbookContractAddress string, collectionAddress string, currencyAddresses []string, tokenIDs []string, isListing bool, priceSort SortOrder, excludeUser *string) ([]*OrderbookOrder, error) // Fetches a single receipt with filter and then will stop the subscription FetchTransactionReceiptWithFilter(ctx context.Context, filter *TransactionFilter, maxBlockWait *int) (*TransactionReceipt, error) @@ -1095,17 +1396,21 @@ const IndexerPathPrefix = "/rpc/Indexer/" type indexerClient struct { client HTTPClient - urls [26]string + urls [30]string } func NewIndexerClient(addr string, client HTTPClient) IndexerClient { prefix := urlBase(addr) + IndexerPathPrefix - urls := [26]string{ + urls := [30]string{ prefix + "Ping", prefix + "Version", prefix + "RuntimeStatus", prefix + "GetChainID", prefix + "GetEtherBalance", + prefix + "GetNativeTokenBalance", + prefix + "GetTokenBalancesSummary", + prefix + "GetTokenBalancesDetails", + prefix + "GetTokenBalancesByContract", prefix + "GetTokenBalances", prefix + "GetTokenSupplies", prefix + "GetTokenSuppliesMap", @@ -1217,6 +1522,91 @@ func (c *indexerClient) GetEtherBalance(ctx context.Context, accountAddress *str return out.Ret0, err } +func (c *indexerClient) GetNativeTokenBalance(ctx context.Context, accountAddress *string) (*NativeTokenBalance, error) { + in := struct { + Arg0 *string `json:"accountAddress"` + }{accountAddress} + out := struct { + Ret0 *NativeTokenBalance `json:"balance"` + }{} + + 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.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + } + } + + return out.Ret0, err +} + +func (c *indexerClient) GetTokenBalancesSummary(ctx context.Context, filter *TokenBalancesFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) { + in := struct { + Arg0 *TokenBalancesFilter `json:"filter"` + Arg1 *bool `json:"omitMetadata"` + Arg2 *Page `json:"page"` + }{filter, omitMetadata, page} + out := struct { + Ret0 *Page `json:"page"` + Ret1 []*TokenBalance `json:"balances"` + }{} + + 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.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + } + } + + return out.Ret0, out.Ret1, err +} + +func (c *indexerClient) GetTokenBalancesDetails(ctx context.Context, filter *TokenBalancesFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) { + in := struct { + Arg0 *TokenBalancesFilter `json:"filter"` + Arg1 *bool `json:"omitMetadata"` + Arg2 *Page `json:"page"` + }{filter, omitMetadata, page} + out := struct { + Ret0 *Page `json:"page"` + Ret1 []*TokenBalance `json:"balances"` + }{} + + 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.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + } + } + + return out.Ret0, out.Ret1, err +} + +func (c *indexerClient) GetTokenBalancesByContract(ctx context.Context, filter *TokenBalancesByContractFilter, omitMetadata *bool, page *Page) (*Page, []*TokenBalance, error) { + in := struct { + Arg0 *TokenBalancesByContractFilter `json:"filter"` + Arg1 *bool `json:"omitMetadata"` + Arg2 *Page `json:"page"` + }{filter, omitMetadata, page} + out := struct { + Ret0 *Page `json:"page"` + Ret1 []*TokenBalance `json:"balances"` + }{} + + 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.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + } + } + + return out.Ret0, out.Ret1, err +} + func (c *indexerClient) GetTokenBalances(ctx context.Context, accountAddress *string, contractAddress *string, tokenID *string, includeMetadata *bool, metadataOptions *MetadataOptions, includeCollectionTokens *bool, page *Page) (*Page, []*TokenBalance, error) { in := struct { Arg0 *string `json:"accountAddress"` @@ -1232,7 +1622,7 @@ func (c *indexerClient) GetTokenBalances(ctx context.Context, accountAddress *st Ret1 []*TokenBalance `json:"balances"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[5], 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 { @@ -1256,7 +1646,7 @@ func (c *indexerClient) GetTokenSupplies(ctx context.Context, contractAddress st Ret2 []*TokenSupply `json:"tokenIDs"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[6], 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 { @@ -1277,7 +1667,7 @@ func (c *indexerClient) GetTokenSuppliesMap(ctx context.Context, tokenMap map[st Ret0 map[string][]*TokenSupply `json:"supplies"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[7], 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 { @@ -1300,7 +1690,7 @@ func (c *indexerClient) GetBalanceUpdates(ctx context.Context, contractAddress s Ret1 []*TokenBalance `json:"balances"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[8], 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 { @@ -1323,7 +1713,7 @@ func (c *indexerClient) GetTransactionHistory(ctx context.Context, filter *Trans Ret1 []*Transaction `json:"transactions"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[9], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[13], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { @@ -1341,7 +1731,7 @@ func (c *indexerClient) SyncBalance(ctx context.Context, accountAddress string, Arg2 *string `json:"tokenID"` }{accountAddress, contractAddress, tokenID} - resp, err := doHTTPRequest(ctx, c.client, c.urls[10], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[14], in, nil) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { @@ -1361,7 +1751,7 @@ func (c *indexerClient) FetchTransactionReceipt(ctx context.Context, txnHash str Ret0 *TransactionReceipt `json:"receipt"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[11], 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 { @@ -1372,22 +1762,21 @@ func (c *indexerClient) FetchTransactionReceipt(ctx context.Context, txnHash str return out.Ret0, err } -func (c *indexerClient) GetOrderbookOrders(ctx context.Context, page *Page, orderbookContractAddress string, collectionAddress string, currencyAddresses []string, filters []*OrderbookOrderFilter, orderStatuses []*OrderStatus, beforeExpiryTimestamp int64) (*Page, []*OrderbookOrder, error) { +func (c *indexerClient) GetOrderbookOrders(ctx context.Context, page *Page, orderbookContractAddress string, collectionAddress string, currencyAddresses []string, filter *OrderbookOrderFilter, orderStatuses []OrderStatus) (*Page, []*OrderbookOrder, error) { in := struct { - Arg0 *Page `json:"page"` - Arg1 string `json:"orderbookContractAddress"` - Arg2 string `json:"collectionAddress"` - Arg3 []string `json:"currencyAddresses"` - Arg4 []*OrderbookOrderFilter `json:"filters"` - Arg5 []*OrderStatus `json:"orderStatuses"` - Arg6 int64 `json:"beforeExpiryTimestamp"` - }{page, orderbookContractAddress, collectionAddress, currencyAddresses, filters, orderStatuses, beforeExpiryTimestamp} + Arg0 *Page `json:"page"` + Arg1 string `json:"orderbookContractAddress"` + Arg2 string `json:"collectionAddress"` + Arg3 []string `json:"currencyAddresses"` + Arg4 *OrderbookOrderFilter `json:"filter"` + Arg5 []OrderStatus `json:"orderStatuses"` + }{page, orderbookContractAddress, collectionAddress, currencyAddresses, filter, orderStatuses} out := struct { Ret0 *Page `json:"page"` Ret1 []*OrderbookOrder `json:"orders"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[12], 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 { @@ -1412,7 +1801,7 @@ func (c *indexerClient) GetTopOrders(ctx context.Context, orderbookContractAddre Ret0 []*OrderbookOrder `json:"orders"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[13], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[17], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { @@ -1432,7 +1821,7 @@ func (c *indexerClient) FetchTransactionReceiptWithFilter(ctx context.Context, f Ret0 *TransactionReceipt `json:"receipt"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[14], 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 { @@ -1451,7 +1840,7 @@ func (c *indexerClient) GetAllWebhookListeners(ctx context.Context, projectId *u Ret0 []*WebhookListener `json:"listeners"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[15], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[19], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { @@ -1471,7 +1860,7 @@ func (c *indexerClient) GetWebhookListener(ctx context.Context, id uint64, proje Ret0 *WebhookListener `json:"listener"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[16], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[20], in, &out) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { @@ -1493,7 +1882,7 @@ func (c *indexerClient) AddWebhookListener(ctx context.Context, url string, filt Ret1 *WebhookListener `json:"listener"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[17], 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 { @@ -1513,7 +1902,7 @@ func (c *indexerClient) UpdateWebhookListener(ctx context.Context, listener *Web Ret0 bool `json:"status"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[18], 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 { @@ -1533,7 +1922,7 @@ func (c *indexerClient) RemoveWebhookListener(ctx context.Context, id uint64, pr Ret0 bool `json:"status"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[19], 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 { @@ -1553,7 +1942,7 @@ func (c *indexerClient) ToggleWebhookListener(ctx context.Context, id uint64, pr Ret0 *WebhookListener `json:"webhookListener"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[20], 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 { @@ -1572,7 +1961,7 @@ func (c *indexerClient) PauseAllWebhookListeners(ctx context.Context, projectId Ret0 bool `json:"status"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[21], 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 { @@ -1591,7 +1980,7 @@ func (c *indexerClient) ResumeAllWebhookListeners(ctx context.Context, projectId Ret0 bool `json:"status"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[22], 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 { @@ -1607,7 +1996,7 @@ func (c *indexerClient) SubscribeReceipts(ctx context.Context, filter *Transacti Arg0 *TransactionFilter `json:"filter"` }{filter} - resp, err := doHTTPRequest(ctx, c.client, c.urls[23], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[27], in, nil) if err != nil { if resp != nil { resp.Body.Close() @@ -1646,7 +2035,7 @@ func (c *indexerClient) SubscribeEvents(ctx context.Context, filter *EventFilter Arg0 *EventFilter `json:"filter"` }{filter} - resp, err := doHTTPRequest(ctx, c.client, c.urls[24], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[28], in, nil) if err != nil { if resp != nil { resp.Body.Close() @@ -1685,7 +2074,7 @@ func (c *indexerClient) SubscribeBalanceUpdates(ctx context.Context, contractAdd Arg0 string `json:"contractAddress"` }{contractAddress} - resp, err := doHTTPRequest(ctx, c.client, c.urls[25], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[29], in, nil) if err != nil { if resp != nil { resp.Body.Close() @@ -1886,6 +2275,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 } @@ -1918,6 +2313,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 //