Skip to content

Commit

Permalink
Merge pull request #239 from kodadot/ideally-destory
Browse files Browse the repository at this point in the history
WIP: Destroy Collection
  • Loading branch information
vikiival authored Apr 16, 2023
2 parents 6fb420c + 9a742ba commit 8b18953
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 5 deletions.
11 changes: 11 additions & 0 deletions db/migrations/1681329677484-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = class Data1681329677484 {
name = 'Data1681329677484'

async up(db) {
await db.query(`ALTER TABLE "collection_entity" ADD "burned" boolean NOT NULL`)
}

async down(db) {
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "burned"`)
}
}
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type CollectionEntity @entity {
blockNumber: BigInt
burned: Boolean!
createdAt: DateTime!
currentOwner: String
distribution: Int!
Expand Down
1 change: 1 addition & 0 deletions src/mappings/v1/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export async function createCollection(context: Context): Promise<void> {
final.currentOwner = caller
final.distribution = 0
final.floor = BigInt(0)
final.burned = false
final.hash = md5(collection.id)
final.highestSale = BigInt(0)
final.issuer = caller
Expand Down
1 change: 1 addition & 0 deletions src/mappings/v2/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export async function createCollection(context: Context): Promise<void> {
final.currentOwner = caller
final.distribution = 0
final.floor = BigInt(0)
final.burned = false
final.hash = md5(collection.id)
final.highestSale = BigInt(0)
final.issuer = caller
Expand Down
35 changes: 35 additions & 0 deletions src/mappings/v2/destroy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getOrFail as get } from '@kodadot1/metasquid/entity'
import { Optional } from '@kodadot1/metasquid/types'

import { BasicInteraction } from '@kodadot1/minimark/v2'
import { CollectionEntity } from '../../model'
import { unwrap } from '../utils'
import { isIssuerOrElseError } from '../utils/consolidator'
import { error, success } from '../utils/logger'
import { Action, Context } from '../utils/types'
import { getInteraction } from './getters'

const OPERATION = Action.DESTROY

export async function destroy(context: Context) {
let interaction: Optional<BasicInteraction> = null

try {
const { value, caller } = unwrap(context, getInteraction)
interaction = value
const collection = await get<CollectionEntity>(context.store, CollectionEntity, interaction.id)

isIssuerOrElseError(collection, caller)

if (collection.supply > 0) {
throw new Error(`Cannot change issuer of collection with supply ${collection.supply}`)
}

collection.burned = true

await context.store.save(collection)
success(OPERATION, `${collection.id} from ${caller}`)
} catch (e) {
error(e, OPERATION, JSON.stringify(interaction))
}
}
11 changes: 6 additions & 5 deletions src/mappings/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import logger, { pending } from '../utils/logger'
import { Context } from '../utils/types'
import { acceptResource } from './accept'
import { addResource } from './addResource'
import { addTheme } from './addTheme'
import { base as createBase } from './base'
import { buy } from './buy'
import { changeIssuer } from './change'
import { createCollection } from './create'
import { destroy } from './destroy'
import { emote } from './emote'
import { equip } from './equip'
import { equippable } from './equippable'
import { lockCollection } from './lock'
import { mintItem } from './mint'
import { setProperty } from './propertySet'
import { send } from './send'
import { setPriority } from './setpriority'
import { addTheme } from './addTheme'
import { equip } from './equip'
import { equippable } from './equippable'
import { setProperty } from './setProperty'

export async function mainFrame(remark: string, context: Context): Promise<void> {
const base = unwrap(context, (_: Context) => ({ value: remark }))
Expand Down Expand Up @@ -80,7 +81,7 @@ export async function mainFrame(remark: string, context: Context): Promise<void>
await setProperty(context)
break
case Interaction.DESTROY:
pending(event, `::${base.blockNumber}::${base.value}`)
await destroy(context)
break
default:
logger.fatal(`[SKIP] ${event}::${base.value}::${base.blockNumber}`)
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/model/generated/collectionEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export class CollectionEntity {
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
blockNumber!: bigint | undefined | null

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

@Column_("timestamp with time zone", {nullable: false})
createdAt!: Date

Expand Down

0 comments on commit 8b18953

Please sign in to comment.