pub struct EventSet { /* private fields */ }Expand description
A set of events – the books as they are known on one device. Merging is set union, in any order, any number of times, with the same result.
Every event is kept in its canonical encoding as well as read: the encoding is what is hashed and what is passed on, so members a later version adds survive this one unchanged.
Implementations§
Source§impl EventSet
impl EventSet
Sourcepub fn balances(&self, until: Option<Date>) -> Result<Balances, BalanceError>
pub fn balances(&self, until: Option<Date>) -> Result<Balances, BalanceError>
The balances of all bookings – recorded and reversing – dated on or before until, or of all bookings.
Sourcepub fn account_parents(&self, chart: &Chart) -> BTreeMap<AccountId, AccountId>
pub fn account_parents(&self, chart: &Chart) -> BTreeMap<AccountId, AccountId>
Which account each account refines: the accounts of chart and those opened in the books.
Sourcepub fn trial_balance(
&self,
chart: &Chart,
until: Option<Date>,
) -> Result<Balances, BalanceError>
pub fn trial_balance( &self, chart: &Chart, until: Option<Date>, ) -> Result<Balances, BalanceError>
A trial balance: the balances on or before until, rolled up the hierarchy of chart and the opened
accounts.
Source§impl EventSet
impl EventSet
Sourcepub fn insert(&mut self, event: Event) -> (EventHash, bool)
pub fn insert(&mut self, event: Event) -> (EventHash, bool)
Adds an event written on this device; returns its hash and whether it was new.
§Panics
If the event has no canonical encoding: an integer above 2^53 − 1, or a Payload::Unknown (which can only
be received).
Sourcepub fn receive(&mut self, json: &[u8]) -> Result<(EventHash, bool), ObjectError>
pub fn receive(&mut self, json: &[u8]) -> Result<(EventHash, bool), ObjectError>
Adds an event received as JSON, in any formatting; returns its hash and whether it was new. The hash is taken over the canonical encoding of what was received, members this version does not know included.
Sourcepub fn merge(&mut self, other: &EventSet) -> usize
pub fn merge(&mut self, other: &EventSet) -> usize
Adds all events of another set; returns how many were new.
Sourcepub fn canonical(&self, hash: &EventHash) -> Option<&[u8]>
pub fn canonical(&self, hash: &EventHash) -> Option<&[u8]>
The canonical encoding of the event with this hash – what is passed on to other devices.
Sourcepub fn ordered(&self) -> Vec<(EventHash, &Event)>
pub fn ordered(&self) -> Vec<(EventHash, &Event)>
All events in the order every device agrees on: by timestamp, then by hash.
Sourcepub fn chain_head(&self, device: &DeviceId) -> (u64, Option<EventHash>)
pub fn chain_head(&self, device: &DeviceId) -> (u64, Option<EventHash>)
The next position and previous hash for a new event of device, if its chain is clean.
Sourcepub fn selected_charts(&self) -> Vec<&str>
pub fn selected_charts(&self) -> Vec<&str>
The charts the books selected, in the agreed order of events, each once. More than one is for review.
Sourcepub fn review_accounts(&self, chart: &Chart) -> Vec<AccountProblem>
pub fn review_accounts(&self, chart: &Chart) -> Vec<AccountProblem>
Checks the accounts against chart and the accounts opened in the books: every opened account refines a
known account of the same kind and is opened once; every posting is on a known account.
Sourcepub fn parties(
&self,
) -> (BTreeMap<&PartyId, &Organisation>, BTreeMap<&PartyId, &Person>)
pub fn parties( &self, ) -> (BTreeMap<&PartyId, &Organisation>, BTreeMap<&PartyId, &Person>)
The organisations and persons as last described, in the agreed order of events.
Sourcepub fn owners(&self) -> Vec<&PartyId>
pub fn owners(&self) -> Vec<&PartyId>
The owners of the books – organisations and persons – after all additions and removals, in order.
Sourcepub fn review_parties(&self) -> Vec<PartyProblem>
pub fn review_parties(&self) -> Vec<PartyProblem>
Checks the parties: the books belong to at least one organisation or person, every owner is described, every organisation a person has a role in is described, the shares held fit the shares an organisation has, and every posting is in the books of an owner.
Sourcepub fn state(&self) -> ContentHash
pub fn state(&self) -> ContentHash
The state of the books: the SHA-256 hash of the canonical encoding of the array of all event hashes in the agreed order. Whatever is derived from the books – a filing, a report – records the state it was derived from.
Sourcepub fn review_documents(&self) -> Vec<DocumentProblem>
pub fn review_documents(&self) -> Vec<DocumentProblem>
Checks the documents: each recorded once, and every document a booking is based on recorded. Whether the bytes of the originals are at hand is a question of the store, not of the events.
Sourcepub fn verify(&self) -> Vec<ChainProblem>
pub fn verify(&self) -> Vec<ChainProblem>
Checks every device’s chain: one event per position, no gaps, each event pointing to its predecessor.
Source§impl EventSet
impl EventSet
Sourcepub fn tax_report(
&self,
mapping: &ReportMapping,
taxes: &TaxTable,
chart: &Chart,
owner: &PartyId,
from: Date,
to: Date,
) -> Result<BTreeMap<String, i128>, BalanceError>
pub fn tax_report( &self, mapping: &ReportMapping, taxes: &TaxTable, chart: &Chart, owner: &PartyId, from: Date, to: Date, ) -> Result<BTreeMap<String, i128>, BalanceError>
The fields of a report computed from tax codes – a VAT return – for owner, over the bookings dated from
from to to inclusive. Amounts are in base units and positive as the form expects them: net amounts and
VAT owed of sales as credit, net amounts of purchases and deductible VAT as debit.
Sourcepub fn account_report(
&self,
mapping: &ReportMapping,
chart: &Chart,
owner: &PartyId,
until: Option<Date>,
) -> Result<BTreeMap<String, i128>, BalanceError>
pub fn account_report( &self, mapping: &ReportMapping, chart: &Chart, owner: &PartyId, until: Option<Date>, ) -> Result<BTreeMap<String, i128>, BalanceError>
The positions of a report computed from accounts – a balance sheet, a profit and loss account – for owner
on until: per position, the sum of the balances of the accounts that fall into it, in base units, debit
positive. Accounts without a position are left out.