Skip to content

Commit

Permalink
rename preprocessed user l2 tx table
Browse files Browse the repository at this point in the history
  • Loading branch information
torztomasz committed Jul 19, 2023
1 parent 5f5745f commit 589c945
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 250 deletions.
21 changes: 11 additions & 10 deletions packages/backend/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { PerpetualHistoryPreprocessor } from './core/preprocessing/PerpetualHist
import { Preprocessor } from './core/preprocessing/Preprocessor'
import { SpotHistoryPreprocessor } from './core/preprocessing/SpotHistoryPreprocessor'
import { StateDetailsPreprocessor } from './core/preprocessing/StateDetailsPreprocessor'
import { UserL2TransactionsPreprocessor } from './core/preprocessing/UserL2TransactionsPreprocessor'
import { UserL2TransactionsStatisticsPreprocessor } from './core/preprocessing/UserL2TransactionsPreprocessor'
import { UserStatisticsPreprocessor } from './core/preprocessing/UserStatisticsPreprocessor'
import { SpotValidiumSyncService } from './core/SpotValidiumSyncService'
import { SpotValidiumUpdater } from './core/SpotValidiumUpdater'
Expand All @@ -71,7 +71,7 @@ import { PositionRepository } from './peripherals/database/PositionRepository'
import { PreprocessedAssetHistoryRepository } from './peripherals/database/PreprocessedAssetHistoryRepository'
import { PreprocessedStateDetailsRepository } from './peripherals/database/PreprocessedStateDetailsRepository'
import { PreprocessedStateUpdateRepository } from './peripherals/database/PreprocessedStateUpdateRepository'
import { PreprocessedUserL2TransactionsRepository } from './peripherals/database/PreprocessedUserL2TransactionsRepository'
import { PreprocessedUserL2TransactionsStatisticsRepository } from './peripherals/database/PreprocessedUserL2TransactionsStatisticsRepository'
import { PreprocessedUserStatisticsRepository } from './peripherals/database/PreprocessedUserStatisticsRepository'
import { Database } from './peripherals/database/shared/Database'
import { StateTransitionRepository } from './peripherals/database/StateTransitionRepository'
Expand Down Expand Up @@ -415,14 +415,15 @@ export class Application {
const preprocessedUserStatisticsRepository =
new PreprocessedUserStatisticsRepository(database, logger)

const preprocessedUserL2TransactionsRepository =
new PreprocessedUserL2TransactionsRepository(database, logger)
const preprocessedUserL2TransactionsStatisticsRepository =
new PreprocessedUserL2TransactionsStatisticsRepository(database, logger)

const userL2TransactionsPreprocessor = new UserL2TransactionsPreprocessor(
preprocessedUserL2TransactionsRepository,
l2TransactionRepository,
logger
)
const userL2TransactionsPreprocessor =
new UserL2TransactionsStatisticsPreprocessor(
preprocessedUserL2TransactionsStatisticsRepository,
l2TransactionRepository,
logger
)

let preprocessor: Preprocessor<AssetHash> | Preprocessor<AssetId>
const isPreprocessorEnabled = config.enablePreprocessing
Expand Down Expand Up @@ -553,7 +554,7 @@ export class Application {
forcedTradeOfferViewService,
withdrawableAssetRepository,
preprocessedUserStatisticsRepository,
preprocessedUserL2TransactionsRepository,
preprocessedUserL2TransactionsStatisticsRepository,
config.starkex.contracts.perpetual
)
const stateUpdateController = new StateUpdateController(
Expand Down
31 changes: 16 additions & 15 deletions packages/backend/src/api/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
PreprocessedAssetHistoryRepository,
} from '../../peripherals/database/PreprocessedAssetHistoryRepository'
import { sumUpTransactionCount } from '../../peripherals/database/PreprocessedL2TransactionsStatistics'
import { PreprocessedUserL2TransactionsRepository } from '../../peripherals/database/PreprocessedUserL2TransactionsRepository'
import { PreprocessedUserL2TransactionsStatisticsRepository } from '../../peripherals/database/PreprocessedUserL2TransactionsStatisticsRepository'
import { PreprocessedUserStatisticsRepository } from '../../peripherals/database/PreprocessedUserStatisticsRepository'
import {
SentTransactionRecord,
Expand Down Expand Up @@ -62,7 +62,7 @@ export class UserController {
private readonly forcedTradeOfferViewService: ForcedTradeOfferViewService,
private readonly withdrawableAssetRepository: WithdrawableAssetRepository,
private readonly preprocessedUserStatisticsRepository: PreprocessedUserStatisticsRepository,
private readonly preprocessedUserL2TransactionsRepository: PreprocessedUserL2TransactionsRepository,
private readonly preprocessedUserL2TransactionsStatisticsRepository: PreprocessedUserL2TransactionsStatisticsRepository,
private readonly exchangeAddress: EthereumAddress
) {}

Expand Down Expand Up @@ -128,7 +128,7 @@ export class UserController {
userAssets,
history,
l2Transactions,
preprocessedUserL2Transactions,
preprocessedUserL2TransactionsStatistics,
sentTransactions,
userTransactions,
userTransactionsCount,
Expand All @@ -152,7 +152,7 @@ export class UserController {
starkKey,
paginationOpts
),
this.preprocessedUserL2TransactionsRepository.findCurrentByStarkKey(
this.preprocessedUserL2TransactionsStatisticsRepository.findCurrentByStarkKey(
starkKey
),
this.sentTransactionRepository.getByStarkKey(starkKey),
Expand Down Expand Up @@ -220,7 +220,7 @@ export class UserController {
ethereumAddress: registeredUser?.ethAddress,
l2Transactions: l2Transactions.map(l2TransactionToEntry),
totalL2Transactions: sumUpTransactionCount(
preprocessedUserL2Transactions?.cumulativeL2TransactionsStatistics
preprocessedUserL2TransactionsStatistics?.cumulativeL2TransactionsStatistics
),
withdrawableAssets: withdrawableAssets.map((asset) => ({
asset: {
Expand Down Expand Up @@ -318,22 +318,23 @@ export class UserController {
pagination: PaginationOptions
): Promise<ControllerResult> {
const context = await this.pageContextService.getPageContext(givenUser)
const [l2Transactions, preprocessedUserL2Transactions] = await Promise.all([
this.l2TransactionRepository.getUserSpecificPaginated(
starkKey,
pagination
),
this.preprocessedUserL2TransactionsRepository.findCurrentByStarkKey(
starkKey
),
])
const [l2Transactions, preprocessedUserL2TransactionsStatistics] =
await Promise.all([
this.l2TransactionRepository.getUserSpecificPaginated(
starkKey,
pagination
),
this.preprocessedUserL2TransactionsStatisticsRepository.findCurrentByStarkKey(
starkKey
),
])

const content = renderUserL2TransactionsPage({
context,
starkKey,
l2Transactions: l2Transactions.map(l2TransactionToEntry),
total: sumUpTransactionCount(
preprocessedUserL2Transactions?.cumulativeL2TransactionsStatistics
preprocessedUserL2TransactionsStatistics?.cumulativeL2TransactionsStatistics
),
...pagination,
})
Expand Down
40 changes: 20 additions & 20 deletions packages/backend/src/core/preprocessing/Preprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Logger } from '../../tools/Logger'
import { PerpetualHistoryPreprocessor } from './PerpetualHistoryPreprocessor'
import { Preprocessor, SyncDirection } from './Preprocessor'
import { StateDetailsPreprocessor } from './StateDetailsPreprocessor'
import { UserL2TransactionsPreprocessor } from './UserL2TransactionsPreprocessor'
import { UserL2TransactionsStatisticsPreprocessor } from './UserL2TransactionsPreprocessor'
import { UserStatisticsPreprocessor } from './UserStatisticsPreprocessor'

const generateFakeStateUpdate = (
Expand All @@ -37,7 +37,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),

mockObject<L2TransactionRepository>(),
Logger.SILENT
Expand Down Expand Up @@ -78,7 +78,7 @@ describe(Preprocessor.name, () => {
catchUp: mockFn().resolvesTo(undefined),
})
const mockUserL2TransactionsPreprocessor =
mockObject<UserL2TransactionsPreprocessor>({
mockObject<UserL2TransactionsStatisticsPreprocessor>({
catchUp: mockFn().resolvesTo(undefined),
})
const mockStateDetailsPreprocessor = mockObject<StateDetailsPreprocessor>(
Expand Down Expand Up @@ -142,7 +142,7 @@ describe(Preprocessor.name, () => {
catchUp: mockFn(),
})
const mockUserL2TransactionsPreprocessor =
mockObject<UserL2TransactionsPreprocessor>({
mockObject<UserL2TransactionsStatisticsPreprocessor>({
catchUp: mockFn(),
})
const mockStateDetailsPreprocessor = mockObject<StateDetailsPreprocessor>(
Expand Down Expand Up @@ -192,7 +192,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand All @@ -218,7 +218,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand All @@ -245,7 +245,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand All @@ -271,7 +271,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -300,7 +300,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -331,7 +331,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -363,7 +363,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -397,7 +397,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -430,7 +430,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -464,7 +464,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -499,7 +499,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -535,7 +535,7 @@ describe(Preprocessor.name, () => {
preprocessNextStateUpdate: async () => undefined,
})
const mockUserL2TransactionsPreprocessor =
mockObject<UserL2TransactionsPreprocessor>({
mockObject<UserL2TransactionsStatisticsPreprocessor>({
catchUp: mockFn(async () => {}),
})
const stateUpdateRepo = mockObject<StateUpdateRepository>({
Expand Down Expand Up @@ -615,7 +615,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -651,7 +651,7 @@ describe(Preprocessor.name, () => {
deleteByStateUpdateId: async () => 1,
})
const mockUserL2TransactionsPreprocessor =
mockObject<UserL2TransactionsPreprocessor>({
mockObject<UserL2TransactionsStatisticsPreprocessor>({
rollbackOneStateUpdate: mockFn().resolvesTo(undefined),
})
const preprocessor = new Preprocessor(
Expand Down Expand Up @@ -697,7 +697,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockObject<L2TransactionRepository>(),
Logger.SILENT
)
Expand Down Expand Up @@ -727,7 +727,7 @@ describe(Preprocessor.name, () => {
mockObject<PerpetualHistoryPreprocessor>(),
mockObject<StateDetailsPreprocessor>(),
mockObject<UserStatisticsPreprocessor>(),
mockObject<UserL2TransactionsPreprocessor>(),
mockObject<UserL2TransactionsStatisticsPreprocessor>(),
mockedL2TransactionRepository,
Logger.SILENT
)
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/preprocessing/Preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Logger } from '../../tools/Logger'
import { HistoryPreprocessor } from './HistoryPreprocessor'
import { StateDetailsPreprocessor } from './StateDetailsPreprocessor'
import { UserL2TransactionsPreprocessor } from './UserL2TransactionsPreprocessor'
import { UserL2TransactionsStatisticsPreprocessor } from './UserL2TransactionsPreprocessor'
import { UserStatisticsPreprocessor } from './UserStatisticsPreprocessor'

export type SyncDirection = 'forward' | 'backward' | 'stop'
Expand All @@ -24,7 +24,7 @@ export class Preprocessor<T extends AssetHash | AssetId> {
private historyPreprocessor: HistoryPreprocessor<T>,
private stateDetailsPreprocessor: StateDetailsPreprocessor,
private userStatisticsPreprocessor: UserStatisticsPreprocessor,
private userL2TransactionsPreprocessor: UserL2TransactionsPreprocessor,
private userL2TransactionsPreprocessor: UserL2TransactionsStatisticsPreprocessor,
private l2TransactionRepository: L2TransactionRepository,
private logger: Logger,
private isEnabled: boolean = true
Expand Down

0 comments on commit 589c945

Please sign in to comment.