Skip to content

Commit 257c6e8

Browse files
committed
introduce event processor
1 parent 5d5ec5b commit 257c6e8

File tree

16 files changed

+1132
-668
lines changed

16 files changed

+1132
-668
lines changed

action/protocol/mock_protocol.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/protocol/staking/contractstake_indexer.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313

1414
"github.com/ethereum/go-ethereum/accounts/abi"
1515
"github.com/iotexproject/iotex-address/address"
16+
"github.com/iotexproject/iotex-core/v2/action"
1617
"github.com/iotexproject/iotex-core/v2/action/protocol"
18+
"github.com/iotexproject/iotex-core/v2/action/protocol/staking/contractstaking"
1719
)
1820

1921
var (
@@ -25,7 +27,18 @@ var (
2527
)
2628

2729
type (
28-
30+
// EventHandler is the interface for handling staking events
31+
EventHandler interface {
32+
PutBucketType(address.Address, *ContractStakingBucketType) error
33+
DeductBucket(address.Address, uint64) (*contractstaking.Bucket, error)
34+
PutBucket(address.Address, uint64, *contractstaking.Bucket) error
35+
DeleteBucket(address.Address, uint64) error
36+
}
37+
// EventProcessor is the interface for processing staking events
38+
EventProcessor interface {
39+
// ProcessReceipts processes receipts
40+
ProcessReceipts(context.Context, ...*action.Receipt) error
41+
}
2942
// ContractStakingIndexer defines the interface of contract staking reader
3043
ContractStakingIndexer interface {
3144
Height() (uint64, error)
@@ -41,6 +54,8 @@ type (
4154
ContractAddress() address.Address
4255
// LoadStakeView loads the contract stake view from state reader
4356
LoadStakeView(context.Context, protocol.StateReader) (ContractStakeView, error)
57+
// CreateEventProcessor creates a new event processor
58+
CreateEventProcessor(context.Context, EventHandler) EventProcessor
4459
}
4560
// ContractStakingIndexerWithBucketType defines the interface of contract staking reader with bucket type
4661
ContractStakingIndexerWithBucketType interface {

action/protocol/staking/contractstake_indexer_mock.go

Lines changed: 154 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/protocol/staking/contractstaking/bucket.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type (
3535
}
3636
)
3737

38+
// ErrBucketNotExist is the error when bucket does not exist
39+
var ErrBucketNotExist = errors.New("bucket does not exist")
40+
3841
func (b *Bucket) toProto() *stakingpb.SystemStakingBucket {
3942
if b == nil {
4043
return nil

0 commit comments

Comments
 (0)