From 896a52373860102e15198c8306ff43b65b277c4b Mon Sep 17 00:00:00 2001 From: Carolyn Russell Date: Thu, 18 Nov 2021 19:04:34 -0700 Subject: [PATCH] Parse scope ownership changes * Added Encryption dependency for signature parsing * Added migration to track ownership changes closes: #247 --- buildSrc/src/main/kotlin/Dependencies.kt | 2 + .../migration/V1_38__Add_scope_transfers.sql | 59 +++++++++++++++++++ service/build.gradle.kts | 4 ++ .../explorer/grpc/v1/AccountGrpcClient.kt | 6 +- .../explorer/grpc/v1/MarkerGrpcClient.kt | 6 +- 5 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 database/src/main/resources/db/migration/V1_38__Add_scope_transfers.sql diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index fac65a3a..0cc6298b 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -60,6 +60,7 @@ object Versions { const val KotlinGrpc = "1.2.0" const val GrpcStarter = "4.5.6" const val Postgres = "42.2.23" + const val Encryption = "0.4.0" // Testing const val Jupiter = "5.7.1" @@ -94,6 +95,7 @@ object Libraries { const val ApacheCommonsText = "org.apache.commons:commons-text:${Versions.ApacheCommonsText}" const val Khttp = "khttp:khttp:${Versions.Khttp}" const val KaseChange = "net.pearx.kasechange:kasechange:${Versions.KaseChange}" + const val Encryption = "io.provenance.scope:encryption:${Versions.Encryption}" // Logging const val LogbackCore = "ch.qos.logback.contrib:logback-json-core:${Versions.Logback}" diff --git a/database/src/main/resources/db/migration/V1_38__Add_scope_transfers.sql b/database/src/main/resources/db/migration/V1_38__Add_scope_transfers.sql new file mode 100644 index 00000000..d3d5499b --- /dev/null +++ b/database/src/main/resources/db/migration/V1_38__Add_scope_transfers.sql @@ -0,0 +1,59 @@ +SELECT 'Add nft_scope_value_owner_transfer' AS comment; +CREATE TABLE IF NOT EXISTS nft_scope_value_owner_transfer +( + id SERIAL PRIMARY KEY, + scope_id INT NOT NULL, + scope_addr VARCHAR(128) NOT NULL, + address VARCHAR(256) NOT NULL, + tx_id INT NOT NULL, + block_height INT NOT NULL, + tx_hash VARCHAR(64) NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS nft_scope_vo_transfer_scope_address_tx_idx + ON nft_scope_value_owner_transfer (scope_id, address, tx_id); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_scope_id_idx ON nft_scope_value_owner_transfer (scope_id); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_scope_addr_idx ON nft_scope_value_owner_transfer (scope_addr); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_address_idx ON nft_scope_value_owner_transfer (address); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_block_height_idx ON nft_scope_value_owner_transfer (block_height); + + +SELECT 'Add nft_scope_owner_changes' AS comment; +CREATE TABLE IF NOT EXISTS nft_scope_owner_changes +( + id SERIAL PRIMARY KEY, + scope_id INT NOT NULL, + scope_addr VARCHAR(128) NOT NULL, + address VARCHAR(256) NOT NULL, + role VARCHAR(256) NOT NULL, + tx_id INT NOT NULL, + block_height INT NOT NULL, + tx_hash VARCHAR(64) NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS nft_scope_owner_changes_scope_address_role_tx_idx + ON nft_scope_owner_changes (scope_id, address, role, tx_id); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_scope_id_idx ON nft_scope_owner_changes (scope_id); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_scope_addr_idx ON nft_scope_owner_changes (scope_addr); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_address_idx ON nft_scope_owner_changes (address); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_block_height_idx ON nft_scope_owner_changes (block_height); + +SELECT 'Add nft_scope_owner_changes' AS comment; +CREATE TABLE IF NOT EXISTS nft_scope_owner_changes +( + id SERIAL PRIMARY KEY, + scope_id INT NOT NULL, + scope_addr VARCHAR(128) NOT NULL, + address VARCHAR(256), + role VARCHAR(256) NOT NULL, + tx_id INT NOT NULL, + block_height INT NOT NULL, + tx_hash VARCHAR(64) NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS nft_scope_owner_changes_scope_address_role_tx_idx + ON nft_scope_owner_changes (scope_id, address, role, tx_id); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_scope_id_idx ON nft_scope_owner_changes (scope_id); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_scope_addr_idx ON nft_scope_owner_changes (scope_addr); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_address_idx ON nft_scope_owner_changes (address); +CREATE INDEX IF NOT EXISTS nft_scope_vo_transfer_block_height_idx ON nft_scope_owner_changes (block_height); diff --git a/service/build.gradle.kts b/service/build.gradle.kts index feeb6495..3bd6ac37 100644 --- a/service/build.gradle.kts +++ b/service/build.gradle.kts @@ -40,6 +40,10 @@ dependencies { api(Libraries.ApacheCommonsText) api(Libraries.Khttp) implementation(Libraries.KaseChange) + api(Libraries.Encryption) { + exclude("io.provenance.scope", "contract-proto") + exclude("io.provenance.protobuf", "pb-proto-java") + } implementation(Libraries.GrpcNetty) diff --git a/service/src/main/kotlin/io/provenance/explorer/grpc/v1/AccountGrpcClient.kt b/service/src/main/kotlin/io/provenance/explorer/grpc/v1/AccountGrpcClient.kt index 1a739a01..18fd5456 100644 --- a/service/src/main/kotlin/io/provenance/explorer/grpc/v1/AccountGrpcClient.kt +++ b/service/src/main/kotlin/io/provenance/explorer/grpc/v1/AccountGrpcClient.kt @@ -43,9 +43,9 @@ class AccountGrpcClient(channelUri: URI) { it.usePlaintext() } } - .idleTimeout(5, TimeUnit.MINUTES) - .keepAliveTime(60, TimeUnit.SECONDS) - .keepAliveTimeout(20, TimeUnit.SECONDS) + .idleTimeout(60, TimeUnit.SECONDS) + .keepAliveTime(10, TimeUnit.SECONDS) + .keepAliveTimeout(10, TimeUnit.SECONDS) .intercept(GrpcLoggingInterceptor()) .build() diff --git a/service/src/main/kotlin/io/provenance/explorer/grpc/v1/MarkerGrpcClient.kt b/service/src/main/kotlin/io/provenance/explorer/grpc/v1/MarkerGrpcClient.kt index 099f8d53..50889a9b 100644 --- a/service/src/main/kotlin/io/provenance/explorer/grpc/v1/MarkerGrpcClient.kt +++ b/service/src/main/kotlin/io/provenance/explorer/grpc/v1/MarkerGrpcClient.kt @@ -33,9 +33,9 @@ class MarkerGrpcClient(channelUri: URI, private val semaphore: Semaphore) { it.usePlaintext() } } - .idleTimeout(5, TimeUnit.MINUTES) - .keepAliveTime(60, TimeUnit.SECONDS) - .keepAliveTimeout(20, TimeUnit.SECONDS) + .idleTimeout(60, TimeUnit.SECONDS) + .keepAliveTime(10, TimeUnit.SECONDS) + .keepAliveTimeout(10, TimeUnit.SECONDS) .intercept(GrpcLoggingInterceptor()) .build()