PaymentChannelAggregate class

Payment Channel Aggregate Root

One instance per payment channel, identified by channelId. Handles all channel commands and emits events as the source of truth.

Constructors

PaymentChannelAggregate({required String aggregateId, required EventStore eventStore, required CryptoService cryptoService, NetworkType networkType = dartsv.NetworkType.TEST})

Properties

aggregateId String
The aggregate ID for this aggregate root
no setterinherited
aggregateType String
The aggregate type for this aggregate root
no setterinherited
commandHandlers → CommandHandlerRegistry<ChannelState>
Command handler registry for this aggregate
no setterinherited
currentState ChannelState
Current state of the aggregate (non-nullable) Throws if the aggregate hasn't been initialized
no setterinherited
eventHandlers → EventHandlerRegistry<ChannelState>
Event handler registry for this aggregate
no setterinherited
eventStore → EventStore
Current event store instance
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isInitialized bool
Whether the aggregate has been initialized with state
no setterinherited
isRecovered bool
Whether this actor has completed recovery
no setterinherited
isRecovering bool
Whether this actor is currently recovering from events
no setterinherited
persistenceId String
Unique identifier for this persistent actor Used to store and retrieve events from the event store
no setterinherited
recoveryComplete Future<void>
Future that completes when recovery finishes.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sequenceNumber int
Current sequence number for this actor Incremented with each persisted event
no setterinherited
state ChannelState?
Current state of the aggregate Returns null if the aggregate hasn't been initialized yet
no setterinherited

Methods

applyEvent(ChannelState currentState, Event event) ChannelState
Apply an event to the current state and return the new state This is the core method for event sourcing state transitions
inherited
canApplyEvent(Event event) bool
Check if the aggregate can apply a specific event Override in subclasses for custom event routing
inherited
canHandleCommand(Command command) bool
Check if the aggregate can handle a specific command Override in subclasses for custom command routing
inherited
checkConcurrency(int expectedVersion) Future<void>
Check optimistic concurrency control with expected version Public method for explicit concurrency checking
inherited
commandHandler(Command command) Future<void>
Process a command through the full pipeline This is the main entry point for command processing
inherited
createInitialState() ChannelState
Create the initial state for this aggregate Override in subclasses to provide the initial state
createSnapshot() Future<void>
Create a snapshot of current state Override to provide custom snapshot logic
inherited
ensureStateInitialized() → void
Initialize the aggregate state This is a protected method that subclasses can use when overriding eventHandler to ensure state is initialized before processing events (replicating base class behavior)
inherited
eventHandler(Event event) → void
Apply an event to update the aggregate state This is called during both command processing and recovery
getAggregateInfo() → AggregateInfo
Get aggregate information for debugging and monitoring
inherited
getBusinessRuleViolations(ChannelState state) List<String>
Get business rule violations for the current state Override in subclasses to provide specific violation messages
inherited
getSnapshotState() Future
Get the current state for snapshot creation
inherited
handleCommand(ChannelState currentState, Command command) Future<List<Event>>
Handle a command and generate events This is the core method for command processing
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onCommandFailure(Command command, dynamic error) Future<void>
Called when command processing fails Override to handle command failures
onCommandProcessed(Command command, List<Event> events) Future<void>
Called after a command has been successfully processed Override to perform post-command processing actions
onError(Object error, StackTrace stackTrace) → void
Called when an error occurs.
inherited
onEventApplicationFailure(Event event, dynamic error) → void
Called when event application fails Override to handle event application failures
inherited
onEventApplied(Event event, ChannelState newState) → void
Called after an event has been applied to the state Override to perform post-event application actions
inherited
onMessage(dynamic message) Future<void>
Handle incoming messages with command/event routing
onMessageDropped(dynamic message) Future<void>
Called when a message is dropped because recovery timed out or failed. Override to send error responses, log, or enqueue for retry.
inherited
onPersist(Event event) Future<void>
Called after successful event persistence Override to perform post-persistence actions
inherited
onPersistBatch(List<Event> events) Future<void>
Called after successful batch event persistence Override to perform post-persistence actions for batches
inherited
onPersistBatchFailure(List<Event> events, dynamic error) Future<void>
Called when batch event persistence fails Override to handle batch persistence failures
inherited
onPersistFailure(Event event, dynamic error) Future<void>
Called when event persistence fails Override to handle persistence failures
inherited
onRecover() Future<void>
Called at the start of recovery process Override to perform custom recovery initialization
inherited
onRecoveryComplete() Future<void>
Called when recovery is complete Override to perform post-recovery initialization
inherited
onRecoveryFailure(dynamic error) Future<void>
Called when recovery fails Override to handle recovery failures
inherited
onReplay(Event event) Future<void>
Called for each event during replay Override to perform custom replay logic
inherited
onSnapshot(dynamic snapshotState, int sequenceNumber) Future<void>
Restore state from snapshot during recovery
inherited
onSnapshotCreated(dynamic state, int sequenceNumber) Future<void>
Called when a snapshot is created Override to perform post-snapshot actions
inherited
onSnapshotRestorationFailure(dynamic snapshotData, int sequenceNumber, dynamic error) Future<void>
Called when snapshot restoration fails Override to handle snapshot restoration failures
inherited
onSnapshotRestored(ChannelState state, int sequenceNumber) Future<void>
Called after state has been restored from a snapshot Override to perform post-snapshot restoration actions
inherited
persistEvent(Event event) Future<void>
Persist an event to the event store Events are immutable and stored permanently
inherited
persistEvents(List<Event> events) Future<void>
Persist multiple events atomically All events succeed or all fail together
inherited
postStop() → void
Called when the actor is stopped.
inherited
preStart() → void
Called when the actor is started.
inherited
queryHandler(dynamic message) Future<void>
Handles incoming queries or other non-persistent messages.
inherited
registerHandlers() → void
Register command and event handlers for this aggregate Override in subclasses to register domain-specific handlers
replay(List<Event> events) → void
Replay events to rebuild aggregate state Used during recovery and testing
inherited
restoreFromSnapshot(dynamic snapshotData, int sequenceNumber) Future<ChannelState>
Restore state from snapshot data Override in subclasses to provide custom restoration logic
inherited
restoreStateFromMap(Map<String, dynamic> map, int sequenceNumber) Future<ChannelState>
Restore state from a map representation Override in subclasses to provide custom map restoration
inherited
toString() String
A string representation of this object.
inherited
validateBusinessRules(ChannelState state) bool
Validate business rules for the current state Override in subclasses to implement domain-specific validation
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited