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

Is Address? #231

Merged
merged 2 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: 4 additions & 0 deletions src/mappings/utils/consolidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export function isIssuer(entity: Entity, caller: string) {
return entity.issuer === caller
}

export function realAddress(address?: string): boolean {
return !!address && isAddress(address)
}

export function isOwnerOrElseError(entity: Entity, caller: string) {
if (!isOwner(entity, caller)) {
throw new ReferenceError(`[CONSOLIDATE Bad Owner] Entity: ${entity.currentOwner} Caller: ${caller}`)
Expand Down
6 changes: 4 additions & 2 deletions src/mappings/v1/send.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { getOrFail as get } from '@kodadot1/metasquid/entity'
import { Optional } from '@kodadot1/metasquid/types'

import { plsBe } from '@kodadot1/metasquid/consolidator'
import { NFTEntity } from '../../model'
import { createEvent } from '../shared/event'
import { unwrap } from '../utils'
import { isOwnerOrElseError, validateInteraction } from '../utils/consolidator'
import { isOwnerOrElseError, realAddress, 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 '../shared/event'

const OPERATION = Action.SEND

Expand All @@ -21,6 +22,7 @@ export async function send(context: Context) {
const nft = await get<NFTEntity>(context.store, NFTEntity, interaction.id)
validateInteraction(nft, interaction)
isOwnerOrElseError(nft, caller)
plsBe(realAddress, interaction.value)
const originalOwner = nft.currentOwner ?? undefined
nft.currentOwner = interaction.value
nft.price = BigInt(0)
Expand Down