mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
app/ship_processor.go: implement StateLoader and StateSaver.
This commit is contained in:
parent
1ae3da425c
commit
9946bd59e1
1 changed files with 12 additions and 4 deletions
|
|
@ -43,6 +43,9 @@ type ShipProcessor struct {
|
|||
// Encoder used to encode messages
|
||||
encode message.Encoder
|
||||
|
||||
// Function for saving state.
|
||||
saver StateSaver
|
||||
|
||||
// Internal state
|
||||
state State
|
||||
|
||||
|
|
@ -51,18 +54,18 @@ type ShipProcessor struct {
|
|||
}
|
||||
|
||||
// SpawnProcessor creates a new ShipProccessor that consumes the shipclient.Stream passed to it.
|
||||
func SpawnProccessor(shipStream *shipclient.Stream, writer api.Writer, abi *abi.AbiManager, codec message.Codec) *ShipProcessor {
|
||||
func SpawnProccessor(shipStream *shipclient.Stream, loader StateLoader, saver StateSaver, writer api.Writer, abi *abi.AbiManager, codec message.Codec) *ShipProcessor {
|
||||
processor := &ShipProcessor{
|
||||
saver: saver,
|
||||
abi: abi,
|
||||
writer: writer,
|
||||
shipStream: shipStream,
|
||||
encode: logDecoratedEncoder(codec.Encoder),
|
||||
syscontract: eos.AccountName("eosio"),
|
||||
state: State{
|
||||
CurrentBlock: shipStream.StartBlock,
|
||||
},
|
||||
}
|
||||
|
||||
loader(&processor.state)
|
||||
|
||||
// Attach handlers
|
||||
shipStream.BlockHandler = processor.processBlock
|
||||
|
||||
|
|
@ -274,6 +277,11 @@ func (processor *ShipProcessor) processBlock(block *ship.GetBlocksResultV0) {
|
|||
if err != nil {
|
||||
log.WithError(err).Error("Failed to send messages")
|
||||
}
|
||||
|
||||
err = processor.saver(processor.state)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to save state")
|
||||
}
|
||||
}
|
||||
|
||||
// Close closes the writer associated with the processor.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue