2023-10-24 10:43:18 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
2024-01-25 13:29:29 +00:00
|
|
|
"errors"
|
2023-10-24 10:43:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ProfileShowcaseVisibility int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ProfileShowcaseVisibilityNoOne ProfileShowcaseVisibility = iota
|
|
|
|
ProfileShowcaseVisibilityIDVerifiedContacts
|
|
|
|
ProfileShowcaseVisibilityContacts
|
|
|
|
ProfileShowcaseVisibilityEveryone
|
|
|
|
)
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
const upsertProfileShowcaseCommunityPreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_communities_preferences(community_id, visibility, sort_order) VALUES (?, ?, ?)" // #nosec G101
|
|
|
|
const selectProfileShowcaseCommunityPreferenceQuery = "SELECT community_id, visibility, sort_order FROM profile_showcase_communities_preferences" // #nosec G101
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
const upsertProfileShowcaseAccountPreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_accounts_preferences(address, name, color_id, emoji, visibility, sort_order) VALUES (?, ?, ?, ?, ?, ?)" // #nosec G101
|
|
|
|
const selectProfileShowcaseAccountPreferenceQuery = "SELECT address, name, color_id, emoji, visibility, sort_order FROM profile_showcase_accounts_preferences" // #nosec G101
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
const upsertProfileShowcaseCollectiblePreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_collectibles_preferences(contract_address, chain_id, token_id, community_id, account_address, visibility, sort_order) VALUES (?, ?, ?, ?, ?, ?, ?)" // #nosec G101
|
|
|
|
const selectProfileShowcaseCollectiblePreferenceQuery = "SELECT contract_address, chain_id, token_id, community_id, account_address, visibility, sort_order FROM profile_showcase_collectibles_preferences" // #nosec G101
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
const upsertProfileShowcaseVerifiedTokenPreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_verified_tokens_preferences(symbol, visibility, sort_order) VALUES (?, ?, ?)" // #nosec G101
|
|
|
|
const selectProfileShowcaseVerifiedTokenPreferenceQuery = "SELECT symbol, visibility, sort_order FROM profile_showcase_verified_tokens_preferences" // #nosec G101
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
const upsertProfileShowcaseUnverifiedTokenPreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_unverified_tokens_preferences(contract_address, chain_id, community_id, visibility, sort_order) VALUES (?, ?, ?, ?, ?)" // #nosec G101
|
|
|
|
const selectProfileShowcaseUnverifiedTokenPreferenceQuery = "SELECT contract_address, chain_id, community_id, visibility, sort_order FROM profile_showcase_unverified_tokens_preferences" // #nosec G101
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
const upsertContactProfileShowcaseCommunityQuery = "INSERT OR REPLACE INTO profile_showcase_communities_contacts(contact_id, community_id, sort_order) VALUES (?, ?, ?)" // #nosec G101
|
|
|
|
const selectContactProfileShowcaseCommunityQuery = "SELECT community_id, sort_order FROM profile_showcase_communities_contacts WHERE contact_id = ?" // #nosec G101
|
|
|
|
const removeContactProfileShowcaseCommunityQuery = "DELETE FROM profile_showcase_communities_contacts WHERE contact_id = ?" // #nosec G101
|
|
|
|
|
|
|
|
const upsertContactProfileShowcaseAccountQuery = "INSERT OR REPLACE INTO profile_showcase_accounts_contacts(contact_id, address, name, color_id, emoji, sort_order) VALUES (?, ?, ?, ?, ?, ?)" // #nosec G101
|
2024-01-25 13:29:29 +00:00
|
|
|
const selectContactProfileShowcaseAccountQuery = "SELECT * FROM profile_showcase_accounts_contacts WHERE contact_id = ?" // #nosec G101
|
|
|
|
const removeContactProfileShowcaseAccountQuery = "DELETE FROM profile_showcase_accounts_contacts WHERE contact_id = ?" // #nosec G101
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
const upsertContactProfileShowcaseCollectibleQuery = "INSERT OR REPLACE INTO profile_showcase_collectibles_contacts(contact_id, contract_address, chain_id, token_id, community_id, account_address, sort_order) VALUES (?, ?, ?, ?, ?, ?, ?)" // #nosec G101
|
|
|
|
const selectContactProfileShowcaseCollectibleQuery = "SELECT contract_address, chain_id, token_id, community_id, account_address, sort_order FROM profile_showcase_collectibles_contacts WHERE contact_id = ?" // #nosec G101
|
|
|
|
const removeContactProfileShowcaseCollectibleQuery = "DELETE FROM profile_showcase_collectibles_contacts WHERE contact_id = ?" // #nosec G101
|
|
|
|
|
|
|
|
const upsertContactProfileShowcaseVerifiedTokenQuery = "INSERT OR REPLACE INTO profile_showcase_verified_tokens_contacts(contact_id, symbol, sort_order) VALUES (?, ?, ?)" // #nosec G101
|
|
|
|
const selectContactProfileShowcaseVerifiedTokenQuery = "SELECT symbol, sort_order FROM profile_showcase_verified_tokens_contacts WHERE contact_id = ?" // #nosec G101
|
|
|
|
const removeContactProfileShowcaseVerifiedTokenQuery = "DELETE FROM profile_showcase_verified_tokens_contacts WHERE contact_id = ?" // #nosec G101
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
const upsertContactProfileShowcaseUnverifiedTokenQuery = "INSERT OR REPLACE INTO profile_showcase_unverified_tokens_contacts(contact_id, contract_address, chain_id, community_id, sort_order) VALUES (?, ?, ?, ?, ?)" // #nosec G101
|
|
|
|
const selectContactProfileShowcaseUnverifiedTokenQuery = "SELECT contract_address, chain_id, community_id, sort_order FROM profile_showcase_unverified_tokens_contacts WHERE contact_id = ?" // #nosec G101
|
|
|
|
const removeContactProfileShowcaseUnverifiedTokenQuery = "DELETE FROM profile_showcase_unverified_tokens_contacts WHERE contact_id = ?" // #nosec G101
|
2023-10-24 10:43:18 +00:00
|
|
|
|
2024-01-25 13:29:29 +00:00
|
|
|
const selectProfileShowcaseAccountsWhichMatchTheAddress = `
|
|
|
|
SELECT psa.*
|
|
|
|
FROM
|
|
|
|
contacts c
|
|
|
|
LEFT JOIN
|
|
|
|
profile_showcase_accounts_contacts psa
|
|
|
|
ON
|
|
|
|
c.id = psa.contact_id
|
|
|
|
WHERE
|
|
|
|
psa.address = ?
|
|
|
|
`
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
type ProfileShowcaseCommunityPreference struct {
|
|
|
|
CommunityID string `json:"communityId"`
|
2023-10-24 10:43:18 +00:00
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
type ProfileShowcaseAccountPreference struct {
|
|
|
|
Address string `json:"address"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
ColorID string `json:"colorId"`
|
|
|
|
Emoji string `json:"emoji"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseCollectiblePreference struct {
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress string `json:"contractAddress"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
TokenID string `json:"tokenId"`
|
|
|
|
CommunityID string `json:"communityId"`
|
|
|
|
AccountAddress string `json:"accountAddress"`
|
2023-11-09 18:59:01 +00:00
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
type ProfileShowcaseVerifiedTokenPreference struct {
|
2023-11-09 18:59:01 +00:00
|
|
|
Symbol string `json:"symbol"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
type ProfileShowcaseUnverifiedTokenPreference struct {
|
|
|
|
ContractAddress string `json:"contractAddress"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
CommunityID string `json:"communityId"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
type ProfileShowcasePreferences struct {
|
2024-01-25 16:48:27 +00:00
|
|
|
Communities []*ProfileShowcaseCommunityPreference `json:"communities"`
|
|
|
|
Accounts []*ProfileShowcaseAccountPreference `json:"accounts"`
|
|
|
|
Collectibles []*ProfileShowcaseCollectiblePreference `json:"collectibles"`
|
|
|
|
VerifiedTokens []*ProfileShowcaseVerifiedTokenPreference `json:"verifiedTokens"`
|
|
|
|
UnverifiedTokens []*ProfileShowcaseUnverifiedTokenPreference `json:"unverifiedTokens"`
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseCommunity struct {
|
|
|
|
CommunityID string `json:"communityId"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseAccount struct {
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID string `json:"contactId"`
|
|
|
|
Address string `json:"address"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
ColorID string `json:"colorId"`
|
|
|
|
Emoji string `json:"emoji"`
|
|
|
|
Order int `json:"order"`
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseCollectible struct {
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress string `json:"contractAddress"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
TokenID string `json:"tokenId"`
|
|
|
|
CommunityID string `json:"communityId"`
|
|
|
|
AccountAddress string `json:"accountAddress"`
|
|
|
|
Order int `json:"order"`
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
type ProfileShowcaseVerifiedToken struct {
|
2023-11-09 18:59:01 +00:00
|
|
|
Symbol string `json:"symbol"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
type ProfileShowcaseUnverifiedToken struct {
|
|
|
|
ContractAddress string `json:"contractAddress"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
CommunityID string `json:"communityId"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
type ProfileShowcase struct {
|
2024-01-25 16:48:27 +00:00
|
|
|
ContactID string `json:"contactId"`
|
|
|
|
Communities []*ProfileShowcaseCommunity `json:"communities"`
|
|
|
|
Accounts []*ProfileShowcaseAccount `json:"accounts"`
|
|
|
|
Collectibles []*ProfileShowcaseCollectible `json:"collectibles"`
|
|
|
|
VerifiedTokens []*ProfileShowcaseVerifiedToken `json:"verifiedTokens"`
|
|
|
|
UnverifiedTokens []*ProfileShowcaseUnverifiedToken `json:"unverifiedTokens"`
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Queries for showcase preferences
|
|
|
|
func (db sqlitePersistence) saveProfileShowcaseCommunityPreference(tx *sql.Tx, community *ProfileShowcaseCommunityPreference) error {
|
|
|
|
_, err := tx.Exec(upsertProfileShowcaseCommunityPreferenceQuery,
|
|
|
|
community.CommunityID,
|
|
|
|
community.ShowcaseVisibility,
|
|
|
|
community.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) getProfileShowcaseCommunitiesPreferences(tx *sql.Tx) ([]*ProfileShowcaseCommunityPreference, error) {
|
|
|
|
rows, err := tx.Query(selectProfileShowcaseCommunityPreferenceQuery)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
communities := []*ProfileShowcaseCommunityPreference{}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
community := &ProfileShowcaseCommunityPreference{}
|
|
|
|
|
|
|
|
err := rows.Scan(
|
|
|
|
&community.CommunityID,
|
|
|
|
&community.ShowcaseVisibility,
|
|
|
|
&community.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
communities = append(communities, community)
|
|
|
|
}
|
|
|
|
return communities, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) saveProfileShowcaseAccountPreference(tx *sql.Tx, account *ProfileShowcaseAccountPreference) error {
|
|
|
|
_, err := tx.Exec(upsertProfileShowcaseAccountPreferenceQuery,
|
|
|
|
account.Address,
|
|
|
|
account.Name,
|
|
|
|
account.ColorID,
|
|
|
|
account.Emoji,
|
|
|
|
account.ShowcaseVisibility,
|
|
|
|
account.Order,
|
2023-10-24 10:43:18 +00:00
|
|
|
)
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) getProfileShowcaseAccountsPreferences(tx *sql.Tx) ([]*ProfileShowcaseAccountPreference, error) {
|
|
|
|
rows, err := tx.Query(selectProfileShowcaseAccountPreferenceQuery)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
accounts := []*ProfileShowcaseAccountPreference{}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
account := &ProfileShowcaseAccountPreference{}
|
|
|
|
|
|
|
|
err := rows.Scan(
|
|
|
|
&account.Address,
|
|
|
|
&account.Name,
|
|
|
|
&account.ColorID,
|
|
|
|
&account.Emoji,
|
|
|
|
&account.ShowcaseVisibility,
|
|
|
|
&account.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
accounts = append(accounts, account)
|
|
|
|
}
|
|
|
|
return accounts, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) saveProfileShowcaseCollectiblePreference(tx *sql.Tx, collectible *ProfileShowcaseCollectiblePreference) error {
|
|
|
|
_, err := tx.Exec(upsertProfileShowcaseCollectiblePreferenceQuery,
|
2024-01-25 16:48:27 +00:00
|
|
|
collectible.ContractAddress,
|
|
|
|
collectible.ChainID,
|
|
|
|
collectible.TokenID,
|
|
|
|
collectible.CommunityID,
|
|
|
|
collectible.AccountAddress,
|
2023-11-09 18:59:01 +00:00
|
|
|
collectible.ShowcaseVisibility,
|
|
|
|
collectible.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) getProfileShowcaseCollectiblesPreferences(tx *sql.Tx) ([]*ProfileShowcaseCollectiblePreference, error) {
|
|
|
|
rows, err := tx.Query(selectProfileShowcaseCollectiblePreferenceQuery)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
collectibles := []*ProfileShowcaseCollectiblePreference{}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
collectible := &ProfileShowcaseCollectiblePreference{}
|
|
|
|
|
|
|
|
err := rows.Scan(
|
2024-01-25 16:48:27 +00:00
|
|
|
&collectible.ContractAddress,
|
|
|
|
&collectible.ChainID,
|
|
|
|
&collectible.TokenID,
|
|
|
|
&collectible.CommunityID,
|
|
|
|
&collectible.AccountAddress,
|
2023-11-09 18:59:01 +00:00
|
|
|
&collectible.ShowcaseVisibility,
|
|
|
|
&collectible.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
collectibles = append(collectibles, collectible)
|
|
|
|
}
|
|
|
|
return collectibles, nil
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
func (db sqlitePersistence) saveProfileShowcaseVerifiedTokenPreference(tx *sql.Tx, token *ProfileShowcaseVerifiedTokenPreference) error {
|
|
|
|
_, err := tx.Exec(upsertProfileShowcaseVerifiedTokenPreferenceQuery,
|
|
|
|
token.Symbol,
|
|
|
|
token.ShowcaseVisibility,
|
|
|
|
token.Order,
|
2023-11-09 18:59:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
func (db sqlitePersistence) saveProfileShowcaseUnverifiedTokenPreference(tx *sql.Tx, token *ProfileShowcaseUnverifiedTokenPreference) error {
|
|
|
|
_, err := tx.Exec(upsertProfileShowcaseUnverifiedTokenPreferenceQuery,
|
|
|
|
token.ContractAddress,
|
|
|
|
token.ChainID,
|
|
|
|
token.CommunityID,
|
|
|
|
token.ShowcaseVisibility,
|
|
|
|
token.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) getProfileShowcaseVerifiedTokensPreferences(tx *sql.Tx) ([]*ProfileShowcaseVerifiedTokenPreference, error) {
|
|
|
|
rows, err := tx.Query(selectProfileShowcaseVerifiedTokenPreferenceQuery)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
tokens := []*ProfileShowcaseVerifiedTokenPreference{}
|
2023-11-09 18:59:01 +00:00
|
|
|
|
|
|
|
for rows.Next() {
|
2024-01-25 16:48:27 +00:00
|
|
|
token := &ProfileShowcaseVerifiedTokenPreference{}
|
2023-11-09 18:59:01 +00:00
|
|
|
|
|
|
|
err := rows.Scan(
|
2024-01-25 16:48:27 +00:00
|
|
|
&token.Symbol,
|
|
|
|
&token.ShowcaseVisibility,
|
|
|
|
&token.Order,
|
2023-11-09 18:59:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
tokens = append(tokens, token)
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
2024-01-25 16:48:27 +00:00
|
|
|
return tokens, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) getProfileShowcaseUnverifiedTokensPreferences(tx *sql.Tx) ([]*ProfileShowcaseUnverifiedTokenPreference, error) {
|
|
|
|
rows, err := tx.Query(selectProfileShowcaseUnverifiedTokenPreferenceQuery)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens := []*ProfileShowcaseUnverifiedTokenPreference{}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
token := &ProfileShowcaseUnverifiedTokenPreference{}
|
|
|
|
|
|
|
|
err := rows.Scan(
|
|
|
|
&token.ContractAddress,
|
|
|
|
&token.ChainID,
|
|
|
|
&token.CommunityID,
|
|
|
|
&token.ShowcaseVisibility,
|
|
|
|
&token.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens = append(tokens, token)
|
|
|
|
}
|
|
|
|
return tokens, nil
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Queries for contacts showcase
|
|
|
|
func (db sqlitePersistence) saveProfileShowcaseCommunityContact(tx *sql.Tx, contactID string, community *ProfileShowcaseCommunity) error {
|
|
|
|
_, err := tx.Exec(upsertContactProfileShowcaseCommunityQuery,
|
|
|
|
contactID,
|
|
|
|
community.CommunityID,
|
|
|
|
community.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) getProfileShowcaseCommunitiesContact(tx *sql.Tx, contactID string) ([]*ProfileShowcaseCommunity, error) {
|
|
|
|
rows, err := tx.Query(selectContactProfileShowcaseCommunityQuery, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
communities := []*ProfileShowcaseCommunity{}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
community := &ProfileShowcaseCommunity{}
|
|
|
|
|
|
|
|
err := rows.Scan(&community.CommunityID, &community.Order)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
communities = append(communities, community)
|
|
|
|
}
|
|
|
|
return communities, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) clearProfileShowcaseCommunityContact(tx *sql.Tx, contactID string) error {
|
|
|
|
_, err := tx.Exec(removeContactProfileShowcaseCommunityQuery, contactID)
|
2023-10-24 10:43:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
func (db sqlitePersistence) saveProfileShowcaseAccountContact(tx *sql.Tx, contactID string, account *ProfileShowcaseAccount) error {
|
|
|
|
_, err := tx.Exec(upsertContactProfileShowcaseAccountQuery,
|
|
|
|
contactID,
|
|
|
|
account.Address,
|
|
|
|
account.Name,
|
|
|
|
account.ColorID,
|
|
|
|
account.Emoji,
|
|
|
|
account.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-25 13:29:29 +00:00
|
|
|
func (db sqlitePersistence) processProfileShowcaseAccounts(rows *sql.Rows) (result []*ProfileShowcaseAccount, err error) {
|
|
|
|
if rows == nil {
|
|
|
|
return nil, errors.New("rows is nil")
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
account := &ProfileShowcaseAccount{}
|
|
|
|
|
2024-01-25 13:29:29 +00:00
|
|
|
err = rows.Scan(&account.Address, &account.Name, &account.ColorID, &account.Emoji, &account.Order, &account.ContactID)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
2024-01-25 13:29:29 +00:00
|
|
|
return
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 13:29:29 +00:00
|
|
|
result = append(result, account)
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
2024-01-25 13:29:29 +00:00
|
|
|
|
|
|
|
err = rows.Err()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) getProfileShowcaseAccountsContact(tx *sql.Tx, contactID string) ([]*ProfileShowcaseAccount, error) {
|
|
|
|
rows, err := tx.Query(selectContactProfileShowcaseAccountQuery, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return db.processProfileShowcaseAccounts(rows)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) GetProfileShowcaseAccountsByAddress(address string) ([]*ProfileShowcaseAccount, error) {
|
|
|
|
rows, err := db.db.Query(selectProfileShowcaseAccountsWhichMatchTheAddress, address)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return db.processProfileShowcaseAccounts(rows)
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) clearProfileShowcaseAccountsContact(tx *sql.Tx, contactID string) error {
|
|
|
|
_, err := tx.Exec(removeContactProfileShowcaseAccountQuery, contactID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
func (db sqlitePersistence) saveProfileShowcaseCollectibleContact(tx *sql.Tx, contactID string, collectible *ProfileShowcaseCollectible) error {
|
2023-11-09 18:59:01 +00:00
|
|
|
_, err := tx.Exec(upsertContactProfileShowcaseCollectibleQuery,
|
|
|
|
contactID,
|
2024-01-25 16:48:27 +00:00
|
|
|
collectible.ContractAddress,
|
|
|
|
collectible.ChainID,
|
|
|
|
collectible.TokenID,
|
|
|
|
collectible.CommunityID,
|
|
|
|
collectible.AccountAddress,
|
|
|
|
collectible.Order,
|
2023-11-09 18:59:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) getProfileShowcaseCollectiblesContact(tx *sql.Tx, contactID string) ([]*ProfileShowcaseCollectible, error) {
|
|
|
|
rows, err := tx.Query(selectContactProfileShowcaseCollectibleQuery, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
collectibles := []*ProfileShowcaseCollectible{}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
collectible := &ProfileShowcaseCollectible{}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
err := rows.Scan(
|
|
|
|
&collectible.ContractAddress,
|
|
|
|
&collectible.ChainID,
|
|
|
|
&collectible.TokenID,
|
|
|
|
&collectible.CommunityID,
|
|
|
|
&collectible.AccountAddress,
|
|
|
|
&collectible.Order)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
collectibles = append(collectibles, collectible)
|
|
|
|
}
|
|
|
|
return collectibles, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) clearProfileShowcaseCollectiblesContact(tx *sql.Tx, contactID string) error {
|
|
|
|
_, err := tx.Exec(removeContactProfileShowcaseCollectibleQuery, contactID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
func (db sqlitePersistence) saveProfileShowcaseVerifiedTokenContact(tx *sql.Tx, contactID string, token *ProfileShowcaseVerifiedToken) error {
|
|
|
|
_, err := tx.Exec(upsertContactProfileShowcaseVerifiedTokenQuery,
|
|
|
|
contactID,
|
|
|
|
token.Symbol,
|
|
|
|
token.Order,
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) saveProfileShowcaseUnverifiedTokenContact(tx *sql.Tx, contactID string, token *ProfileShowcaseUnverifiedToken) error {
|
|
|
|
_, err := tx.Exec(upsertContactProfileShowcaseUnverifiedTokenQuery,
|
2023-11-09 18:59:01 +00:00
|
|
|
contactID,
|
2024-01-25 16:48:27 +00:00
|
|
|
token.ContractAddress,
|
|
|
|
token.ChainID,
|
|
|
|
token.CommunityID,
|
|
|
|
token.Order,
|
2023-11-09 18:59:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
func (db sqlitePersistence) getProfileShowcaseVerifiedTokensContact(tx *sql.Tx, contactID string) ([]*ProfileShowcaseVerifiedToken, error) {
|
|
|
|
rows, err := tx.Query(selectContactProfileShowcaseVerifiedTokenQuery, contactID)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
tokens := []*ProfileShowcaseVerifiedToken{}
|
2023-11-09 18:59:01 +00:00
|
|
|
|
|
|
|
for rows.Next() {
|
2024-01-25 16:48:27 +00:00
|
|
|
token := &ProfileShowcaseVerifiedToken{}
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
err := rows.Scan(
|
|
|
|
&token.Symbol,
|
|
|
|
&token.Order)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
tokens = append(tokens, token)
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
2024-01-25 16:48:27 +00:00
|
|
|
return tokens, nil
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
func (db sqlitePersistence) getProfileShowcaseUnverifiedTokensContact(tx *sql.Tx, contactID string) ([]*ProfileShowcaseUnverifiedToken, error) {
|
|
|
|
rows, err := tx.Query(selectContactProfileShowcaseUnverifiedTokenQuery, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens := []*ProfileShowcaseUnverifiedToken{}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
token := &ProfileShowcaseUnverifiedToken{}
|
|
|
|
|
|
|
|
err := rows.Scan(
|
|
|
|
&token.ContractAddress,
|
|
|
|
&token.ChainID,
|
|
|
|
&token.CommunityID,
|
|
|
|
&token.Order)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens = append(tokens, token)
|
|
|
|
}
|
|
|
|
return tokens, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) clearProfileShowcaseVerifiedTokensContact(tx *sql.Tx, contactID string) error {
|
|
|
|
_, err := tx.Exec(removeContactProfileShowcaseVerifiedTokenQuery, contactID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) clearProfileShowcaseUnverifiedTokensContact(tx *sql.Tx, contactID string) error {
|
|
|
|
_, err := tx.Exec(removeContactProfileShowcaseUnverifiedTokenQuery, contactID)
|
2023-11-09 18:59:01 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// public functions
|
|
|
|
func (db sqlitePersistence) SaveProfileShowcasePreferences(preferences *ProfileShowcasePreferences) error {
|
2023-10-24 10:43:18 +00:00
|
|
|
tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err == nil {
|
|
|
|
err = tx.Commit()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// don't shadow original error
|
|
|
|
_ = tx.Rollback()
|
|
|
|
}()
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
for _, community := range preferences.Communities {
|
|
|
|
err = db.saveProfileShowcaseCommunityPreference(tx, community)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2023-10-24 10:43:18 +00:00
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
for _, account := range preferences.Accounts {
|
|
|
|
err = db.saveProfileShowcaseAccountPreference(tx, account)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, collectible := range preferences.Collectibles {
|
|
|
|
err = db.saveProfileShowcaseCollectiblePreference(tx, collectible)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
for _, token := range preferences.VerifiedTokens {
|
|
|
|
err = db.saveProfileShowcaseVerifiedTokenPreference(tx, token)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, token := range preferences.UnverifiedTokens {
|
|
|
|
err = db.saveProfileShowcaseUnverifiedTokenPreference(tx, token)
|
2023-10-24 10:43:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
func (db sqlitePersistence) GetProfileShowcasePreferences() (*ProfileShowcasePreferences, error) {
|
|
|
|
tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err == nil {
|
|
|
|
err = tx.Commit()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// don't shadow original error
|
|
|
|
_ = tx.Rollback()
|
|
|
|
}()
|
2023-10-24 10:43:18 +00:00
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
communities, err := db.getProfileShowcaseCommunitiesPreferences(tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-10-24 10:43:18 +00:00
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
accounts, err := db.getProfileShowcaseAccountsPreferences(tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
collectibles, err := db.getProfileShowcaseCollectiblesPreferences(tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
verifiedTokens, err := db.getProfileShowcaseVerifiedTokensPreferences(tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
unverifiedTokens, err := db.getProfileShowcaseUnverifiedTokensPreferences(tx)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ProfileShowcasePreferences{
|
2024-01-25 16:48:27 +00:00
|
|
|
Communities: communities,
|
|
|
|
Accounts: accounts,
|
|
|
|
Collectibles: collectibles,
|
|
|
|
VerifiedTokens: verifiedTokens,
|
|
|
|
UnverifiedTokens: unverifiedTokens,
|
2023-11-09 18:59:01 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) SaveProfileShowcaseForContact(showcase *ProfileShowcase) error {
|
|
|
|
tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err == nil {
|
|
|
|
err = tx.Commit()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// don't shadow original error
|
|
|
|
_ = tx.Rollback()
|
|
|
|
}()
|
2023-10-24 10:43:18 +00:00
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
for _, community := range showcase.Communities {
|
|
|
|
err = db.saveProfileShowcaseCommunityContact(tx, showcase.ContactID, community)
|
2023-10-24 10:43:18 +00:00
|
|
|
if err != nil {
|
2023-11-09 18:59:01 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, account := range showcase.Accounts {
|
|
|
|
err = db.saveProfileShowcaseAccountContact(tx, showcase.ContactID, account)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-10-24 10:43:18 +00:00
|
|
|
}
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
2023-10-24 10:43:18 +00:00
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
for _, collectible := range showcase.Collectibles {
|
|
|
|
err = db.saveProfileShowcaseCollectibleContact(tx, showcase.ContactID, collectible)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-10-24 10:43:18 +00:00
|
|
|
}
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
for _, token := range showcase.VerifiedTokens {
|
|
|
|
err = db.saveProfileShowcaseVerifiedTokenContact(tx, showcase.ContactID, token)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, token := range showcase.UnverifiedTokens {
|
|
|
|
err = db.saveProfileShowcaseUnverifiedTokenContact(tx, showcase.ContactID, token)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2023-10-24 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
func (db sqlitePersistence) GetProfileShowcaseForContact(contactID string) (*ProfileShowcase, error) {
|
|
|
|
tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
|
2023-10-24 10:43:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-11-09 18:59:01 +00:00
|
|
|
defer func() {
|
|
|
|
if err == nil {
|
|
|
|
err = tx.Commit()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// don't shadow original error
|
|
|
|
_ = tx.Rollback()
|
|
|
|
}()
|
2023-10-24 10:43:18 +00:00
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
communities, err := db.getProfileShowcaseCommunitiesContact(tx, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-10-24 10:43:18 +00:00
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
accounts, err := db.getProfileShowcaseAccountsContact(tx, contactID)
|
2023-10-24 10:43:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:59:01 +00:00
|
|
|
collectibles, err := db.getProfileShowcaseCollectiblesContact(tx, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
verifiedTokens, err := db.getProfileShowcaseVerifiedTokensContact(tx, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
unverifiedTokens, err := db.getProfileShowcaseUnverifiedTokensContact(tx, contactID)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ProfileShowcase{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContactID: contactID,
|
|
|
|
Communities: communities,
|
|
|
|
Accounts: accounts,
|
|
|
|
Collectibles: collectibles,
|
|
|
|
VerifiedTokens: verifiedTokens,
|
|
|
|
UnverifiedTokens: unverifiedTokens,
|
2023-11-09 18:59:01 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db sqlitePersistence) ClearProfileShowcaseForContact(contactID string) error {
|
|
|
|
tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err == nil {
|
|
|
|
err = tx.Commit()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// don't shadow original error
|
|
|
|
_ = tx.Rollback()
|
|
|
|
}()
|
|
|
|
|
|
|
|
err = db.clearProfileShowcaseCommunityContact(tx, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.clearProfileShowcaseAccountsContact(tx, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.clearProfileShowcaseCollectiblesContact(tx, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:48:27 +00:00
|
|
|
err = db.clearProfileShowcaseVerifiedTokensContact(tx, contactID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.clearProfileShowcaseUnverifiedTokensContact(tx, contactID)
|
2023-11-09 18:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2023-10-24 10:43:18 +00:00
|
|
|
}
|