Skip to content

Commit

Permalink
Merge pull request #36 from kodadot/hashes
Browse files Browse the repository at this point in the history
Hashes for the NFTs
  • Loading branch information
vikiival authored Feb 16, 2022
2 parents 38e6b2e + e309883 commit 0b63be2
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 3 deletions.
13 changes: 13 additions & 0 deletions db/migrations/1645015239078-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = class Data1645015239078 {
name = 'Data1645015239078'

async up(db) {
await db.query(`ALTER TABLE "nft_entity" ADD "hash" text NOT NULL`)
await db.query(`CREATE INDEX "IDX_16e57ac8478b6ea1f383e3eb03" ON "nft_entity" ("hash") `)
}

async down(db) {
await db.query(`ALTER TABLE "nft_entity" DROP COLUMN "hash"`)
await db.query(`DROP INDEX "public"."IDX_16e57ac8478b6ea1f383e3eb03"`)
}
}
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ migrate:
@npx sqd db:migrate

update NAME:
npx sqd db:create-migration -n "{{NAME}}"
npx sqd db:create-migration "{{NAME}}"

test:
npm run test:unit
70 changes: 70 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"class-validator": "^0.13.1",
"dotenv": "^16.0.0",
"inflected": "^2.1.0",
"md5": "^2.3.0",
"nanoid": "^3.1.30",
"signale": "^1.4.0",
"type-graphql": "^1.2.0-rc.1"
Expand All @@ -31,6 +32,7 @@
"@subsquid/substrate-typegen": "^0.2.1",
"@types/chai": "^4.3.0",
"@types/inflected": "^1.1.29",
"@types/md5": "^2.3.2",
"@types/mocha": "^9.0.0",
"@types/pg": "^8.6.1",
"chai": "^4.3.4",
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type NFTEntity @entity {
issuer: String
sn: String
id: ID!
hash: String! @index
metadata: String
currentOwner: String
price: BigInt!
Expand Down
6 changes: 4 additions & 2 deletions src/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { create, get } from './utils/entity'
import { fetchMetadata } from './utils/metadata'
import { Store} from '@subsquid/substrate-processor'
import {updateCache} from './utils/cache'
import md5 from 'md5'


export async function handleRemark(context: Context): Promise<void> {
Expand Down Expand Up @@ -158,8 +159,9 @@ async function mintNFT(
canOrElseError<CollectionEntity>(exists, collection, true)
isOwnerOrElseError(collection, remark.caller)
const final = create<NFTEntity>(NFTEntity, collection.id, {})

final.id = getNftId(nft, remark.blockNumber)
const id = getNftId(nft, remark.blockNumber)
final.id = id
final.hash = md5(id)
final.issuer = remark.caller
final.currentOwner = remark.caller
final.blockNumber = BigInt(remark.blockNumber)
Expand Down
4 changes: 4 additions & 0 deletions src/model/generated/nftEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export class NFTEntity {
@PrimaryColumn_()
id!: string

@Index_()
@Column_("text", {nullable: false})
hash!: string

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

Expand Down

0 comments on commit 0b63be2

Please sign in to comment.