Skip to content

Commit 089d788

Browse files
authored
Merge pull request #289 from kodadot/main
🔖 Speck @ V13
2 parents 572177e + 10cc8e1 commit 089d788

14 files changed

+108
-120
lines changed

schema.graphql

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# https://github.com/paritytech/polkadot-sdk/blob/b8ad0d1f565659f004165c5244acba78828d0bf7/substrate/frame/nfts/src/lib.rs#L217
44
type CollectionEntity @entity {
55
attributes: [Attribute!]
6+
baseUri: String
67
blockNumber: BigInt @index
78
burned: Boolean!
89
createdAt: DateTime! @index

speck.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
manifestVersion: subsquid.io/v0.1
22
name: speck
3-
version: 12
3+
version: 13
44
description: 'SubSquid indexer for Uniques and Assets on Statemint'
55
build:
66
deploy:

src/mappings/nfts/mint.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { handleMetadata } from '../shared/metadata'
77
import { unwrap } from '../utils/extract'
88
import { debug, pending, success } from '../utils/logger'
99
import { Action, Context, createTokenId } from '../utils/types'
10-
import { calculateCollectionOwnerCountAndDistribution, versionOf } from '../utils/helper'
10+
import { calculateCollectionOwnerCountAndDistribution, tokenUri, versionOf } from '../utils/helper'
1111
import { mintHandler } from '../shared/token'
1212
import { getCreateTokenEvent } from './getters'
1313

@@ -42,7 +42,7 @@ export async function handleTokenCreate(context: Context): Promise<void> {
4242
final.blockNumber = BigInt(event.blockNumber)
4343
final.collection = collection
4444
final.sn = BigInt(event.sn)
45-
final.metadata = event.metadata || collection.metadata
45+
final.metadata = event.metadata || tokenUri(collection.baseUri, event.sn) || collection.metadata
4646
final.price = BigInt(0)
4747
final.burned = false
4848
final.createdAt = event.timestamp

src/mappings/nfts/setAttribute.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ export async function handleAttributeSet(context: Context): Promise<void> {
2525

2626
if ('royalty' in final && event.trait === 'royalty') {
2727
const value = unHex(event.value)
28-
final.royalty = final.royalty ?? Number.parseFloat(value || '0')
28+
final.royalty = final.royalty || Number.parseFloat(value || '0')
29+
}
30+
31+
if ('baseUri' in final && event.trait === 'baseUri') {
32+
const value = unHex(event.value)
33+
final.baseUri = final.baseUri || value
2934
}
3035

3136
if ('recipient' in final && event.trait === 'recipient') {
3237
try {
33-
final.recipient = final.recipient ?? addressOf(event.value as string)
38+
final.recipient = final.recipient || addressOf(event.value as string)
3439
} catch (error) {
3540
console.log(error)
36-
final.recipient = final.recipient ?? (event.value as string)
41+
final.recipient = '' // final.recipient ?? (event.value as string)
3742
}
3843
}
3944

src/mappings/utils/helper.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { emOf } from '@kodadot1/metasquid/entity'
2-
import { ArchiveCallWithOptionalValue, Store } from '@kodadot1/metasquid/types'
2+
import { ArchiveCallWithOptionalValue, Optional, Store } from '@kodadot1/metasquid/types'
33
import * as ss58 from '@subsquid/ss58'
44
import { decodeHex } from '@subsquid/substrate-processor'
55
import { CHAIN } from '../../environment'
@@ -11,8 +11,6 @@ const codec = CHAIN
1111
export const UNIQUE_PREFIX = 'u' as const
1212
export const EMPTY = '' as const
1313

14-
type Optional<T> = T | undefined
15-
1614
/**
1715
* Check if an object is empty
1816
* @param obj - the object to check
@@ -61,6 +59,20 @@ export function unHex<T>(value: T): T | string {
6159
return isHex(value) ? decodeHex(value).toString() : value
6260
}
6361

62+
/**
63+
* create a token uri from the base uri and the token id
64+
* @param baseUri - base uri from the collection
65+
* @param tokenId - the token id
66+
**/
67+
export function tokenUri(baseUri: Optional<string>, tokenId: Optional<string>): string {
68+
if (!baseUri || !tokenId) {
69+
return ''
70+
}
71+
72+
const uri = baseUri.endsWith('/') ? baseUri : `${baseUri}/`
73+
return `${uri}${tokenId}`
74+
}
75+
6476
/**
6577
* @deprecated Use the unjs/ufo package
6678
**/
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, StringColumn as StringColumn_, IntColumn as IntColumn_} from "@subsquid/typeorm-store"
22

33
@Entity_()
44
export class AssetEntity {
@@ -9,12 +9,12 @@ export class AssetEntity {
99
@PrimaryColumn_()
1010
id!: string
1111

12-
@Column_("text", {nullable: true})
12+
@StringColumn_({nullable: true})
1313
name!: string | undefined | null
1414

15-
@Column_("text", {nullable: true})
15+
@StringColumn_({nullable: true})
1616
symbol!: string | undefined | null
1717

18-
@Column_("int4", {nullable: true})
18+
@IntColumn_({nullable: true})
1919
decimals!: number | undefined | null
2020
}

src/model/generated/cacheStatus.model.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, DateTimeColumn as DateTimeColumn_} from "@subsquid/typeorm-store"
22

33
@Entity_()
44
export class CacheStatus {
@@ -9,6 +9,6 @@ export class CacheStatus {
99
@PrimaryColumn_()
1010
id!: string
1111

12-
@Column_("timestamp with time zone", {nullable: false})
12+
@DateTimeColumn_({nullable: false})
1313
lastBlockTimestamp!: Date
1414
}

src/model/generated/collectionEntity.model.ts

+26-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, Index as Index_, OneToMany as OneToMany_, ManyToOne as ManyToOne_} from "typeorm"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, StringColumn as StringColumn_, BigIntColumn as BigIntColumn_, Index as Index_, BooleanColumn as BooleanColumn_, DateTimeColumn as DateTimeColumn_, IntColumn as IntColumn_, OneToMany as OneToMany_, ManyToOne as ManyToOne_, FloatColumn as FloatColumn_} from "@subsquid/typeorm-store"
22
import * as marshal from "./marshal"
33
import {Attribute} from "./_attribute"
44
import {CollectionEvent} from "./collectionEvent.model"
@@ -16,93 +16,96 @@ export class CollectionEntity {
1616
@Column_("jsonb", {transformer: {to: obj => obj == null ? undefined : obj.map((val: any) => val.toJSON()), from: obj => obj == null ? undefined : marshal.fromList(obj, val => new Attribute(undefined, marshal.nonNull(val)))}, nullable: true})
1717
attributes!: (Attribute)[] | undefined | null
1818

19+
@StringColumn_({nullable: true})
20+
baseUri!: string | undefined | null
21+
1922
@Index_()
20-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
23+
@BigIntColumn_({nullable: true})
2124
blockNumber!: bigint | undefined | null
2225

23-
@Column_("bool", {nullable: false})
26+
@BooleanColumn_({nullable: false})
2427
burned!: boolean
2528

2629
@Index_()
27-
@Column_("timestamp with time zone", {nullable: false})
30+
@DateTimeColumn_({nullable: false})
2831
createdAt!: Date
2932

30-
@Column_("text", {nullable: false})
33+
@StringColumn_({nullable: false})
3134
currentOwner!: string
3235

33-
@Column_("int4", {nullable: false})
36+
@IntColumn_({nullable: false})
3437
distribution!: number
3538

3639
@OneToMany_(() => CollectionEvent, e => e.collection)
3740
events!: CollectionEvent[]
3841

3942
@Index_()
40-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
43+
@BigIntColumn_({nullable: false})
4144
floor!: bigint
4245

4346
@Index_({unique: true})
44-
@Column_("text", {nullable: false})
47+
@StringColumn_({nullable: false})
4548
hash!: string
4649

4750
@Index_()
48-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
51+
@BigIntColumn_({nullable: false})
4952
highestSale!: bigint
5053

5154
@PrimaryColumn_()
5255
id!: string
5356

54-
@Column_("text", {nullable: true})
57+
@StringColumn_({nullable: true})
5558
image!: string | undefined | null
5659

57-
@Column_("text", {nullable: false})
60+
@StringColumn_({nullable: false})
5861
issuer!: string
5962

60-
@Column_("int4", {nullable: true})
63+
@IntColumn_({nullable: true})
6164
max!: number | undefined | null
6265

63-
@Column_("text", {nullable: true})
66+
@StringColumn_({nullable: true})
6467
media!: string | undefined | null
6568

6669
@Index_()
6770
@ManyToOne_(() => MetadataEntity, {nullable: true})
6871
meta!: MetadataEntity | undefined | null
6972

70-
@Column_("text", {nullable: true})
73+
@StringColumn_({nullable: true})
7174
metadata!: string | undefined | null
7275

7376
@Index_()
74-
@Column_("text", {nullable: true})
77+
@StringColumn_({nullable: true})
7578
name!: string | undefined | null
7679

7780
@Index_()
78-
@Column_("int4", {nullable: false})
81+
@IntColumn_({nullable: false})
7982
nftCount!: number
8083

8184
@OneToMany_(() => NFTEntity, e => e.collection)
8285
nfts!: NFTEntity[]
8386

84-
@Column_("int4", {nullable: false})
87+
@IntColumn_({nullable: false})
8588
ownerCount!: number
8689

87-
@Column_("text", {nullable: true})
90+
@StringColumn_({nullable: true})
8891
recipient!: string | undefined | null
8992

90-
@Column_("numeric", {transformer: marshal.floatTransformer, nullable: true})
93+
@FloatColumn_({nullable: true})
9194
royalty!: number | undefined | null
9295

9396
@Index_()
94-
@Column_("int4", {nullable: false})
97+
@IntColumn_({nullable: false})
9598
supply!: number
9699

97100
@Index_()
98-
@Column_("timestamp with time zone", {nullable: false})
101+
@DateTimeColumn_({nullable: false})
99102
updatedAt!: Date
100103

101-
@Column_("int4", {nullable: false})
104+
@IntColumn_({nullable: false})
102105
version!: number
103106

104107
@Index_()
105-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
108+
@BigIntColumn_({nullable: false})
106109
volume!: bigint
107110

108111
@Column_("varchar", {length: 8, nullable: true})

src/model/generated/collectionEvent.model.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, ManyToOne as ManyToOne_, Index as Index_} from "typeorm"
2-
import * as marshal from "./marshal"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, BigIntColumn as BigIntColumn_, DateTimeColumn as DateTimeColumn_, StringColumn as StringColumn_, ManyToOne as ManyToOne_, Index as Index_} from "@subsquid/typeorm-store"
32
import {Interaction} from "./_interaction"
43
import {CollectionEntity} from "./collectionEntity.model"
54

@@ -12,22 +11,22 @@ export class CollectionEvent {
1211
@PrimaryColumn_()
1312
id!: string
1413

15-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
14+
@BigIntColumn_({nullable: true})
1615
blockNumber!: bigint | undefined | null
1716

18-
@Column_("timestamp with time zone", {nullable: false})
17+
@DateTimeColumn_({nullable: false})
1918
timestamp!: Date
2019

21-
@Column_("text", {nullable: false})
20+
@StringColumn_({nullable: false})
2221
caller!: string
2322

24-
@Column_("text", {nullable: true})
23+
@StringColumn_({nullable: true})
2524
currentOwner!: string | undefined | null
2625

2726
@Column_("varchar", {length: 12, nullable: false})
2827
interaction!: Interaction
2928

30-
@Column_("text", {nullable: false})
29+
@StringColumn_({nullable: false})
3130
meta!: string
3231

3332
@Index_()

src/model/generated/event.model.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, ManyToOne as ManyToOne_, Index as Index_} from "typeorm"
2-
import * as marshal from "./marshal"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, BigIntColumn as BigIntColumn_, DateTimeColumn as DateTimeColumn_, StringColumn as StringColumn_, ManyToOne as ManyToOne_, Index as Index_} from "@subsquid/typeorm-store"
32
import {Interaction} from "./_interaction"
43
import {NFTEntity} from "./nftEntity.model"
54

@@ -12,22 +11,22 @@ export class Event {
1211
@PrimaryColumn_()
1312
id!: string
1413

15-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
14+
@BigIntColumn_({nullable: true})
1615
blockNumber!: bigint | undefined | null
1716

18-
@Column_("timestamp with time zone", {nullable: false})
17+
@DateTimeColumn_({nullable: false})
1918
timestamp!: Date
2019

21-
@Column_("text", {nullable: false})
20+
@StringColumn_({nullable: false})
2221
caller!: string
2322

24-
@Column_("text", {nullable: false})
23+
@StringColumn_({nullable: false})
2524
currentOwner!: string
2625

2726
@Column_("varchar", {length: 12, nullable: false})
2827
interaction!: Interaction
2928

30-
@Column_("text", {nullable: false})
29+
@StringColumn_({nullable: false})
3130
meta!: string
3231

3332
@Index_()

src/model/generated/marshal.ts

-30
Original file line numberDiff line numberDiff line change
@@ -127,36 +127,6 @@ export function nonNull<T>(val: T | undefined | null): T {
127127
}
128128

129129

130-
export const bigintTransformer = {
131-
to(x?: bigint) {
132-
return x?.toString()
133-
},
134-
from(s?: string): bigint | undefined {
135-
return s == null ? undefined : BigInt(s)
136-
}
137-
}
138-
139-
140-
export const floatTransformer = {
141-
to(x?: number) {
142-
return x?.toString()
143-
},
144-
from(s?: string): number | undefined {
145-
return s == null ? undefined : Number(s)
146-
}
147-
}
148-
149-
150-
export const bigdecimalTransformer = {
151-
to(x?: any) {
152-
return x?.toString()
153-
},
154-
from(s?: any): any | undefined {
155-
return s == null ? undefined : decimal.BigDecimal(s)
156-
}
157-
}
158-
159-
160130
export function enumFromJson<E extends object>(json: unknown, enumObject: E): E[keyof E] {
161131
assert(typeof json == 'string', 'invalid enum value')
162132
let val = (enumObject as any)[json]
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, StringColumn as StringColumn_} from "@subsquid/typeorm-store"
22
import * as marshal from "./marshal"
33
import {Attribute} from "./_attribute"
44

@@ -11,24 +11,24 @@ export class MetadataEntity {
1111
@PrimaryColumn_()
1212
id!: string
1313

14-
@Column_("text", {nullable: true})
14+
@StringColumn_({nullable: true})
1515
name!: string | undefined | null
1616

17-
@Column_("text", {nullable: true})
17+
@StringColumn_({nullable: true})
1818
description!: string | undefined | null
1919

20-
@Column_("text", {nullable: true})
20+
@StringColumn_({nullable: true})
2121
image!: string | undefined | null
2222

2323
@Column_("jsonb", {transformer: {to: obj => obj == null ? undefined : obj.map((val: any) => val.toJSON()), from: obj => obj == null ? undefined : marshal.fromList(obj, val => new Attribute(undefined, marshal.nonNull(val)))}, nullable: true})
2424
attributes!: (Attribute)[] | undefined | null
2525

26-
@Column_("text", {nullable: true})
26+
@StringColumn_({nullable: true})
2727
animationUrl!: string | undefined | null
2828

29-
@Column_("text", {nullable: true})
29+
@StringColumn_({nullable: true})
3030
type!: string | undefined | null
3131

32-
@Column_("text", {nullable: true})
32+
@StringColumn_({nullable: true})
3333
banner!: string | undefined | null
3434
}

0 commit comments

Comments
 (0)