generated from eldargab/hydra-template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from kodadot/ideally-destory
WIP: Destroy Collection
- Loading branch information
Showing
8 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters