Layr8.Delegated (layr8 v0.3.3)

Copy Markdown View Source

What a join reply says about the parent's wallet.

The node sends an object rather than a bare list precisely so that :unread has a value of its own. When it was a list, an unreadable wallet arrived as [] — the same value that means "read, and it grants nothing" — and that is the reassuring one of the two: a client acting on it sends its messages bare and gets back a denial naming a grant.

Summary

Functions

A join reply's delegated_credentials.revision, or 0 when an older node sent none.

A join reply's delegated_credentials, or nil if it is not a reading.

A pushed delegated_credentials event as {:ok, reading, revision}, or :error if it is not one to apply.

The capability a node announces when it pushes a replacement reading to a live borrowed child whose join asked for it with delegation_refresh: true.

Functions

join_revision(raw)

@spec join_revision(term()) :: non_neg_integer()

A join reply's delegated_credentials.revision, or 0 when an older node sent none.

parse(raw)

@spec parse(term()) :: Layr8.Delegated.Reading.t() | nil

A join reply's delegated_credentials, or nil if it is not a reading.

Anything that is not a well-formed reading — absent, a list (an older node, before status existed), a status this build does not know — is nil, which means "no reading". It is never coerced into %Reading{status: :complete, credentials: []}: that would state that a wallet was read and grants nothing, which is the one thing none of those inputs says.

parse_push(raw)

@spec parse_push(term()) ::
  {:ok, Layr8.Delegated.Reading.t(), non_neg_integer()} | :error

A pushed delegated_credentials event as {:ok, reading, revision}, or :error if it is not one to apply.

The payload is the join reply's reading plus revision, so it goes through parse/1. On top of that:

  • revision must be a non-negative integer. Without it a consumer cannot tell a late push from a new one.
  • status: "unread" is never pushed by the node: a refresh whose read failed sends nothing, and the last reading stands. A push that says unread anyway is dropped rather than applied, because applying it would replace a set that came from a real read with an [] that measures nothing, and take working authority away.

refresh_capability()

@spec refresh_capability() :: String.t()

The capability a node announces when it pushes a replacement reading to a live borrowed child whose join asked for it with delegation_refresh: true.