Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change labels, allow to search for user with only L2 txs #439

Merged
merged 7 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/backend/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ export class Application {
: vaultRepository,
userRegistrationEventRepository,
preprocessedAssetHistoryRepository,
l2TransactionRepository,
config.starkex.tradingMode
)

Expand Down
7 changes: 6 additions & 1 deletion packages/backend/src/api/controllers/SearchController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assertUnreachable, TradingMode } from '@explorer/shared'
import { EthereumAddress, PedersenHash, StarkKey } from '@explorer/types'

import { L2TransactionRepository } from '../../peripherals/database/L2TransactionRepository'
import { PositionRepository } from '../../peripherals/database/PositionRepository'
import { PreprocessedAssetHistoryRepository } from '../../peripherals/database/PreprocessedAssetHistoryRepository'
import { StateUpdateRepository } from '../../peripherals/database/StateUpdateRepository'
Expand All @@ -14,6 +15,7 @@ export class SearchController {
private positionOrVaultRepository: PositionRepository | VaultRepository,
private userRegistrationEventRepository: UserRegistrationEventRepository,
private preprocessedAssetHistoryRepository: PreprocessedAssetHistoryRepository,
private l2TransactionRepository: L2TransactionRepository,
private tradingMode: TradingMode
) {}

Expand Down Expand Up @@ -68,7 +70,10 @@ export class SearchController {
const assetHistoryExistsForStarkKey =
await this.preprocessedAssetHistoryRepository.starkKeyExists(starkKey)

if (!assetHistoryExistsForStarkKey) {
const l2TransactionsExistForStarkKey =
await this.l2TransactionRepository.starkKeyExists(starkKey)

if (!assetHistoryExistsForStarkKey && !l2TransactionsExistForStarkKey) {
return {
type: 'not found',
message: `No user with Stark key ${starkKey.toString()} was found`,
Expand Down
11 changes: 2 additions & 9 deletions packages/backend/src/api/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,6 @@ export class UserController {
this.preprocessedUserStatisticsRepository.findCurrentByStarkKey(starkKey),
])

if (!userStatistics) {
return {
type: 'not found',
message: `User with starkKey ${starkKey.toString()} not found`,
}
}

const ethAddressWithdrawableAssets =
starkKey === givenUser.starkKey && givenUser.address
? await this.withdrawableAssetRepository.getAssetBalancesByStarkKey(
Expand Down Expand Up @@ -281,9 +274,9 @@ export class UserController {
this.forcedTradeOfferViewService.toFinalizableOfferEntry(offer)
),
assets: assetEntries,
totalAssets: userStatistics.assetCount,
totalAssets: userStatistics?.assetCount ?? 0,
balanceChanges: balanceChangesEntries,
totalBalanceChanges: Number(userStatistics.balanceChangeCount), // TODO: don't cast
totalBalanceChanges: userStatistics?.balanceChangeCount ?? 0,
transactions,
totalTransactions,
offers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,18 @@ describe(L2TransactionRepository.name, () => {
expect(transaction?.stateUpdateId).toBeNullish()
})
})

describe(L2TransactionRepository.prototype.starkKeyExists.name, () => {
it("returns false if user doesn't exist", async () => {
expect(await repository.starkKeyExists(StarkKey.fake())).toEqual(false)
})

it('returns true if user exists', async () => {
await repository.addFeederGatewayTransaction(genericDepositTransaction)

expect(
await repository.starkKeyExists(genericDepositTransaction.data.starkKey)
).toEqual(true)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,19 @@ export class L2TransactionRepository extends BaseRepository {
const knex = await this.knex(trx)
await knex.raw('LOCK TABLE l2_transactions IN ROW EXCLUSIVE MODE;')
}

async starkKeyExists(
starkKey: StarkKey,
trx?: Knex.Transaction
): Promise<boolean> {
const knex = await this.knex(trx)
const row = await knex('l2_transactions')
.where('stark_key_a', starkKey.toString())
.orWhere('stark_key_b', starkKey.toString())
.first()

return row !== undefined
}
}

function toRecord(row: L2TransactionRow): Record {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function HomeL2TransactionsPage(props: HomeL2TransactionsPageProps) {
return (
<Page
path={L2_TRANSACTIONS_TABLE_PROPS.path}
description="Latest l2 transactions"
description="Live transactions"
context={props.context}
>
<ContentWrapper>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/view/pages/home/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export const STATE_UPDATE_TABLE_PROPS = {
}

export const L2_TRANSACTIONS_TABLE_PROPS = {
title: 'Latest L2 transactions',
title: 'Live transactions',
entryShortNamePlural: 'transactions',
entryLongNamePlural: 'L2 transactions',
entryLongNamePlural: 'transactions',
path: '/l2-transactions',
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import { StarkKey } from '@explorer/types'
import React from 'react'

import { InfoIcon } from '../../assets/icons/InfoIcon'
import { TooltipWrapper } from '../../components/Tooltip'

export const getUserPageProps = (starkKey: StarkKey) => ({
path: `/users/${starkKey.toString()}`,
description: `Details of user ${starkKey.toString()} including assets, balance changes, transactions and trade offers`,
})

export const getAssetsTableProps = (starkKey: StarkKey) => ({
title: 'Assets',
title: (
<span className="mt-2">
Assets{' '}
<div className="mt-3 text-md text-zinc-500">
Guaranteed state of balances (proven on Ethereum), updated every few
hours:
</div>
</span>
),
entryShortNamePlural: 'assets',
entryLongNamePlural: 'assets',
path: `/users/${starkKey.toString()}/assets`,
description: `Assets of user ${starkKey.toString()}`,
})

export const getL2TransactionTableProps = (starkKey: StarkKey) => ({
title: 'L2 transactions',
title: (
<span className="flex items-center gap-2">
Live Transactions{' '}
<TooltipWrapper content="Only included transactions are reflected in asset balances">
<InfoIcon />
</TooltipWrapper>
</span>
),
entryShortNamePlural: 'transactions',
entryLongNamePlural: 'L2 transactions',
entryLongNamePlural: 'transactions',
path: `/users/${starkKey.toString()}/l2-transactions`,
description: `Layer 2 transactions of user ${starkKey.toString()}`,
})
Expand Down