Drop support for random access to the ledger
No longer store the ledger locally.
This commit is contained in:
parent
13206e4976
commit
7c9681007c
|
@ -19,7 +19,6 @@ use transaction::Transaction;
|
||||||
pub struct AccountantSkel<W: Write + Send + 'static> {
|
pub struct AccountantSkel<W: Write + Send + 'static> {
|
||||||
pub acc: Accountant,
|
pub acc: Accountant,
|
||||||
pub last_id: Hash,
|
pub last_id: Hash,
|
||||||
pub ledger: Vec<Entry>,
|
|
||||||
writer: W,
|
writer: W,
|
||||||
subscribers: Vec<TcpStream>,
|
subscribers: Vec<TcpStream>,
|
||||||
}
|
}
|
||||||
|
@ -29,7 +28,6 @@ pub struct AccountantSkel<W: Write + Send + 'static> {
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
Transaction(Transaction),
|
Transaction(Transaction),
|
||||||
GetBalance { key: PublicKey },
|
GetBalance { key: PublicKey },
|
||||||
GetEntries { last_id: Hash },
|
|
||||||
GetId { is_last: bool },
|
GetId { is_last: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +44,6 @@ impl<W: Write + Send + 'static> AccountantSkel<W> {
|
||||||
AccountantSkel {
|
AccountantSkel {
|
||||||
acc,
|
acc,
|
||||||
last_id,
|
last_id,
|
||||||
ledger: vec![],
|
|
||||||
writer: w,
|
writer: w,
|
||||||
subscribers: vec![],
|
subscribers: vec![],
|
||||||
}
|
}
|
||||||
|
@ -61,8 +58,6 @@ impl<W: Write + Send + 'static> AccountantSkel<W> {
|
||||||
// TODO: Handle errors. If TCP stream is closed, remove it.
|
// TODO: Handle errors. If TCP stream is closed, remove it.
|
||||||
serialize_into(subscriber, &entry).unwrap();
|
serialize_into(subscriber, &entry).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ledger.push(entry);
|
|
||||||
}
|
}
|
||||||
self.last_id
|
self.last_id
|
||||||
}
|
}
|
||||||
|
@ -79,17 +74,6 @@ impl<W: Write + Send + 'static> AccountantSkel<W> {
|
||||||
let val = self.acc.get_balance(&key);
|
let val = self.acc.get_balance(&key);
|
||||||
Some(Response::Balance { key, val })
|
Some(Response::Balance { key, val })
|
||||||
}
|
}
|
||||||
Request::GetEntries { last_id } => {
|
|
||||||
self.sync();
|
|
||||||
let entries = self.ledger
|
|
||||||
.iter()
|
|
||||||
.skip_while(|x| x.id != last_id) // log(n) way to find Entry with id == last_id.
|
|
||||||
.skip(1) // Skip the entry with last_id.
|
|
||||||
.take(256) // TODO: Take while the serialized entries fit into a 64k UDP packet.
|
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
Some(Response::Entries { entries })
|
|
||||||
}
|
|
||||||
Request::GetId { is_last } => Some(Response::Id {
|
Request::GetId { is_last } => Some(Response::Id {
|
||||||
id: if is_last {
|
id: if is_last {
|
||||||
self.sync()
|
self.sync()
|
||||||
|
|
Loading…
Reference in New Issue