Skip to content

Commit

Permalink
Merge pull request #186 from kodadot/main
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiival authored Jan 10, 2024
2 parents f94f698 + ff6c70a commit 8ca7ed8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
17 changes: 17 additions & 0 deletions db/migrations/1704901579526-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = class Data1704901579526 {
name = 'Data1704901579526'

async up(db) {
await db.query(`DROP INDEX "public"."IDX_fb5a810a729fee4b0b0d3301eb"`)
await db.query(`ALTER TABLE "nft_entity" DROP COLUMN "sn"`)
await db.query(`ALTER TABLE "nft_entity" ADD "sn" numeric NOT NULL`)
await db.query(`CREATE INDEX "IDX_fb5a810a729fee4b0b0d3301eb" ON "nft_entity" ("sn") `)
}

async down(db) {
await db.query(`CREATE INDEX "IDX_fb5a810a729fee4b0b0d3301eb" ON "nft_entity" ("sn") `)
await db.query(`ALTER TABLE "nft_entity" ADD "sn" text NOT NULL`)
await db.query(`ALTER TABLE "nft_entity" DROP COLUMN "sn"`)
await db.query(`DROP INDEX "public"."IDX_fb5a810a729fee4b0b0d3301eb"`)
}
}
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type NFTEntity @entity {
price: BigInt @index
recipient: String
royalty: Float
sn: String! @index
sn: BigInt! @index
updatedAt: DateTime! @index
version: Int!
token: TokenEntity
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/nfts/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function handleTokenCreate(context: Context): Promise<void> {
final.currentOwner = event.owner
final.blockNumber = BigInt(event.blockNumber)
final.collection = collection
final.sn = event.sn
final.sn = BigInt(event.sn)
final.metadata = event.metadata || collection.metadata
final.price = BigInt(0)
final.burned = false
Expand Down
35 changes: 17 additions & 18 deletions src/mappings/nfts/setAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { getOrFail as get } from '@kodadot1/metasquid/entity'
import { CollectionEntity, NFTEntity } from '../../model'
import { unwrap } from '../utils/extract'
import { Context, isNFT } from '../utils/types'
// import { addressOf } from '../utils/helper'
import { addressOf } from '../utils/helper'
import { getAttributeEvent } from './getters'
import { tokenIdOf } from './types'
import { attributeFrom, tokenIdOf } from './types'

export async function handleAttributeSet(context: Context): Promise<void> {
const event = unwrap(context, getAttributeEvent)
Expand All @@ -17,30 +17,29 @@ export async function handleAttributeSet(context: Context): Promise<void> {
final.attributes = []
}

// if ('royalty' in final && event.trait === 'royalty') {
// final.royalty = final.royalty ?? Number.parseFloat(event.value as string)
// }
if ('royalty' in final && event.trait === 'royalty') {
final.royalty = final.royalty ?? Number.parseFloat(event.value as string)
}

// if ('recipient' in final && event.trait === 'recipient') {
// try {
// final.recipient = final.recipient ?? addressOf(event.value as string)
// } catch (error) {
// console.log(error)
// final.recipient = final.recipient ?? (event.value as string)
// }
// }
if ('recipient' in final && event.trait === 'recipient') {
try {
final.recipient = final.recipient ?? addressOf(event.value as string)
} catch (error) {
console.log(error)
final.recipient = final.recipient ?? (event.value as string)
}
}

if (event.value === null) {
final.attributes = final.attributes?.filter((attr) => attr.trait !== event.trait)
} else {
const attribute = final.attributes?.find((attr) => attr.trait === event.trait)
if (attribute) {
attribute.value = String(event.value)
}
// else if (event.trait !== 'royalty' && event.trait !== 'recipient') {
// const newAttribute = attributeFrom({ trait_type: event.trait, value: String(event.value) })
// final.attributes?.push(newAttribute)
// }
} else if (event.trait !== 'royalty' && event.trait !== 'recipient') {
const newAttribute = attributeFrom({ trait_type: event.trait, value: String(event.value) })
final.attributes?.push(newAttribute)
}
}

await context.store.save(final)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/uniques/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function handleTokenCreate(context: Context): Promise<void> {
final.currentOwner = event.owner
final.blockNumber = BigInt(event.blockNumber)
final.collection = collection
final.sn = event.sn
final.sn = BigInt(event.sn)
final.metadata = event.metadata || collection.metadata
final.price = BigInt(0)
final.burned = false
Expand Down
4 changes: 2 additions & 2 deletions src/model/generated/nftEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export class NFTEntity {
royalty!: number | undefined | null

@Index_()
@Column_("text", {nullable: false})
sn!: string
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
sn!: bigint

@Index_()
@Column_("timestamp with time zone", {nullable: false})
Expand Down

0 comments on commit 8ca7ed8

Please sign in to comment.