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

169 no buy for you #171

Merged
merged 5 commits into from
Jan 9, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"update": "npx npm-check-updates --filter /subsquid/ --upgrade && npm i -f",
"db:migrate": "npx squid-typeorm-migration apply",
"processor:start": "node lib/processor.js",
"query-node:start": "squid-graphql-server --subscriptions --dumb-cache in-memory --dumb-cache-ttl 1000 --dumb-cache-size 100 --dumb-cache-max-age 1000",
"query-node:start": "squid-graphql-server --subscriptions --max-root-fields 50 --dumb-cache in-memory --dumb-cache-ttl 1000 --dumb-cache-size 100 --dumb-cache-max-age 1000",
"test:unit": "mocha -r ts-node/register tests/unit/**.spec.ts"
},
"dependencies": {
Expand Down
11 changes: 6 additions & 5 deletions src/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { updateCache } from './utils/cache'
import { burned, isBuyLegalOrElseError, isInteractive, isOwnerOrElseError, isPositiveOrElseError, plsBe, plsNotBe, real, validateInteraction, withMeta } from './utils/consolidator'
import { create, get } from './utils/entity'
import { getCreateCollection, getCreateToken, getInteraction, getInteractionWithExtra } from './utils/getters'
import { emoteId, ensure, eventId, isEmpty } from './utils/helper'
import { collectionIdFrom, emoteId, ensure, eventId, isEmpty } from './utils/helper'
import logger, { logError } from './utils/logger'
import { fetchMetadata } from './utils/metadata'
import {
Expand Down Expand Up @@ -230,8 +230,8 @@ async function buy(context: Context) {
nft.price = BigInt(0)
nft.updatedAt = timestamp

plsBe(real, nft.collection)
const collection = ensure<CollectionEntity>(await get<CollectionEntity>(context.store, CollectionEntity, nft.collection.toString()))
const collectionId = collectionIdFrom(nft.id)
const collection = ensure<CollectionEntity>(await get<CollectionEntity>(context.store, CollectionEntity, collectionId))
plsBe(real, collection)
collection.updatedAt = timestamp

Expand Down Expand Up @@ -261,8 +261,9 @@ async function consume(context: Context) {
nft.price = BigInt(0)
nft.burned = true
nft.updatedAt = timestamp
plsBe(real, nft.collection)
const collection = ensure<CollectionEntity>(await get<CollectionEntity>(context.store, CollectionEntity, nft.collection.toString()))

const collectionId = collectionIdFrom(nft.id)
const collection = ensure<CollectionEntity>(await get<CollectionEntity>(context.store, CollectionEntity, collectionId))
plsBe(real, collection)
collection.updatedAt = timestamp
collection.supply -= 1
Expand Down
5 changes: 5 additions & 0 deletions src/mappings/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export const eventId = (id: string, event: RmrkEvent) => `${id}-${event}${nanoid

export const ensureInteraction = ({ id, value: metadata }: RmrkInteraction): RmrkInteraction => ({ id: trim(id), value: trimAll(metadata) })

export const collectionIdFrom = (nftId: string) => {
const [_blockNumber, id, symbol] = nftId.split('-')
return `${id}-${symbol}`
}

export function ensure<T>(value: any): T {
return value as T
}
Expand Down