@@ -30,6 +30,7 @@ import (
3030
3131// PeerLedgerProvider provides handle to ledger instances
3232type PeerLedgerProvider interface {
33+ Initialize (statelisteners StateListeners )
3334 // Create creates a new ledger with the given genesis block.
3435 // This function guarantees that the creation of ledger and committing the genesis block would an atomic action
3536 // The chain id retrieved from the genesis block is treated as a ledger id
@@ -269,3 +270,24 @@ func (txSim *TxSimulationResults) GetPvtSimulationBytes() ([]byte, error) {
269270func (txSim * TxSimulationResults ) ContainsPvtWrites () bool {
270271 return txSim .PvtSimulationResults != nil
271272}
273+
274+ // StateListener allows a custom code for performing additional stuff upon state change
275+ // for a perticular namespace against which the listener is registered.
276+ // This helps to perform custom tasks other than the state updates.
277+ // A ledger implemetation is expected to invoke Function `HandleStateUpdates` once per block and
278+ // the `stateUpdates` parameter passed to the function captures the state changes caused by the block
279+ // for the namespace. The actual data type of stateUpdates depends on the data model enabled.
280+ // For instance, for KV data model, the actual type would be proto message
281+ // `github.com/hyperledger/fabric/protos/ledger/rwset/kvrwset.KVWrite`
282+ // Function `HandleStateUpdates` is expected to be invoked before block is committed and if this
283+ // function returns an error, the ledger implementation is expected to halt block commit operation
284+ // and result in a panic
285+ type StateListener interface {
286+ HandleStateUpdates (ledgerID string , stateUpdates StateUpdates ) error
287+ }
288+
289+ // StateUpdates is the generic type to represent the state updates
290+ type StateUpdates interface {}
291+
292+ // StateListeners maintains the association between a namespace to its corresponding listener
293+ type StateListeners map [string ]StateListener
0 commit comments