diff --git a/src/mappings/v2/lock.ts b/src/mappings/v2/lock.ts new file mode 100644 index 00000000..dc69c85b --- /dev/null +++ b/src/mappings/v2/lock.ts @@ -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 = null + + try { + const { value, caller } = unwrap(context, getInteraction); + interaction = value + plsBe(withMeta, interaction) + const collection = ensure( + await get(context.store, CollectionEntity, interaction.id) + ) + plsBe(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)}`) + ) + } +} \ No newline at end of file