Smart Account Event Emitter
Event emitter for Smart Account lifecycle events.
This class manages event subscriptions and dispatches events to all registered listeners. It provides thread-safe subscription management and error handling.
All synchronization uses platformSynchronized on the internal listeners map as the single lock. Event emission snapshots the listener list under the lock, then invokes listeners outside the lock to avoid holding the lock during callbacks.
Features:
Thread-safe listener management with platformSynchronized
Multiple listeners per event type
Error isolation (one failing listener does not affect others)
Optional error handler for debugging listener failures
Public addListener() for Java/Swift/non-Kotlin callers
Example:
val emitter = SmartAccountEventEmitter()
// Type-safe subscription (Kotlin only, uses reified generics)
val unsubscribe = emitter.on<SmartAccountEvent.WalletConnected> { event ->
println("Connected to ${event.contractId}")
}
// Non-generic subscription (works from Java, Swift, etc.)
val unsub = emitter.addListener { event ->
when (event) {
is SmartAccountEvent.WalletConnected ->
println("Connected to ${event.contractId}")
else -> {}
}
}
// One-time listener
emitter.once<SmartAccountEvent.TransactionSubmitted> { event ->
println("First transaction: ${event.hash}")
}
// Remove listener
unsubscribe()Functions
Subscribes a listener to receive all Smart Account events.
Returns the number of listeners for a specific event type.
Removes all listeners for a specific event type, or all listeners if no type is specified.
Sets the error handler for listener errors.