Implement GetLastId with EntryInfo subscription

This commit is contained in:
Greg Fitzgerald
2018-05-03 13:29:54 -06:00
parent c9c7fb0a27
commit f752e02487
2 changed files with 1 additions and 17 deletions

View File

@ -43,7 +43,6 @@ pub struct AccountantSkel {
pub enum Request { pub enum Request {
Transaction(Transaction), Transaction(Transaction),
GetBalance { key: PublicKey }, GetBalance { key: PublicKey },
GetLastId,
Subscribe { subscriptions: Vec<Subscription> }, Subscribe { subscriptions: Vec<Subscription> },
} }
@ -75,7 +74,6 @@ type SharedSkel = Arc<AccountantSkel>;
pub enum Response { pub enum Response {
Balance { key: PublicKey, val: Option<i64> }, Balance { key: PublicKey, val: Option<i64> },
EntryInfo(EntryInfo), EntryInfo(EntryInfo),
LastId { id: Hash },
} }
impl AccountantSkel { impl AccountantSkel {
@ -216,12 +214,6 @@ impl AccountantSkel {
let val = self.acc.lock().unwrap().get_balance(&key); let val = self.acc.lock().unwrap().get_balance(&key);
Some((Response::Balance { key, val }, rsp_addr)) Some((Response::Balance { key, val }, rsp_addr))
} }
Request::GetLastId => Some((
Response::LastId {
id: self.acc.lock().unwrap().last_id(),
},
rsp_addr,
)),
Request::Transaction(_) => unreachable!(), Request::Transaction(_) => unreachable!(),
Request::Subscribe { subscriptions } => { Request::Subscribe { subscriptions } => {
for subscription in subscriptions { for subscription in subscriptions {

View File

@ -57,9 +57,6 @@ impl AccountantStub {
Response::Balance { key, val } => { Response::Balance { key, val } => {
self.balances.insert(key, val); self.balances.insert(key, val);
} }
Response::LastId { id } => {
self.last_id = Some(id);
}
Response::EntryInfo(entry_info) => { Response::EntryInfo(entry_info) => {
self.last_id = Some(entry_info.id); self.last_id = Some(entry_info.id);
self.num_events += entry_info.num_events; self.num_events += entry_info.num_events;
@ -111,15 +108,10 @@ impl AccountantStub {
/// Request the last Entry ID from the server. This method blocks /// Request the last Entry ID from the server. This method blocks
/// until the server sends a response. /// until the server sends a response.
pub fn get_last_id(&mut self) -> FutureResult<Hash, ()> { pub fn get_last_id(&mut self) -> FutureResult<Hash, ()> {
let req = Request::GetLastId;
let data = serialize(&req).expect("serialize GetId");
self.socket
.send_to(&data, &self.addr)
.expect("buffer error");
let mut done = false; let mut done = false;
while !done { while !done {
let resp = self.recv_response().expect("recv response"); let resp = self.recv_response().expect("recv response");
if let &Response::LastId { .. } = &resp { if let &Response::EntryInfo { .. } = &resp {
done = true; done = true;
} }
self.process_response(resp); self.process_response(resp);