Skip to content

Commit

Permalink
🚧 lock depends on #153
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiival committed Oct 25, 2022
1 parent d036a31 commit 2e90000
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/mappings/v2/lock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ensure } from '@kodadot1/metasquid'
import { plsBe, real } from '@kodadot1/metasquid/consolidator'
import { get } from '@kodadot1/metasquid/entity'
import { Optional } from '@kodadot1/metasquid/types'

import { CollectionEntity } from '../../model'
import { unwrap } from '../utils'
import { isOwnerOrElseError, withMeta } from '../utils/consolidator'
import { getInteraction } from '../utils/getters'
import logger, { logError } from '../utils/logger'
import { Context, RmrkInteraction } from '../utils/types'


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

try {
const { value, caller } = unwrap(context, getInteraction);
interaction = value
plsBe(withMeta, interaction)
const collection = ensure<CollectionEntity>(
await get<CollectionEntity>(context.store, CollectionEntity, interaction.id)
)
plsBe<CollectionEntity>(real, collection)
isOwnerOrElseError(collection, caller)
// TODO: implement lock
// collection.max = 100


logger.success(`[CHANGEISSUER] ${collection.id} from ${caller}`)
await context.store.save(collection)
} catch (e) {
logError(e, (e) =>
logger.warn(`[CHANGEISSUER] ${e.message} ${JSON.stringify(interaction)}`)
)
}
}

0 comments on commit 2e90000

Please sign in to comment.