Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

221 move to v1 #227

Merged
merged 4 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/mappings/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export * from './burn'
export * from './change'
export * from './create'
export * from './emote'
export * from './event'
export * from './list'
export * from './metadata'
export * from './send'
2 changes: 1 addition & 1 deletion src/mappings/shared/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RmrkInteraction> = null
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
10 changes: 7 additions & 3 deletions src/mappings/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { unwrapRemark, Interaction } from '@kodadot1/minimark/v1'
import { Interaction, unwrapRemark } from '@kodadot1/minimark/v1'
import { unwrap } from '../utils'

import { changeIssuer, burn as consume, createCollection, emote, 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<void> {
const base = unwrap(context, (_: Context) => ({ value: remark }))
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/shared/mint.ts → src/mappings/v1/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/mappings/shared/send.ts → src/mappings/v1/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions src/mappings/v2/change.ts
Original file line number Diff line number Diff line change
@@ -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 '../utils'
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<RmrkInteraction> = null

try {
const { value, caller } = unwrap(context, getInteraction)
interaction = value
plsBe(withMeta, interaction)
const collection = await get<CollectionEntity>(context.store, CollectionEntity, interaction.id)
plsBe<CollectionEntity>(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))
}
}
53 changes: 53 additions & 0 deletions src/mappings/v2/emote.ts
Original file line number Diff line number Diff line change
@@ -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<RmrkInteraction> = null

try {
const { value, caller, timestamp, version } = unwrap(context, getInteraction)
interaction = value
plsBe(withMeta, interaction)
const nft = await get<NFTEntity>(context.store, NFTEntity, interaction.id)
plsBe<NFTEntity>(real, nft)
plsNotBe<NFTEntity>(burned, nft)
const id = emoteId(interaction, caller)
let emote = await get<Emote>(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>(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, '')
}
}
4 changes: 3 additions & 1 deletion src/mappings/v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Interaction, unwrapRemarkV2 as unwrapRemark } from '@kodadot1/minimark/v2'

import { burn, changeIssuer, 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'
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'
Expand Down