Implement GetLastId with EntryInfo subscription
This commit is contained in:
parent
c9c7fb0a27
commit
f752e02487
|
@ -43,7 +43,6 @@ pub struct AccountantSkel {
|
|||
pub enum Request {
|
||||
Transaction(Transaction),
|
||||
GetBalance { key: PublicKey },
|
||||
GetLastId,
|
||||
Subscribe { subscriptions: Vec<Subscription> },
|
||||
}
|
||||
|
||||
|
@ -75,7 +74,6 @@ type SharedSkel = Arc<AccountantSkel>;
|
|||
pub enum Response {
|
||||
Balance { key: PublicKey, val: Option<i64> },
|
||||
EntryInfo(EntryInfo),
|
||||
LastId { id: Hash },
|
||||
}
|
||||
|
||||
impl AccountantSkel {
|
||||
|
@ -216,12 +214,6 @@ impl AccountantSkel {
|
|||
let val = self.acc.lock().unwrap().get_balance(&key);
|
||||
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::Subscribe { subscriptions } => {
|
||||
for subscription in subscriptions {
|
||||
|
|
|
@ -57,9 +57,6 @@ impl AccountantStub {
|
|||
Response::Balance { key, val } => {
|
||||
self.balances.insert(key, val);
|
||||
}
|
||||
Response::LastId { id } => {
|
||||
self.last_id = Some(id);
|
||||
}
|
||||
Response::EntryInfo(entry_info) => {
|
||||
self.last_id = Some(entry_info.id);
|
||||
self.num_events += entry_info.num_events;
|
||||
|
@ -111,15 +108,10 @@ impl AccountantStub {
|
|||
/// Request the last Entry ID from the server. This method blocks
|
||||
/// until the server sends a response.
|
||||
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;
|
||||
while !done {
|
||||
let resp = self.recv_response().expect("recv response");
|
||||
if let &Response::LastId { .. } = &resp {
|
||||
if let &Response::EntryInfo { .. } = &resp {
|
||||
done = true;
|
||||
}
|
||||
self.process_response(resp);
|
||||
|
|
Loading…
Reference in New Issue