diff --git a/db/gen/coredb/contract_gallery.sql.go b/db/gen/coredb/contract_gallery.sql.go index daacb796f..fe52065f0 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,10 +20,11 @@ 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, parent_id, address) where parent_id is not null do update set deleted = excluded.deleted , name = excluded.name , creator_address = excluded.creator_address @@ -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, ) @@ -94,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[]) @@ -104,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, 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 @@ -134,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"` @@ -149,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, diff --git a/db/gen/coredb/query.sql.go b/db/gen/coredb/query.sql.go index 130621fb5..d30e35f2d 100644 --- a/db/gen/coredb/query.sql.go +++ b/db/gen/coredb/query.sql.go @@ -1958,12 +1958,12 @@ 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 @@ -1981,7 +1981,7 @@ 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 @@ -1994,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"` } @@ -2005,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 } diff --git a/db/queries/core/contract_gallery.sql b/db/queries/core/contract_gallery.sql index 2a4b5c519..722dd0584 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, 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, 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 ce83c8ef3..32cd716ad 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..d3944d64e 100644 --- a/service/multichain/multichain.go +++ b/service/multichain/multichain.go @@ -936,6 +936,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 +1464,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 +2141,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..6e0f69fb5 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..6e16e1b93 100644 --- a/service/persist/postgres/contract_gallery.go +++ b/service/persist/postgres/contract_gallery.go @@ -45,16 +45,17 @@ 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) + 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,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, '')), + 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, chain = $7 + l1_chain = $8 returning id; `) checkNoErr(err) @@ -154,8 +155,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 +184,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)