diff --git a/indexer/indexer.gen.go b/indexer/indexer.gen.go index d085bfa4..3a577f62 100644 --- a/indexer/indexer.gen.go +++ b/indexer/indexer.gen.go @@ -1,4 +1,4 @@ -// sequence-indexer v0.4.0 d33d29bc84a4439a42a4e1533035bc80c4ea226e +// sequence-indexer v0.4.0 604761d36d9ef082fa97d028f8315ccdedf19838 // -- // Code generated by webrpc-gen@v0.18.6 with golang generator. DO NOT EDIT. // @@ -33,7 +33,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "d33d29bc84a4439a42a4e1533035bc80c4ea226e" + return "604761d36d9ef082fa97d028f8315ccdedf19838" } // @@ -66,6 +66,7 @@ type ContractInfoExtensions struct { Blacklist bool `json:"blacklist,omitempty" cbor:"-"` Verified bool `json:"verified" cbor:"-"` VerifiedBy string `json:"verifiedBy,omitempty" cbor:"-"` + Featured bool `json:"featured,omitempty" cbor:"-"` } // TokenMetadata based on 721/1155 standards, as well including some @@ -84,8 +85,14 @@ type TokenMetadata struct { // url Video string `json:"video,omitempty" cbor:"-"` // url - Audio string `json:"audio,omitempty" cbor:"-"` - Properties map[string]interface{} `json:"properties" cbor:"-"` + Audio string `json:"audio,omitempty" cbor:"-"` + Properties map[string]interface{} `json:"properties" cbor:"-"` + // OpenSea fields + // see https://docs.opensea.io/docs/metadata-standards + // + // NOTE: its a bit unfortunate OpenSea didn't use camelCase, and + // also introduces 'attributes' when 'properties' is actually the correct property name. + // TODO: we could smooth this out / normalize it, but we can leave it for now. Attributes []map[string]interface{} `json:"attributes" cbor:"-"` ImageData string `json:"image_data,omitempty" cbor:"-"` ExternalUrl string `json:"external_url,omitempty" cbor:"-"` @@ -103,15 +110,13 @@ type TokenMetadata struct { // Asset is a database type used by 'collections' to record static assets for // a particular 'token' for the token metadata. -// -// db table: assets type Asset struct { // asset id ID uint64 `json:"id" db:"id,omitempty"` // collection id associated to this asset CollectionID uint64 `json:"collectionId" db:"collection_id"` // token id associated to this collection - TokenID prototyp.BigInt `json:"tokenId" db:"token_id"` + TokenID *prototyp.BigInt `json:"tokenId" db:"token_id,omitempty"` // url where we can view the asset contents // ie. https://metadata.sequence.app/projects/1/collections/1/tokens/1/image URL string `json:"url" db:"-"` @@ -538,6 +543,7 @@ type WALWriterRuntimeStatus struct { type RuntimeChecks struct { Running bool `json:"running"` + Runnables interface{} `json:"runnables"` CgoEnabled bool `json:"cgoEnabled"` QuotaControlEnabled bool `json:"quotaControlEnabled"` SyncMode string `json:"syncMode"` @@ -622,7 +628,7 @@ type TokenBalance struct { ContractType ContractType `json:"contractType" cbor:"2,omitempty"` ContractAddress prototyp.Hash `json:"contractAddress" cbor:"1,extension"` AccountAddress prototyp.HashMaybe `json:"accountAddress,omitempty" cbor:"3,extension,omitempty"` - TokenID prototyp.BigInt `json:"tokenID,omitempty" cbor:"4,extension"` + TokenID *prototyp.BigInt `json:"tokenID,omitempty" cbor:"4,extension"` Balance prototyp.BigInt `json:"balance" cbor:"5,extension"` BlockHash prototyp.Hash `json:"blockHash,omitempty" cbor:"6,extension"` BlockNumber uint64 `json:"blockNumber,omitempty" cbor:"7"` @@ -787,7 +793,9 @@ type WebhookListener struct { ProjectID uint64 `json:"projectID" db:"project_id"` Url string `json:"url" db:"url"` Filters *EventFilter `json:"filters" db:"filters"` + Name string `json:"name" db:"name"` UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` + Active bool `json:"active" db:"active"` } type EventFilter struct { @@ -807,6 +815,11 @@ type EventFilter struct { Accounts []prototyp.Hash `json:"accounts"` } +type TokenBalanceFilter struct { + ContractAddress prototyp.Hash `json:"contractAddress"` + SinceBlockNumber uint64 `json:"sinceBlockNumber"` +} + type MetadataOptions struct { VerifiedOnly bool `json:"verifiedOnly"` UnverifiedOnly bool `json:"unverifiedOnly"` @@ -835,8 +848,12 @@ var WebRPCServices = map[string][]string{ "AddWebhookListener", "UpdateWebhookListener", "RemoveWebhookListener", + "ToggleWebhookListener", + "PauseAllWebhookListeners", + "ResumeAllWebhookListeners", "SubscribeReceipts", "SubscribeEvents", + "SubscribeBalanceUpdates", }, } @@ -890,10 +907,14 @@ type Indexer interface { AddWebhookListener(ctx context.Context, url string, filters *EventFilter, projectId *uint64) (bool, *WebhookListener, error) UpdateWebhookListener(ctx context.Context, listener *WebhookListener, projectId *uint64) (bool, error) RemoveWebhookListener(ctx context.Context, id uint64, projectId *uint64) (bool, error) + ToggleWebhookListener(ctx context.Context, id uint64, projectId *uint64) (*WebhookListener, error) + PauseAllWebhookListeners(ctx context.Context, projectId *uint64) (bool, error) + ResumeAllWebhookListeners(ctx context.Context, projectId *uint64) (bool, error) SubscribeReceipts(ctx context.Context, filter *TransactionFilter, stream SubscribeReceiptsStreamWriter) error // TODO: pass optional block ... // can pass too, reorg true, etc. or stay behind, etc. SubscribeEvents(ctx context.Context, filter *EventFilter, stream SubscribeEventsStreamWriter) error + SubscribeBalanceUpdates(ctx context.Context, contractAddress string, stream SubscribeBalanceUpdatesStreamWriter) error } type SubscribeReceiptsStreamWriter interface { @@ -904,6 +925,10 @@ type SubscribeEventsStreamWriter interface { Write(log *EventLog) error } +type SubscribeBalanceUpdatesStreamWriter interface { + Write(balance *TokenBalance) error +} + type subscribeReceiptsStreamWriter struct { streamWriter } @@ -932,6 +957,20 @@ func (w *subscribeEventsStreamWriter) Write(log *EventLog) error { return w.streamWriter.write(out) } +type subscribeBalanceUpdatesStreamWriter struct { + streamWriter +} + +func (w *subscribeBalanceUpdatesStreamWriter) Write(balance *TokenBalance) error { + out := struct { + Ret0 *TokenBalance `json:"balance"` + }{ + Ret0: balance, + } + + return w.streamWriter.write(out) +} + type streamWriter struct { mu sync.Mutex // Guards concurrent writes to w. w http.ResponseWriter @@ -1026,10 +1065,14 @@ type IndexerClient interface { AddWebhookListener(ctx context.Context, url string, filters *EventFilter, projectId *uint64) (bool, *WebhookListener, error) UpdateWebhookListener(ctx context.Context, listener *WebhookListener, projectId *uint64) (bool, error) RemoveWebhookListener(ctx context.Context, id uint64, projectId *uint64) (bool, error) + ToggleWebhookListener(ctx context.Context, id uint64, projectId *uint64) (*WebhookListener, error) + PauseAllWebhookListeners(ctx context.Context, projectId *uint64) (bool, error) + ResumeAllWebhookListeners(ctx context.Context, projectId *uint64) (bool, error) SubscribeReceipts(ctx context.Context, filter *TransactionFilter) (SubscribeReceiptsStreamReader, error) // TODO: pass optional block ... // can pass too, reorg true, etc. or stay behind, etc. SubscribeEvents(ctx context.Context, filter *EventFilter) (SubscribeEventsStreamReader, error) + SubscribeBalanceUpdates(ctx context.Context, contractAddress string) (SubscribeBalanceUpdatesStreamReader, error) } type SubscribeReceiptsStreamReader interface { @@ -1040,6 +1083,10 @@ type SubscribeEventsStreamReader interface { Read() (log *EventLog, err error) } +type SubscribeBalanceUpdatesStreamReader interface { + Read() (balance *TokenBalance, err error) +} + // // Client // @@ -1048,12 +1095,12 @@ const IndexerPathPrefix = "/rpc/Indexer/" type indexerClient struct { client HTTPClient - urls [22]string + urls [26]string } func NewIndexerClient(addr string, client HTTPClient) IndexerClient { prefix := urlBase(addr) + IndexerPathPrefix - urls := [22]string{ + urls := [26]string{ prefix + "Ping", prefix + "Version", prefix + "RuntimeStatus", @@ -1074,8 +1121,12 @@ func NewIndexerClient(addr string, client HTTPClient) IndexerClient { prefix + "AddWebhookListener", prefix + "UpdateWebhookListener", prefix + "RemoveWebhookListener", + prefix + "ToggleWebhookListener", + prefix + "PauseAllWebhookListeners", + prefix + "ResumeAllWebhookListeners", prefix + "SubscribeReceipts", prefix + "SubscribeEvents", + prefix + "SubscribeBalanceUpdates", } return &indexerClient{ client: client, @@ -1493,12 +1544,70 @@ func (c *indexerClient) RemoveWebhookListener(ctx context.Context, id uint64, pr return out.Ret0, err } +func (c *indexerClient) ToggleWebhookListener(ctx context.Context, id uint64, projectId *uint64) (*WebhookListener, error) { + in := struct { + Arg0 uint64 `json:"id"` + Arg1 *uint64 `json:"projectId"` + }{id, projectId} + out := struct { + Ret0 *WebhookListener `json:"webhookListener"` + }{} + + 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)) + } + } + + return out.Ret0, err +} + +func (c *indexerClient) PauseAllWebhookListeners(ctx context.Context, projectId *uint64) (bool, error) { + in := struct { + Arg0 *uint64 `json:"projectId"` + }{projectId} + out := struct { + Ret0 bool `json:"status"` + }{} + + 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)) + } + } + + return out.Ret0, err +} + +func (c *indexerClient) ResumeAllWebhookListeners(ctx context.Context, projectId *uint64) (bool, error) { + in := struct { + Arg0 *uint64 `json:"projectId"` + }{projectId} + out := struct { + Ret0 bool `json:"status"` + }{} + + 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)) + } + } + + return out.Ret0, err +} + func (c *indexerClient) SubscribeReceipts(ctx context.Context, filter *TransactionFilter) (SubscribeReceiptsStreamReader, error) { in := struct { Arg0 *TransactionFilter `json:"filter"` }{filter} - resp, err := doHTTPRequest(ctx, c.client, c.urls[20], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[23], in, nil) if err != nil { if resp != nil { resp.Body.Close() @@ -1537,7 +1646,7 @@ func (c *indexerClient) SubscribeEvents(ctx context.Context, filter *EventFilter Arg0 *EventFilter `json:"filter"` }{filter} - resp, err := doHTTPRequest(ctx, c.client, c.urls[21], in, nil) + resp, err := doHTTPRequest(ctx, c.client, c.urls[24], in, nil) if err != nil { if resp != nil { resp.Body.Close() @@ -1571,6 +1680,45 @@ func (r *subscribeEventsStreamReader) Read() (*EventLog, error) { return out.Ret0, nil } +func (c *indexerClient) SubscribeBalanceUpdates(ctx context.Context, contractAddress string) (SubscribeBalanceUpdatesStreamReader, error) { + in := struct { + Arg0 string `json:"contractAddress"` + }{contractAddress} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[25], in, nil) + if err != nil { + if resp != nil { + resp.Body.Close() + } + return nil, err + } + + buf := bufio.NewReader(resp.Body) + return &subscribeBalanceUpdatesStreamReader{streamReader{ctx: ctx, c: resp.Body, r: buf}}, nil +} + +type subscribeBalanceUpdatesStreamReader struct { + streamReader +} + +func (r *subscribeBalanceUpdatesStreamReader) Read() (*TokenBalance, error) { + out := struct { + Ret0 *TokenBalance `json:"balance"` + WebRPCError *WebRPCError `json:"webrpcError"` + }{} + + err := r.streamReader.read(&out) + if err != nil { + return out.Ret0, err + } + + if out.WebRPCError != nil { + return out.Ret0, out.WebRPCError + } + + return out.Ret0, nil +} + type streamReader struct { ctx context.Context c io.Closer @@ -1853,6 +2001,7 @@ var ( ErrInvalidArgument = WebRPCError{Code: 2001, Name: "InvalidArgument", Message: "Invalid argument", HTTPStatus: 400} ErrUnavailable = WebRPCError{Code: 2002, Name: "Unavailable", Message: "Unavailable resource", HTTPStatus: 400} ErrQueryFailed = WebRPCError{Code: 2003, Name: "QueryFailed", Message: "Query failed", HTTPStatus: 400} + ErrResourceExhausted = WebRPCError{Code: 2004, Name: "ResourceExhausted", Message: "Resource exhausted", HTTPStatus: 400} ErrNotFound = WebRPCError{Code: 3000, Name: "NotFound", Message: "Resource not found", HTTPStatus: 400} ErrProjectNotFound = WebRPCError{Code: 3002, Name: "ProjectNotFound", Message: "Project not found", HTTPStatus: 400} ErrMetadataCallFailed = WebRPCError{Code: 3003, Name: "MetadataCallFailed", Message: "Metadata service call failed", HTTPStatus: 400}