Skip to content

Commit

Permalink
Merge pull request #102 from plasma-group/dev-k1
Browse files Browse the repository at this point in the history
Rename Ethereum-related event services to `EthEventX`
  • Loading branch information
smartcontracts committed Mar 26, 2019
2 parents cef3d46 + 8d3c48b commit 1516c50
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 55 deletions.
3 changes: 1 addition & 2 deletions packages/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import {
OperatorService,
ChainService,
EthModule,
EventModule,
DBModule,
ProofModule,
} from './services'

@Module({
imports: [EthModule, EventModule, DBModule, ProofModule],
imports: [EthModule, DBModule, ProofModule],
services: [
SyncService,
GuardService,
Expand Down
24 changes: 0 additions & 24 deletions packages/core/src/models/chain/pretty-print.ts

This file was deleted.

10 changes: 9 additions & 1 deletion packages/core/src/services/eth/eth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ import { Module } from '@nestd/core'
import { EthDataService } from './eth-data.service'
import { ContractService } from './contract.service'
import { WalletService } from './wallet.service'
import { EthEventWatcherService } from './events/eth-event-watcher.service'
import { EthEventHandlerService } from './events/eth-event-handler.service'

@Module({
services: [EthDataService, ContractService, WalletService],
services: [
EthDataService,
ContractService,
WalletService,
EthEventWatcherService,
EthEventHandlerService,
],
})
export class EthModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
import { Service, OnStart } from '@nestd/core'

/* Services */
import { EventWatcherService } from './event-watcher.service'
import { EventService } from '../event.service'
import { LoggerService, SyncLogger } from '../logging'
import { EthEventWatcherService } from './eth-event-watcher.service'
import { EventService } from '../../event.service'
import { LoggerService, SyncLogger } from '../../logging'

/* Internal Imports */
import { EthereumEvent } from '../../models/eth'
import { PlasmaBlock, Deposit, Exit } from '../../models/chain'
import { EthereumEvent } from '../../../models/eth'
import { PlasmaBlock, Deposit, Exit } from '../../../models/chain'

/**
* Service that handles events coming from
* EventWatcherService and parses them into
* useable objects.
*/
@Service()
export class EventHandlerService implements OnStart {
export class EthEventHandlerService implements OnStart {
private readonly name = 'eventHandler'
private readonly logger = new SyncLogger(this.name, this.logs)

constructor(
private readonly logs: LoggerService,
private readonly events: EventService,
private readonly eventWatcher: EventWatcherService
private readonly eventWatcher: EthEventWatcherService
) {}

public async onStart(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { Service, OnStart, OnStop } from '@nestd/core'
import { EventWatcher } from 'watch-eth'

/* Services */
import { SyncDB } from '../db/interfaces/sync-db'
import { EthDataService } from '../eth/eth-data.service'
import { ContractService } from '../eth/contract.service'
import { ConfigService } from '../config.service'
import { EventService } from '../event.service'
import { SyncDB } from '../../db/interfaces/sync-db'
import { EthDataService } from '../eth-data.service'
import { ContractService } from '../contract.service'
import { ConfigService } from '../../config.service'
import { EventService } from '../../event.service'

/* Internal Imports */
import { CONFIG } from '../../constants'
import { CONFIG } from '../../../constants'

interface EventWatcherOptions {
finalityDepth: number
Expand All @@ -21,7 +21,7 @@ interface EventWatcherOptions {
* Service that watches for events from Ethereum.
*/
@Service()
export class EventWatcherService implements OnStart, OnStop {
export class EthEventWatcherService implements OnStart, OnStop {
public watcher: EventWatcher
private readonly name = 'eventWatcher'

Expand Down
11 changes: 0 additions & 11 deletions packages/core/src/services/events/event.module.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/core/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ export { JsonRpcService } from './jsonrpc/jsonrpc.service'
export { DBService } from './db/db.service'
export { ChainService } from './chain.service'
export { ProofVerificationService } from './proof/proof-verification.service'
export { EventWatcherService } from './events/event-watcher.service'
export { EventHandlerService } from './events/event-handler.service'
export { OperatorService } from './operator.service'
export { SyncService } from './sync.service'
export { WalletService } from './eth/wallet.service'
export { EthDataService } from './eth/eth-data.service'
export { EthEventWatcherService } from './eth/events/eth-event-watcher.service'
export { EthEventHandlerService } from './eth/events/eth-event-handler.service'

/* Modules */
export { DBModule } from './db/db.module'
export { EthModule } from './eth/eth.module'
export { EventModule } from './events/event.module'
export { ProofModule } from './proof/proof.module'
20 changes: 20 additions & 0 deletions packages/core/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ export const bnMin = (a: BigNum, b: BigNum): BigNum => {
export const bnMax = (a: BigNum, b: BigNum): BigNum => {
return a.gt(b) ? a : b
}

interface PrettyPrintable {
[key: string]: string | number | BigNum | boolean | any
}

/**
* Converts an object to a pretty JSON string.
* @param obj Object to convert.
* @returns the object as a pretty JSON string.
*/
export const prettify = (obj: PrettyPrintable): string => {
const parsed: PrettyPrintable = {}
for (const key of Object.keys(obj)) {
const value = obj[key]
parsed[key] = BigNum.isBN(value)
? `${value.toString(16)} (${value.toString(10)})`
: value
}
return JSON.stringify(parsed, null, 2)
}

0 comments on commit 1516c50

Please sign in to comment.