Skip to content

Commit

Permalink
rec blocks, ens text records
Browse files Browse the repository at this point in the history
  • Loading branch information
0xthrpw committed Sep 3, 2024
1 parent 609b0ef commit 2a8c033
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BEGIN
FROM public.efp_recommended
WHERE NOT EXISTS (
SELECT 1
FROM query.get_following_by_list(p_list_id) fol
FROM query.get_all_following_by_list(p_list_id) fol
WHERE efp_recommended.address = fol.following_address
)
ORDER BY efp_recommended.index
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
--migrate:up
-------------------------------------------------------------------------------
-- Function: get_following__record_type_001
-- Description: Retrieves a list of addresses followed by a user from the
-- view_list_records_with_nft_manager_user_tags, ensuring
-- addresses are valid 20-byte, lower-case hexadecimals (0x
-- followed by 40 hex chars). Filters tokens by version and type,
-- including blocked or muted relationships. Leverages primary
-- list token ID from get_primary_list. If no primary list is
-- found, returns an empty result set.
-- Parameters:
-- - address (VARCHAR(42)): Identifier of the user to find the
-- following addresses.
-- Returns: A table with 'efp_list_nft_token_id' (BIGINT), 'record_version'
-- (types.uint8), 'record_type' (types.uint8), and 'following_address'
-- (types.eth_address), representing the list token ID, record
-- version, record type, and following address.
-------------------------------------------------------------------------------
CREATE
OR REPLACE FUNCTION query.get_all_following__record_type_001 (p_address VARCHAR(42)) RETURNS TABLE (
efp_list_nft_token_id BIGINT,
record_version types.uint8,
record_type types.uint8,
following_address types.eth_address,
tags types.efp_tag [],
updated_at TIMESTAMP WITH TIME ZONE
) LANGUAGE plpgsql AS $$
DECLARE
normalized_addr types.eth_address;
primary_list_token_id BIGINT;
list_storage_location_chain_id BIGINT;
list_storage_location_contract_address VARCHAR(42);
list_storage_location_storage_slot types.efp_list_storage_location_slot;
BEGIN
-- Normalize the input address to lowercase
normalized_addr := public.normalize_eth_address(p_address);

-- Get the primary list token id
SELECT v.primary_list_token_id
INTO primary_list_token_id
FROM public.view__events__efp_accounts_with_primary_list AS v
WHERE v.address = normalized_addr;

-- If no primary list token id is found, return an empty result set
IF primary_list_token_id IS NULL THEN
RETURN; -- Exit the function without returning any rows
END IF;

-- Now determine the list storage location for the primary list token id
SELECT
v.efp_list_storage_location_chain_id,
v.efp_list_storage_location_contract_address,
v.efp_list_storage_location_slot
INTO
list_storage_location_chain_id,
list_storage_location_contract_address,
list_storage_location_storage_slot
FROM
public.view__events__efp_list_storage_locations AS v
WHERE
v.efp_list_nft_token_id = primary_list_token_id;

-- following query
RETURN QUERY
SELECT
(primary_list_token_id)::BIGINT AS efp_list_nft_token_id,
v.record_version,
v.record_type,
PUBLIC.hexlify(v.record_data)::types.eth_address AS following_address,
COALESCE(v.tags, '{}') AS tags,
v.updated_at
FROM
public.view__join__efp_list_records_with_tags AS v
WHERE
v.chain_id = list_storage_location_chain_id AND
v.contract_address = list_storage_location_contract_address AND
v.slot = list_storage_location_storage_slot AND
-- only version 1
v.record_version = 1 AND
-- address record type (1)
v.record_type = 1 AND
-- where the address record data field is a valid address
public.is_valid_address(v.record_data)
ORDER BY
v.updated_at DESC,
v.record_version ASC,
v.record_type ASC,
v.record_data ASC;
END;
$$;



--migrate:down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ OR REPLACE FUNCTION query.get_ens_metadata_by_address (p_address types.eth_addre
name TEXT,
address types.eth_address,
avatar TEXT,
records TEXT,
updated_at timestamp WITH TIME ZONE
) LANGUAGE plpgsql AS $$
DECLARE
Expand All @@ -24,7 +25,8 @@ BEGIN
metadata.name as name,
metadata.address as address,
metadata.avatar as avatar,
metadata.updated_at
metadata.records::text as records,
metadata.updated_at
FROM
public.ens_metadata as metadata
WHERE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ OR REPLACE FUNCTION query.get_ens_metadata_by_name (p_name TEXT) RETURNS TABLE (
name TEXT,
address types.eth_address,
avatar TEXT,
records TEXT,
updated_at timestamp WITH TIME ZONE
) LANGUAGE plpgsql AS $$
BEGIN
Expand All @@ -21,6 +22,7 @@ BEGIN
metadata.name as name,
metadata.address as address,
metadata.avatar as avatar,
metadata.records::text as records,
metadata.updated_at
FROM
public.ens_metadata as metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BEGIN
FROM public.efp_recommended
WHERE NOT EXISTS (
SELECT 1
FROM query.get_following__record_type_001(normalized_addr) fol
FROM query.get_all_following__record_type_001(normalized_addr) fol
WHERE efp_recommended.address = fol.following_address
)
ORDER BY efp_recommended.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ DECLARE
normalized_addr types.eth_address;
BEGIN
normalized_addr := public.normalize_eth_address(p_address);

normalized_addr := public.normalize_eth_address(p_address);

IF public.is_valid_address(p_term) THEN
RETURN QUERY
SELECT
Expand Down
2 changes: 1 addition & 1 deletion db/schema/020__tables/001/create_table__ens_metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE
"address" types.eth_address NOT NULL,
"avatar" TEXT,
"display" TEXT,
"records" TEXT[],
"records" JSON,
"chains" TEXT[],
"fresh" BIGINT,
"resolver" types.eth_address,
Expand Down
138 changes: 138 additions & 0 deletions src/abi/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ export const efpListMinterAbi = [
name: 'mintNoMeta',
outputs: []
},
{
stateMutability: 'payable',
type: 'function',
inputs: [{ name: 'listStorageLocation', internalType: 'bytes', type: 'bytes' }],
name: 'mintPrimaryListNoMeta',
outputs: []
},
{
stateMutability: 'payable',
type: 'function',
Expand Down Expand Up @@ -1137,6 +1144,98 @@ export const efpListRegistryAbi = [
name: 'withdraw',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }]
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true
},
{
name: 'approved',
internalType: 'address',
type: 'address',
indexed: true
},
{
name: 'tokenId',
internalType: 'uint256',
type: 'uint256',
indexed: true
}
],
name: 'Approval'
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true
},
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true
},
{ name: 'approved', internalType: 'bool', type: 'bool', indexed: false }
],
name: 'ApprovalForAll'
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'fromTokenId',
internalType: 'uint256',
type: 'uint256',
indexed: true
},
{
name: 'toTokenId',
internalType: 'uint256',
type: 'uint256',
indexed: false
},
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
{ name: 'to', internalType: 'address', type: 'address', indexed: true }
],
name: 'ConsecutiveTransfer'
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'maxMintBatchSize',
internalType: 'uint256',
type: 'uint256',
indexed: false
}
],
name: 'MaxMintBatchSizeChange'
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'mintState',
internalType: 'enum IEFPListRegistry.MintState',
type: 'uint8',
indexed: false
}
],
name: 'MintStateChange'
},
{
type: 'event',
anonymous: false,
Expand All @@ -1156,6 +1255,45 @@ export const efpListRegistryAbi = [
],
name: 'OwnershipTransferred'
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'account',
internalType: 'address',
type: 'address',
indexed: false
}
],
name: 'Paused'
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'priceOracle',
internalType: 'address',
type: 'address',
indexed: false
}
],
name: 'PriceOracleChange'
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'tokenURIProvider',
internalType: 'address',
type: 'address',
indexed: false
}
],
name: 'TokenURIProviderChange'
},
{
type: 'event',
anonymous: false,
Expand Down

0 comments on commit 2a8c033

Please sign in to comment.