Skip to content

Commit

Permalink
improve redis keys naming
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed Jul 22, 2019
1 parent f9802a9 commit 27a837d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ where
let self_clone = self.clone();
// Skip transactions which have already been credited to the connector
store.check_tx_credited(tx_hash)
.map_err(move |_| error!("Transaction {} has already been credited!", tx_hash))
.map_err(move |_| error!("Error when querying store about transaction: {:?}", tx_hash))
.and_then(move |credited| {
if !credited {
Either::A(
Expand Down Expand Up @@ -362,6 +362,8 @@ where
self_clone.notify_connector(id.to_string(), amount.low_u64())
})
.and_then(move |_| {
// only save the transaction hash if the connector
// was successfully notified
store.credit_tx(tx_hash)
}))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::stores::redis_store::{EngineRedisStore, EngineRedisStoreBuilder};
// avoid double crediting transactions which have already been processed, and in
// order to resume watching from the last observed point.
static RECENTLY_OBSERVED_DATA_KEY: &str = "recently_observed_data";
static SAVED_TRANSACTIONS_KEY: &str = "transactions";
static SETTLEMENT_ENGINES_KEY: &str = "settlement";
static LEDGER_KEY: &str = "ledger";
static ETHEREUM_KEY: &str = "eth";
Expand All @@ -37,10 +38,18 @@ impl AccountTrait for Account {
}
}

fn ethereum_transactions_key(tx_hash: H256) -> String {
format!(
"{}:{}:{}:{}",
ETHEREUM_KEY, LEDGER_KEY, SAVED_TRANSACTIONS_KEY, tx_hash,
)
}


fn ethereum_ledger_key(account_id: u64) -> String {
format!(
"{}:{}:{}:{}",
SETTLEMENT_ENGINES_KEY, LEDGER_KEY, ETHEREUM_KEY, account_id
ETHEREUM_KEY, LEDGER_KEY, SETTLEMENT_ENGINES_KEY, account_id
)
}

Expand Down Expand Up @@ -226,7 +235,7 @@ impl EthereumStore for EthereumLedgerRedisStore {
fn check_tx_credited(&self, tx_hash: H256) -> Box<dyn Future<Item = bool, Error = ()> + Send> {
Box::new(
cmd("EXISTS")
.arg(tx_hash.to_string())
.arg(ethereum_transactions_key(tx_hash))
.arg(true)
.query_async(self.connection.clone())
.map_err(move |err| error!("Error loading account data: {:?}", err))
Expand All @@ -245,7 +254,7 @@ impl EthereumStore for EthereumLedgerRedisStore {
fn credit_tx(&self, tx_hash: H256) -> Box<dyn Future<Item = (), Error = ()> + Send> {
Box::new(
cmd("SETNX")
.arg(tx_hash.to_string())
.arg(ethereum_transactions_key(tx_hash))
.arg(true)
.query_async(self.connection.clone())
.map_err(move |err| error!("Error loading account data: {:?}", err))
Expand Down

0 comments on commit 27a837d

Please sign in to comment.