From 2ef3f483136f1cd372f781c1491b4e1c0bf8f5b7 Mon Sep 17 00:00:00 2001 From: Ben Carman Date: Wed, 15 Jul 2020 14:09:44 -0500 Subject: [PATCH] Enforce unique outpoints for SpendingInfoDb (#1673) --- .../src/test/scala/org/bitcoins/db/DbManagementTest.scala | 2 +- .../wallet/migration/V6__unique_spendinginfodb_outpoint.sql | 1 + .../wallet/migration/V6__unique_spendinginfodb_outpoint.sql | 1 + .../main/scala/org/bitcoins/wallet/models/SpendingInfoDAO.scala | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 wallet/src/main/resources/postgresql/wallet/migration/V6__unique_spendinginfodb_outpoint.sql create mode 100644 wallet/src/main/resources/sqlite/wallet/migration/V6__unique_spendinginfodb_outpoint.sql diff --git a/db-commons-test/src/test/scala/org/bitcoins/db/DbManagementTest.scala b/db-commons-test/src/test/scala/org/bitcoins/db/DbManagementTest.scala index 68a924cde5..5a6ae4a292 100644 --- a/db-commons-test/src/test/scala/org/bitcoins/db/DbManagementTest.scala +++ b/db-commons-test/src/test/scala/org/bitcoins/db/DbManagementTest.scala @@ -58,7 +58,7 @@ class DbManagementTest extends BitcoinSAsyncTest with EmbeddedPg { dbConfig(ProjectType.Wallet)) val walletDbManagement = createWalletDbManagement(walletAppConfig) val result = walletDbManagement.migrate() - val expected = if (walletAppConfig.driverName == "postgresql") 2 else 5 + val expected = if (walletAppConfig.driverName == "postgresql") 3 else 6 assert(result == expected) } diff --git a/wallet/src/main/resources/postgresql/wallet/migration/V6__unique_spendinginfodb_outpoint.sql b/wallet/src/main/resources/postgresql/wallet/migration/V6__unique_spendinginfodb_outpoint.sql new file mode 100644 index 0000000000..bb409a4d7e --- /dev/null +++ b/wallet/src/main/resources/postgresql/wallet/migration/V6__unique_spendinginfodb_outpoint.sql @@ -0,0 +1 @@ +CREATE UNIQUE INDEX utxo_outpoints ON txo_spending_info (tx_outpoint); diff --git a/wallet/src/main/resources/sqlite/wallet/migration/V6__unique_spendinginfodb_outpoint.sql b/wallet/src/main/resources/sqlite/wallet/migration/V6__unique_spendinginfodb_outpoint.sql new file mode 100644 index 0000000000..0915f68a21 --- /dev/null +++ b/wallet/src/main/resources/sqlite/wallet/migration/V6__unique_spendinginfodb_outpoint.sql @@ -0,0 +1 @@ +CREATE UNIQUE INDEX "utxo_outpoints" ON "txo_spending_info" ("tx_outpoint"); diff --git a/wallet/src/main/scala/org/bitcoins/wallet/models/SpendingInfoDAO.scala b/wallet/src/main/scala/org/bitcoins/wallet/models/SpendingInfoDAO.scala index ccd85ec0ff..5c902938b9 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/models/SpendingInfoDAO.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/models/SpendingInfoDAO.scala @@ -203,7 +203,7 @@ case class SpendingInfoDAO()(implicit extends TableAutoInc[SpendingInfoDb](tag, "txo_spending_info") { def outPoint: Rep[TransactionOutPoint] = - column("tx_outpoint") + column("tx_outpoint", O.Unique) def txid: Rep[DoubleSha256DigestBE] = column("txid")