PrismStateMongoDB

fmgp.did.method.prism.PrismStateMongoDB
See thePrismStateMongoDB companion object
case class PrismStateMongoDB(reactiveMongoApi: ReactiveMongoApi) extends PrismState

MongoDB-backed implementation of PrismState for production use.

This implementation uses a sophisticated two-collection strategy to Debug out-of-order blockchain events:

==Collections==

'''Main Collection (events):''' Stores events with known parent relationships. Each event is stored with a rootRef field that tracks the root event (Create operation) of its chain. This enables efficient querying of all events for a DID or VDR by querying on the rootRef field.

'''Lost Collection (events_lost):''' Stores orphaned events whose parent (referenced via previousEventHash) has not yet been seen. This handles the case where Update or Deactivate operations arrive before their corresponding Create operation.

==Event Chain Tracking==

Events form chains through previousEventHash references:

  • Create operations (CreateDidOP, CreateStorageEntryOP) start chains and have no previous hash
  • Update/Deactivate operations reference the previous event's hash
  • All events in a chain share the same rootRef (the hash of the Create event)

When adding an event:

  1. If it has no previousEventHash, it's inserted with rootRef = eventHash
  2. If it has a previousEventHash, we search for the parent event
  3. If parent exists, event is inserted with parent's rootRef
  4. If parent is missing, event goes to lost collection for potential later recovery

Value parameters

reactiveMongoApi

MongoDB connection wrapper using ReactiveMongo driver

Attributes

Constructor

Creates a MongoDB-backed PRISM state

Example
val mongoApi: ReactiveMongoApi = ???
val state = PrismStateMongoDB(mongoApi)
for {
 _ <- state.addEvent(createEvent)
 _ <- state.addEvent(updateEvent)
 ssi <- state.getSSI(didSubject)
} yield ssi
Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait PrismState
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def addEvent(event: MySignedPrismEvent[OP]): ZIO[Any, Exception, Unit]

Adds event to MongoDB with automatic rootRef tracking.

Adds event to MongoDB with automatic rootRef tracking.

Implements two-collection strategy:

  • Events with no previousEventHash (Create ops) go to main collection with rootRef = eventHash
  • Events with previousEventHash look up the parent:
    • If parent exists, event goes to main collection with parent's rootRef
    • If parent missing, event goes to lost collection

Attributes

Note

VoidOP operations are not supported and will fail with RuntimeException

Definition Classes

Returns the main events MongoDB collection.

Returns the main events MongoDB collection.

Attributes

Name of the main events collection.

Name of the main events collection.

Attributes

override def cursor: ZIO[Any, Nothing, EventCursor]

Returns the cursor of the latest event stored in the database.

Returns the cursor of the latest event stored in the database.

Uses MongoDB sort to efficiently find the maximum EventCursor by (b, o) indices. If no events exist, returns EventCursor.init (-1, -1).

Attributes

Definition Classes
override def getEventByHash(refHash: EventHash): ZIO[Any, Exception, Option[MySignedPrismEvent[OP]]]

Gets a specific event by its EventHash.

Gets a specific event by its EventHash.

Attributes

Definition Classes

Fetches all events in the chain for the given DID.

Fetches all events in the chain for the given DID.

Attributes

Returns

ZIO effect that may fail with Throwable (RuntimeException if event hash missing or type validation fails) and succeeds with sequence of DID-related MySignedPrismEvent

Definition Classes

Fetches all events in the chain for the given VDR reference.

Fetches all events in the chain for the given VDR reference.

Value parameters

refVDR

The VDR reference to query

Attributes

Returns

ZIO effect that may fail with Throwable (RuntimeException if event hash missing or type validation fails) and succeeds with sequence of storage-related MySignedPrismEvent

Definition Classes
override def getEventsIdBySSI(ssi: DIDSubject): ZIO[Any, Nothing, Seq[EventRef]]

Returns event references for a specific SSI DID.

Returns event references for a specific SSI DID.

Attributes

Definition Classes
override def getEventsIdByVDR(id: RefVDR): ZIO[Any, Nothing, Seq[EventRef]]

Returns event references for a specific VDR.

Returns event references for a specific VDR.

Attributes

Definition Classes

Returns the lost events MongoDB collection.

Returns the lost events MongoDB collection.

Attributes

Name of the lost/orphaned events collection.

Name of the lost/orphaned events collection.

Attributes

override def ssi2eventsRef: ZIO[Any, Nothing, Map[DIDSubject, Seq[EventRef]]]

Returns mapping of all SSI DIDs to their event references.

Returns mapping of all SSI DIDs to their event references.

Attributes

Note

TODO: make it a Stream of (DIDSubject, Seq[EventRef])

Definition Classes
override def vdr2eventsRef: ZIO[Any, Nothing, Map[RefVDR, Seq[EventRef]]]

Returns mapping of all VDRs to their event references.

Returns mapping of all VDRs to their event references.

Attributes

Note

TODO: make it a Stream of (RefVDR, Seq[EventRef])

Definition Classes

Inherited methods

def addMaybeEvent(maybeEvent: MaybeEvent[OP]): ZIO[Any, Exception, Unit]

Adds an event after filtering out invalid ones.

Adds an event after filtering out invalid ones.

Only valid MySignedPrismEvent instances are added; invalid objects are silently ignored.

Attributes

Inherited from:
PrismState
def getSSI(ssi: DIDSubject): ZIO[Any, Throwable, SSI]

Gets the current SSI state.

Gets the current SSI state.

Attributes

Inherited from:
PrismStateRead

Gets the full SSIHistory for a SSI.

Gets the full SSIHistory for a SSI.

Attributes

Inherited from:
PrismStateRead
def getVDR(ref: RefVDR): ZIO[Any, Throwable, VDR]

Gets the VDR state with full ownership validation.

Gets the VDR state with full ownership validation.

Attributes

Inherited from:
PrismStateRead

Returns the last synced block timestamp.

Returns the last synced block timestamp.

Attributes

Returns

Tuple of (epoch seconds, nanoseconds)

Note

Current implementation returns current time (FIXME: should track actual sync state)

Inherited from:
PrismStateRead

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product
def ssiCount: ZIO[Any, Nothing, Int]

Returns count of SSI DIDs in the state.

Returns count of SSI DIDs in the state.

Attributes

Note

TODO: improve in specific implementations for better performance

Inherited from:
PrismStateRead
def vdrCount: ZIO[Any, Nothing, Int]

Returns count of VDRs in the state.

Returns count of VDRs in the state.

Attributes

Note

TODO: improve in specific implementations for better performance

Inherited from:
PrismStateRead