Skip to content
Snippets Groups Projects
Select Git revision
  • 360627a0c6e8d6d89fc027002bf4ed25b0eb91a3
  • main default protected
  • account-balance
  • hugo-rebase-mr-23
  • fix-23-before-rebase
  • add-certifications-date
  • proxy-limiter
  • convert-hash-bytes-to-hexa
  • 0.2.9
  • 0.2.8
  • 0.2.7
  • 0.2.6
  • 0.2.4
  • 0.2.3
  • 0.2.2
  • 0.2.0
  • 0.1.3
  • 0.1.2
  • 0.1.1
19 results

data_handler.ts

Blame
  • data_handler.ts 26.49 KiB
    import { strict as assert } from 'assert';
    import { In } from "typeorm";
    import {
      Account,
      Cert,
      CertEvent,
      ChangeOwnerKey,
      Event,
      EventType,
      Identity,
      IdentityStatus,
      MembershipEvent,
      SmithEvent,
      SmithEventType,
      Smith,
      SmithCert,
      SmithStatus,
      PopulationHistory,
      Transfer,
      TxComment,
      UdReeval,
      UniversalDividend,
      Validator,
    } from "./model";
    import { Address, BlockNumber, Ctx, Data, IdtyIndex, NewData } from "./types_custom";
    import { hexToString } from "./utils";
    import { events } from "./types";
    import { getCommentType } from "./comment";
    
    export class DataHandler {
      private data: Data;
    
      constructor() {
        this.data = {
          accounts: new Map(),
          identities: new Map(),
          smiths: new Map(),
          populationHistories: [],
          validators: new Map(),
          membershipEvents: [],
          smithEvents: [],
          changeOwnerKey: [],
          transfers: new Map(),
          certification: new Map(),
          certEvent: [],
          smithCert: new Map(),
          universalDividend: [],
          udReeval: [],
          comments: []
        };
      }
    
      async processNewData(newData: NewData, ctx: Ctx) {
    
        // Process population history by adding the value
        // of the last point in database.
        if (newData.populationHistories) {
          const lastHistory = await ctx.store.findOneOrFail(PopulationHistory, {
            where: {},
            order: { blockNumber: 'DESC' }
          });
    
          this.data.populationHistories = newData.populationHistories.map(history => (new PopulationHistory({
            activeAccountCount: history.activeAccountCount + lastHistory.activeAccountCount,
            memberCount: history.memberCount + lastHistory.memberCount,
            smithCount: history.smithCount + lastHistory.smithCount,
            blockNumber: history.blockNumber,
            id: `population-${history.blockNumber}`,
          })));
        }