Skip to content

Commit 313afb5

Browse files
committed
server: Remove corrupted balance logs
As #5 has been closed because the balances tables hasn't been corrupted again, the logs are unnecessary now.
1 parent f10e0ad commit 313afb5

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

server/app/com/xsn/explorer/data/anorm/dao/BalancePostgresDAO.scala

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import anorm._
77
import com.alexitc.playsonify.models.{Count, FieldOrdering, PaginatedQuery}
88
import com.xsn.explorer.data.anorm.interpreters.FieldOrderingSQLInterpreter
99
import com.xsn.explorer.data.anorm.parsers.BalanceParsers._
10+
import com.xsn.explorer.models.Balance
1011
import com.xsn.explorer.models.fields.BalanceField
11-
import com.xsn.explorer.models.{Address, Balance}
1212
import org.slf4j.LoggerFactory
1313

1414
class BalancePostgresDAO @Inject() (fieldOrderingSQLInterpreter: FieldOrderingSQLInterpreter) {
@@ -17,13 +17,9 @@ class BalancePostgresDAO @Inject() (fieldOrderingSQLInterpreter: FieldOrderingSQ
1717

1818
/**
1919
* create or update the balance for an address
20-
*
21-
* NOTE: ensure the connection has an open transaction, this is required
22-
* until the debug log is removed.
2320
*/
2421
def upsert(partial: Balance)(implicit conn: Connection): Option[Balance] = {
25-
val computedMaybe = computeBalance(partial.address)
26-
val updatedBalance = SQL(
22+
SQL(
2723
"""
2824
|INSERT INTO balances
2925
| (address, received, spent)
@@ -39,35 +35,6 @@ class BalancePostgresDAO @Inject() (fieldOrderingSQLInterpreter: FieldOrderingSQ
3935
'received -> partial.received,
4036
'spent -> partial.spent,
4137
).as(parseBalance.singleOpt).flatten
42-
43-
for {
44-
balance <- updatedBalance
45-
computed <- computedMaybe if computed != balance
46-
} {
47-
logger.warn(s"CORRUPTED_BALANCE, expected spent = ${computed.spent}, actual = ${balance.spent}, expected received = ${computed.received}, actual = ${balance.received}")
48-
}
49-
50-
updatedBalance
51-
}
52-
53-
private def computeBalance(address: Address)(implicit conn: Connection) = {
54-
SQL(
55-
"""
56-
|SELECT {address} AS address,
57-
| (
58-
| SELECT COALESCE(SUM(value), 0)
59-
| FROM transaction_inputs
60-
| WHERE address = {address}
61-
| ) AS spent,
62-
| (
63-
| SELECT COALESCE(SUM(value), 0)
64-
| FROM transaction_outputs
65-
| WHERE address = {address}
66-
| ) AS received
67-
""".stripMargin
68-
).on(
69-
'address -> address.string
70-
).as(parseBalance.single)
7138
}
7239

7340
def get(

0 commit comments

Comments
 (0)