From c386d564980103d15dbd2a2f56c25728c79923a5 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 9 Aug 2024 13:30:52 +0700 Subject: [PATCH 1/5] Update cargo lock --- packages/indexer/Cargo.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/indexer/Cargo.lock b/packages/indexer/Cargo.lock index 6ed2a4c1..f7b29100 100644 --- a/packages/indexer/Cargo.lock +++ b/packages/indexer/Cargo.lock @@ -493,7 +493,7 @@ dependencies = [ [[package]] name = "dashpay-contract" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "platform-value", "platform-version", @@ -503,7 +503,7 @@ dependencies = [ [[package]] name = "data-contracts" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "dashpay-contract", "dpns-contract", @@ -592,7 +592,7 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] name = "dpns-contract" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "platform-value", "platform-version", @@ -602,7 +602,7 @@ dependencies = [ [[package]] name = "dpp" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "anyhow", "async-trait", @@ -713,7 +713,7 @@ checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "feature-flags-contract" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "platform-value", "platform-version", @@ -1208,7 +1208,7 @@ dependencies = [ [[package]] name = "json-schema-compatibility-validator" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "json-patch", "once_cell", @@ -1279,7 +1279,7 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "masternode-reward-shares-contract" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "platform-value", "platform-version", @@ -1547,7 +1547,7 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "platform-serialization" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "bincode", "platform-version", @@ -1555,7 +1555,7 @@ dependencies = [ [[package]] name = "platform-serialization-derive" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "proc-macro2", "quote", @@ -1565,7 +1565,7 @@ dependencies = [ [[package]] name = "platform-value" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "base64 0.22.1", "bincode", @@ -1584,7 +1584,7 @@ dependencies = [ [[package]] name = "platform-version" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "bincode", "grovedb-version", @@ -1595,7 +1595,7 @@ dependencies = [ [[package]] name = "platform-versioning" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "proc-macro2", "quote", @@ -3112,7 +3112,7 @@ dependencies = [ [[package]] name = "withdrawals-contract" -version = "1.0.0-beta.4" +version = "1.0.0-rc.2" dependencies = [ "num_enum", "platform-value", From 132f7e6ef772bd0447179d0545df58fd7b65d965 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 9 Aug 2024 13:34:37 +0700 Subject: [PATCH 2/5] Upgrade JS Dash SDK library to v1.0.0-rc.2 (testnet) and fix decode state transitions unit tests --- packages/api/package.json | 2 +- .../api/test/unit/mocks/documents_batch.json | 2 +- packages/api/test/unit/utils.spec.js | 226 +++++++++--------- packages/data-contract/package.json | 2 +- 4 files changed, 116 insertions(+), 116 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index 81b91e3f..f2a2d1b5 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -15,7 +15,7 @@ "@dashevo/dashd-rpc": "^19.0.0", "@fastify/cors": "^8.3.0", "@scure/base": "^1.1.5", - "dash": "4.0.0-beta.4", + "dash": "4.0.0-rc.2", "dotenv": "^16.3.1", "fastify": "^4.21.0", "fastify-metrics": "^11.0.0", diff --git a/packages/api/test/unit/mocks/documents_batch.json b/packages/api/test/unit/mocks/documents_batch.json index 43ca210a..5b9f5bd4 100644 --- a/packages/api/test/unit/mocks/documents_batch.json +++ b/packages/api/test/unit/mocks/documents_batch.json @@ -1,3 +1,3 @@ { - "data": "AgCrhZtAwveRrwo9QITiR9MqJcHQHFHPUS0ewKXF/s/aogEAAAAb4QihbPKQQmYJ0J+5i90c2y+1HTU6QkLOH0g3pMmIyQEIcHJlb3JkZXLmaMZZr2au4ecsGG3ee1t+Ch1xKgnEDVch9iK/U8UxVfCoJzXeOElnkW/7iiSHA9PCSsQ86oIcaa7sYXNXFSW1ARBzYWx0ZWREb21haW5IYXNoCiBJjPigm6iNZsJXABN4cnRUdXCdvwHjgrKFV8L5kAgQZwABQR9Fti5v8aobfhQTmxxAAUmJrV2WNJKqnWsXasr63DHUqA2/o2QWYJs1hq7MDw6aNTZnKdHfoJGXgbxuRRcnenSp" + "data": "AgAOCeQUD4t3d4EL5WxH8KtcvZvtHnc6vZ+f3y/memaf9wEAAABgCLhdmCbncK0httWF8BDx37Oz8q3GSSMpu++P3sGx1wIEbm90ZdpXZPiQJeml9oBjOQnbWPb39tNYLERTk/FarViCHJ8r8Jo86sqi8SuYeboiPVuMZsMQbv5Y7cURVW8x7pZ2QSsBB21lc3NhZ2USMFR1dG9yaWFsIENJIFRlc3QgQCBUaHUsIDA4IEF1ZyAyMDI0IDIwOjI1OjAzIEdNVAAAAUEfLtRrTrHXdpT9Pzp4PcNiKV13nnAYAqrl0w3KfWI8QR5f7TTen0N66ZUU7R7AoXV8kliIwVqpxiCVwChbh2XiYQ==" } diff --git a/packages/api/test/unit/utils.spec.js b/packages/api/test/unit/utils.spec.js index 7fa2c319..2693adcb 100644 --- a/packages/api/test/unit/utils.spec.js +++ b/packages/api/test/unit/utils.spec.js @@ -1,113 +1,113 @@ -// const { describe, it, before } = require('node:test') -// const assert = require('node:assert').strict -// const utils = require('../../src/utils') -// const createIdentityMock = require('./mocks/create_identity.json') -// const dataContractCreateMock = require('./mocks/data_contract_create.json') -// const documentsBatchMock = require('./mocks/documents_batch.json') -// const identityTopUpMock = require('./mocks/identity_top_up.json') -// const dataContractUpdateMock = require('./mocks/data_contract_update.json') -// const identityUpdateMock = require('./mocks/identity_update.json') -// const identityCreditTransfer = require('./mocks/identity_credit_transfer.json') -// const identityWithdrawal = require('./mocks/identity_withdrawal.json') -// const Dash = require('dash') -// -// describe('Utils', () => { -// let client -// -// before(async () => { -// client = new Dash.Client() -// await client.platform.initialize() -// }) -// -// describe('decodeStateTransition()', () => { -// it('should decode DataContractCreate', async () => { -// const decoded = await utils.decodeStateTransition(client, dataContractCreateMock.data) -// -// assert.deepEqual(decoded, { -// identityId: '7dwjL5frrkM69pv3BsKSQb4ELrMYmDeE11KNoDSefG6c', -// dataContractId: 'GbGD5YbS9GVh7FSZjz3uUJpbrXo9ctbdKycfTqqg3Cmn', -// type: 0 -// }) -// }) -// -// it('should decode DocumentsBatch', async () => { -// const decoded = await utils.decodeStateTransition(client, documentsBatchMock.data) -// -// assert.deepEqual(decoded, { -// type: 1, -// transitions: [ -// { -// action: 0, -// dataContractId: 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', -// id: '2sq2fsVgNrrNKFyRgcLvT8SSVFmCLoMTUfNBY3yEdyeQ', -// revision: 1 -// } -// ] -// }) -// }) -// -// it('should decode CreateIdentity', async () => { -// const decoded = await utils.decodeStateTransition(client, createIdentityMock.data) -// -// assert.deepEqual(decoded, { -// identityId: '3B3pVgtqLyZx9tUYoSTubXQMs6BQN6kkLURvGG8ax8NJ', -// type: 2 -// }) -// }) -// -// it('should decode IdentityTopUp', async () => { -// const decoded = await utils.decodeStateTransition(client, identityTopUpMock.data) -// -// assert.deepEqual(decoded, { -// identityId: '4EfA9Jrvv3nnCFdSf7fad59851iiTRZ6Wcu6YVJ4iSeF', -// type: 3, -// amount: 300000000 -// }) -// }) -// -// it.only('should decode DataContractUpdate', async () => { -// const decoded = await utils.decodeStateTransition(client, dataContractUpdateMock.data) -// -// assert.deepEqual(decoded, { -// identityId: '7dwjL5frrkM69pv3BsKSQb4ELrMYmDeE11KNoDSefG6c', -// dataContractId: '8BzeH7dmyLHNzcCtG6DGowAkWyRgWEq15y88Zz2zBxVg', -// type: 4, -// version: 2 -// }) -// }) -// -// it('should decode IdentityUpdate', async () => { -// const decoded = await utils.decodeStateTransition(client, identityUpdateMock.data) -// -// assert.deepEqual(decoded, { -// identityId: '4NGALjtX2t3AXE3ZCqJiSmYuiWEY3ZPQNUBxNWWRrRSp', -// type: 5, -// revision: 2 -// }) -// }) -// -// it('should decode IdentityCreditTransfer', async () => { -// const decoded = await utils.decodeStateTransition(client, identityCreditTransfer.data) -// -// assert.deepEqual(decoded, { -// senderId: '4CpFVPyU95ZxNeDnRWfkpjUa9J72i3nZ4YPsTnpdUudu', -// recipientId: 'GxdRSLivPDeACYU8Z6JSNvtrRPX7QG715JoumnctbwWN', -// amount: 9998363, -// type: 7 -// }) -// }) -// -// it('should decode IdentityWithdrawal', async () => { -// const decoded = await utils.decodeStateTransition(client, identityWithdrawal.data) -// -// assert.deepEqual(decoded, { -// senderId: 'FvqzjDyub72Hk51pcmJvd1JUACuor7vA3aJawiVG7Z17', -// amount: 1000000, -// nonce: 1, -// outputScript: '76a9148dc5fd6be194390035cca6293a357bac8e3c35c588ac', -// coreFeePerByte: 2, -// type: 6 -// }) -// }) -// }) -// }) +const { describe, it, before } = require('node:test') +const assert = require('node:assert').strict +const utils = require('../../src/utils') +const createIdentityMock = require('./mocks/create_identity.json') +const dataContractCreateMock = require('./mocks/data_contract_create.json') +const documentsBatchMock = require('./mocks/documents_batch.json') +const identityTopUpMock = require('./mocks/identity_top_up.json') +const dataContractUpdateMock = require('./mocks/data_contract_update.json') +const identityUpdateMock = require('./mocks/identity_update.json') +const identityCreditTransfer = require('./mocks/identity_credit_transfer.json') +const identityWithdrawal = require('./mocks/identity_withdrawal.json') +const Dash = require('dash') + +describe('Utils', () => { + let client + + before(async () => { + client = new Dash.Client() + await client.platform.initialize() + }) + + describe('decodeStateTransition()', () => { + it('should decode DataContractCreate', async () => { + const decoded = await utils.decodeStateTransition(client, dataContractCreateMock.data) + + assert.deepEqual(decoded, { + identityId: '7dwjL5frrkM69pv3BsKSQb4ELrMYmDeE11KNoDSefG6c', + dataContractId: 'GbGD5YbS9GVh7FSZjz3uUJpbrXo9ctbdKycfTqqg3Cmn', + type: 0 + }) + }) + + it('should decode DocumentsBatch', async () => { + const decoded = await utils.decodeStateTransition(client, documentsBatchMock.data) + + assert.deepEqual(decoded, { + type: 1, + transitions: [ + { + action: 0, + dataContractId: 'FhKAsUnPbqe7K4TZxgRdtPUrfSvNCtYV8iPsvjX7ZG58', + id: '7TsrNHXDy14fYoRcoYjZHH14K4riMGU2VeHMwopG82DL', + revision: 1 + } + ] + }) + }) + + it('should decode CreateIdentity', async () => { + const decoded = await utils.decodeStateTransition(client, createIdentityMock.data) + + assert.deepEqual(decoded, { + identityId: '3B3pVgtqLyZx9tUYoSTubXQMs6BQN6kkLURvGG8ax8NJ', + type: 2 + }) + }) + + it('should decode IdentityTopUp', async () => { + const decoded = await utils.decodeStateTransition(client, identityTopUpMock.data) + + assert.deepEqual(decoded, { + identityId: '4EfA9Jrvv3nnCFdSf7fad59851iiTRZ6Wcu6YVJ4iSeF', + type: 3, + amount: 300000000 + }) + }) + + it.only('should decode DataContractUpdate', async () => { + const decoded = await utils.decodeStateTransition(client, dataContractUpdateMock.data) + + assert.deepEqual(decoded, { + identityId: '7dwjL5frrkM69pv3BsKSQb4ELrMYmDeE11KNoDSefG6c', + dataContractId: '8BzeH7dmyLHNzcCtG6DGowAkWyRgWEq15y88Zz2zBxVg', + type: 4, + version: 2 + }) + }) + + it('should decode IdentityUpdate', async () => { + const decoded = await utils.decodeStateTransition(client, identityUpdateMock.data) + + assert.deepEqual(decoded, { + identityId: '4NGALjtX2t3AXE3ZCqJiSmYuiWEY3ZPQNUBxNWWRrRSp', + type: 5, + revision: 2 + }) + }) + + it('should decode IdentityCreditTransfer', async () => { + const decoded = await utils.decodeStateTransition(client, identityCreditTransfer.data) + + assert.deepEqual(decoded, { + senderId: '4CpFVPyU95ZxNeDnRWfkpjUa9J72i3nZ4YPsTnpdUudu', + recipientId: 'GxdRSLivPDeACYU8Z6JSNvtrRPX7QG715JoumnctbwWN', + amount: 9998363, + type: 7 + }) + }) + + it('should decode IdentityWithdrawal', async () => { + const decoded = await utils.decodeStateTransition(client, identityWithdrawal.data) + + assert.deepEqual(decoded, { + senderId: 'FvqzjDyub72Hk51pcmJvd1JUACuor7vA3aJawiVG7Z17', + amount: 1000000, + nonce: 1, + outputScript: '76a9148dc5fd6be194390035cca6293a357bac8e3c35c588ac', + coreFeePerByte: 2, + type: 6 + }) + }) + }) +}) diff --git a/packages/data-contract/package.json b/packages/data-contract/package.json index e007f08a..4bf7f5aa 100644 --- a/packages/data-contract/package.json +++ b/packages/data-contract/package.json @@ -18,7 +18,7 @@ "homepage": "https://github.com/pshenmic/platform-explorer#readme", "description": "", "dependencies": { - "dash": "4.0.0-dev.12", + "dash": "4.0.0-rc.2", "dotenv": "^16.4.5" }, "devDependencies": { From 980523cd3130b52d4752258136ec1ed8b5b12467 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 9 Aug 2024 13:36:10 +0700 Subject: [PATCH 3/5] Drop identity aliases unique index (it is not one-to-many) --- .../migrations/V41__drop_identity_aliases_unque_index.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 packages/indexer/migrations/V41__drop_identity_aliases_unque_index.sql diff --git a/packages/indexer/migrations/V41__drop_identity_aliases_unque_index.sql b/packages/indexer/migrations/V41__drop_identity_aliases_unque_index.sql new file mode 100644 index 00000000..931bdcfa --- /dev/null +++ b/packages/indexer/migrations/V41__drop_identity_aliases_unque_index.sql @@ -0,0 +1,2 @@ +DROP INDEX identity_aliases_alias; + From c4f296e18b6a0934521e1eaa9a553385bda3b714 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 9 Aug 2024 13:36:44 +0700 Subject: [PATCH 4/5] Update identity aliases indexer to latest DPNS contract schema --- packages/indexer/src/processor/psql/mod.rs | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/indexer/src/processor/psql/mod.rs b/packages/indexer/src/processor/psql/mod.rs index 984ddf01..27663ca0 100644 --- a/packages/indexer/src/processor/psql/mod.rs +++ b/packages/indexer/src/processor/psql/mod.rs @@ -9,7 +9,7 @@ use crate::processor::psql::dao::PostgresDAO; use base64::{Engine as _, engine::{general_purpose}}; use data_contracts::SystemDataContract; use dpp::identifier::Identifier; -use dpp::platform_value::{platform_value, BinaryData}; +use dpp::platform_value::{platform_value, BinaryData, Value}; use dpp::platform_value::btreemap_extensions::BTreeValueMapPathHelper; use dpp::platform_value::string_encoding::Encoding::Base58; use dpp::serialization::PlatformSerializable; @@ -91,6 +91,9 @@ impl PSQLProcessor { for (_, document_transition) in transitions.iter().enumerate() { let document = Document::from(document_transition.clone()); + + self.dao.create_document(document, Some(st_hash.clone())).await.unwrap(); + let document_type = document_transition.document_type_name(); if document_type == "domain" && document_transition.data_contract_id() == SystemDataContract::DPNS.id() { @@ -103,24 +106,15 @@ impl PSQLProcessor { let normalized_parent_domain_name = document_transition .data() .unwrap() - .get_str_at_path("normalizedParentDomainName") + .get_str_at_path("parentDomainName") .unwrap(); - let primary_alias = document_transition + let identity_identifier = document_transition .data() .unwrap() - .get_optional_at_path("records.dashUniqueIdentityId").unwrap(); - - let identity_identifier = match primary_alias { - None => { - document_transition - .data() - .unwrap() - .get_optional_at_path("records.dashAliasIdentityId").unwrap() - .expect("Could not find dashAliasIdentityId") - } - Some(value) => value - }; + .get_optional_at_path("records.identity") + .unwrap() + .expect("Could not find DPNS domain document identity identifier"); let identity_identifier = Identifier::from_bytes(&identity_identifier.clone().into_identifier_bytes().unwrap()).unwrap().to_string(Base58); let identity = self.dao.get_identity_by_identifier(identity_identifier.clone()).await.unwrap().expect(&format!("Could not find identity with identifier {}", identity_identifier)); @@ -157,9 +151,6 @@ impl PSQLProcessor { println!("Failed to set custom data contract name for contract {}, owner of the tx {} does not match data contract", st_hash, document.identifier.to_string(Base58)); } } - - - self.dao.create_document(document, Some(st_hash.clone())).await.unwrap(); } } From cda77f90a3018a9638cedcf82ae456bc3206ab95 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 9 Aug 2024 13:42:31 +0700 Subject: [PATCH 5/5] Fix value borrowed is moved --- packages/indexer/src/processor/psql/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/indexer/src/processor/psql/mod.rs b/packages/indexer/src/processor/psql/mod.rs index 27663ca0..e002f45e 100644 --- a/packages/indexer/src/processor/psql/mod.rs +++ b/packages/indexer/src/processor/psql/mod.rs @@ -91,6 +91,7 @@ impl PSQLProcessor { for (_, document_transition) in transitions.iter().enumerate() { let document = Document::from(document_transition.clone()); + let document_identifier = document.identifier.clone(); self.dao.create_document(document, Some(st_hash.clone())).await.unwrap(); @@ -148,7 +149,7 @@ impl PSQLProcessor { if data_contract.owner == state_transition.owner_id() { self.dao.set_data_contract_name(data_contract, String::from(data_contract_name)).await.unwrap(); } else { - println!("Failed to set custom data contract name for contract {}, owner of the tx {} does not match data contract", st_hash, document.identifier.to_string(Base58)); + println!("Failed to set custom data contract name for contract {}, owner of the tx {} does not match data contract", st_hash, document_identifier.to_string(Base58)); } } }