Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas Haimerl authored and Nikolas Haimerl committed Jan 16, 2025
1 parent 9c49c62 commit 6cdc0f8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 57 deletions.
10 changes: 5 additions & 5 deletions backend/lib/deal-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
/** @import {Provider} from 'ethers' */

import { EVENT_TYPES } from './config.js'
import { ActorEventFilter, EventService } from './rpc-service/service.js'
import { ActorEventFilter, RpcService } from './rpc-service/service.js'

class DealObserver {
#pgPool
#eventService
#rpcService
#cache

constructor (pgPool = null, chainHead = null) {
Expand All @@ -17,16 +17,16 @@ class DealObserver {
}

async build () {
this.#eventService = await (new EventService()).build()
this.#rpcService = await (new RpcService()).build()
if (!this.#cache.get('chainHead')) {
const chainHead = await this.#eventService.getChainHead()
const chainHead = await this.#rpcService.getChainHead()
this.#cache.set('chainHead', chainHead)
}
return this
}

async observeBuiltinActorEvents (fromHeight = this.#cache.get('chainHead').Height, toHeight = this.#cache.get('chainHead').Height, eventTypes = EVENT_TYPES) {
return this.#eventService.getActorEvents(new ActorEventFilter(fromHeight, toHeight, eventTypes))
return this.#rpcService.getActorEvents(new ActorEventFilter(fromHeight, toHeight, eventTypes))
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/lib/rpc-service/ipld-schema-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { create } from '@ipld/schema/typed.js'
import { schemaDmt } from './builtin-actor-events-schemas.js'

class IpldSchemaValidator {
// A transformer which takes in a json object and returns a typed ClaimEvent object
// A validator which takes in a json object and returns a typed ClaimEvent object if the data matches the schema
#claimEventSchema
#rawActorEventSchema

Expand Down
37 changes: 0 additions & 37 deletions backend/lib/rpc-service/ipld-schema.js

This file was deleted.

8 changes: 4 additions & 4 deletions backend/lib/rpc-service/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { base64pad } from 'multiformats/bases/base64'
import { encode as cborEncode } from '@ipld/dag-cbor'
import { decode as jsonDecode } from '@ipld/dag-json'
import { request } from 'undici'
import { IpldSchemaValidator } from './ipld-schema.js'
import { IpldSchemaValidator } from './ipld-schema-validator.js'
import { rawEventEntriesToEvent } from './utils.js'

const makeRpcRequest = async (method, params) => {
Expand All @@ -19,9 +19,9 @@ const makeRpcRequest = async (method, params) => {
}

/*
A class to interact with the Lotus HTTP RPC API.
A class to interact with.
*/
class EventService {
class RpcService {
#ipldSchema
#make_rpc_request

Expand Down Expand Up @@ -87,5 +87,5 @@ class ActorEventFilter {

export {
ActorEventFilter,
EventService
RpcService
}
2 changes: 1 addition & 1 deletion backend/lib/rpc-service/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const encodeCborInBase64 = (data) => {
}

const rawEventEntriesToEvent = (rawEventEntries) => {
// Each event is defined by a list of even entries which will will transform into a typed event
// Each event is defined by a list of event entries which will parsed into a typed event
const event = {}
// TODO handle if there is no type entry
let eventType
Expand Down
18 changes: 9 additions & 9 deletions backend/test/observer.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { after, before, beforeEach, describe, it } from 'node:test'
import { createPgPool, migrateWithPgClient } from '@filecoin-station/deal-observer-db'
import { IpldSchemaValidator } from '../lib/rpc-service/ipld-schema.js'
import { IpldSchemaValidator } from '../lib/rpc-service/ipld-schema-validator.js'
import assert from 'assert'
import { claimTestEvent } from './test_data/claimEvent.js'
import { ActorEventFilter, EventService } from '../lib/rpc-service/service.js'
import { ActorEventFilter, RpcService } from '../lib/rpc-service/service.js'
import { chainHeadTestData } from './test_data/chainHead.js'
import { rawActorEventTestData } from './test_data/rawActorEvent.js'
import { parseCIDs } from './utils.js'
Expand Down Expand Up @@ -31,22 +31,22 @@ describe('deal-observer-backend', () => {
})
})

describe('Transformer', () => {
describe('IPLD Schema Validator', () => {
let claimEvent

before(() => {
claimEvent = parseCIDs(claimTestEvent)
})
it('transforms a claim event payload to a typed object', async () => {
it('validates and converts a claim event payload to a typed object', async () => {
const ipldSchema = await (new IpldSchemaValidator().build())
const typedClaimEvent = ipldSchema.applyType('ClaimEvent', claimEvent)
assert(typedClaimEvent !== undefined, 'typedClaimEvent is undefined')
assert.deepStrictEqual(typedClaimEvent, claimTestEvent)
})
})

describe('EventService', () => {
let eventService
describe('RpcService', () => {
let rpcService

before(async () => {
const makeRpcRequest = async (method, params) => {
Expand All @@ -60,16 +60,16 @@ describe('deal-observer-backend', () => {
}
}

eventService = await (new EventService(makeRpcRequest)).build()
rpcService = await (new RpcService(makeRpcRequest)).build()
})
it('test the retrieval of the chainHead', async () => {
const chainHead = await eventService.getChainHead()
const chainHead = await rpcService.getChainHead()
assert(chainHead)
assert.deepStrictEqual(JSON.stringify(chainHead), JSON.stringify(chainHeadTestData))
})

it('test the retrieval of rawActorEvents', async () => {
const actorEvents = await eventService.getActorEvents(new ActorEventFilter(4622129, 4622139, ['claim']))
const actorEvents = await rpcService.getActorEvents(new ActorEventFilter(4622129, 4622139, ['claim']))
assert(actorEvents)
actorEvents.forEach(e => {
assert(e.height >= 4622129 && e.height <= 4622139)
Expand Down

0 comments on commit 6cdc0f8

Please sign in to comment.