validatorstats.ts 945 B

1234567891011121314151617181920212223242526272829303132333435
  1. import db from '../db'
  2. import { DataTypes, Op, Model } from 'sequelize'
  3. class ValidatorStats extends Model {}
  4. ValidatorStats.init({
  5. accountId: {type: DataTypes.INTEGER, allowNull: false},
  6. eraId: {type: DataTypes.INTEGER, allowNull: false},
  7. stake_total: { type: DataTypes.DECIMAL, defaultValue: 0},
  8. stake_own: { type: DataTypes.DECIMAL, defaultValue: 0},
  9. points: { type: DataTypes.INTEGER, defaultValue: 0},
  10. rewards: { type: DataTypes.DECIMAL, defaultValue: 0},
  11. commission: DataTypes.DECIMAL
  12. },
  13. {modelName: 'validator_stats', sequelize: db, indexes: [
  14. {
  15. unique: true,
  16. fields: ['accountId', 'eraId']
  17. }
  18. ]
  19. })
  20. ValidatorStats.removeAttribute('id')
  21. export const findByAccountAndEra = (account: number, era: number): Promise<ValidatorStats> => {
  22. return ValidatorStats.findOne(
  23. {
  24. where: {
  25. accountId: { [Op.eq]: account },
  26. eraId: { [Op.eq]: era }
  27. }
  28. })
  29. }
  30. export default ValidatorStats