Skip to content
Snippets Groups Projects
Select Git revision
  • feature/android_api_19
  • master default protected
  • chrome-manifest-v3
  • feature/migrate-cordova-13
  • feat/improve-network-scan
  • feat/force-migration-check
  • develop
  • feature/encrypted_comment
  • gitlab_migration_1
  • rml8
  • v1.7.15-rc1
  • v1.7.14
  • v1.7.13
  • v1.7.12
  • v1.7.11
  • v1.7.10
  • v1.7.9
  • v1.7.8
  • v1.7.7
  • v1.7.6
  • v1.7.5
  • v1.7.4
  • v1.7.3
  • v1.7.2
  • v1.7.1
  • v1.7.0
  • v1.7.0-rc2
  • v1.7.0-rc1
  • v1.6.12
  • v1.6.11
30 results

install.sh

Blame
  • data_handler.ts 26.50 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, 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}`,
          })));
        }