Skip to content

Commit

Permalink
remove handle increaseAmount & extendDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Jun 7, 2023
1 parent bca927d commit b81470c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 192 deletions.
94 changes: 0 additions & 94 deletions blockindex/contractstaking/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,6 @@ import (
const (
// StakingContractABI is the ABI of system staking contract
StakingContractABI = `[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "AmountIncreased",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -149,25 +130,6 @@ const (
"name": "DelegateChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "duration",
"type": "uint256"
}
],
"name": "DurationExtended",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -442,10 +404,6 @@ func (eh *contractStakingEventHandler) HandleEvent(ctx context.Context, blk *blo
return eh.handleUnstakedEvent(event, blk.Height())
case "Merged":
return eh.handleMergedEvent(event)
case "DurationExtended":
return eh.handleDurationExtendedEvent(event)
case "AmountIncreased":
return eh.handleAmountIncreasedEvent(event)
case "BucketExpanded":
return eh.handleBucketExpandedEvent(event)
case "DelegateChanged":
Expand Down Expand Up @@ -641,58 +599,6 @@ func (eh *contractStakingEventHandler) handleMergedEvent(event eventParam) error
return eh.dirty.updateBucketInfo(tokenIDsParam[0].Uint64(), b)
}

func (eh *contractStakingEventHandler) handleDurationExtendedEvent(event eventParam) error {
tokenIDParam, err := event.IndexedFieldUint256("tokenId")
if err != nil {
return err
}
durationParam, err := event.FieldUint256("duration")
if err != nil {
return err
}

b, ok := eh.dirty.getBucketInfo(tokenIDParam.Uint64())
if !ok {
return errors.Wrapf(ErrBucketNotExist, "token id %d", tokenIDParam.Uint64())
}
bt, ok := eh.dirty.getBucketType(b.TypeIndex)
if !ok {
return errors.Wrapf(errBucketTypeNotExist, "id %d", b.TypeIndex)
}
newBtIdx, _, ok := eh.dirty.matchBucketType(bt.Amount, durationParam.Uint64())
if !ok {
return errors.Wrapf(errBucketTypeNotExist, "amount %d, duration %d", bt.Amount.Int64(), durationParam.Uint64())
}
b.TypeIndex = newBtIdx
return eh.dirty.updateBucketInfo(tokenIDParam.Uint64(), b)
}

func (eh *contractStakingEventHandler) handleAmountIncreasedEvent(event eventParam) error {
tokenIDParam, err := event.IndexedFieldUint256("tokenId")
if err != nil {
return err
}
amountParam, err := event.FieldUint256("amount")
if err != nil {
return err
}

b, ok := eh.dirty.getBucketInfo(tokenIDParam.Uint64())
if !ok {
return errors.Wrapf(ErrBucketNotExist, "token id %d", tokenIDParam.Uint64())
}
bt, ok := eh.dirty.getBucketType(b.TypeIndex)
if !ok {
return errors.Wrapf(errBucketTypeNotExist, "id %d", b.TypeIndex)
}
newBtIdx, _, ok := eh.dirty.matchBucketType(amountParam, bt.Duration)
if !ok {
return errors.Wrapf(errBucketTypeNotExist, "amount %d, duration %d", amountParam.Int64(), bt.Duration)
}
b.TypeIndex = newBtIdx
return eh.dirty.updateBucketInfo(tokenIDParam.Uint64(), b)
}

func (eh *contractStakingEventHandler) handleBucketExpandedEvent(event eventParam) error {
tokenIDParam, err := event.IndexedFieldUint256("tokenId")
if err != nil {
Expand Down
Loading

0 comments on commit b81470c

Please sign in to comment.