Skip to content

Commit 0e4eb4a

Browse files
committed
eth-engine: implement LeftoversStore for tests
1 parent beeb4da commit 0e4eb4a

File tree

2 files changed

+31
-2
lines changed
  • crates/interledger-settlement-engines/src

2 files changed

+31
-2
lines changed

crates/interledger-settlement-engines/src/engines/ethereum_ledger/test_helpers.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ pub struct TestStore {
6161
pub last_observed_block: Arc<RwLock<U256>>,
6262
pub saved_hashes: Arc<RwLock<HashMap<H256, bool>>>,
6363
pub cache_hits: Arc<RwLock<u64>>,
64+
pub leftovers: Arc<RwLock<HashMap<String, String>>>,
65+
}
66+
67+
use crate::stores::LeftoversStore;
68+
use num_bigint::BigUint;
69+
impl LeftoversStore for TestStore {
70+
fn save_leftovers(
71+
&self,
72+
account_id: String,
73+
leftovers: BigUint,
74+
) -> Box<Future<Item = (), Error = ()> + Send> {
75+
Box::new(ok(()))
76+
}
6477
}
6578

6679
impl EthereumStore for TestStore {
@@ -236,6 +249,7 @@ impl TestStore {
236249
cache_hits: Arc::new(RwLock::new(0)),
237250
last_observed_block: Arc::new(RwLock::new(U256::from(0))),
238251
saved_hashes: Arc::new(RwLock::new(HashMap::new())),
252+
leftovers: Arc::new(RwLock::new(HashMap::new())),
239253
}
240254
}
241255
}
@@ -263,7 +277,13 @@ pub fn test_engine<Si, S, A>(
263277
) -> EthereumLedgerSettlementEngine<S, Si, A>
264278
where
265279
Si: EthereumLedgerTxSigner + Clone + Send + Sync + 'static,
266-
S: EthereumStore<Account = A> + IdempotentStore + Clone + Send + Sync + 'static,
280+
S: EthereumStore<Account = A>
281+
+ LeftoversStore
282+
+ IdempotentStore
283+
+ Clone
284+
+ Send
285+
+ Sync
286+
+ 'static,
267287
A: EthereumAccount + Send + Sync + 'static,
268288
{
269289
EthereumLedgerSettlementEngineBuilder::new(store, key)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,16 @@ impl EthereumLedgerRedisStore {
109109

110110
impl LeftoversStore for EthereumLedgerRedisStore {
111111
fn save_leftovers(&self, account_id: String, leftovers: BigUint) -> Box<dyn Future<Item = (), Error = ()> + Send> {
112-
Box::new(ok(()))
112+
let mut pipe = redis::pipe();
113+
pipe.set(format!("leftovers:{}", account_id), leftovers.to_string())
114+
.ignore();
115+
Box::new(
116+
pipe.query_async(self.connection.clone())
117+
.map_err(move |err| {
118+
error!("Error saving leftovers {:?}: {:?}", leftovers, err)
119+
})
120+
.and_then(move |(_conn, _ret): (_, Value)| Ok(())),
121+
)
113122
}
114123
}
115124

0 commit comments

Comments
 (0)