From 21e4aef3dc00c6c390a8c2e5d4897d0c6de4c800 Mon Sep 17 00:00:00 2001 From: Viki Val Date: Tue, 11 Apr 2023 18:05:01 +0200 Subject: [PATCH 1/4] :truck: changeIssuer --- src/mappings/shared/index.ts | 1 - src/mappings/v1/change.ts | 32 +++++++++++++++++++++++++++ src/mappings/v1/index.ts | 3 ++- src/mappings/{shared => v2}/change.ts | 0 src/mappings/v2/index.ts | 3 ++- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/mappings/v1/change.ts rename src/mappings/{shared => v2}/change.ts (100%) diff --git a/src/mappings/shared/index.ts b/src/mappings/shared/index.ts index 0f742804..7cefe161 100644 --- a/src/mappings/shared/index.ts +++ b/src/mappings/shared/index.ts @@ -1,5 +1,4 @@ export * from './burn' -export * from './change' export * from './create' export * from './emote' export * from './event' diff --git a/src/mappings/v1/change.ts b/src/mappings/v1/change.ts new file mode 100644 index 00000000..65d37af6 --- /dev/null +++ b/src/mappings/v1/change.ts @@ -0,0 +1,32 @@ +import { plsBe, real } from '@kodadot1/metasquid/consolidator' +import { getOrFail as get } from '@kodadot1/metasquid/entity' +import { Optional } from '@kodadot1/metasquid/types' + +import { CollectionEntity } from '../../model' +import { unwrap } from '../shared' +import { isOwnerOrElseError, withMeta } from '../utils/consolidator' +import { getInteraction } from '../utils/getters' +import { error, success } from '../utils/logger' +import { Action, Context, RmrkInteraction } from '../utils/types' + +const OPERATION = Action.CHANGEISSUER + +// TODO: can also change BASE in V2 (not implemented yet) +export async function changeIssuer(context: Context) { + let interaction: Optional = null + + try { + const { value, caller } = unwrap(context, getInteraction) + interaction = value + plsBe(withMeta, interaction) + const collection = await get(context.store, CollectionEntity, interaction.id) + plsBe(real, collection) + isOwnerOrElseError(collection, caller) + collection.currentOwner = interaction.value + + success(OPERATION, `${collection.id} from ${caller}`) + await context.store.save(collection) + } catch (e) { + error(e, OPERATION, JSON.stringify(interaction)) + } +} diff --git a/src/mappings/v1/index.ts b/src/mappings/v1/index.ts index 3c605bab..99133c49 100644 --- a/src/mappings/v1/index.ts +++ b/src/mappings/v1/index.ts @@ -1,11 +1,12 @@ import { unwrapRemark, Interaction } from '@kodadot1/minimark/v1' import { unwrap } from '../utils' -import { changeIssuer, burn as consume, createCollection, emote, list, send } from '../shared' +import { burn as consume, createCollection, emote, list, send } from '../shared' import { mintItem } from '../shared/mint' import logger, { pending } from '../utils/logger' import { Context, RmrkInteraction } from '../utils/types' import { buy } from './buy' +import { changeIssuer } from './change' export async function mainFrame(remark: string, context: Context): Promise { const base = unwrap(context, (_: Context) => ({ value: remark })) diff --git a/src/mappings/shared/change.ts b/src/mappings/v2/change.ts similarity index 100% rename from src/mappings/shared/change.ts rename to src/mappings/v2/change.ts diff --git a/src/mappings/v2/index.ts b/src/mappings/v2/index.ts index a7288e09..8c661108 100644 --- a/src/mappings/v2/index.ts +++ b/src/mappings/v2/index.ts @@ -1,6 +1,6 @@ import { Interaction, unwrapRemarkV2 as unwrapRemark } from '@kodadot1/minimark/v2' -import { burn, changeIssuer, emote, list } from '../shared' +import { burn, emote, list } from '../shared' import { unwrap } from '../utils/extract' import logger, { pending } from '../utils/logger' import { Context } from '../utils/types' @@ -13,6 +13,7 @@ import { lockCollection } from './lock' import { mintItem } from './mint' import { send } from './send' import { setPriority } from './setpriority' +import { changeIssuer } from './change' export async function mainFrame(remark: string, context: Context): Promise { const base = unwrap(context, (_: Context) => ({ value: remark })) From c8dfc3adab3de0c978102e41584b7ab78bb20d95 Mon Sep 17 00:00:00 2001 From: Viki Val Date: Tue, 11 Apr 2023 18:06:47 +0200 Subject: [PATCH 2/4] :truck: moved emotes --- src/mappings/shared/index.ts | 1 - src/mappings/{shared => v1}/emote.ts | 0 src/mappings/v1/index.ts | 5 +-- src/mappings/v2/emote.ts | 53 ++++++++++++++++++++++++++++ src/mappings/v2/index.ts | 5 +-- 5 files changed, 59 insertions(+), 5 deletions(-) rename src/mappings/{shared => v1}/emote.ts (100%) create mode 100644 src/mappings/v2/emote.ts diff --git a/src/mappings/shared/index.ts b/src/mappings/shared/index.ts index 7cefe161..6d595163 100644 --- a/src/mappings/shared/index.ts +++ b/src/mappings/shared/index.ts @@ -1,6 +1,5 @@ export * from './burn' export * from './create' -export * from './emote' export * from './event' export * from './list' export * from './metadata' diff --git a/src/mappings/shared/emote.ts b/src/mappings/v1/emote.ts similarity index 100% rename from src/mappings/shared/emote.ts rename to src/mappings/v1/emote.ts diff --git a/src/mappings/v1/index.ts b/src/mappings/v1/index.ts index 99133c49..ce31d65c 100644 --- a/src/mappings/v1/index.ts +++ b/src/mappings/v1/index.ts @@ -1,12 +1,13 @@ -import { unwrapRemark, Interaction } from '@kodadot1/minimark/v1' +import { Interaction, unwrapRemark } from '@kodadot1/minimark/v1' import { unwrap } from '../utils' -import { burn as consume, createCollection, emote, list, send } from '../shared' +import { burn as consume, createCollection, list, send } from '../shared' import { mintItem } from '../shared/mint' import logger, { pending } from '../utils/logger' import { Context, RmrkInteraction } from '../utils/types' import { buy } from './buy' import { changeIssuer } from './change' +import { emote } from './emote' export async function mainFrame(remark: string, context: Context): Promise { const base = unwrap(context, (_: Context) => ({ value: remark })) diff --git a/src/mappings/v2/emote.ts b/src/mappings/v2/emote.ts new file mode 100644 index 00000000..4d7a20ec --- /dev/null +++ b/src/mappings/v2/emote.ts @@ -0,0 +1,53 @@ +import { burned, plsBe, plsNotBe, real } from '@kodadot1/metasquid/consolidator' +import { create, getOrFail as get } from '@kodadot1/metasquid/entity' +import { Optional } from '@kodadot1/metasquid/types' +import { toVersion } from '@kodadot1/minimark/shared' + +import { Emote, NFTEntity } from '../../model' +import { unwrap } from '../utils' +import { withMeta } from '../utils/consolidator' +import { getInteraction } from '../utils/getters' +import { emoteId } from '../utils/helper' +import { error, success } from '../utils/logger' +import { Action, Context, RmrkInteraction } from '../utils/types' + +const OPERATION = Action.EMOTE + +export async function emote(context: Context) { + let interaction: Optional = null + + try { + const { value, caller, timestamp, version } = unwrap(context, getInteraction) + interaction = value + plsBe(withMeta, interaction) + const nft = await get(context.store, NFTEntity, interaction.id) + plsBe(real, nft) + plsNotBe(burned, nft) + const id = emoteId(interaction, caller) + let emote = await get(context.store, Emote, interaction.id) + nft.updatedAt = timestamp + + if (emote) { + nft.emoteCount -= 1 + await context.store.remove(emote) + await context.store.save(nft) + return + } + + emote = create(Emote, id, { + id, + caller, + value: interaction.value, + version: toVersion(version), + }) + + emote.nft = nft + nft.emoteCount += 1 + + success(OPERATION, `${nft.id} from ${caller}`) + await context.store.save(emote) + await context.store.save(nft) + } catch (e) { + error(e, OPERATION, '') + } +} diff --git a/src/mappings/v2/index.ts b/src/mappings/v2/index.ts index 8c661108..82e73d46 100644 --- a/src/mappings/v2/index.ts +++ b/src/mappings/v2/index.ts @@ -1,6 +1,6 @@ import { Interaction, unwrapRemarkV2 as unwrapRemark } from '@kodadot1/minimark/v2' -import { burn, emote, list } from '../shared' +import { burn, list } from '../shared' import { unwrap } from '../utils/extract' import logger, { pending } from '../utils/logger' import { Context } from '../utils/types' @@ -8,12 +8,13 @@ import { acceptResource } from './accept' import { addResource } from './addResource' import { base as createBase } from './base' import { buy } from './buy' +import { changeIssuer } from './change' import { createCollection } from './create' +import { emote } from './emote' import { lockCollection } from './lock' import { mintItem } from './mint' import { send } from './send' import { setPriority } from './setpriority' -import { changeIssuer } from './change' export async function mainFrame(remark: string, context: Context): Promise { const base = unwrap(context, (_: Context) => ({ value: remark })) From 1f94d95fbbd40ea47f018d9af0d6e5a2e0a0a2cc Mon Sep 17 00:00:00 2001 From: Viki Val Date: Tue, 11 Apr 2023 18:07:41 +0200 Subject: [PATCH 3/4] :ambulance: Operation is LIST --- src/mappings/shared/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mappings/shared/list.ts b/src/mappings/shared/list.ts index 051737cc..04a80c42 100644 --- a/src/mappings/shared/list.ts +++ b/src/mappings/shared/list.ts @@ -14,7 +14,7 @@ import { error, success } from '../utils/logger' import { Action, Context, RmrkInteraction } from '../utils/types' import { createEvent } from './event' -const OPERATION = Action.BUY +const OPERATION = Action.LIST export async function list(context: Context) { let interaction: Optional = null From f5fd9705505805f15eb004e979de98c5cf294b8d Mon Sep 17 00:00:00 2001 From: Viki Val Date: Tue, 11 Apr 2023 18:11:41 +0200 Subject: [PATCH 4/4] :truck: last move of V1 interactions --- src/mappings/shared/index.ts | 2 -- src/mappings/v1/change.ts | 2 +- src/mappings/{shared => v1}/create.ts | 2 +- src/mappings/v1/index.ts | 6 ++++-- src/mappings/{shared => v1}/mint.ts | 4 ++-- src/mappings/{shared => v1}/send.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/mappings/{shared => v1}/create.ts (97%) rename src/mappings/{shared => v1}/mint.ts (96%) rename src/mappings/{shared => v1}/send.ts (96%) diff --git a/src/mappings/shared/index.ts b/src/mappings/shared/index.ts index 6d595163..bd9d9124 100644 --- a/src/mappings/shared/index.ts +++ b/src/mappings/shared/index.ts @@ -1,6 +1,4 @@ export * from './burn' -export * from './create' export * from './event' export * from './list' export * from './metadata' -export * from './send' diff --git a/src/mappings/v1/change.ts b/src/mappings/v1/change.ts index 65d37af6..f627a73a 100644 --- a/src/mappings/v1/change.ts +++ b/src/mappings/v1/change.ts @@ -3,7 +3,7 @@ import { getOrFail as get } from '@kodadot1/metasquid/entity' import { Optional } from '@kodadot1/metasquid/types' import { CollectionEntity } from '../../model' -import { unwrap } from '../shared' +import { unwrap } from '../utils' import { isOwnerOrElseError, withMeta } from '../utils/consolidator' import { getInteraction } from '../utils/getters' import { error, success } from '../utils/logger' diff --git a/src/mappings/shared/create.ts b/src/mappings/v1/create.ts similarity index 97% rename from src/mappings/shared/create.ts rename to src/mappings/v1/create.ts index 491dcaee..0603d256 100644 --- a/src/mappings/shared/create.ts +++ b/src/mappings/v1/create.ts @@ -8,7 +8,7 @@ import { unwrap } from '../utils/extract' import { getCreateCollection } from '../utils/getters' import { error, success } from '../utils/logger' import { Action, Collection, Context } from '../utils/types' -import { handleMetadata } from './metadata' +import { handleMetadata } from '../shared/metadata' const OPERATION = Action.CREATE diff --git a/src/mappings/v1/index.ts b/src/mappings/v1/index.ts index ce31d65c..f7feb5f4 100644 --- a/src/mappings/v1/index.ts +++ b/src/mappings/v1/index.ts @@ -1,13 +1,15 @@ import { Interaction, unwrapRemark } from '@kodadot1/minimark/v1' import { unwrap } from '../utils' -import { burn as consume, createCollection, list, send } from '../shared' -import { mintItem } from '../shared/mint' +import { burn as consume, list } from '../shared' import logger, { pending } from '../utils/logger' import { Context, RmrkInteraction } from '../utils/types' import { buy } from './buy' import { changeIssuer } from './change' +import { createCollection } from './create' import { emote } from './emote' +import { mintItem } from './mint' +import { send } from './send' export async function mainFrame(remark: string, context: Context): Promise { const base = unwrap(context, (_: Context) => ({ value: remark })) diff --git a/src/mappings/shared/mint.ts b/src/mappings/v1/mint.ts similarity index 96% rename from src/mappings/shared/mint.ts rename to src/mappings/v1/mint.ts index 70861e2a..833acbda 100644 --- a/src/mappings/shared/mint.ts +++ b/src/mappings/v1/mint.ts @@ -8,8 +8,8 @@ import { create } from '../utils/entity' import { getCreateToken } from '../utils/getters' import { error, success } from '../utils/logger' import { Action, Context, getNftId, NFT, Optional } from '../utils/types' -import { createEvent } from './event' -import { handleMetadata } from './metadata' +import { createEvent } from '../shared/event' +import { handleMetadata } from '../shared/metadata' const OPERATION = Action.MINT diff --git a/src/mappings/shared/send.ts b/src/mappings/v1/send.ts similarity index 96% rename from src/mappings/shared/send.ts rename to src/mappings/v1/send.ts index a18d9803..6b81713b 100644 --- a/src/mappings/shared/send.ts +++ b/src/mappings/v1/send.ts @@ -7,7 +7,7 @@ import { isOwnerOrElseError, validateInteraction } from '../utils/consolidator' import { getInteraction } from '../utils/getters' import { error, success } from '../utils/logger' import { Action, Context, RmrkInteraction } from '../utils/types' -import { createEvent } from './event' +import { createEvent } from '../shared/event' const OPERATION = Action.SEND