-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,101 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package store | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/Conflux-Chain/go-conflux-util/store/mysql" | ||
"github.com/shopspring/decimal" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type AddressReward struct { | ||
MinerID uint64 `gorm:"primaryKey;autoIncrement:false"` | ||
PricingIndex uint64 `gorm:"primaryKey;autoIncrement:false"` | ||
Amount decimal.Decimal `gorm:"type:decimal(65);not null"` | ||
BlockNumber uint64 `gorm:"not null;index:idx_bn"` | ||
BlockTime time.Time `gorm:"not null"` | ||
TxHash string `gorm:"size:66;not null"` | ||
} | ||
|
||
func (AddressReward) TableName() string { | ||
return "address_rewards" | ||
} | ||
|
||
type AddressRewardStore struct { | ||
*mysql.Store | ||
} | ||
|
||
func newAddressRewardStore(db *gorm.DB) *AddressRewardStore { | ||
return &AddressRewardStore{ | ||
Store: mysql.NewStore(db), | ||
} | ||
} | ||
|
||
func (ars *AddressRewardStore) Add(dbTx *gorm.DB, addressRewards []AddressReward) error { | ||
return dbTx.CreateInBatches(addressRewards, batchSizeInsert).Error | ||
} | ||
|
||
func (ars *AddressRewardStore) Pop(dbTx *gorm.DB, block uint64) error { | ||
return dbTx.Where("block_number >= ?", block).Delete(&AddressReward{}).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package store | ||
|
||
import ( | ||
"time" | ||
|
||
nhContract "github.com/0glabs/0g-storage-scan/contract" | ||
"github.com/Conflux-Chain/go-conflux-util/store/mysql" | ||
"github.com/openweb3/web3go/types" | ||
"github.com/shopspring/decimal" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type Reward struct { | ||
PricingIndex uint64 `gorm:"primaryKey;autoIncrement:false"` | ||
Miner string `gorm:"-"` | ||
MinerID uint64 `gorm:"not null"` | ||
Amount decimal.Decimal `gorm:"type:decimal(65);not null"` | ||
BlockNumber uint64 `gorm:"not null;index:idx_bn"` | ||
BlockTime time.Time `gorm:"not null"` | ||
TxHash string `gorm:"size:66;not null"` | ||
} | ||
|
||
func NewReward(blockTime time.Time, log types.Log, filter *nhContract.OnePoolRewardFilterer) (*Reward, error) { | ||
distributeReward, err := filter.ParseDistributeReward(*log.ToEthLog()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
reward := &Reward{ | ||
PricingIndex: distributeReward.PricingIndex.Uint64(), | ||
Miner: distributeReward.Beneficiary.String(), | ||
Amount: decimal.NewFromBigInt(distributeReward.Amount, 0), | ||
BlockNumber: log.BlockNumber, | ||
BlockTime: blockTime, | ||
TxHash: log.TxHash.String(), | ||
} | ||
|
||
return reward, nil | ||
} | ||
|
||
func (Reward) TableName() string { | ||
return "rewards" | ||
} | ||
|
||
type RewardStore struct { | ||
*mysql.Store | ||
} | ||
|
||
func newRewardStore(db *gorm.DB) *RewardStore { | ||
return &RewardStore{ | ||
Store: mysql.NewStore(db), | ||
} | ||
} | ||
|
||
func (rs *RewardStore) Add(dbTx *gorm.DB, rewards []*Reward) error { | ||
return dbTx.CreateInBatches(rewards, batchSizeInsert).Error | ||
} | ||
|
||
func (rs *RewardStore) Pop(dbTx *gorm.DB, block uint64) error { | ||
return dbTx.Where("block_number >= ?", block).Delete(&Reward{}).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.