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

chore: update matrix@v1004 and matrix@v1005 #934

Merged
merged 27 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
process: migrate
@node -r dotenv/config lib/processor.js
@NODE_OPTIONS="--max-old-space-size=16384" node -r dotenv/config lib/processor.js

build:
@npm run build
Expand Down
17 changes: 17 additions & 0 deletions db/migrations/1709204458056-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = class Data1709204458056 {
name = 'Data1709204458056'

async up(db) {
await db.query(`ALTER TABLE "account" ADD "verified" boolean NOT NULL`)
await db.query(`CREATE INDEX "IDX_9bfdaf06643c9b6d75a4292582" ON "token_account" ("created_at") `)
await db.query(`CREATE INDEX "IDX_73e1ad9383189937588f24d128" ON "listing" ("created_at") `)
await db.query(`CREATE INDEX "IDX_95d4beb28c1702ce48aa7f55e3" ON "token" ("created_at") `)
}

async down(db) {
await db.query(`ALTER TABLE "account" DROP COLUMN "verified"`)
await db.query(`DROP INDEX "public"."IDX_9bfdaf06643c9b6d75a4292582"`)
await db.query(`DROP INDEX "public"."IDX_73e1ad9383189937588f24d128"`)
await db.query(`DROP INDEX "public"."IDX_95d4beb28c1702ce48aa7f55e3"`)
}
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"scripts": {
"build": "rm -rf lib && tsc",
"db:migrate": "npx squid-typeorm-migration apply",
"processor:start": "node lib/processor.js",
"processor:debug": "node -r dotenv/config lib/processor.js",
"processor:start": "node -r dotenv/config lib/processor.js",
"query-node:start": "squid-graphql-server --subscriptions",
"worker:start": "node -r dotenv/config lib/job-handlers/worker.js",
"lint": "eslint src --ext .ts,.js",
Expand Down
7 changes: 4 additions & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ type Account @entity {
# profile
username: String
verifiedAt: DateTime
verified: Boolean!
image: String
}

Expand Down Expand Up @@ -585,7 +586,7 @@ type Token @entity {
# Extras
nonFungible: Boolean!
metadata: Metadata
createdAt: DateTime!
createdAt: DateTime! @index
}

type TokenApproval {
Expand Down Expand Up @@ -623,7 +624,7 @@ type TokenAccount @entity {
token: Token! @index

# Extras
createdAt: DateTime!
createdAt: DateTime! @index
updatedAt: DateTime!
}

Expand Down Expand Up @@ -768,7 +769,7 @@ type Listing @entity {
isActive: Boolean! @index
type: ListingType! @index

createdAt: DateTime!
createdAt: DateTime! @index
updatedAt: DateTime!
}

Expand Down
10 changes: 10 additions & 0 deletions src/common/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable max-classes-per-file */
import * as Sentry from '@sentry/node'

export class UnknownVersionError extends Error {
constructor(name: string) {
super(`There is no relevant version for ${name}`)
Expand All @@ -16,3 +18,11 @@ export class CallNotDefinedError extends Error {
super('Call is not defined')
}
}

export function throwError(message: string, severity: Sentry.SeverityLevel = 'error'): void {
if (process.env.NODE_ENV === 'development') {
throw new Error(message)
} else {
Sentry.captureMessage(message, severity)
}
}
1 change: 1 addition & 0 deletions src/job-handlers/fetch-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {
account.username = _d.username
account.image = _d.image
account.verifiedAt = _d.verifiedAt
account.verified = !!_d.verifiedAt

return account
})
Expand Down
6 changes: 3 additions & 3 deletions src/job-handlers/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express from 'express'
import { createBullBoard } from '@bull-board/api'
import { BullAdapter } from '@bull-board/api/bullAdapter'
import { ExpressAdapter } from '@bull-board/express'
import * as Sentry from '@sentry/node'
import { throwError } from 'src/common/errors'
import connection from '../connection'
import { collectionStatsQueue } from '../jobs/collection-stats'
import { metadataQueue } from '../jobs/process-metadata'
Expand Down Expand Up @@ -34,11 +34,11 @@ async function main() {
invalidateExpiredListings.process(1, `${__dirname}/invalidate-expired-listings.js`)

traitsQueue.on('global:failed', (job, err) => {
Sentry.captureMessage(`traitsQueue:Job ${job.id} failed with error: ${err.message}`, 'warning')
throwError(`traitsQueue:Job ${job.id} failed with error: ${err.message}`, 'warning')
})

metadataQueue.on('global:failed', (job, err) => {
Sentry.captureMessage(`metadataQueue:Job ${job.id} failed with error: ${err.message}`, 'warning')
throwError(`metadataQueue:Job ${job.id} failed with error: ${err.message}`, 'warning')
})

const serverAdapter = new ExpressAdapter()
Expand Down
2 changes: 2 additions & 0 deletions src/mappings/balances/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export async function saveAccounts(ctx: CommonContext, block: SubstrateBlock) {
id,
address: isAddressSS58(accountsU8a[i]) ? encodeId(accountsU8a[i]) : u8aToHex(accountsU8a[i]),
nonce: accountInfo.nonce,
verified: false,
balance: new Balance({
transferable: accountData.free - accountData.frozen,
free: accountData.free,
Expand All @@ -354,6 +355,7 @@ export async function saveAccounts(ctx: CommonContext, block: SubstrateBlock) {
id,
address: isAddressSS58(accountsU8a[i]) ? encodeId(accountsU8a[i]) : u8aToHex(accountsU8a[i]),
nonce: accountInfo.nonce,
verified: false,
balance: new Balance({
transferable: accountData.free - accountData.miscFrozen,
free: accountData.free,
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/fuelTanks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export function getTankDataFromCall(ctx: CommonContext, call: Call) {
data = new FuelTanksDispatchAndTouchCall(ctx, call)
}

if (data.isMatrixEnjinV1004) {
return data.asMatrixEnjinV1004
}

if (data.isMatrixEnjinV1003) {
return data.asMatrixEnjinV1003
}
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/fuelTanks/events/accountAdded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function getEventData(ctx: CommonContext, event: Event) {
return data.asV1000
}

if (data.isV500) {
return data.asV500
}

throw new UnknownVersionError(data.constructor.name)
}

Expand Down
4 changes: 4 additions & 0 deletions src/mappings/fuelTanks/events/accountRuleDataRemoved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function getEventData(ctx: CommonContext, event: Event) {
return data.asV1000
}

if (data.isV500) {
return data.asV500
}

throw new UnknownVersionError(data.constructor.name)
}

Expand Down
12 changes: 8 additions & 4 deletions src/mappings/fuelTanks/events/fuelTankCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ function getCallData(ctx: CommonContext, call: Call) {
} else {
data = new FuelTanksCreateFuelTankCall(ctx, call)

if (data.isV604) {
return data.asV604
}

if (data.isV602) {
return data.asV602
}
Expand All @@ -60,6 +56,10 @@ function getCallData(ctx: CommonContext, call: Call) {
}
}

if (data.isMatrixEnjinV1004) {
return data.asMatrixEnjinV1004
}

if (data.isMatrixEnjinV1003) {
return data.asMatrixEnjinV1003
}
Expand All @@ -84,6 +84,10 @@ function getCallData(ctx: CommonContext, call: Call) {
return data.asV1000
}

if (data.isV604) {
return data.asV604
}

throw new UnknownVersionError(data.constructor.name)
}

Expand Down
4 changes: 4 additions & 0 deletions src/mappings/fuelTanks/events/ruleSetInserted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function getEventData(ctx: CommonContext, event: Event) {
function getCallData(ctx: CommonContext, call: Call) {
const data = new FuelTanksInsertRuleSetCall(ctx, call)

if (data.isMatrixEnjinV1004) {
return data.asMatrixEnjinV1004
}

if (data.isMatrixEnjinV1003) {
return data.asMatrixEnjinV1003
}
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/marketplace/events/auction_finalized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function auctionFinalized(
if (bestListing) {
listing.makeAssetId.bestListing = bestListing
}
ctx.store.save(listing.makeAssetId)
await ctx.store.save(listing.makeAssetId)
}

await Promise.all([ctx.store.insert(ListingStatus, listingStatus as any), ctx.store.save(listing)])
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/marketplace/events/listing_cancelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function listingCancelled(
if (bestListing) {
listing.makeAssetId.bestListing = bestListing
}
ctx.store.save(listing.makeAssetId)
await ctx.store.save(listing.makeAssetId)
}

await Promise.all([ctx.store.insert(ListingStatus, listingStatus as any), ctx.store.save(listing)])
Expand Down
8 changes: 8 additions & 0 deletions src/mappings/marketplace/events/listing_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ import { syncCollectionStats } from '../../../jobs/collection-stats'
function getEventData(ctx: CommonContext, event: Event) {
const data = new MarketplaceListingCreatedEvent(ctx, event)

if (data.isMatrixEnjinV1004) {
return data.asMatrixEnjinV1004
}

if (data.isMatrixEnjinV603) {
return data.asMatrixEnjinV603
}

if (data.isV500) {
return data.asV500
}

if (data.isV1004) {
return data.asV1004
}
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/marketplace/events/listing_filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function listingFilled(
if (bestListing) {
listing.makeAssetId.bestListing = bestListing
}
ctx.store.save(listing.makeAssetId)
await ctx.store.save(listing.makeAssetId)
}

await Promise.all([ctx.store.save(listing), ctx.store.save(sale)])
Expand Down
10 changes: 3 additions & 7 deletions src/mappings/multiTokens/events/approved.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { u8aToHex } from '@polkadot/util'
import { SubstrateBlock } from '@subsquid/substrate-processor'
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'
import * as Sentry from '@sentry/node'
import { UnknownVersionError } from '../../../common/errors'
import { UnknownVersionError, throwError } from '../../../common/errors'
import {
CollectionAccount,
TokenAccount,
Expand Down Expand Up @@ -66,10 +65,7 @@ export async function approved(
})

if (!tokenAccount) {
Sentry.captureMessage(
`[Approved] We have not found token account ${address}-${data.collectionId}-${data.tokenId}.`,
'fatal'
)
throwError(`[Approved] We have not found token account ${address}-${data.collectionId}-${data.tokenId}.`, 'fatal')
return getEvent(item, data)
}

Expand All @@ -91,7 +87,7 @@ export async function approved(
})

if (!collectionAccount) {
Sentry.captureMessage(`[Approved] We have not found collection account ${data.collectionId}-${address}.`, 'fatal')
throwError(`[Approved] We have not found collection account ${data.collectionId}-${address}.`, 'fatal')
return getEvent(item, data)
}

Expand Down
7 changes: 3 additions & 4 deletions src/mappings/multiTokens/events/attribute_removed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SubstrateBlock } from '@subsquid/substrate-processor'
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'
import * as Sentry from '@sentry/node'
import { UnknownVersionError } from '../../../common/errors'
import { UnknownVersionError, throwError } from '../../../common/errors'
import { MultiTokensAttributeRemovedEvent } from '../../../types/generated/events'
import { Attribute, Collection, Event as EventModel, Extrinsic, MultiTokensAttributeRemoved, Token } from '../../../model'
import { Event } from '../../../types/generated/support'
Expand Down Expand Up @@ -69,7 +68,7 @@ export async function attributeRemoved(
})

if (!token) {
Sentry.captureMessage(`[AttributeRemoved] We have not found token ${data.collectionId}-${data.tokenId}.`, 'fatal')
throwError(`[AttributeRemoved] We have not found token ${data.collectionId}-${data.tokenId}.`, 'fatal')
return getEvent(item, data)
}

Expand All @@ -83,7 +82,7 @@ export async function attributeRemoved(
})

if (!collection) {
Sentry.captureMessage(`[AttributeRemoved] We have not found collection ${data.collectionId}.`, 'fatal')
throwError(`[AttributeRemoved] We have not found collection ${data.collectionId}.`, 'fatal')
return getEvent(item, data)
}

Expand Down
7 changes: 3 additions & 4 deletions src/mappings/multiTokens/events/attribute_set.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SubstrateBlock } from '@subsquid/substrate-processor'
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'
import * as Sentry from '@sentry/node'
import { UnknownVersionError } from '../../../common/errors'
import { UnknownVersionError, throwError } from '../../../common/errors'
import { MultiTokensAttributeSetEvent } from '../../../types/generated/events'
import {
Attribute,
Expand Down Expand Up @@ -113,14 +112,14 @@ export async function attributeSet(
await ctx.store.save(collection)
}

let token = null
let token: Token | null = null
if (data.tokenId !== undefined) {
token = await ctx.store.findOne<Token>(Token, {
where: { id: `${data.collectionId}-${data.tokenId}` },
})

if (!token) {
Sentry.captureMessage(`[AttributeSet] We have not found token ${data.collectionId}-${data.tokenId}.`, 'fatal')
throwError(`[AttributeSet] We have not found token ${data.collectionId}-${data.tokenId}.`, 'fatal')
return getEvent(item, data)
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/mappings/multiTokens/events/burned.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { u8aToHex } from '@polkadot/util'
import { SubstrateBlock } from '@subsquid/substrate-processor'
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'
import * as Sentry from '@sentry/node'
import { UnknownVersionError } from '../../../common/errors'
import { UnknownVersionError, throwError } from '../../../common/errors'
import { MultiTokensBurnedEvent } from '../../../types/generated/events'
import {
Account,
Expand Down Expand Up @@ -39,7 +38,7 @@ function getEventData(ctx: CommonContext, event: Event): EventData {
function getEvent(
item: EventItem<'MultiTokens.Burned', { event: { args: true; extrinsic: true } }>,
data: ReturnType<typeof getEventData>,
token?: Token
token?: Token | null
): [EventModel, AccountTokenEvent] | undefined | EventModel {
const event = new EventModel({
id: item.event.id,
Expand Down Expand Up @@ -102,10 +101,7 @@ export async function burned(
tokenAccount.updatedAt = new Date(block.timestamp)
await ctx.store.save(tokenAccount)
} else {
Sentry.captureMessage(
`[Burned] We have not found token account ${address}-${data.collectionId}-${data.tokenId}.`,
'fatal'
)
throwError(`[Burned] We have not found token account ${address}-${data.collectionId}-${data.tokenId}.`, 'fatal')
}

if (token) {
Expand All @@ -114,8 +110,8 @@ export async function burned(
await ctx.store.save(token)
syncCollectionStats(data.collectionId.toString())
} else {
Sentry.captureMessage(`[Burned] We have not found token ${data.collectionId}-${data.tokenId}.`, 'fatal')
throwError(`[Burned] We have not found token ${data.collectionId}-${data.tokenId}.`, 'fatal')
}

return getEvent(item, data)
return getEvent(item, data, token)
}
Loading