@@ -11,6 +11,8 @@ use tokio_postgres::{
11
11
use super :: { DbPool , PoolError } ;
12
12
use thiserror:: Error ;
13
13
14
+ static UPDATE_ACCOUNTING_STATEMENT : & str = "INSERT INTO accounting(channel_id, side, address, amount, updated, created) VALUES($1, $2, $3, $4, $5, $6) ON CONFLICT ON CONSTRAINT accounting_pkey DO UPDATE SET amount = accounting.amount + $4, updated = $6 WHERE accounting.channel_id = $1 AND accounting.side = $2 AND accounting.address = $3 RETURNING channel_id, side, address, amount, updated, created" ;
15
+
14
16
#[ derive( Debug , Error ) ]
15
17
pub enum Error {
16
18
#[ error( "Accounting Balances error: {0}" ) ]
@@ -84,7 +86,6 @@ pub async fn get_accounting(
84
86
/// Will update current Spender/Earner amount or insert a new Accounting record
85
87
///
86
88
/// See `UPDATE_ACCOUNTING_STATEMENT` static for full query.
87
- static UPDATE_ACCOUNTING_STATEMENT : & str = "INSERT INTO accounting(channel_id, side, address, amount, updated, created) VALUES($1, $2, $3, $4, $5, $6) ON CONFLICT ON CONSTRAINT accounting_pkey DO UPDATE SET amount = accounting.amount + $4, updated = $6 WHERE accounting.channel_id = $1 AND accounting.side = $2 AND accounting.address = $3 RETURNING channel_id, side, address, amount, updated, created" ;
88
89
pub async fn update_accounting (
89
90
pool : DbPool ,
90
91
channel_id : ChannelId ,
@@ -204,7 +205,7 @@ mod test {
204
205
. expect ( "Should insert" ) ;
205
206
assert_eq ! ( spender, inserted. address) ;
206
207
assert_eq ! ( Side :: Spender , inserted. side) ;
207
- assert_eq ! ( UnifiedNum :: from ( 100_000_000 ) , inserted. amount) ;
208
+ assert_eq ! ( amount , inserted. amount) ;
208
209
209
210
let updated = update_accounting (
210
211
database. pool . clone ( ) ,
@@ -218,7 +219,7 @@ mod test {
218
219
assert_eq ! ( spender, updated. address) ;
219
220
assert_eq ! ( Side :: Spender , updated. side) ;
220
221
assert_eq ! (
221
- UnifiedNum :: from ( 300_000_000 ) ,
222
+ amount + update_amount ,
222
223
updated. amount,
223
224
"Should add the newly spent amount to the existing one"
224
225
) ;
@@ -247,7 +248,7 @@ mod test {
247
248
. expect ( "Should insert" ) ;
248
249
assert_eq ! ( earner, inserted. address) ;
249
250
assert_eq ! ( Side :: Earner , inserted. side) ;
250
- assert_eq ! ( UnifiedNum :: from ( 100_000_000 ) , inserted. amount) ;
251
+ assert_eq ! ( amount , inserted. amount) ;
251
252
252
253
let updated = update_accounting (
253
254
database. pool . clone ( ) ,
@@ -261,7 +262,7 @@ mod test {
261
262
assert_eq ! ( earner, updated. address) ;
262
263
assert_eq ! ( Side :: Earner , updated. side) ;
263
264
assert_eq ! (
264
- UnifiedNum :: from ( 300_000_000 ) ,
265
+ amount + update_amount ,
265
266
updated. amount,
266
267
"Should add the newly earned amount to the existing one"
267
268
) ;
@@ -293,7 +294,7 @@ mod test {
293
294
. expect ( "Should insert" ) ;
294
295
assert_eq ! ( spender_as_earner, inserted. address) ;
295
296
assert_eq ! ( Side :: Earner , inserted. side) ;
296
- assert_eq ! ( UnifiedNum :: from ( 100_000_000 ) , inserted. amount) ;
297
+ assert_eq ! ( amount , inserted. amount) ;
297
298
298
299
let updated = update_accounting (
299
300
database. pool . clone ( ) ,
0 commit comments