Skip to content

Commit

Permalink
fix update shares bug (#108)
Browse files Browse the repository at this point in the history
Co-authored-by: liutian <[email protected]>
  • Loading branch information
tiantianlikeu and 0xweb3King authored Apr 10, 2024
1 parent 37cdc54 commit 4c3c034
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions appchain/appchain_l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ func (l *L2AppChainListener) operatorSharesTask() error {
}

type ToStakeShares struct {
TotalShares *big.Int
UserInfoShares []*UserInfoShares
TotalShares *big.Int
UserInfoShares []*UserInfoShares
NeedUpdateShares []*appchain.AppChainOperatorSharesIncreased
}
type UserInfoShares struct {
UserShares *big.Int
Expand Down Expand Up @@ -221,24 +222,25 @@ func (l *L2AppChainListener) operatorSharesIncreased() error {
totalShares = big.NewInt(0).Add(totalShares, thisNeedShares)
needStakeShare.UseShares = big.NewInt(0).Add(useShares, thisNeedShares)
}
err := l.db.AppChainOperatorSharesIncreased.UpdateOperatorUseShares(*needStakeShare)
if err != nil {
return err
}

userInfoShares := toStakeShares.UserInfoShares
userInfoShares = append(userInfoShares, &UserInfoShares{
UserShares: needStakeShare.UseShares,
Staker: needStakeShare.Staker,
StrategyAddress: strategyAddress,
Operator: operatorAddress,
})
needUpdateShares := toStakeShares.NeedUpdateShares
needUpdateShares = append(needUpdateShares, needStakeShare)
toStakeShares.TotalShares = totalShares
toStakeShares.UserInfoShares = userInfoShares
toStakeShares.NeedUpdateShares = needUpdateShares
}
if toStakeShares.TotalShares.Cmp(StakeAmount) == 0 {
batchIdInt := time.Now().Unix()
batchId := big.NewInt(batchIdInt)
increaseBatches := make([]appchain.AppChainIncreaseBatch, 0)
// create batchMint param
mintMap := make(map[string]string)
for _, userInfoShares := range toStakeShares.UserInfoShares {
increaseBatches = append(increaseBatches, appchain.AppChainIncreaseBatch{
Expand All @@ -252,6 +254,16 @@ func (l *L2AppChainListener) operatorSharesIncreased() error {
})
mintMap[userInfoShares.Staker.String()] = userInfoShares.UserShares.String()
}

// update shares
log.Info("operatorSharesIncreased", "needStakeSharesSize", len(toStakeShares.NeedUpdateShares))
for _, needStakeShare := range toStakeShares.NeedUpdateShares {
err := l.db.AppChainOperatorSharesIncreased.UpdateOperatorUseShares(*needStakeShare)
if err != nil {
return err
}
}

log.Info("operatorSharesIncreased", "increaseBatchesSize", len(increaseBatches))
// save batch
err := l.db.AppChainIncreaseBatch.StoreAppChainIncreasedBatch(increaseBatches)
Expand Down

0 comments on commit 4c3c034

Please sign in to comment.