Spectre.GAM.Ledger.Entry (Spectre v0.4.0)

Copy Markdown View Source

One immutable record in a Domain ledger.

Entries are numbered from one and form a SHA-256 chain. The digest covers the Domain, revision, batch coordinates, trusted recording time, previous digest, and payload. The payload must be a plain portable map; executable values and structs are rejected by Spectre.GAM.Canonical.Value.

Entry structs are an in-memory convenience only. The durable form returned by to_data/1 is a plain map with string keys.

Summary

Functions

Computes the stable identity of a logical batch request.

Builds a complete linked batch after validating its portable payloads.

Decodes and verifies canonical Entry bytes.

Encodes an Entry with the canonical value codec.

Restores and verifies an Entry from its plain-map durable form.

Returns the fixed predecessor digest used by revision one.

Returns the maximum number of entries accepted in one atomic batch.

Builds and validates an Entry from its complete durable fields.

Returns the durable Entry schema version.

Returns the plain-map durable representation of an Entry.

Verifies that an Entry digest exactly matches its durable contents.

Verifies a contiguous chain without consulting a projection or store.

Types

digest()

@type digest() :: <<_::512>>

t()

@type t() :: %Spectre.GAM.Ledger.Entry{
  batch_id: String.t(),
  batch_index: non_neg_integer(),
  batch_size: pos_integer(),
  digest: digest(),
  domain_ref: String.t(),
  payload: map(),
  prev_digest: digest(),
  recorded_at: non_neg_integer(),
  revision: pos_integer(),
  schema_version: pos_integer()
}

Functions

batch_identity(domain_ref, batch_id, payloads, expected_revision)

@spec batch_identity(String.t(), String.t(), [map()], non_neg_integer()) ::
  {:ok, digest()} | {:error, term()}

Computes the stable identity of a logical batch request.

build(domain_ref, revision, batch_id, batch_index, batch_size, recorded_at, prev_digest, payload)

@spec build(
  String.t(),
  pos_integer(),
  String.t(),
  non_neg_integer(),
  pos_integer(),
  non_neg_integer(),
  digest(),
  map()
) :: {:ok, t()} | {:error, term()}

Builds a new Entry and computes its canonical digest.

build_batch(domain_ref, batch_id, payloads, expected_revision, recorded_at, prev_digest)

@spec build_batch(
  String.t(),
  String.t(),
  [map()],
  non_neg_integer(),
  non_neg_integer(),
  digest()
) :: {:ok, [t()]} | {:error, term()}

Builds a complete linked batch after validating its portable payloads.

decode(encoded)

@spec decode(binary()) :: {:ok, t()} | {:error, term()}

Decodes and verifies canonical Entry bytes.

encode(entry)

@spec encode(t()) :: {:ok, binary()} | {:error, term()}

Encodes an Entry with the canonical value codec.

from_data(data)

@spec from_data(map()) :: {:ok, t()} | {:error, term()}

Restores and verifies an Entry from its plain-map durable form.

genesis_digest()

@spec genesis_digest() :: digest()

Returns the fixed predecessor digest used by revision one.

max_batch_entries()

@spec max_batch_entries() :: pos_integer()

Returns the maximum number of entries accepted in one atomic batch.

new(entry)

@spec new(t() | map() | keyword()) :: {:ok, t()} | {:error, term()}

Builds and validates an Entry from its complete durable fields.

schema_version()

@spec schema_version() :: pos_integer()

Returns the durable Entry schema version.

to_data(entry)

@spec to_data(t()) :: map()

Returns the plain-map durable representation of an Entry.

verify(entry)

@spec verify(t()) :: :ok | {:error, term()}

Verifies that an Entry digest exactly matches its durable contents.

verify_chain(entries, opts \\ [])

@spec verify_chain(
  [t() | map()],
  keyword()
) :: {:ok, map()} | {:error, term()}

Verifies a contiguous chain without consulting a projection or store.