diff --git a/db/gen/coredb/batch.go b/db/gen/coredb/batch.go index 4bf1263c7..432ff6313 100644 --- a/db/gen/coredb/batch.go +++ b/db/gen/coredb/batch.go @@ -743,7 +743,7 @@ func (b *GetAdmiresByActorIDBatchBatchResults) Close() error { } const getChildContractsByParentIDBatchPaginate = `-- name: GetChildContractsByParentIDBatchPaginate :batchmany -select c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id +select c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, c.l1_chain from contracts c where c.parent_id = $1 and c.deleted = false @@ -825,6 +825,7 @@ func (b *GetChildContractsByParentIDBatchPaginateBatchResults) Query(f func(int, &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ); err != nil { return err } @@ -1035,7 +1036,7 @@ func (b *GetCommentByCommentIDBatchBatchResults) Close() error { } const getContractByChainAddressBatch = `-- name: GetContractByChainAddressBatch :batchone -select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id FROM contracts WHERE address = $1 AND chain = $2 AND deleted = false +select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id, l1_chain FROM contracts WHERE address = $1 AND chain = $2 AND deleted = false ` type GetContractByChainAddressBatchBatchResults struct { @@ -1092,6 +1093,7 @@ func (b *GetContractByChainAddressBatchBatchResults) QueryRow(f func(int, Contra &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ) if f != nil { f(t, i, err) @@ -1127,7 +1129,7 @@ displayed as ( and galleries.last_updated > last_refreshed.last_updated and collections.last_updated > last_refreshed.last_updated ) -select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id from contracts, displayed +select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, contracts.l1_chain from contracts, displayed where contracts.id = displayed.contract_id and contracts.deleted = false ` @@ -1186,6 +1188,7 @@ func (b *GetContractsDisplayedByUserIDBatchBatchResults) Query(f func(int, []Con &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ); err != nil { return err } @@ -1205,7 +1208,7 @@ func (b *GetContractsDisplayedByUserIDBatchBatchResults) Close() error { } const getCreatedContractsBatchPaginate = `-- name: GetCreatedContractsBatchPaginate :batchmany -select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id +select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, contracts.l1_chain from contracts join contract_creators on contracts.id = contract_creators.contract_id and contract_creators.creator_user_id = $1 where ($2::bool or contracts.chain = any(string_to_array($3, ',')::int[])) @@ -1291,6 +1294,7 @@ func (b *GetCreatedContractsBatchPaginateBatchResults) Query(f func(int, []Contr &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ); err != nil { return err } @@ -2453,7 +2457,7 @@ func (b *GetProfileImageByIDBatchResults) Close() error { } const getSharedContractsBatchPaginate = `-- name: GetSharedContractsBatchPaginate :batchmany -select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, a.displayed as displayed_by_user_a, b.displayed as displayed_by_user_b, a.owned_count +select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, contracts.l1_chain, a.displayed as displayed_by_user_a, b.displayed as displayed_by_user_b, a.owned_count from owned_contracts a, owned_contracts b, contracts left join marketplace_contracts on contracts.id = marketplace_contracts.contract_id where a.user_id = $1 @@ -2531,6 +2535,7 @@ type GetSharedContractsBatchPaginateRow struct { IsProviderMarkedSpam bool `json:"is_provider_marked_spam"` ParentID persist.DBID `json:"parent_id"` OverrideCreatorUserID persist.DBID `json:"override_creator_user_id"` + L1Chain persist.L1Chain `json:"l1_chain"` DisplayedByUserA bool `json:"displayed_by_user_a"` DisplayedByUserB bool `json:"displayed_by_user_b"` OwnedCount int64 `json:"owned_count"` @@ -2596,6 +2601,7 @@ func (b *GetSharedContractsBatchPaginateBatchResults) Query(f func(int, []GetSha &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, &i.DisplayedByUserA, &i.DisplayedByUserB, &i.OwnedCount, diff --git a/db/gen/coredb/contract_gallery.sql.go b/db/gen/coredb/contract_gallery.sql.go index b81e96abc..9dfa8f5e9 100644 --- a/db/gen/coredb/contract_gallery.sql.go +++ b/db/gen/coredb/contract_gallery.sql.go @@ -10,7 +10,7 @@ import ( ) const upsertChildContracts = `-- name: UpsertChildContracts :many -insert into contracts(id, deleted, version, created_at, name, address, creator_address, owner_address, chain, description, parent_id) ( +insert into contracts(id, deleted, version, created_at, name, address, creator_address, owner_address, chain, l1_chain, description, parent_id) ( select unnest($1::varchar[]) as id , false , 0 @@ -20,17 +20,18 @@ insert into contracts(id, deleted, version, created_at, name, address, creator_a , unnest($4::varchar[]) , unnest($5::varchar[]) , unnest($6::int[]) - , unnest($7::varchar[]) + , unnest($7::int[]) , unnest($8::varchar[]) + , unnest($9::varchar[]) ) -on conflict (chain, parent_id, address) where parent_id is not null +on conflict (l1_chain, chain, parent_id, address) where parent_id is not null do update set deleted = excluded.deleted , name = excluded.name , creator_address = excluded.creator_address , owner_address = excluded.owner_address , description = excluded.description , last_updated = now() -returning id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id +returning id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id, l1_chain ` type UpsertChildContractsParams struct { @@ -40,6 +41,7 @@ type UpsertChildContractsParams struct { CreatorAddress []string `json:"creator_address"` OwnerAddress []string `json:"owner_address"` Chain []int32 `json:"chain"` + L1Chain []int32 `json:"l1_chain"` Description []string `json:"description"` ParentIds []string `json:"parent_ids"` } @@ -52,6 +54,7 @@ func (q *Queries) UpsertChildContracts(ctx context.Context, arg UpsertChildContr arg.CreatorAddress, arg.OwnerAddress, arg.Chain, + arg.L1Chain, arg.Description, arg.ParentIds, ) @@ -81,6 +84,7 @@ func (q *Queries) UpsertChildContracts(ctx context.Context, arg UpsertChildContr &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ); err != nil { return nil, err } @@ -93,7 +97,7 @@ func (q *Queries) UpsertChildContracts(ctx context.Context, arg UpsertChildContr } const upsertParentContracts = `-- name: UpsertParentContracts :many -insert into contracts(id, deleted, version, created_at, address, symbol, name, owner_address, chain, description, profile_image_url, is_provider_marked_spam) ( +insert into contracts(id, deleted, version, created_at, address, symbol, name, owner_address, chain, l1_chain, description, profile_image_url, is_provider_marked_spam) ( select unnest($1::varchar[]) , false , unnest($2::int[]) @@ -103,17 +107,18 @@ insert into contracts(id, deleted, version, created_at, address, symbol, name, o , unnest($5::varchar[]) , unnest($6::varchar[]) , unnest($7::int[]) - , unnest($8::varchar[]) + , unnest($8::int[]) , unnest($9::varchar[]) - , unnest($10::bool[]) + , unnest($10::varchar[]) + , unnest($11::bool[]) ) -on conflict (chain, address) where parent_id is null +on conflict (l1_chain, chain, address) where parent_id is null do update set symbol = coalesce(nullif(excluded.symbol, ''), nullif(contracts.symbol, '')) , version = excluded.version , name = coalesce(nullif(excluded.name, ''), nullif(contracts.name, '')) , owner_address = case - when nullif(contracts.owner_address, '') is null or ($11::bool and nullif (excluded.owner_address, '') is not null) + when nullif(contracts.owner_address, '') is null or ($12::bool and nullif (excluded.owner_address, '') is not null) then excluded.owner_address else contracts.owner_address @@ -122,7 +127,7 @@ do update set symbol = coalesce(nullif(excluded.symbol, ''), nullif(contracts.sy , profile_image_url = coalesce(nullif(excluded.profile_image_url, ''), nullif(contracts.profile_image_url, '')) , deleted = excluded.deleted , last_updated = now() -returning id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id +returning id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id, l1_chain ` type UpsertParentContractsParams struct { @@ -133,6 +138,7 @@ type UpsertParentContractsParams struct { Name []string `json:"name"` OwnerAddress []string `json:"owner_address"` Chain []int32 `json:"chain"` + L1Chain []int32 `json:"l1_chain"` Description []string `json:"description"` ProfileImageUrl []string `json:"profile_image_url"` ProviderMarkedSpam []bool `json:"provider_marked_spam"` @@ -148,6 +154,7 @@ func (q *Queries) UpsertParentContracts(ctx context.Context, arg UpsertParentCon arg.Name, arg.OwnerAddress, arg.Chain, + arg.L1Chain, arg.Description, arg.ProfileImageUrl, arg.ProviderMarkedSpam, @@ -179,6 +186,7 @@ func (q *Queries) UpsertParentContracts(ctx context.Context, arg UpsertParentCon &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ); err != nil { return nil, err } diff --git a/db/gen/coredb/models_gen.go b/db/gen/coredb/models_gen.go index cd3ad9f5f..ab9b232bf 100644 --- a/db/gen/coredb/models_gen.go +++ b/db/gen/coredb/models_gen.go @@ -81,6 +81,7 @@ type Contract struct { IsProviderMarkedSpam bool `json:"is_provider_marked_spam"` ParentID persist.DBID `json:"parent_id"` OverrideCreatorUserID persist.DBID `json:"override_creator_user_id"` + L1Chain persist.L1Chain `json:"l1_chain"` } type ContractCreator struct { diff --git a/db/gen/coredb/query.sql.go b/db/gen/coredb/query.sql.go index 764128d68..d30e35f2d 100644 --- a/db/gen/coredb/query.sql.go +++ b/db/gen/coredb/query.sql.go @@ -1456,7 +1456,7 @@ func (q *Queries) GetAllTimeTrendingUserIDs(ctx context.Context, limit int32) ([ const getAllTokensWithContractsByIDs = `-- name: GetAllTokensWithContractsByIDs :many select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name, tokens.description, tokens.collectors_note, tokens.token_uri, tokens.token_type, tokens.token_id, tokens.quantity, tokens.ownership_history, tokens.external_url, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract, tokens.is_user_marked_spam, tokens.is_provider_marked_spam, tokens.last_synced, tokens.fallback_media, tokens.token_media_id, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, - contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, + contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, contracts.l1_chain, ( select wallets.address from wallets @@ -1523,6 +1523,7 @@ type GetAllTokensWithContractsByIDsRow struct { IsProviderMarkedSpam_2 bool `json:"is_provider_marked_spam_2"` ParentID persist.DBID `json:"parent_id"` OverrideCreatorUserID persist.DBID `json:"override_creator_user_id"` + L1Chain persist.L1Chain `json:"l1_chain"` WalletAddress persist.Address `json:"wallet_address"` } @@ -1581,6 +1582,7 @@ func (q *Queries) GetAllTokensWithContractsByIDs(ctx context.Context, arg GetAll &i.IsProviderMarkedSpam_2, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, &i.WalletAddress, ); err != nil { return nil, err @@ -1763,7 +1765,7 @@ func (q *Queries) GetCommentsByCommentIDs(ctx context.Context, commentIds persis } const getContractByChainAddress = `-- name: GetContractByChainAddress :one -select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id FROM contracts WHERE address = $1 AND chain = $2 AND deleted = false +select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id, l1_chain FROM contracts WHERE address = $1 AND chain = $2 AND deleted = false ` type GetContractByChainAddressParams struct { @@ -1793,12 +1795,13 @@ func (q *Queries) GetContractByChainAddress(ctx context.Context, arg GetContract &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ) return i, err } const getContractByID = `-- name: GetContractByID :one -select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id FROM contracts WHERE id = $1 AND deleted = false +select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id, l1_chain FROM contracts WHERE id = $1 AND deleted = false ` func (q *Queries) GetContractByID(ctx context.Context, id persist.DBID) (Contract, error) { @@ -1823,6 +1826,7 @@ func (q *Queries) GetContractByID(ctx context.Context, id persist.DBID) (Contrac &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ) return i, err } @@ -1859,7 +1863,7 @@ func (q *Queries) GetContractCreatorsByIds(ctx context.Context, contractIds []st } const getContractsByIDs = `-- name: GetContractsByIDs :many -SELECT id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id from contracts WHERE id = ANY($1) AND deleted = false +SELECT id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id, l1_chain from contracts WHERE id = ANY($1) AND deleted = false ` func (q *Queries) GetContractsByIDs(ctx context.Context, contractIds persist.DBIDList) ([]Contract, error) { @@ -1890,6 +1894,7 @@ func (q *Queries) GetContractsByIDs(ctx context.Context, contractIds persist.DBI &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ); err != nil { return nil, err } @@ -1902,7 +1907,7 @@ func (q *Queries) GetContractsByIDs(ctx context.Context, contractIds persist.DBI } const getContractsByTokenIDs = `-- name: GetContractsByTokenIDs :many -select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id from contracts join tokens on contracts.id = tokens.contract where tokens.id = any($1) and contracts.deleted = false +select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, contracts.l1_chain from contracts join tokens on contracts.id = tokens.contract where tokens.id = any($1) and contracts.deleted = false ` func (q *Queries) GetContractsByTokenIDs(ctx context.Context, tokenIds persist.DBIDList) ([]Contract, error) { @@ -1933,6 +1938,7 @@ func (q *Queries) GetContractsByTokenIDs(ctx context.Context, tokenIds persist.D &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ); err != nil { return nil, err } @@ -1945,19 +1951,19 @@ func (q *Queries) GetContractsByTokenIDs(ctx context.Context, tokenIds persist.D } const getCreatedContractsByUserID = `-- name: GetCreatedContractsByUserID :many -select c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, +select c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, c.l1_chain, w.id as wallet_id, false as is_override_creator from users u, contracts c, wallets w where u.id = $1 and c.chain = any($2::int[]) and w.id = any(u.wallets) and coalesce(nullif(c.owner_address, ''), nullif(c.creator_address, '')) = w.address - and w.chain = any($3::int[]) + and w.l1_chain = c.l1_chain and u.deleted = false and c.deleted = false and w.deleted = false and c.override_creator_user_id is null - and (not $4::bool or not exists( + and (not $3::bool or not exists( select 1 from tokens t where t.owner_user_id = $1 and t.contract = c.id @@ -1968,14 +1974,14 @@ where u.id = $1 union all -select c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, +select c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, c.l1_chain, null as wallet_id, true as is_override_creator from contracts c where c.override_creator_user_id = $1 and c.chain = any($2::int[]) and c.deleted = false - and (not $4::bool or not exists( + and (not $3::bool or not exists( select 1 from tokens t where t.owner_user_id = $1 and t.contract = c.id @@ -1988,7 +1994,6 @@ where c.override_creator_user_id = $1 type GetCreatedContractsByUserIDParams struct { UserID persist.DBID `json:"user_id"` Chains []int32 `json:"chains"` - L1Chains []int32 `json:"l1_chains"` NewContractsOnly bool `json:"new_contracts_only"` } @@ -1999,12 +2004,7 @@ type GetCreatedContractsByUserIDRow struct { } func (q *Queries) GetCreatedContractsByUserID(ctx context.Context, arg GetCreatedContractsByUserIDParams) ([]GetCreatedContractsByUserIDRow, error) { - rows, err := q.db.Query(ctx, getCreatedContractsByUserID, - arg.UserID, - arg.Chains, - arg.L1Chains, - arg.NewContractsOnly, - ) + rows, err := q.db.Query(ctx, getCreatedContractsByUserID, arg.UserID, arg.Chains, arg.NewContractsOnly) if err != nil { return nil, err } @@ -2031,6 +2031,7 @@ func (q *Queries) GetCreatedContractsByUserID(ctx context.Context, arg GetCreate &i.Contract.IsProviderMarkedSpam, &i.Contract.ParentID, &i.Contract.OverrideCreatorUserID, + &i.Contract.L1Chain, &i.WalletID, &i.IsOverrideCreator, ); err != nil { @@ -2309,7 +2310,7 @@ func (q *Queries) GetEventsInWindow(ctx context.Context, arg GetEventsInWindowPa const getFallbackTokenByUserTokenIdentifiers = `-- name: GetFallbackTokenByUserTokenIdentifiers :one with contract as ( - select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id from contracts where contracts.chain = $3 and contracts.address = $4 and not contracts.deleted + select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id, l1_chain from contracts where contracts.chain = $3 and contracts.address = $4 and not contracts.deleted ) select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name, tokens.description, tokens.collectors_note, tokens.token_uri, tokens.token_type, tokens.token_id, tokens.quantity, tokens.ownership_history, tokens.external_url, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract, tokens.is_user_marked_spam, tokens.is_provider_marked_spam, tokens.last_synced, tokens.fallback_media, tokens.token_media_id, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable from tokens, contract @@ -2715,7 +2716,7 @@ func (q *Queries) GetLastFeedEventForUser(ctx context.Context, arg GetLastFeedEv const getMediaByUserTokenIdentifiers = `-- name: GetMediaByUserTokenIdentifiers :one with contract as ( - select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id from contracts where contracts.chain = $1 and contracts.address = $2 and not contracts.deleted + select id, deleted, version, created_at, last_updated, name, symbol, address, creator_address, chain, profile_banner_url, profile_image_url, badge_url, description, owner_address, is_provider_marked_spam, parent_id, override_creator_user_id, l1_chain from contracts where contracts.chain = $1 and contracts.address = $2 and not contracts.deleted ), matching_media as ( select token_medias.id, token_medias.created_at, token_medias.last_updated, token_medias.version, token_medias.contract_id, token_medias.token_id, token_medias.chain, token_medias.active, token_medias.metadata, token_medias.media, token_medias.name, token_medias.description, token_medias.processing_job_id, token_medias.deleted @@ -2830,7 +2831,7 @@ func (q *Queries) GetMerchDiscountCodeByTokenID(ctx context.Context, tokenHex pe const getMissingThumbnailTokensByIDRange = `-- name: GetMissingThumbnailTokensByIDRange :many SELECT tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name, tokens.description, tokens.collectors_note, tokens.token_uri, tokens.token_type, tokens.token_id, tokens.quantity, tokens.ownership_history, tokens.external_url, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract, tokens.is_user_marked_spam, tokens.is_provider_marked_spam, tokens.last_synced, tokens.fallback_media, tokens.token_media_id, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, - contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, + contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, contracts.l1_chain, ( SELECT wallets.address FROM wallets @@ -2895,6 +2896,7 @@ type GetMissingThumbnailTokensByIDRangeRow struct { IsProviderMarkedSpam_2 bool `json:"is_provider_marked_spam_2"` ParentID persist.DBID `json:"parent_id"` OverrideCreatorUserID persist.DBID `json:"override_creator_user_id"` + L1Chain persist.L1Chain `json:"l1_chain"` WalletAddress persist.Address `json:"wallet_address"` } @@ -2953,6 +2955,7 @@ func (q *Queries) GetMissingThumbnailTokensByIDRange(ctx context.Context, arg Ge &i.IsProviderMarkedSpam_2, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, &i.WalletAddress, ); err != nil { return nil, err @@ -3392,7 +3395,7 @@ func (q *Queries) GetReprocessJobRangeByID(ctx context.Context, id int) (Reproce const getSVGTokensWithContractsByIDs = `-- name: GetSVGTokensWithContractsByIDs :many SELECT tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name, tokens.description, tokens.collectors_note, tokens.token_uri, tokens.token_type, tokens.token_id, tokens.quantity, tokens.ownership_history, tokens.external_url, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract, tokens.is_user_marked_spam, tokens.is_provider_marked_spam, tokens.last_synced, tokens.fallback_media, tokens.token_media_id, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, - contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, + contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, contracts.l1_chain, ( SELECT wallets.address FROM wallets @@ -3460,6 +3463,7 @@ type GetSVGTokensWithContractsByIDsRow struct { IsProviderMarkedSpam_2 bool `json:"is_provider_marked_spam_2"` ParentID persist.DBID `json:"parent_id"` OverrideCreatorUserID persist.DBID `json:"override_creator_user_id"` + L1Chain persist.L1Chain `json:"l1_chain"` WalletAddress persist.Address `json:"wallet_address"` } @@ -3518,6 +3522,7 @@ func (q *Queries) GetSVGTokensWithContractsByIDs(ctx context.Context, arg GetSVG &i.IsProviderMarkedSpam_2, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, &i.WalletAddress, ); err != nil { return nil, err diff --git a/db/gen/coredb/search.sql.go b/db/gen/coredb/search.sql.go index 56c1d43f9..38958de3d 100644 --- a/db/gen/coredb/search.sql.go +++ b/db/gen/coredb/search.sql.go @@ -20,7 +20,7 @@ poap_weight as ( -- to offset the fact that we're going to multiply all addresses by 1000000000. select $5::float4 / 1000000000 as weight ) -select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id from contracts left join contract_relevance on contract_relevance.id = contracts.id, +select contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, contracts.l1_chain from contracts left join contract_relevance on contract_relevance.id = contracts.id, to_tsquery('simple', websearch_to_tsquery('simple', $1)::text || ':*') simple_partial_query, websearch_to_tsquery('simple', $1) simple_full_query, websearch_to_tsquery('english', $1) english_full_query, @@ -84,6 +84,7 @@ func (q *Queries) SearchContracts(ctx context.Context, arg SearchContractsParams &i.IsProviderMarkedSpam, &i.ParentID, &i.OverrideCreatorUserID, + &i.L1Chain, ); err != nil { return nil, err } diff --git a/db/migrations/core/000112_contract_l1.up.sql b/db/migrations/core/000112_contract_l1.up.sql new file mode 100644 index 000000000..6169313ce --- /dev/null +++ b/db/migrations/core/000112_contract_l1.up.sql @@ -0,0 +1,28 @@ +alter table contracts add column l1_chain int; +update contracts set l1_chain = 0; +alter table contracts alter column l1_chain set not null; +update contracts set l1_chain = 4 where chain = 4; +create index contracts_l1_chain_idx on contracts (address,chain,l1_chain) where deleted = false; +create unique index contracts_l1_chain_unique_idx on contracts (l1_chain,chain,address) where parent_id is null; +create unique index contracts_l1_chain_parent_unique_idx on contracts (l1_chain,chain,parent_id,address) where parent_id is not null; + +drop view if exists contract_creators; + +create view contract_creators as + select c.id as contract_id, + u.id as creator_user_id, + c.chain as chain, + coalesce(nullif(c.owner_address, ''), nullif(c.creator_address, '')) as creator_address + from contracts c + left join wallets w on + w.deleted = false and + w.l1_chain = c.l1_chain and + coalesce(nullif(c.owner_address, ''), nullif(c.creator_address, '')) = w.address + left join users u on + u.deleted = false and + ( + (c.override_creator_user_id is not null and c.override_creator_user_id = u.id) + or + (c.override_creator_user_id is null and w.address is not null and array[w.id] <@ u.wallets) + ) + where c.deleted = false; \ No newline at end of file diff --git a/db/queries/core/contract_gallery.sql b/db/queries/core/contract_gallery.sql index 2a4b5c519..74787010c 100644 --- a/db/queries/core/contract_gallery.sql +++ b/db/queries/core/contract_gallery.sql @@ -1,5 +1,5 @@ -- name: UpsertParentContracts :many -insert into contracts(id, deleted, version, created_at, address, symbol, name, owner_address, chain, description, profile_image_url, is_provider_marked_spam) ( +insert into contracts(id, deleted, version, created_at, address, symbol, name, owner_address, chain, l1_chain, description, profile_image_url, is_provider_marked_spam) ( select unnest(@ids::varchar[]) , false , unnest(@version::int[]) @@ -9,11 +9,12 @@ insert into contracts(id, deleted, version, created_at, address, symbol, name, o , unnest(@name::varchar[]) , unnest(@owner_address::varchar[]) , unnest(@chain::int[]) + , unnest(@l1_chain::int[]) , unnest(@description::varchar[]) , unnest(@profile_image_url::varchar[]) , unnest(@provider_marked_spam::bool[]) ) -on conflict (chain, address) where parent_id is null +on conflict (l1_chain, chain, address) where parent_id is null do update set symbol = coalesce(nullif(excluded.symbol, ''), nullif(contracts.symbol, '')) , version = excluded.version , name = coalesce(nullif(excluded.name, ''), nullif(contracts.name, '')) @@ -31,7 +32,7 @@ do update set symbol = coalesce(nullif(excluded.symbol, ''), nullif(contracts.sy returning *; -- name: UpsertChildContracts :many -insert into contracts(id, deleted, version, created_at, name, address, creator_address, owner_address, chain, description, parent_id) ( +insert into contracts(id, deleted, version, created_at, name, address, creator_address, owner_address, chain, l1_chain, description, parent_id) ( select unnest(@id::varchar[]) as id , false , 0 @@ -41,10 +42,11 @@ insert into contracts(id, deleted, version, created_at, name, address, creator_a , unnest(@creator_address::varchar[]) , unnest(@owner_address::varchar[]) , unnest(@chain::int[]) + , unnest(@l1_chain::int[]) , unnest(@description::varchar[]) , unnest(@parent_ids::varchar[]) ) -on conflict (chain, parent_id, address) where parent_id is not null +on conflict (l1_chain, chain, parent_id, address) where parent_id is not null do update set deleted = excluded.deleted , name = excluded.name , creator_address = excluded.creator_address diff --git a/db/queries/core/query.sql b/db/queries/core/query.sql index ad3427369..cbbd1bc0c 100644 --- a/db/queries/core/query.sql +++ b/db/queries/core/query.sql @@ -1589,7 +1589,7 @@ from users u, contracts c, wallets w where u.id = @user_id and c.chain = any(@chains::int[]) and w.id = any(u.wallets) and coalesce(nullif(c.owner_address, ''), nullif(c.creator_address, '')) = w.address - and w.chain = any(@l1_chains::int[]) + and w.l1_chain = c.l1_chain and u.deleted = false and c.deleted = false and w.deleted = false diff --git a/service/multichain/multichain.go b/service/multichain/multichain.go index 6723a25ee..c1242d75c 100644 --- a/service/multichain/multichain.go +++ b/service/multichain/multichain.go @@ -701,11 +701,8 @@ func (p *Provider) SyncCreatedTokensForNewContracts(ctx context.Context, userID chainInts := util.MapWithoutError(chains, func(c persist.Chain) int32 { return int32(c) }) rows, err := p.Queries.GetCreatedContractsByUserID(ctx, db.GetCreatedContractsByUserIDParams{ - UserID: userID, - Chains: chainInts, - L1Chains: util.MapWithoutError(chainInts, func(c int32) int32 { - return int32(persist.Chain(c).L1Chain()) - }), + UserID: userID, + Chains: chainInts, NewContractsOnly: true, }) @@ -936,6 +933,7 @@ func (p *Provider) SyncTokensCreatedOnSharedContracts(ctx context.Context, userI params.CreatorAddress = append(params.CreatorAddress, child.CreatorAddress.String()) params.OwnerAddress = append(params.OwnerAddress, child.OwnerAddress.String()) params.Chain = append(params.Chain, int32(result.Chain)) + params.L1Chain = append(params.L1Chain, int32(result.Chain.L1Chain())) params.Description = append(params.Description, child.Description) params.ParentIds = append(params.ParentIds, contractToDBID[persist.NewContractIdentifiers(edge.Parent.Address, result.Chain)].String()) } @@ -1463,8 +1461,9 @@ func (p *Provider) RefreshTokenDescriptorsByTokenIdentifiers(ctx context.Context return persist.ErrTokenNotFoundByTokenIdentifiers{Token: ti} } - contractID, err := p.Repos.ContractRepository.UpsertByAddress(ctx, ti.ContractAddress, ti.Chain, persist.ContractGallery{ + contractID, err := p.Repos.ContractRepository.UpsertByAddress(ctx, ti.ContractAddress, persist.ContractGallery{ Chain: ti.Chain, + L1Chain: ti.Chain.L1Chain(), Address: persist.Address(ti.Chain.NormalizeAddress(ti.ContractAddress)), Symbol: persist.NullString(finalContractDescriptors.Symbol), Name: persist.NullString(finalContractDescriptors.Name), @@ -2139,6 +2138,7 @@ func contractsToNewDedupedContracts(contracts []chainContracts, existingContract for address, meta := range contractMetadatas { res = append(res, persist.ContractGallery{ Chain: address.Chain(), + L1Chain: address.Chain().L1Chain(), Address: address.Address(), Symbol: persist.NullString(meta.Symbol), Name: persist.NullString(meta.Name), diff --git a/service/persist/contract_gallery.go b/service/persist/contract_gallery.go index 0f6aa5d1c..56a273214 100644 --- a/service/persist/contract_gallery.go +++ b/service/persist/contract_gallery.go @@ -15,6 +15,7 @@ type ContractGallery struct { LastUpdated time.Time `json:"last_updated"` Chain Chain `json:"chain"` + L1Chain L1Chain `json:"l1_chain"` Address Address `json:"address"` Symbol NullString `json:"symbol"` Name NullString `json:"name"` diff --git a/service/persist/postgres/contract_gallery.go b/service/persist/postgres/contract_gallery.go index a74a577f7..1e99d5c82 100644 --- a/service/persist/postgres/contract_gallery.go +++ b/service/persist/postgres/contract_gallery.go @@ -45,16 +45,15 @@ func NewContractGalleryRepository(db *sql.DB, queries *db.Queries) *ContractGall checkNoErr(err) upsertByAddressStmt, err := db.PrepareContext(ctx, ` - insert into contracts (id,version,address,symbol,name,owner_address,chain,description,profile_image_url) values ($1,$2,$3,$4,$5,$6,$7,$8,$9) - on conflict (address,chain) where parent_id is null do update set + insert into contracts (id,version,address,symbol,name,owner_address,chain,l1_chain,description,profile_image_url) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) + on conflict (address,l1_chain) where parent_id is null do update set version = $2, address = $3, symbol = coalesce(nullif(contracts.symbol, ''), nullif($4, '')), name = coalesce(nullif(contracts.name, ''), nullif($5, '')), - description = coalesce(nullif(contracts.description, ''), nullif($8, '')), - profile_image_url = coalesce(nullif(contracts.profile_image_url, ''), nullif($9, '')), - owner_address = case when nullif(contracts.owner_address, '') is null then $6 else contracts.owner_address end, - chain = $7 + description = coalesce(nullif(contracts.description, ''), nullif($9, '')), + profile_image_url = coalesce(nullif(contracts.profile_image_url, ''), nullif($10, '')), + owner_address = case when nullif(contracts.owner_address, '') is null then $6 else contracts.owner_address end returning id; `) checkNoErr(err) @@ -154,8 +153,8 @@ func (c *ContractGalleryRepository) GetByTokenIDs(pCtx context.Context, pDBIDs p } // UpsertByAddress upserts the contract with the given address -func (c *ContractGalleryRepository) UpsertByAddress(pCtx context.Context, pAddress persist.Address, pChain persist.Chain, pContract persist.ContractGallery) (contractID persist.DBID, err error) { - err = c.upsertByAddressStmt.QueryRowContext(pCtx, persist.GenerateID(), pContract.Version, pContract.Address, pContract.Symbol, pContract.Name, pContract.OwnerAddress, pContract.Chain, pContract.Description, pContract.ProfileImageURL).Scan(&contractID) +func (c *ContractGalleryRepository) UpsertByAddress(pCtx context.Context, pAddress persist.Address, pContract persist.ContractGallery) (contractID persist.DBID, err error) { + err = c.upsertByAddressStmt.QueryRowContext(pCtx, persist.GenerateID(), pContract.Version, pContract.Address, pContract.Symbol, pContract.Name, pContract.OwnerAddress, pContract.Chain, pContract.L1Chain, pContract.Description, pContract.ProfileImageURL).Scan(&contractID) if err != nil { return "", err } @@ -183,6 +182,7 @@ func (c *ContractGalleryRepository) BulkUpsert(pCtx context.Context, pContracts params.Name = append(params.Name, c.Name.String()) params.OwnerAddress = append(params.OwnerAddress, c.OwnerAddress.String()) params.Chain = append(params.Chain, int32(c.Chain)) + params.L1Chain = append(params.L1Chain, int32(c.Chain.L1Chain())) params.Description = append(params.Description, c.Description.String()) params.ProfileImageUrl = append(params.ProfileImageUrl, c.ProfileImageURL.String()) params.ProviderMarkedSpam = append(params.ProviderMarkedSpam, c.IsProviderMarkedSpam)