Skip to content

Commit

Permalink
Merge pull request #119 from FigureTechnologies/allow_duplicate_tx
Browse files Browse the repository at this point in the history
Allow recording of duplicate transactions
  • Loading branch information
rchaing-figure authored Mar 6, 2023
2 parents 6c7bff9 + 9f12cc5 commit 8da6452
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tech.figure.aggregate.common.domain

import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.EntityClass
import org.jetbrains.exposed.dao.UUIDEntity
import org.jetbrains.exposed.dao.UUIDEntityClass
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.dao.id.UUIDTable
import java.time.OffsetDateTime
import java.util.UUID

object AttributesTable: IdTable<String>("attributes") {
object AttributesTable: UUIDTable("attributes", columnName = "uuid") {
val hash = text("hash")
val eventType = text("event_type")
val blockHeight = double("block_height")
Expand All @@ -16,13 +17,9 @@ object AttributesTable: IdTable<String>("attributes") {
val type = text("type")
val account = text("account")
val owner = text("owner")

override val id = hash.entityId()
}

open class AttributesEntityClass: EntityClass<String, AttributesRecord>(AttributesTable) {

private fun findByHash(hash: String) = find { AttributesTable.id eq hash }.firstOrNull()
open class AttributesEntityClass: UUIDEntityClass<AttributesRecord>(AttributesTable) {

fun insert(
hash: String,
Expand All @@ -35,7 +32,8 @@ open class AttributesEntityClass: EntityClass<String, AttributesRecord>(Attribut
account: String,
owner: String
) {
findByHash(hash) ?: new(hash) {
new(UUID.randomUUID()) {
this.hash = hash
this.eventType = eventType
this.blockHeight = blockHeight
this.blockTimestamp = blockTimestamp
Expand All @@ -48,10 +46,11 @@ open class AttributesEntityClass: EntityClass<String, AttributesRecord>(Attribut
}
}

class AttributesRecord(hash: EntityID<String>): Entity<String>(hash) {
class AttributesRecord(uuid: EntityID<UUID>): UUIDEntity(uuid) {
companion object: AttributesEntityClass()

var hash by AttributesTable.id
var uuid by AttributesTable.id
var hash by AttributesTable.hash
var eventType by AttributesTable.eventType
var blockHeight by AttributesTable.blockHeight
var blockTimestamp by AttributesTable.blockTimestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tech.figure.aggregate.common.domain

import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.EntityClass
import org.jetbrains.exposed.dao.UUIDEntity
import org.jetbrains.exposed.dao.UUIDEntityClass
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.dao.id.UUIDTable
import java.time.OffsetDateTime
import java.util.UUID

object CoinTransferTable: IdTable<String>("coin_transfer") {
object CoinTransferTable: UUIDTable("coin_transfer", columnName = "uuid") {
val hash = text("hash")
val eventType = text("event_type")
val blockHeight = double("block_height")
Expand All @@ -16,13 +17,9 @@ object CoinTransferTable: IdTable<String>("coin_transfer") {
val sender = text("sender")
val amount = text("amount")
val denom = text("denom")

override val id = hash.entityId()
}

open class CoinTransferEntityClass: EntityClass<String, CoinTransferRecord>(CoinTransferTable) {

private fun findByHash(hash: String) = find { CoinTransferTable.id eq hash }.firstOrNull()
open class CoinTransferEntityClass: UUIDEntityClass<CoinTransferRecord>(CoinTransferTable) {

fun insert(
hash: String,
Expand All @@ -35,7 +32,8 @@ open class CoinTransferEntityClass: EntityClass<String, CoinTransferRecord>(Coin
amount: String,
denom: String
) {
findByHash(hash) ?: new(hash) {
new(UUID.randomUUID()) {
this.hash = hash
this.eventType = eventType
this.blockHeight = blockHeight
this.blockTimestamp = blockTimestamp
Expand All @@ -46,13 +44,13 @@ open class CoinTransferEntityClass: EntityClass<String, CoinTransferRecord>(Coin
this.denom = denom
}
}

}

class CoinTransferRecord(hash: EntityID<String>): Entity<String>(hash) {
class CoinTransferRecord(uuid: EntityID<UUID>): UUIDEntity(uuid) {
companion object: CoinTransferEntityClass()

var hash by CoinTransferTable.id
var uuid by CoinTransferTable.id
var hash by CoinTransferTable.hash
var eventType by CoinTransferTable.eventType
var blockHeight by CoinTransferTable.blockHeight
var blockTimestamp by CoinTransferTable.blockTimestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package tech.figure.aggregate.common.domain

import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.EntityClass
import org.jetbrains.exposed.dao.UUIDEntity
import org.jetbrains.exposed.dao.UUIDEntityClass
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.dao.id.UUIDTable
import java.time.OffsetDateTime
import java.util.UUID

object FeesTable: IdTable<String>("fees") {
object FeesTable: UUIDTable("fees", columnName = "uuid") {
val hash = text("hash")
val txHash = text("tx_hash")
val blockHeight = double("block_height")
val blockTimestamp = offsetDatetime("block_timestamp")
val fee = text("fee")
val feeDenom = text("fee_denom")
val sender = text("sender")

override val id = hash.entityId()
}

open class FeeEntityClass: EntityClass<String, FeeRecords>(FeesTable) {

private fun findByHash(hash: String) = find { FeesTable.id eq hash }.firstOrNull()
open class FeeEntityClass: UUIDEntityClass<FeeRecords>(FeesTable) {

fun insert(
hash: String,
Expand All @@ -30,21 +27,22 @@ open class FeeEntityClass: EntityClass<String, FeeRecords>(FeesTable) {
fee: String,
feeDenom: String,
sender: String
) = findByHash(hash) ?: new(hash) {
this.txHash = txHash
this.blockHeight = blockHeight
this.blockTimestamp = blockTimestamp
this.fee = fee
this.feeDenom = feeDenom
this.sender = sender
) = new(UUID.randomUUID()) {
this.hash = hash
this.txHash = txHash
this.blockHeight = blockHeight
this.blockTimestamp = blockTimestamp
this.fee = fee
this.feeDenom = feeDenom
this.sender = sender
}

}

class FeeRecords (hash: EntityID<String>): Entity<String>(hash) {
class FeeRecords (uuid: EntityID<UUID>): UUIDEntity(uuid) {
companion object: FeeEntityClass()

var hash by FeesTable.id
var uuid by FeesTable.id
var hash by FeesTable.hash
var txHash by FeesTable.txHash
var blockHeight by FeesTable.blockHeight
var blockTimestamp by FeesTable.blockTimestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tech.figure.aggregate.common.domain

import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.EntityClass
import org.jetbrains.exposed.dao.UUIDEntity
import org.jetbrains.exposed.dao.UUIDEntityClass
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.dao.id.UUIDTable
import java.time.OffsetDateTime
import java.util.UUID

object MarkerSupplyTable: IdTable<String>("marker_supply") {
object MarkerSupplyTable: UUIDTable("marker_supply", columnName = "uuid") {
val hash = text("hash")
val eventType = text("event_type")
val blockHeight = double("block_height")
Expand All @@ -23,14 +24,9 @@ object MarkerSupplyTable: IdTable<String>("marker_supply") {
val metadataDenomUnits = text("metadata_denom_units")
val metadataName = text("metadata_name")
val metadataSymbol = text("metadata_symbol")

override val id = hash.entityId()
}

open class MarkerSupplyEntityClass: EntityClass<String, MarkerSupplyRecord>(MarkerSupplyTable) {

private fun findByHash(hash: String) = find { MarkerSupplyTable.id eq hash }.firstOrNull()

open class MarkerSupplyEntityClass: UUIDEntityClass<MarkerSupplyRecord>(MarkerSupplyTable) {
fun insert(
hash: String,
eventType: String,
Expand All @@ -49,7 +45,8 @@ open class MarkerSupplyEntityClass: EntityClass<String, MarkerSupplyRecord>(Mark
metadataName: String,
metadataSymbol: String
) {
findByHash(hash) ?: new(hash) {
new(UUID.randomUUID()) {
this.hash = hash
this.eventType = eventType
this.blockHeight = blockHeight
this.blockTimestamp = blockTimestamp
Expand All @@ -69,11 +66,12 @@ open class MarkerSupplyEntityClass: EntityClass<String, MarkerSupplyRecord>(Mark
}
}

class MarkerSupplyRecord(hash: EntityID<String>): Entity<String>(hash) {
class MarkerSupplyRecord(uuid: EntityID<UUID>): UUIDEntity(uuid) {

companion object: MarkerSupplyEntityClass()

var hash by MarkerSupplyTable.id
var uuid by MarkerSupplyTable.id
var hash by MarkerSupplyTable.hash
var eventType by MarkerSupplyTable.eventType
var blockHeight by MarkerSupplyTable.blockHeight
var blockTimestamp by MarkerSupplyTable.blockTimestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tech.figure.aggregate.common.domain

import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.EntityClass
import org.jetbrains.exposed.dao.UUIDEntity
import org.jetbrains.exposed.dao.UUIDEntityClass
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.dao.id.UUIDTable
import java.time.OffsetDateTime
import java.util.UUID

object MarkerTransferTable: IdTable<String>("marker_transfer") {
object MarkerTransferTable: UUIDTable("marker_transfer", columnName = "uuid") {
val hash = text("hash")
val eventType = text("event_type")
val blockHeight = double("block_height")
Expand All @@ -16,14 +17,9 @@ object MarkerTransferTable: IdTable<String>("marker_transfer") {
val administrator = text("administrator")
val toAddress = text("to_address")
val fromAddress = text("from_address")

override val id = hash.entityId()
}

open class MarkerTransferEntityClass: EntityClass<String, MarkerTransferRecord>(MarkerTransferTable) {

private fun findByHash(hash: String) = find { MarkerTransferTable.id eq hash }.firstOrNull()

open class MarkerTransferEntityClass: UUIDEntityClass<MarkerTransferRecord>(MarkerTransferTable) {
fun insert(
hash: String,
eventType: String,
Expand All @@ -35,7 +31,8 @@ open class MarkerTransferEntityClass: EntityClass<String, MarkerTransferRecord>(
toAddress: String,
fromAddress: String
) {
findByHash(hash) ?: new(hash) {
new(UUID.randomUUID()) {
this.hash = hash
this.eventType = eventType
this.blockHeight = blockHeight
this.blockTimestamp = blockTimestamp
Expand All @@ -48,10 +45,11 @@ open class MarkerTransferEntityClass: EntityClass<String, MarkerTransferRecord>(
}
}

class MarkerTransferRecord(hash: EntityID<String>): Entity<String>(hash) {
class MarkerTransferRecord(uuid: EntityID<UUID>): UUIDEntity(uuid) {
companion object: MarkerTransferEntityClass()

var hash by MarkerTransferTable.id
var uuid by MarkerTransferTable.id
var hash by MarkerTransferTable.hash
var eventType by MarkerTransferTable.eventType
var blockHeight by MarkerTransferTable.blockHeight
var blockTimestamp by MarkerTransferTable.blockTimestamp
Expand Down
19 changes: 19 additions & 0 deletions migrations/sql/V2__UUID_AS_PRIMARY_KEY.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ALTER TABLE ATTRIBUTES ADD IF NOT EXISTS uuid UUID;
ALTER TABLE ATTRIBUTES DROP CONSTRAINT attributes_pkey;
ALTER TABLE ATTRIBUTES ADD PRIMARY KEY (uuid);

ALTER TABLE COIN_TRANSFER ADD IF NOT EXISTS uuid UUID;
ALTER TABLE COIN_TRANSFER DROP CONSTRAINT coin_transfer_pkey;
ALTER TABLE COIN_TRANSFER ADD PRIMARY KEY (uuid);

ALTER TABLE FEES ADD IF NOT EXISTS uuid UUID;
ALTER TABLE FEES DROP CONSTRAINT fees_pkey;
ALTER TABLE FEES ADD PRIMARY KEY (uuid);

ALTER TABLE MARKER_SUPPLY ADD IF NOT EXISTS uuid UUID;
ALTER TABLE MARKER_SUPPLY DROP CONSTRAINT marker_supply_pkey;
ALTER TABLE MARKER_SUPPLY ADD PRIMARY KEY (uuid);

ALTER TABLE MARKER_TRANSFER ADD IF NOT EXISTS uuid UUID;
ALTER TABLE MARKER_TRANSFER DROP CONSTRAINT marker_transfer_pkey;
ALTER TABLE MARKER_TRANSFER ADD PRIMARY KEY (uuid);
2 changes: 0 additions & 2 deletions src/main/kotlin/tech/figure/aggregate/service/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import tech.figure.aggregate.common.Config
import tech.figure.aggregate.common.recordMaxBlockHeight
import tech.figure.aggregate.common.unwrapEnvOrError
import tech.figure.aggregate.common.logger
import tech.figure.aggregate.common.models.UploadResult
import tech.figure.aggregate.service.stream.consumers.EventStreamUploader
Expand All @@ -30,7 +29,6 @@ import tech.figure.aggregate.repository.database.RavenDB
import tech.figure.block.api.client.BlockAPIClient
import tech.figure.block.api.proto.BlockServiceOuterClass
import tech.figure.block.api.proto.BlockServiceOuterClass.PREFER
import java.util.Properties
import kotlin.time.Duration
import io.grpc.internal.PickFirstLoadBalancerProvider
import kotlinx.coroutines.flow.catch
Expand Down

0 comments on commit 8da6452

Please sign in to comment.