Skip to content

Commit 0d5a477

Browse files
committed
chore: prefix uncredited amount key
1 parent 27e451f commit 0d5a477

File tree

1 file changed

+14
-6
lines changed
  • crates/interledger-settlement-engines/src/stores/redis_ethereum_ledger

1 file changed

+14
-6
lines changed

crates/interledger-settlement-engines/src/stores/redis_ethereum_ledger/store.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static SAVED_TRANSACTIONS_KEY: &str = "transactions";
2626
static SETTLEMENT_ENGINES_KEY: &str = "settlement";
2727
static LEDGER_KEY: &str = "ledger";
2828
static ETHEREUM_KEY: &str = "eth";
29+
static UNCREDITED_AMOUNT_KEY: &str = "uncredited_settlement_amount";
2930

3031
#[derive(Clone, Debug, Serialize)]
3132
pub struct Account {
@@ -56,6 +57,13 @@ fn ethereum_ledger_key(account_id: u64) -> String {
5657
)
5758
}
5859

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+
5967
impl EthereumAccount for Account {
6068
fn token_address(&self) -> Option<EthAddress> {
6169
self.token_address
@@ -123,8 +131,12 @@ impl LeftoversStore for EthereumLedgerRedisStore {
123131
uncredited_settlement_amount
124132
);
125133
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.
126138
pipe.lpush(
127-
format!("uncredited_settlement_amount:{}", account_id),
139+
ethereum_uncredited_amount_key(account_id.clone()),
128140
uncredited_settlement_amount.to_string(),
129141
)
130142
.ignore();
@@ -147,11 +159,7 @@ impl LeftoversStore for EthereumLedgerRedisStore {
147159
trace!("Loading uncredited_settlement_amount {:?}", account_id);
148160
let mut pipe = redis::pipe();
149161
// 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);
155163
pipe.del(format!("uncredited_settlement_amount:{}", account_id))
156164
.ignore();
157165
Box::new(

0 commit comments

Comments
 (0)