@@ -26,6 +26,7 @@ static SAVED_TRANSACTIONS_KEY: &str = "transactions";
26
26
static SETTLEMENT_ENGINES_KEY : & str = "settlement" ;
27
27
static LEDGER_KEY : & str = "ledger" ;
28
28
static ETHEREUM_KEY : & str = "eth" ;
29
+ static UNCREDITED_AMOUNT_KEY : & str = "uncredited_settlement_amount" ;
29
30
30
31
#[ derive( Clone , Debug , Serialize ) ]
31
32
pub struct Account {
@@ -56,6 +57,13 @@ fn ethereum_ledger_key(account_id: u64) -> String {
56
57
)
57
58
}
58
59
60
+ fn ethereum_uncredited_amount_key ( account_id : String ) -> String {
61
+ format ! (
62
+ "{}:{}:{}:{}" ,
63
+ ETHEREUM_KEY , LEDGER_KEY , UNCREDITED_AMOUNT_KEY , account_id,
64
+ )
65
+ }
66
+
59
67
impl EthereumAccount for Account {
60
68
fn token_address ( & self ) -> Option < EthAddress > {
61
69
self . token_address
@@ -123,8 +131,12 @@ impl LeftoversStore for EthereumLedgerRedisStore {
123
131
uncredited_settlement_amount
124
132
) ;
125
133
let mut pipe = redis:: pipe ( ) ;
134
+ // We store these amounts as lists of strings
135
+ // because we cannot do BigNumber arithmetic in the store
136
+ // When loading the amounts, we convert them to the appropriate data
137
+ // type and sum them up.
126
138
pipe. lpush (
127
- format ! ( "uncredited_settlement_amount:{}" , account_id) ,
139
+ ethereum_uncredited_amount_key ( account_id. clone ( ) ) ,
128
140
uncredited_settlement_amount. to_string ( ) ,
129
141
)
130
142
. ignore ( ) ;
@@ -147,11 +159,7 @@ impl LeftoversStore for EthereumLedgerRedisStore {
147
159
trace ! ( "Loading uncredited_settlement_amount {:?}" , account_id) ;
148
160
let mut pipe = redis:: pipe ( ) ;
149
161
// Loads the value and resets it to 0
150
- pipe. lrange (
151
- format ! ( "uncredited_settlement_amount:{}" , account_id) ,
152
- 0 ,
153
- -1 ,
154
- ) ;
162
+ pipe. lrange ( ethereum_uncredited_amount_key ( account_id. clone ( ) ) , 0 , -1 ) ;
155
163
pipe. del ( format ! ( "uncredited_settlement_amount:{}" , account_id) )
156
164
. ignore ( ) ;
157
165
Box :: new (
0 commit comments