forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DI-75][Indexer] Create Token V2 data models and convert token v1 (ap…
…tos-labs#7359) * Add token v2 initial indexing * lint * remove index for performance * remove token activities v2 * Remove fungible asset indexing * [indexer] token v2 property map (cherry picked from commit 96e0116) * Apply property map parsing * handle burn nft --------- Co-authored-by: Aaron Gao <[email protected]>
- Loading branch information
1 parent
9af7ef7
commit 68efb02
Showing
21 changed files
with
2,850 additions
and
39 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
crates/indexer/migrations/2023-04-28-053048_object_token_v2/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- This file should undo anything in `up.sql` | ||
DROP TABLE IF EXISTS objects; | ||
DROP INDEX IF EXISTS o_owner_idx; | ||
DROP INDEX IF EXISTS o_object_skh_idx; | ||
DROP INDEX IF EXISTS o_skh_idx; | ||
DROP INDEX IF EXISTS o_insat_idx; | ||
DROP TABLE IF EXISTS current_objects; | ||
DROP INDEX IF EXISTS co_owner_idx; | ||
DROP INDEX IF EXISTS co_object_skh_idx; | ||
DROP INDEX IF EXISTS co_skh_idx; | ||
DROP INDEX IF EXISTS co_insat_idx; | ||
ALTER TABLE move_resources DROP COLUMN IF EXISTS state_key_hash; | ||
DROP TABLE IF EXISTS token_ownerships_v2; | ||
DROP INDEX IF EXISTS to2_id_index; | ||
DROP INDEX IF EXISTS to2_owner_index; | ||
DROP INDEX IF EXISTS to2_insat_index; | ||
DROP TABLE IF EXISTS current_token_ownerships_v2; | ||
DROP INDEX IF EXISTS curr_to2_owner_index; | ||
DROP INDEX IF EXISTS curr_to2_wa_index; | ||
DROP INDEX IF EXISTS curr_to2_insat_index; | ||
DROP TABLE IF EXISTS collections_v2; | ||
DROP INDEX IF EXISTS col2_id_index; | ||
DROP INDEX IF EXISTS col2_crea_cn_index; | ||
DROP INDEX IF EXISTS col2_insat_index; | ||
DROP TABLE IF EXISTS current_collections_v2; | ||
DROP INDEX IF EXISTS cur_col2_crea_cn_index; | ||
DROP INDEX IF EXISTS cur_col2_insat_index; | ||
DROP TABLE IF EXISTS token_datas_v2; | ||
DROP INDEX IF EXISTS td2_id_index; | ||
DROP INDEX IF EXISTS td2_cid_name_index; | ||
DROP INDEX IF EXISTS td2_insat_index; | ||
DROP TABLE IF EXISTS current_token_datas_v2; | ||
DROP INDEX IF EXISTS cur_td2_cid_name_index; | ||
DROP INDEX IF EXISTS cur_td2_insat_index; | ||
ALTER TABLE current_token_pending_claims DROP COLUMN IF EXISTS token_data_id; | ||
ALTER TABLE current_token_pending_claims DROP COLUMN IF EXISTS collection_id; |
170 changes: 170 additions & 0 deletions
170
crates/indexer/migrations/2023-04-28-053048_object_token_v2/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
-- Your SQL goes here | ||
-- objects, basically normalizing ObjectCore | ||
CREATE TABLE IF NOT EXISTS objects ( | ||
transaction_version BIGINT NOT NULL, | ||
write_set_change_index BIGINT NOT NULL, | ||
object_address VARCHAR(66) NOT NULL, | ||
owner_address VARCHAR(66), | ||
state_key_hash VARCHAR(66) NOT NULL, | ||
guid_creation_num NUMERIC, | ||
allow_ungated_transfer BOOLEAN, | ||
is_deleted BOOLEAN NOT NULL, | ||
inserted_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
-- constraints | ||
PRIMARY KEY (transaction_version, write_set_change_index) | ||
); | ||
CREATE INDEX IF NOT EXISTS o_owner_idx ON objects (owner_address); | ||
CREATE INDEX IF NOT EXISTS o_object_skh_idx ON objects (object_address, state_key_hash); | ||
CREATE INDEX IF NOT EXISTS o_skh_idx ON objects (state_key_hash); | ||
CREATE INDEX IF NOT EXISTS o_insat_idx ON objects (inserted_at); | ||
-- latest instance of objects | ||
CREATE TABLE IF NOT EXISTS current_objects ( | ||
object_address VARCHAR(66) UNIQUE PRIMARY KEY NOT NULL, | ||
owner_address VARCHAR(66) NOT NULL, | ||
state_key_hash VARCHAR(66) NOT NULL, | ||
allow_ungated_transfer BOOLEAN NOT NULL, | ||
last_guid_creation_num NUMERIC NOT NULL, | ||
last_transaction_version BIGINT NOT NULL, | ||
is_deleted BOOLEAN NOT NULL, | ||
inserted_at TIMESTAMP NOT NULL DEFAULT NOW() | ||
); | ||
CREATE INDEX IF NOT EXISTS co_owner_idx ON current_objects (owner_address); | ||
CREATE INDEX IF NOT EXISTS co_object_skh_idx ON current_objects (object_address, state_key_hash); | ||
CREATE INDEX IF NOT EXISTS co_skh_idx ON current_objects (state_key_hash); | ||
CREATE INDEX IF NOT EXISTS co_insat_idx ON current_objects (inserted_at); | ||
-- Add this so that we can find resource groups by their state_key_hash | ||
ALTER TABLE move_resources | ||
ADD COLUMN IF NOT EXISTS state_key_hash VARCHAR(66) NOT NULL DEFAULT ''; | ||
-- NFT stuff | ||
-- tracks who owns tokens | ||
CREATE TABLE IF NOT EXISTS token_ownerships_v2 ( | ||
transaction_version BIGINT NOT NULL, | ||
write_set_change_index BIGINT NOT NULL, | ||
token_data_id VARCHAR(66) NOT NULL, | ||
property_version_v1 NUMERIC NOT NULL, | ||
owner_address VARCHAR(66), | ||
storage_id VARCHAR(66) NOT NULL, | ||
amount NUMERIC NOT NULL, | ||
table_type_v1 VARCHAR(66), | ||
token_properties_mutated_v1 JSONB, | ||
is_soulbound_v2 BOOLEAN, | ||
token_standard VARCHAR(10) NOT NULL, | ||
is_fungible_v2 BOOLEAN, | ||
transaction_timestamp TIMESTAMP NOT NULL, | ||
inserted_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
PRIMARY KEY (transaction_version, write_set_change_index) | ||
); | ||
CREATE INDEX IF NOT EXISTS to2_id_index ON token_ownerships_v2 (token_data_id); | ||
CREATE INDEX IF NOT EXISTS to2_owner_index ON token_ownerships_v2 (owner_address); | ||
CREATE INDEX IF NOT EXISTS to2_insat_index ON token_ownerships_v2 (inserted_at); | ||
CREATE TABLE IF NOT EXISTS current_token_ownerships_v2 ( | ||
token_data_id VARCHAR(66) NOT NULL, | ||
property_version_v1 NUMERIC NOT NULL, | ||
owner_address VARCHAR(66) NOT NULL, | ||
storage_id VARCHAR(66) NOT NULL, | ||
amount NUMERIC NOT NULL, | ||
table_type_v1 VARCHAR(66), | ||
token_properties_mutated_v1 JSONB, | ||
is_soulbound_v2 BOOLEAN, | ||
token_standard VARCHAR(10) NOT NULL, | ||
is_fungible_v2 BOOLEAN, | ||
last_transaction_version BIGINT NOT NULL, | ||
last_transaction_timestamp TIMESTAMP NOT NULL, | ||
inserted_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
PRIMARY KEY ( | ||
token_data_id, | ||
property_version_v1, | ||
owner_address, | ||
storage_id | ||
) | ||
); | ||
CREATE INDEX IF NOT EXISTS curr_to2_owner_index ON current_token_ownerships_v2 (owner_address); | ||
CREATE INDEX IF NOT EXISTS curr_to2_wa_index ON current_token_ownerships_v2 (storage_id); | ||
CREATE INDEX IF NOT EXISTS curr_to2_insat_index ON current_token_ownerships_v2 (inserted_at); | ||
-- tracks collections | ||
CREATE TABLE IF NOT EXISTS collections_v2 ( | ||
transaction_version BIGINT NOT NULL, | ||
write_set_change_index BIGINT NOT NULL, | ||
collection_id VARCHAR(66) NOT NULL, | ||
creator_address VARCHAR(66) NOT NULL, | ||
collection_name VARCHAR(128) NOT NULL, | ||
description TEXT NOT NULL, | ||
uri VARCHAR(512) NOT NULL, | ||
current_supply NUMERIC NOT NULL, | ||
max_supply NUMERIC, | ||
total_minted_v2 NUMERIC, | ||
mutable_description BOOLEAN, | ||
mutable_uri BOOLEAN, | ||
table_handle_v1 VARCHAR(66), | ||
token_standard VARCHAR(10) NOT NULL, | ||
transaction_timestamp TIMESTAMP NOT NULL, | ||
inserted_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
PRIMARY KEY (transaction_version, write_set_change_index) | ||
); | ||
CREATE INDEX IF NOT EXISTS col2_id_index ON collections_v2 (collection_id); | ||
CREATE INDEX IF NOT EXISTS col2_crea_cn_index ON collections_v2 (creator_address, collection_name); | ||
CREATE INDEX IF NOT EXISTS col2_insat_index ON collections_v2 (inserted_at); | ||
CREATE TABLE IF NOT EXISTS current_collections_v2 ( | ||
collection_id VARCHAR(66) UNIQUE PRIMARY KEY NOT NULL, | ||
creator_address VARCHAR(66) NOT NULL, | ||
collection_name VARCHAR(128) NOT NULL, | ||
description TEXT NOT NULL, | ||
uri VARCHAR(512) NOT NULL, | ||
current_supply NUMERIC NOT NULL, | ||
max_supply NUMERIC, | ||
total_minted_v2 NUMERIC, | ||
mutable_description BOOLEAN, | ||
mutable_uri BOOLEAN, | ||
table_handle_v1 VARCHAR(66), | ||
token_standard VARCHAR(10) NOT NULL, | ||
last_transaction_version BIGINT NOT NULL, | ||
last_transaction_timestamp TIMESTAMP NOT NULL, | ||
inserted_at TIMESTAMP NOT NULL DEFAULT NOW() | ||
); | ||
CREATE INDEX IF NOT EXISTS cur_col2_crea_cn_index ON current_collections_v2 (creator_address, collection_name); | ||
CREATE INDEX IF NOT EXISTS cur_col2_insat_index ON current_collections_v2 (inserted_at); | ||
-- tracks token metadata | ||
CREATE TABLE IF NOT EXISTS token_datas_v2 ( | ||
transaction_version BIGINT NOT NULL, | ||
write_set_change_index BIGINT NOT NULL, | ||
token_data_id VARCHAR(66) NOT NULL, | ||
collection_id VARCHAR(66) NOT NULL, | ||
token_name VARCHAR(128) NOT NULL, | ||
maximum NUMERIC, | ||
supply NUMERIC NOT NULL, | ||
largest_property_version_v1 NUMERIC, | ||
token_uri VARCHAR(512) NOT NULL, | ||
token_properties JSONB NOT NULL, | ||
description TEXT NOT NULL, | ||
token_standard VARCHAR(10) NOT NULL, | ||
is_fungible_v2 BOOLEAN, | ||
transaction_timestamp TIMESTAMP NOT NULL, | ||
inserted_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
PRIMARY KEY (transaction_version, write_set_change_index) | ||
); | ||
CREATE INDEX IF NOT EXISTS td2_id_index ON token_datas_v2 (token_data_id); | ||
CREATE INDEX IF NOT EXISTS td2_cid_name_index ON token_datas_v2 (collection_id, token_name); | ||
CREATE INDEX IF NOT EXISTS td2_insat_index ON token_datas_v2 (inserted_at); | ||
CREATE TABLE IF NOT EXISTS current_token_datas_v2 ( | ||
token_data_id VARCHAR(66) UNIQUE PRIMARY KEY NOT NULL, | ||
collection_id VARCHAR(66) NOT NULL, | ||
token_name VARCHAR(128) NOT NULL, | ||
maximum NUMERIC, | ||
supply NUMERIC NOT NULL, | ||
largest_property_version_v1 NUMERIC, | ||
token_uri VARCHAR(512) NOT NULL, | ||
description TEXT NOT NULL, | ||
token_properties JSONB NOT NULL, | ||
token_standard VARCHAR(10) NOT NULL, | ||
is_fungible_v2 BOOLEAN, | ||
last_transaction_version BIGINT NOT NULL, | ||
last_transaction_timestamp TIMESTAMP NOT NULL, | ||
inserted_at TIMESTAMP NOT NULL DEFAULT NOW() | ||
); | ||
CREATE INDEX IF NOT EXISTS cur_td2_cid_name_index ON current_token_datas_v2 (collection_id, token_name); | ||
CREATE INDEX IF NOT EXISTS cur_td2_insat_index ON current_token_datas_v2 (inserted_at); | ||
-- Add ID (with 0x prefix) | ||
ALTER TABLE current_token_pending_claims | ||
ADD COLUMN IF NOT EXISTS token_data_id VARCHAR(66) NOT NULL DEFAULT ''; | ||
ALTER TABLE current_token_pending_claims | ||
ADD COLUMN IF NOT EXISTS collection_id VARCHAR(66) NOT NULL DEFAULT ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.