Entries and the chain

Every movement of money appends an entry to a hash chain kept in the book.

What an entry is

An entry records one deposit, withdrawal, spend or payment in. It is not stored as an account. The program emits it as an Entry event and folds it into a single 32-byte head stored in the book.

kindNameWritten by
0Depositdeposit
1Withdrawwithdraw
2Spendspend
3Earnearn

How an entry is folded in

The new head is the SHA-256 of the old head followed by the entry's fields:

head' = sha256(
  head           // 32 bytes
  index          // u64, little endian
  kind, category // 1 byte each
  amount         // u64, little endian
  agent          // 32 bytes: the wallet's address, or zero for owner moves
  counterparty   // 32 bytes: payee token account, payer, or owner
  memo           // 32 bytes
  ts             // i64, little endian
)

A new book's head is 32 zero bytes. index starts at 0 and goes up by one per entry.

The memo

A spend and a payment in each carry a 32-byte memo: the hash of the offchain receipt for what was bought or delivered. The program does not check it. It is there so an entry can later be matched to an invoice or a routed call.

Reading entries back

Because entries are events, a reader gets them from the book's transaction logs. A node only keeps those logs for a while, so anything that needs the full history has to store the events as they happen. The app reads them from the node directly today.

SealsVerify a bookEntry event fields

NextSeals