From 58ae07bce4355bd8aa05defabde3373b7e0a4474 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 19 Dec 2024 01:15:05 +0700 Subject: [PATCH 1/4] Add state_transition_hash in the identity aliases --- .../indexer/migrations/V43__add_identity_alias_st_hash.sql | 2 ++ packages/indexer/src/processor/psql/dao/mod.rs | 7 ++++--- packages/indexer/src/processor/psql/mod.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 packages/indexer/migrations/V43__add_identity_alias_st_hash.sql diff --git a/packages/indexer/migrations/V43__add_identity_alias_st_hash.sql b/packages/indexer/migrations/V43__add_identity_alias_st_hash.sql new file mode 100644 index 000000000..608ca4e6a --- /dev/null +++ b/packages/indexer/migrations/V43__add_identity_alias_st_hash.sql @@ -0,0 +1,2 @@ +ALTER TABLE identity_aliases +ADD COLUMN "state_transition_hash" CHAR(64) NOT NULL; diff --git a/packages/indexer/src/processor/psql/dao/mod.rs b/packages/indexer/src/processor/psql/dao/mod.rs index 6366ad66f..792b05a4c 100644 --- a/packages/indexer/src/processor/psql/dao/mod.rs +++ b/packages/indexer/src/processor/psql/dao/mod.rs @@ -179,19 +179,20 @@ impl PostgresDAO { Ok(()) } - pub async fn create_identity_alias(&self, identity: Identity, alias: String) -> Result<(), PoolError> { + pub async fn create_identity_alias(&self, identity: Identity, alias: String, st_hash: String) -> Result<(), PoolError> { let client = self.connection_pool.get().await.unwrap(); - let query = "INSERT INTO identity_aliases(identity_identifier,alias) VALUES ($1, $2);"; + let query = "INSERT INTO identity_aliases(identity_identifier,alias,state_transition_hash) VALUES ($1, $2, $3);"; let stmt = client.prepare_cached(query).await.unwrap(); client.query(&stmt, &[ &identity.identifier.to_string(Base58), &alias, + &st_hash, ]).await.unwrap(); - println!("Created Identity Alias {} -> {}", identity.identifier.to_string(Base58), alias); + println!("Created Identity Alias {} -> {} ({})", identity.identifier.to_string(Base58), alias, &st_hash); Ok(()) } diff --git a/packages/indexer/src/processor/psql/mod.rs b/packages/indexer/src/processor/psql/mod.rs index 872908909..940609e72 100644 --- a/packages/indexer/src/processor/psql/mod.rs +++ b/packages/indexer/src/processor/psql/mod.rs @@ -145,7 +145,7 @@ impl PSQLProcessor { let identity = self.dao.get_identity_by_identifier(identity_identifier.clone()).await.unwrap().expect(&format!("Could not find identity with identifier {}", identity_identifier)); let alias = format!("{}.{}", label, normalized_parent_domain_name); - self.dao.create_identity_alias(identity, alias).await.unwrap(); + self.dao.create_identity_alias(identity, alias, st_hash.clone()).await.unwrap(); } if document_type == "dataContracts" && document_transition.data_contract_id() == self.platform_explorer_identifier { From 889f7f5c433ce8476842b22d2b3efc158ee6cf26 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 19 Dec 2024 01:38:56 +0700 Subject: [PATCH 2/4] Fix identities.spec.js --- .../api/test/integration/identities.spec.js | 19 ++++++++++--------- .../api/test/integration/transactions.spec.js | 2 +- packages/api/test/utils/fixtures.js | 5 +++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/api/test/integration/identities.spec.js b/packages/api/test/integration/identities.spec.js index ab717dea1..58468ce75 100644 --- a/packages/api/test/integration/identities.spec.js +++ b/packages/api/test/integration/identities.spec.js @@ -212,7 +212,8 @@ describe('Identities routes', () => { const { alias } = await fixtures.identity_alias(knex, { alias: 'test.dash', - identity + identity, + state_transition_hash: transaction.hash } ) @@ -320,7 +321,7 @@ describe('Identities routes', () => { it('should return identity by dpns', async () => { const block = await fixtures.block(knex) const identity = await fixtures.identity(knex, { block_hash: block.hash }) - const { alias } = await fixtures.identity_alias(knex, { alias: 'test-name.1.dash', identity }) + const { alias } = await fixtures.identity_alias(knex, { alias: 'test-name.1.dash', identity, state_transition_hash: identity.transaction.hash }) const { body } = await client.get('/dpns/identity?dpns=test-name.1.dash') .expect(200) @@ -342,7 +343,7 @@ describe('Identities routes', () => { it('should return identity by dpns with any case', async () => { const block = await fixtures.block(knex) const identity = await fixtures.identity(knex, { block_hash: block.hash }) - const { alias } = await fixtures.identity_alias(knex, { alias: 'test-name.2.dash', identity }) + const { alias } = await fixtures.identity_alias(knex, { alias: 'test-name.2.dash', identity, state_transition_hash: identity.transaction.hash }) const { body } = await client.get('/dpns/identity?dpns=TeSt-NaME.2.DAsH') .expect(200) @@ -376,7 +377,7 @@ describe('Identities routes', () => { for (let i = 0; i < 30; i++) { block = await fixtures.block(knex, { height: i + 1 }) identity = await fixtures.identity(knex, { block_hash: block.hash }) - alias = await fixtures.identity_alias(knex, { alias: `#test$${i}`, identity }) + alias = await fixtures.identity_alias(knex, { alias: `#test$${i}`, identity, state_transition_hash: identity.transaction.hash }) identities.push({ identity, block }) aliases.push(alias) } @@ -423,7 +424,7 @@ describe('Identities routes', () => { for (let i = 0; i < 30; i++) { block = await fixtures.block(knex, { height: i + 1 }) identity = await fixtures.identity(knex, { block_hash: block.hash }) - alias = await fixtures.identity_alias(knex, { alias: `#test1$${i}`, identity }) + alias = await fixtures.identity_alias(knex, { alias: `#test1$${i}`, identity, state_transition_hash: identity.transaction.hash }) identities.push({ identity, block }) aliases.push(alias) } @@ -473,7 +474,7 @@ describe('Identities routes', () => { for (let i = 0; i < 30; i++) { block = await fixtures.block(knex, { height: i + 1 }) identity = await fixtures.identity(knex, { block_hash: block.hash }) - alias = await fixtures.identity_alias(knex, { alias: `#test2$${i}`, identity }) + alias = await fixtures.identity_alias(knex, { alias: `#test2$${i}`, identity, state_transition_hash: identity.transaction.hash }) identities.push({ identity, block }) aliases.push(alias) } @@ -523,7 +524,7 @@ describe('Identities routes', () => { for (let i = 0; i < 30; i++) { block = await fixtures.block(knex, { height: i + 1 }) identity = await fixtures.identity(knex, { block_hash: block.hash }) - alias = await fixtures.identity_alias(knex, { alias: `#test3$${i}`, identity }) + alias = await fixtures.identity_alias(knex, { alias: `#test3$${i}`, identity, state_transition_hash: identity.transaction.hash }) identities.push({ identity, block }) aliases.push(alias) } @@ -590,7 +591,7 @@ describe('Identities routes', () => { identity.transactions = transactions identities.push({ identity, block }) - alias = await fixtures.identity_alias(knex, { alias: `#test3$${i}`, identity }) + alias = await fixtures.identity_alias(knex, { alias: `#test3$${i}`, identity, state_transition_hash: identity.transaction.hash }) aliases.push(alias) } @@ -654,7 +655,7 @@ describe('Identities routes', () => { identity.balance = transfer.amount identities.push({ identity, block, transfer }) - alias = await fixtures.identity_alias(knex, { alias: `#test3$${i}`, identity }) + alias = await fixtures.identity_alias(knex, { alias: `#test3$${i}`, identity, state_transition_hash: identity.transaction.hash }) aliases.push(alias) } diff --git a/packages/api/test/integration/transactions.spec.js b/packages/api/test/integration/transactions.spec.js index 9bcf199d7..9db9b375f 100644 --- a/packages/api/test/integration/transactions.spec.js +++ b/packages/api/test/integration/transactions.spec.js @@ -42,7 +42,7 @@ describe('Transaction routes', () => { }) identity = await fixtures.identity(knex, { block_hash: block.hash }) - identityAlias = await fixtures.identity_alias(knex, { alias: 'test.dash', identity }) + identityAlias = await fixtures.identity_alias(knex, { alias: 'test.dash', identity, state_transition_hash: identity.transaction.hash }) transactions = [{ transaction: identity.transaction, block }] diff --git a/packages/api/test/utils/fixtures.js b/packages/api/test/utils/fixtures.js index c1ebf0da5..e088e5c30 100644 --- a/packages/api/test/utils/fixtures.js +++ b/packages/api/test/utils/fixtures.js @@ -84,14 +84,15 @@ const fixtures = { return { ...row, txHash: state_transition_hash ?? transaction.hash, id: result[0].id, transaction } }, - identity_alias: async (knex, { alias, identity, block_hash } = {}) => { + identity_alias: async (knex, { alias, identity, block_hash, state_transition_hash } = {}) => { if (!identity) { identity = this.identity(knex, { block_hash }) } const row = { identity_identifier: identity.identifier, - alias + alias, + state_transition_hash } await knex('identity_aliases').insert(row).returning('id') From 53099b1347100bf709129c42d07214c169f50a3f Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 19 Dec 2024 01:49:12 +0700 Subject: [PATCH 3/4] Fix main.spec.js --- packages/api/test/integration/main.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/api/test/integration/main.spec.js b/packages/api/test/integration/main.spec.js index c118f362b..181cb2cef 100644 --- a/packages/api/test/integration/main.spec.js +++ b/packages/api/test/integration/main.spec.js @@ -84,7 +84,8 @@ describe('Other routes', () => { identityAlias = await fixtures.identity_alias(knex, { alias: 'dpns.dash', - identity + identity, + state_transition_hash: identityTransaction.hash, }) dataContractTransaction = await fixtures.transaction(knex, { From ccdaffe708771ca2487c79b4fa9ee4abfa07876e Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 19 Dec 2024 03:55:00 +0700 Subject: [PATCH 4/4] Fix lint --- packages/api/test/integration/main.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/test/integration/main.spec.js b/packages/api/test/integration/main.spec.js index 181cb2cef..06bc23bd2 100644 --- a/packages/api/test/integration/main.spec.js +++ b/packages/api/test/integration/main.spec.js @@ -85,7 +85,7 @@ describe('Other routes', () => { identityAlias = await fixtures.identity_alias(knex, { alias: 'dpns.dash', identity, - state_transition_hash: identityTransaction.hash, + state_transition_hash: identityTransaction.hash }) dataContractTransaction = await fixtures.transaction(knex, {