Skip to content

Commit

Permalink
[indexer] Adding query_object api to indexer (MystenLabs#9600)
Browse files Browse the repository at this point in the history
## Description 

Adding the `query_objects` call to indexer api. Currently only including
the filters for type / owners
## Test Plan 

How did you test the new or updated feature?

Will run locally, and query

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes

---------

Co-authored-by: patrick <[email protected]>
  • Loading branch information
healthydeve and patrickkuo authored Mar 24, 2023
1 parent 27487bd commit 75c756d
Show file tree
Hide file tree
Showing 26 changed files with 785 additions and 267 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sui-indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pg_integration = []
sui-framework-build = { path = "../sui-framework-build" }
sui-keys = { path = "../sui-keys" }
test-utils = { path = "../test-utils" }
ntest = "0.9.0"

[[bin]]
name = "sui-indexer"
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ And to execute a single test such as just `test_event_query_e2e`, you can do
POSTGRES_PORT=5432 cargo test test_event_query_e2e --package sui-indexer --test integration_tests --features pg_integration -- --test-threads=1
```

**Note** all existing data will be wiped during the test.
**Note** all existing data will be wiped during the test.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ DROP TABLE IF EXISTS objects;
DROP TABLE IF EXISTS objects_history;

DROP TYPE IF EXISTS owner_type;
DROP TYPE IF EXISTS change_type;
DROP TYPE IF EXISTS bcs_bytes;
DROP TYPE IF EXISTS object_status;

Expand Down
55 changes: 35 additions & 20 deletions crates/sui-indexer/migrations/2022-12-01-034426_objects/up.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
DO $$
BEGIN
CREATE TYPE owner_type AS ENUM ('address_owner', 'object_owner', 'shared', 'immutable');
CREATE TYPE object_status AS ENUM ('created', 'mutated', 'deleted', 'wrapped', 'unwrapped', 'unwrapped_then_deleted');
CREATE TYPE bcs_bytes AS
(
name TEXT,
data bytea
);
EXCEPTION
WHEN duplicate_object THEN
-- Type already exists, do nothing
NULL;
END $$;
DO
$$
BEGIN
CREATE TYPE owner_type AS ENUM ('address_owner', 'object_owner', 'shared', 'immutable');
CREATE TYPE object_status AS ENUM ('created', 'mutated', 'deleted', 'wrapped', 'unwrapped', 'unwrapped_then_deleted');
CREATE TYPE bcs_bytes AS
(
name TEXT,
data bytea
);
EXCEPTION
WHEN duplicate_object THEN
-- Type already exists, do nothing
NULL;
END
$$;

CREATE TABLE objects
(
epoch BIGINT NOT NULL,
checkpoint BIGINT NOT NULL,
object_id address PRIMARY KEY,
object_id address PRIMARY KEY,
version BIGINT NOT NULL,
object_digest base58digest NOT NULL,
-- owner related
Expand Down Expand Up @@ -46,24 +48,37 @@ CREATE TABLE objects_history
object_digest base58digest NOT NULL,
owner_type owner_type NOT NULL,
owner_address address,
old_owner_type owner_type,
old_owner_address address,
initial_shared_version BIGINT,
previous_transaction base58digest NOT NULL,
object_type VARCHAR NOT NULL,
object_status object_status NOT NULL,
has_public_transfer BOOLEAN NOT NULL,
storage_rebate BIGINT NOT NULL,
bcs bcs_bytes[] NOT NULL,
CONSTRAINT objects_history_pk PRIMARY KEY (epoch, object_id, version)
) PARTITION BY RANGE (epoch);
CREATE TABLE objects_history_partition_0 PARTITION OF objects_history FOR VALUES FROM (0) TO (1);
CONSTRAINT objects_history_pk PRIMARY KEY (checkpoint, object_id, version)
) PARTITION BY RANGE (checkpoint);
CREATE INDEX objects_history_id_version_index ON objects_history (object_id, version);
CREATE INDEX objects_history_owner_index ON objects_history (owner_type, owner_address);
CREATE INDEX objects_history_old_owner_index ON objects_history (old_owner_type, old_owner_address);
CREATE TABLE objects_history_partition_0 PARTITION OF objects_history FOR VALUES FROM (0) TO (MAXVALUE);

CREATE OR REPLACE FUNCTION objects_modified_func() RETURNS TRIGGER AS
$body$
BEGIN
IF (TG_OP = 'UPDATE' OR TG_OP = 'INSERT') THEN
IF (TG_OP = 'INSERT') THEN
INSERT INTO objects_history
VALUES (NEW.epoch, NEW.checkpoint, NEW.object_id, NEW.version, NEW.object_digest, NEW.owner_type,
NEW.owner_address, NULL, NULL,
NEW.initial_shared_version,
NEW.previous_transaction, NEW.object_type, NEW.object_status, NEW.has_public_transfer,
NEW.storage_rebate, NEW.bcs);
RETURN NEW;
ELSEIF (TG_OP = 'UPDATE') THEN
INSERT INTO objects_history
VALUES (NEW.epoch, NEW.checkpoint, NEW.object_id, NEW.version, NEW.object_digest, NEW.owner_type,
NEW.owner_address,
NEW.owner_address, OLD.owner_type, OLD.owner_address,
NEW.initial_shared_version,
NEW.previous_transaction, NEW.object_type, NEW.object_status, NEW.has_public_transfer,
NEW.storage_rebate, NEW.bcs);
Expand Down

This file was deleted.

165 changes: 0 additions & 165 deletions crates/sui-indexer/migrations/2023-03-01-193733_owner/up.sql

This file was deleted.

Loading

0 comments on commit 75c756d

Please sign in to comment.