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

feat: Add lewd tag to collection and nft #262

Merged
merged 1 commit into from
Jun 2, 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
15 changes: 15 additions & 0 deletions db/migrations/1684773436602-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = class Data1684773436602 {
name = 'Data1684773436602'

async up(db) {
await db.query(`ALTER TABLE "nft_entity" ADD "lewd" boolean NOT NULL DEFAULT false`)
await db.query(`ALTER TABLE "nft_entity" ALTER COLUMN "lewd" DROP DEFAULT`)
await db.query(`ALTER TABLE "collection_entity" ADD "lewd" boolean NOT NULL DEFAULT false`)
await db.query(`ALTER TABLE "collection_entity" ALTER COLUMN "lewd" DROP DEFAULT`)
}

async down(db) {
await db.query(`ALTER TABLE "nft_entity" DROP COLUMN "lewd"`)
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "lewd"`)
}
}
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type CollectionEntity @entity {
id: ID!
image: String
issuer: String
lewd: Boolean!
max: Int!
media: String
meta: MetadataEntity
Expand Down Expand Up @@ -41,6 +42,7 @@ type NFTEntity @entity {
instance: String
image: String
issuer: String
lewd: Boolean!
media: String
meta: MetadataEntity
metadata: String
Expand Down
10 changes: 9 additions & 1 deletion src/mappings/shared/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Optional, TokenMetadata } from '@kodadot1/metasquid/types'
import { isEmpty } from '@kodadot1/minimark/utils'

import { logger } from '@kodadot1/metasquid/logger'
import { MetadataEntity as Metadata } from '../../model/generated'
import { Attribute, MetadataEntity as Metadata, MetadataEntity } from '../../model/generated'
import { fetchMetadata } from '../utils/metadata'
import { attributeFrom, Store } from '../utils/types'

Expand Down Expand Up @@ -42,3 +42,11 @@ export async function handleMetadata(id: string, name: string, store: Store): Pr
}
return final
}

export const isLewd = (metadata: MetadataEntity) => {
return Boolean(
metadata.attributes?.find((item) => {
return item.trait === 'NSFW'
})
)
}
4 changes: 3 additions & 1 deletion src/mappings/v1/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { unwrap } from '../utils/extract'
import { getCreateCollection } from '../utils/getters'
import { error, success } from '../utils/logger'
import { Action, Collection, Context } from '../utils/types'
import { handleMetadata } from '../shared/metadata'
import { handleMetadata, isLewd } from '../shared/metadata'

const OPERATION = Action.CREATE

Expand All @@ -33,6 +33,7 @@ export async function createCollection(context: Context): Promise<void> {
final.hash = md5(collection.id)
final.highestSale = BigInt(0)
final.issuer = caller
final.lewd = false
final.max = Number(collection.max) || 0
final.metadata = collection.metadata
final.name = (collection.name || '').trim()
Expand All @@ -49,6 +50,7 @@ export async function createCollection(context: Context): Promise<void> {
final.meta = metadata
final.image = metadata?.image
final.media = metadata?.animationUrl
final.lewd = metadata ? isLewd(metadata) : false
}

await context.store.save(final)
Expand Down
7 changes: 6 additions & 1 deletion src/mappings/v1/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getCreateToken } from '../utils/getters'
import { error, success } from '../utils/logger'
import { Action, Context, getNftId, NFT, Optional } from '../utils/types'
import { createEvent } from '../shared/event'
import { handleMetadata } from '../shared/metadata'
import { handleMetadata, isLewd } from '../shared/metadata'
import { calculateCollectionOwnerCountAndDistribution } from '../utils/helper'

const OPERATION = Action.MINT
Expand All @@ -34,6 +34,7 @@ export async function mintItem(context: Context): Promise<void> {
final.blockNumber = BigInt(blockNumber)
final.name = nft.name
final.instance = nft.instance
final.lewd = false
final.transferable = nft.transferable
final.collection = collection
final.sn = nft.sn
Expand Down Expand Up @@ -62,6 +63,10 @@ export async function mintItem(context: Context): Promise<void> {
final.meta = metadata
final.image = metadata?.image
final.media = metadata?.animationUrl
if (metadata && isLewd(metadata)) {
final.lewd = true
collection.lewd = true
}
}

await context.store.save(final)
Expand Down
4 changes: 3 additions & 1 deletion src/mappings/v2/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Optional } from '@kodadot1/metasquid/types'

import md5 from 'md5'
import { CollectionEntity } from '../../model'
import { handleMetadata } from '../shared'
import { handleMetadata, isLewd } from '../shared'
import { unwrap } from '../utils/extract'
import { error, success } from '../utils/logger'
import { Action, Collection, Context } from '../utils/types'
Expand Down Expand Up @@ -33,6 +33,7 @@ export async function createCollection(context: Context): Promise<void> {
final.hash = md5(collection.id)
final.highestSale = BigInt(0)
final.issuer = caller
final.lewd = false
final.max = Number(collection.max) || 0
final.metadata = collection.metadata
final.name = (collection.name || '').trim()
Expand All @@ -49,6 +50,7 @@ export async function createCollection(context: Context): Promise<void> {
final.meta = metadata
final.image = metadata?.image
final.media = metadata?.animationUrl
final.lewd = metadata ? isLewd(metadata) : false
if (metadata?.name && !final.name) {
final.name = metadata.name
}
Expand Down
7 changes: 6 additions & 1 deletion src/mappings/v2/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isOwnerOrElseError } from '../utils/consolidator'

import { CollectionEntity, NFTEntity, Property } from '../../model/generated'
import { createEvent } from '../shared/event'
import { handleMetadata } from '../shared/metadata'
import { handleMetadata, isLewd } from '../shared/metadata'
import { findRootItemById } from '../utils/entity'
import { calculateCollectionOwnerCountAndDistribution, isDummyAddress } from '../utils/helper'
import logger, { error, success } from '../utils/logger'
Expand All @@ -34,6 +34,7 @@ export async function mintItem(context: Context): Promise<void> {
final.blockNumber = BigInt(blockNumber)
final.name = nft.name
final.instance = nft.symbol
final.lewd = false
final.transferable = nft.transferable
final.collection = collection
final.sn = nft.sn
Expand All @@ -55,6 +56,10 @@ export async function mintItem(context: Context): Promise<void> {
final.meta = metadata
final.image = metadata?.image
final.media = metadata?.animationUrl
if (metadata && isLewd(metadata)) {
final.lewd = true
collection.lewd = true
}
if (metadata?.name && !final.name) {
final.name = metadata.name
}
Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/collectionEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export class CollectionEntity {
@Column_("text", {nullable: true})
issuer!: string | undefined | null

@Column_("bool", {nullable: false})
lewd!: boolean

@Column_("int4", {nullable: false})
max!: number

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/nftEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class NFTEntity {
@Column_("text", {nullable: true})
issuer!: string | undefined | null

@Column_("bool", {nullable: false})
lewd!: boolean

@Column_("text", {nullable: true})
media!: string | undefined | null

Expand Down