Skip to content

Commit

Permalink
Merge pull request #138 from kodadot/main
Browse files Browse the repository at this point in the history
🔖 Speck v6.0.3
  • Loading branch information
daiagi authored Oct 30, 2023
2 parents 16e7df1 + ff3cf54 commit 8260eca
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

# IDE files
/.idea
/suite
/suite
/.vscode
2 changes: 1 addition & 1 deletion src/mappings/nfts/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function handleTokenBurn(context: Context): Promise<void> {

await burnHandler(context, entity)

success(OPERATION, `${id} by ${event.caller}}`)
success(OPERATION, `${id} by ${event.caller}`)
await context.store.save(entity)
const meta = entity.metadata ?? ''
await createEvent(entity, OPERATION, event, meta, context.store)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/nfts/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function handleCollectionOwnerChange(context: Context): Promise<voi
const entity = await get(context.store, CE, event.id)
entity.currentOwner = event.owner

success(OPERATION, `${event.id} by ${event.caller}}`)
success(OPERATION, `${event.id} by ${event.caller}`)
await context.store.save(entity)
}
2 changes: 1 addition & 1 deletion src/mappings/nfts/changeTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export async function handleCollectionTeamChange(context: Context): Promise<void

entity.issuer = event.issuer

success(OPERATION, `${event.id} by ${event.caller}}`)
success(OPERATION, `${event.id} by ${event.caller}`)
await context.store.save(entity)
}
2 changes: 1 addition & 1 deletion src/mappings/nfts/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function handleCollectionDestroy(context: Context): Promise<void> {
const entity = await get(context.store, CE, event.id)
entity.burned = true

success(OPERATION, `${event.id} by ${event.caller}}`)
success(OPERATION, `${event.id} by ${event.caller}`)
await context.store.save(entity)
}
12 changes: 6 additions & 6 deletions src/mappings/nfts/getters/statemine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ export function getChangeTeamEvent(ctx: Context): ChangeCollectionTeam {
const { collection: classId, issuer, admin, freezer } = event.asV9420
return {
id: classId.toString(),
issuer: addressOf(issuer || ''),
admin: addressOf(admin || ''),
freezer: addressOf(freezer || ''),
issuer: issuer ? addressOf(issuer) : '',
admin: admin ? addressOf(admin) : '',
freezer: freezer ? addressOf(freezer) : '',
}
}

ctx.log.warn('USING UNSAFE GETTER! PLS UPDATE TYPES!')
const { collection: classId, issuer, admin, freezer } = ctx._chain.decodeEvent(ctx.event)
return {
id: classId.toString(),
issuer: addressOf(issuer || ''),
admin: addressOf(admin || ''),
freezer: addressOf(freezer || ''),
issuer: issuer ? addressOf(issuer) : '',
admin: admin ? addressOf(admin) : '',
freezer: freezer ? addressOf(freezer) : '',
}
}
12 changes: 6 additions & 6 deletions src/mappings/nfts/getters/statemint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ export function getChangeTeamEvent(ctx: Context): ChangeCollectionTeam {
const { collection: classId, issuer, admin, freezer } = event.asV9430
return {
id: classId.toString(),
issuer: addressOf(issuer || ''),
admin: addressOf(admin || ''),
freezer: addressOf(freezer || ''),
issuer: issuer ? addressOf(issuer) : '',
admin: admin ? addressOf(admin) : '',
freezer: freezer ? addressOf(freezer) : '',
}
}

ctx.log.warn('USING UNSAFE GETTER! PLS UPDATE TYPES!')
const { collection: classId, issuer, admin, freezer } = ctx._chain.decodeEvent(ctx.event)
return {
id: classId.toString(),
issuer: addressOf(issuer || ''),
admin: addressOf(admin || ''),
freezer: addressOf(freezer || ''),
issuer: issuer ? addressOf(issuer) : '',
admin: admin ? addressOf(admin) : '',
freezer: freezer ? addressOf(freezer) : '',
}
}
2 changes: 1 addition & 1 deletion src/mappings/nfts/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function handleCollectionLock(context: Context): Promise<void> {
const entity = await get(context.store, CE, event.id)
entity.max = event.max

success(OPERATION, `${event.id} by ${event.caller}}`)
success(OPERATION, `${event.id} by ${event.caller}`)
await context.store.save(entity)
}
6 changes: 2 additions & 4 deletions src/mappings/nfts/setAttribute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getOrFail as get } from '@kodadot1/metasquid/entity'
import { CollectionEntity, NFTEntity } from '../../model'
import { unwrap } from '../utils/extract'
import { addressOf } from '../utils/helper'
import { Context, isNFT } from '../utils/types'
import { getAttributeEvent } from './getters'
import { attributeFrom, tokenIdOf } from './types'
Expand All @@ -13,13 +12,12 @@ export async function handleAttributeSet(context: Context): Promise<void> {
isNFT(event)
? await get(context.store, NFTEntity, tokenIdOf(event as any))
: await get(context.store, CollectionEntity, event.collectionId)

if (!final.attributes) {
final.attributes = []
}

if ('royalty' in final && event.trait === 'royalty') {
final.royalty = final.royalty ?? Number.parseInt(event.value as string)
final.royalty = final.royalty ?? Number.parseFloat(event.value as string)
}

if ('recipient' in final && event.trait === 'recipient') {
Expand All @@ -32,7 +30,7 @@ export async function handleAttributeSet(context: Context): Promise<void> {
const attribute = final.attributes?.find((attr) => attr.trait === event.trait)
if (attribute) {
attribute.value = String(event.value)
} else {
} else if (event.trait !== 'royalty' && event.trait !== 'recipient') {
const newAttribute = attributeFrom({ trait_type: event.trait, value: String(event.value) })
final.attributes?.push(newAttribute)
}
Expand Down
4 changes: 3 additions & 1 deletion src/mappings/nfts/setMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export async function handleMetadataSet(context: Context): Promise<void> {

if (final.metadata) {
const metadata = await handleMetadata(final.metadata, context.store)
const previousNftMedia = final?.image || final?.media
const newNftMedia = metadata?.image || metadata?.animationUrl
final.meta = metadata
final.name = metadata?.name
final.image = metadata?.image
Expand All @@ -51,7 +53,7 @@ export async function handleMetadataSet(context: Context): Promise<void> {
warn(OPERATION, `collection ${event.collectionId} not found`)
return
}
if (final instanceof NFTEntity) {
if (final instanceof NFTEntity && newNftMedia !== previousNftMedia) {
await setMetadataHandler(context, collection, final)
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/mappings/shared/token/setMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ export async function setMetadataHandler(context: Context, collection: CE, nft:
if (!nftMedia) {
return
}
const tokenAPI = new TokenAPI(context.store)

let nftWithToken, existingToken
try {
[nftWithToken, existingToken] = await Promise.all([
getWith(context.store, NE, nft.id, { token: true }),
getOptional<TE>(context.store, TE, generateTokenId(collection.id, nftMedia)),
])
const nftWithToken = await getWith(context.store, NE, nft.id, { token: true })
if (nftWithToken?.token) {
await tokenAPI.removeNftFromToken(nft, nftWithToken.token)
}
} catch (error) {
warn(OPERATION, `ERROR ${error}`)
return
}

const tokenAPI = new TokenAPI(context.store)

if (nftWithToken.token) {
await tokenAPI.removeNftFromToken(nft, nftWithToken.token)
}
const existingToken = await getOptional<TE>(context.store, TE, generateTokenId(collection.id, nftMedia))
return await (existingToken ? tokenAPI.addNftToToken(nft, existingToken) : tokenAPI.create(collection, nft))
}
2 changes: 1 addition & 1 deletion src/mappings/uniques/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function handleTokenBurn(context: Context): Promise<void> {

await burnHandler(context, entity)

success(OPERATION, `${id} by ${event.caller}}`)
success(OPERATION, `${id} by ${event.caller}`)
await context.store.save(entity)
const meta = entity.metadata ?? ''
await createEvent(entity, OPERATION, event, meta, context.store)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/uniques/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function handleCollectionOwnerChange(context: Context): Promise<voi
const entity = await get(context.store, CE, event.id)
entity.currentOwner = event.owner

success(OPERATION, `${event.id} by ${event.caller}}`)
success(OPERATION, `${event.id} by ${event.caller}`)
await context.store.save(entity)
}
2 changes: 1 addition & 1 deletion src/mappings/uniques/changeTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function handleCollectionTeamChange(context: Context): Promise<void
const entity = await get(context.store, CE, event.id)
entity.issuer = event.issuer

success(OPERATION, `${event.id} by ${event.caller}}`)
success(OPERATION, `${event.id} by ${event.caller}`)
await context.store.save(entity)
}
2 changes: 1 addition & 1 deletion src/mappings/uniques/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function handleCollectionDestroy(context: Context): Promise<void> {
const entity = await get(context.store, CE, event.id)
entity.burned = true

success(OPERATION, `${event.id} by ${event.caller}}`)
success(OPERATION, `${event.id} by ${event.caller}`)
await context.store.save(entity)
}
2 changes: 1 addition & 1 deletion src/mappings/uniques/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function handleCollectionLock(context: Context): Promise<void> {
const entity = await get(context.store, CE, event.id)
entity.max = event.max

success(OPERATION, `${event.id} by ${event.caller}}`)
success(OPERATION, `${event.id} by ${event.caller}`)
await context.store.save(entity)
}

0 comments on commit 8260eca

Please sign in to comment.