Skip to content

Commit

Permalink
Merge pull request #231 from kodadot/180-is-address
Browse files Browse the repository at this point in the history
Is Address?
  • Loading branch information
vikiival authored Apr 11, 2023
2 parents d4b3e65 + 11593a8 commit a616ee4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit a616ee4

Please sign in to comment.