Skip to main content

EventSet

Struct EventSet 

Source
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

Source

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.

Source

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.

Source

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

Source

pub fn new() -> Self

An empty set.

Source

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).

Source

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.

Source

pub fn merge(&mut self, other: &EventSet) -> usize

Adds all events of another set; returns how many were new.

Source

pub fn get(&self, hash: &EventHash) -> Option<&Event>

The event with this hash.

Source

pub fn canonical(&self, hash: &EventHash) -> Option<&[u8]>

The canonical encoding of the event with this hash – what is passed on to other devices.

Source

pub fn len(&self) -> usize

The number of events.

Source

pub fn is_empty(&self) -> bool

Whether there are no events.

Source

pub fn ordered(&self) -> Vec<(EventHash, &Event)>

All events in the order every device agrees on: by timestamp, then by hash.

Source

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.

Source

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.

Source

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.

Source

pub fn parties( &self, ) -> (BTreeMap<&PartyId, &Organisation>, BTreeMap<&PartyId, &Person>)

The organisations and persons as last described, in the agreed order of events.

Source

pub fn owners(&self) -> Vec<&PartyId>

The owners of the books – organisations and persons – after all additions and removals, in order.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for EventSet

Source§

fn clone(&self) -> EventSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EventSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EventSet

Source§

fn default() -> EventSet

Returns the “default value” for a type. Read more
Source§

impl Eq for EventSet

Source§

impl PartialEq for EventSet

Source§

fn eq(&self, other: &EventSet) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for EventSet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.