Skip to content

Commit 8b1bcc7

Browse files
committed
cleanup + name and symbol
1 parent d50df36 commit 8b1bcc7

8 files changed

Lines changed: 79 additions & 79 deletions

File tree

src/components/Indexer/processors/AddressRemovedEventProcessor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ export class AddressRemovedEventProcessor extends BaseEventProcessor {
2727
const result = await accessList.removeUserByTokenId(
2828
chainId,
2929
contractAddress,
30-
tokenId,
31-
event.blockNumber,
32-
event.transactionHash
30+
tokenId
3331
)
3432

3533
INDEXER_LOGGER.logMessage(

src/components/Indexer/processors/NewAccessListEventProcessor.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,26 @@ export class NewAccessListEventProcessor extends BaseEventProcessor {
2424
const contractAddress = decoded.args[0].toString().toLowerCase()
2525

2626
let transferable = false
27+
let name: string | undefined
28+
let symbol: string | undefined
2729
try {
2830
const accessListContract = new ethers.Contract(
2931
contractAddress,
3032
AccessList.abi,
3133
provider
3234
)
33-
transferable = Boolean(await accessListContract.transferable())
35+
const [transferableRaw, nameRaw, symbolRaw] = await Promise.all([
36+
accessListContract.transferable(),
37+
accessListContract.name(),
38+
accessListContract.symbol()
39+
])
40+
transferable = Boolean(transferableRaw)
41+
name = nameRaw
42+
symbol = symbolRaw
3443
} catch (err) {
3544
INDEXER_LOGGER.log(
3645
LOG_LEVELS_STR.LEVEL_WARN,
37-
`Failed to read transferable() on ${contractAddress}: ${err.message}`
46+
`Failed to read on-chain metadata for ${contractAddress}: ${err.message}`
3847
)
3948
}
4049

@@ -44,11 +53,13 @@ export class NewAccessListEventProcessor extends BaseEventProcessor {
4453
contractAddress,
4554
transferable,
4655
event.blockNumber,
47-
event.transactionHash
56+
event.transactionHash,
57+
name,
58+
symbol
4859
)
4960

5061
INDEXER_LOGGER.logMessage(
51-
`[NewAccessList] Indexed access list ${contractAddress} on chain ${chainId} (transferable=${transferable})`
62+
`[NewAccessList] Indexed access list ${contractAddress} on chain ${chainId} (name=${name}, symbol=${symbol}, transferable=${transferable})`
5263
)
5364
return result
5465
} catch (err) {

src/components/database/BaseDatabase.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export abstract class AbstractAccessListDatabase extends AbstractDatabase {
4545
contractAddress: string,
4646
transferable: boolean,
4747
block: number,
48-
txId: string
48+
txId: string,
49+
name?: string,
50+
symbol?: string
4951
): Promise<any>
5052

5153
abstract retrieve(chainId: number, contractAddress: string): Promise<any>
@@ -58,9 +60,7 @@ export abstract class AbstractAccessListDatabase extends AbstractDatabase {
5860
abstract removeUserByTokenId(
5961
chainId: number,
6062
contractAddress: string,
61-
tokenId: number,
62-
block: number,
63-
txId: string
63+
tokenId: number
6464
): Promise<any>
6565

6666
abstract searchByWallet(wallet: string, chainId?: number): Promise<any[]>

src/components/database/ElasticSchemas.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ export const elasticSchemas: ElasticsearchSchemas = {
173173
properties: {
174174
chainId: { type: 'integer' },
175175
contractAddress: { type: 'keyword' },
176-
factoryDeployed: { type: 'boolean' },
176+
name: { type: 'keyword' },
177+
symbol: { type: 'keyword' },
177178
transferable: { type: 'boolean' },
178179
users: {
179180
type: 'nested',
@@ -184,8 +185,8 @@ export const elasticSchemas: ElasticsearchSchemas = {
184185
txId: { type: 'keyword' }
185186
}
186187
},
187-
lastUpdatedBlock: { type: 'long' },
188-
lastTxId: { type: 'keyword' }
188+
deploymentBlock: { type: 'long' },
189+
deploymentTxId: { type: 'keyword' }
189190
}
190191
}
191192
}

src/components/database/ElasticSearchDatabase.ts

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,8 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
10531053
properties: {
10541054
chainId: { type: 'integer' },
10551055
contractAddress: { type: 'keyword' },
1056-
factoryDeployed: { type: 'boolean' },
1056+
name: { type: 'keyword' },
1057+
symbol: { type: 'keyword' },
10571058
transferable: { type: 'boolean' },
10581059
users: {
10591060
type: 'nested',
@@ -1064,8 +1065,8 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
10641065
txId: { type: 'keyword' }
10651066
}
10661067
},
1067-
lastUpdatedBlock: { type: 'long' },
1068-
lastTxId: { type: 'keyword' }
1068+
deploymentBlock: { type: 'long' },
1069+
deploymentTxId: { type: 'keyword' }
10691070
}
10701071
}
10711072
}
@@ -1081,7 +1082,9 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
10811082
contractAddress: string,
10821083
transferable: boolean,
10831084
block: number,
1084-
txId: string
1085+
txId: string,
1086+
name?: string,
1087+
symbol?: string
10851088
) {
10861089
const id = this.docId(chainId, contractAddress)
10871090
const lowerContract = contractAddress.toLowerCase()
@@ -1092,22 +1095,24 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
10921095
body: {
10931096
script: {
10941097
source: `
1095-
ctx._source.factoryDeployed = true;
10961098
ctx._source.transferable = params.transferable;
1097-
ctx._source.lastUpdatedBlock = params.block;
1098-
ctx._source.lastTxId = params.txId;
1099+
ctx._source.deploymentBlock = params.block;
1100+
ctx._source.deploymentTxId = params.txId;
1101+
if (params.name != null) { ctx._source.name = params.name; }
1102+
if (params.symbol != null) { ctx._source.symbol = params.symbol; }
10991103
`,
11001104
lang: 'painless',
1101-
params: { transferable, block, txId }
1105+
params: { transferable, block, txId, name, symbol }
11021106
},
11031107
upsert: {
11041108
chainId,
11051109
contractAddress: lowerContract,
1106-
factoryDeployed: true,
1110+
name,
1111+
symbol,
11071112
transferable,
11081113
users: [],
1109-
lastUpdatedBlock: block,
1110-
lastTxId: txId
1114+
deploymentBlock: block,
1115+
deploymentTxId: txId
11111116
}
11121117
},
11131118
refresh: 'wait_for'
@@ -1166,20 +1171,15 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
11661171
if (ctx._source.users[i].tokenId == params.user.tokenId) { exists = true; break; }
11671172
}
11681173
if (!exists) { ctx._source.users.add(params.user); }
1169-
ctx._source.lastUpdatedBlock = params.block;
1170-
ctx._source.lastTxId = params.txId;
11711174
`,
11721175
lang: 'painless',
1173-
params: { user: normalized, block: normalized.block, txId: normalized.txId }
1176+
params: { user: normalized }
11741177
},
11751178
upsert: {
11761179
chainId,
11771180
contractAddress: lowerContract,
1178-
factoryDeployed: false,
11791181
transferable: false,
1180-
users: [normalized],
1181-
lastUpdatedBlock: normalized.block,
1182-
lastTxId: normalized.txId
1182+
users: [normalized]
11831183
}
11841184
},
11851185
refresh: 'wait_for'
@@ -1197,13 +1197,7 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
11971197
}
11981198
}
11991199

1200-
async removeUserByTokenId(
1201-
chainId: number,
1202-
contractAddress: string,
1203-
tokenId: number,
1204-
block: number,
1205-
txId: string
1206-
) {
1200+
async removeUserByTokenId(chainId: number, contractAddress: string, tokenId: number) {
12071201
const id = this.docId(chainId, contractAddress)
12081202
try {
12091203
await this.client.update({
@@ -1215,11 +1209,9 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
12151209
if (ctx._source.users != null) {
12161210
ctx._source.users.removeIf(u -> u.tokenId == params.tokenId);
12171211
}
1218-
ctx._source.lastUpdatedBlock = params.block;
1219-
ctx._source.lastTxId = params.txId;
12201212
`,
12211213
lang: 'painless',
1222-
params: { tokenId, block, txId }
1214+
params: { tokenId }
12231215
}
12241216
},
12251217
refresh: 'wait_for'
@@ -1252,8 +1244,7 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
12521244
{
12531245
nested: {
12541246
path: 'users',
1255-
query: { term: { 'users.wallet': lowerWallet } },
1256-
inner_hits: { _source: { includes: ['users'] } }
1247+
query: { term: { 'users.wallet': lowerWallet } }
12571248
}
12581249
}
12591250
]
@@ -1268,10 +1259,7 @@ export class ElasticsearchAccessListDatabase extends AbstractAccessListDatabase
12681259
query: { bool: { must: filters } }
12691260
}
12701261
} as any)
1271-
return result.hits.hits.map((h: any) => ({
1272-
...(h._source as object),
1273-
innerHits: h.inner_hits?.users?.hits?.hits?.map((ih: any) => ih._source) ?? []
1274-
}))
1262+
return result.hits.hits.map((h: any) => h._source)
12751263
} catch (error) {
12761264
const errorMsg = `Error when searching access lists by wallet ${lowerWallet}: ${error.message}`
12771265
DATABASE_LOGGER.logMessageWithEmoji(

src/components/database/TypesenseDatabase.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,9 @@ export class TypesenseAccessListDatabase extends AbstractAccessListDatabase {
967967
contractAddress: string,
968968
transferable: boolean,
969969
block: number,
970-
txId: string
970+
txId: string,
971+
name?: string,
972+
symbol?: string
971973
) {
972974
const id = this.docId(chainId, contractAddress)
973975
const lowerContract = contractAddress.toLowerCase()
@@ -977,11 +979,12 @@ export class TypesenseAccessListDatabase extends AbstractAccessListDatabase {
977979
id,
978980
chainId,
979981
contractAddress: lowerContract,
980-
factoryDeployed: true,
982+
name,
983+
symbol,
981984
transferable,
982985
users: existing?.users ?? [],
983-
lastUpdatedBlock: block,
984-
lastTxId: txId
986+
deploymentBlock: block,
987+
deploymentTxId: txId
985988
}
986989
if (existing) {
987990
return await this.provider
@@ -999,7 +1002,11 @@ export class TypesenseAccessListDatabase extends AbstractAccessListDatabase {
9991002
async retrieve(chainId: number, contractAddress: string) {
10001003
const id = this.docId(chainId, contractAddress)
10011004
try {
1002-
return await this.provider.collections(this.schema.name).documents().retrieve(id)
1005+
const doc: any = await this.provider
1006+
.collections(this.schema.name)
1007+
.documents()
1008+
.retrieve(id)
1009+
return stripId(doc)
10031010
} catch (error) {
10041011
if (error instanceof TypesenseError && error.httpStatus === 404) {
10051012
return null
@@ -1018,36 +1025,26 @@ export class TypesenseAccessListDatabase extends AbstractAccessListDatabase {
10181025
const users: AccessListUser[] = existing?.users ?? []
10191026
const exists = users.some((u) => u.tokenId === normalized.tokenId)
10201027
const nextUsers = exists ? users : [...users, normalized]
1021-
const doc = {
1022-
id,
1023-
chainId,
1024-
contractAddress: lowerContract,
1025-
factoryDeployed: existing?.factoryDeployed ?? false,
1026-
transferable: existing?.transferable ?? false,
1027-
users: nextUsers,
1028-
lastUpdatedBlock: normalized.block,
1029-
lastTxId: normalized.txId
1030-
}
10311028
if (existing) {
10321029
return await this.provider
10331030
.collections(this.schema.name)
10341031
.documents()
1035-
.update(id, doc)
1032+
.update(id, { users: nextUsers })
10361033
}
1037-
return await this.provider.collections(this.schema.name).documents().create(doc)
1034+
return await this.provider.collections(this.schema.name).documents().create({
1035+
id,
1036+
chainId,
1037+
contractAddress: lowerContract,
1038+
transferable: false,
1039+
users: nextUsers
1040+
})
10381041
} catch (error) {
10391042
this.logError(`adding user ${normalized.wallet} to access list ${id}`, error)
10401043
return null
10411044
}
10421045
}
10431046

1044-
async removeUserByTokenId(
1045-
chainId: number,
1046-
contractAddress: string,
1047-
tokenId: number,
1048-
block: number,
1049-
txId: string
1050-
) {
1047+
async removeUserByTokenId(chainId: number, contractAddress: string, tokenId: number) {
10511048
const id = this.docId(chainId, contractAddress)
10521049
try {
10531050
const existing: any = await this.retrieve(chainId, contractAddress)
@@ -1058,7 +1055,7 @@ export class TypesenseAccessListDatabase extends AbstractAccessListDatabase {
10581055
return await this.provider
10591056
.collections(this.schema.name)
10601057
.documents()
1061-
.update(id, { users: nextUsers, lastUpdatedBlock: block, lastTxId: txId })
1058+
.update(id, { users: nextUsers })
10621059
} catch (error) {
10631060
this.logError(`removing tokenId ${tokenId} from access list ${id}`, error)
10641061
return null
@@ -1079,7 +1076,7 @@ export class TypesenseAccessListDatabase extends AbstractAccessListDatabase {
10791076
filter_by: filterParts.join(' && '),
10801077
per_page: 250
10811078
})
1082-
return (result.hits ?? []).map((h: any) => h.document)
1079+
return (result.hits ?? []).map((h: any) => stripId(h.document))
10831080
} catch (error) {
10841081
this.logError(`searching access lists by wallet ${lowerWallet}`, error)
10851082
return []
@@ -1105,3 +1102,9 @@ export class TypesenseAccessListDatabase extends AbstractAccessListDatabase {
11051102
)
11061103
}
11071104
}
1105+
1106+
function stripId(doc: any): any {
1107+
if (!doc) return doc
1108+
const { id: _id, ...rest } = doc
1109+
return rest
1110+
}

src/components/database/TypesenseSchemas.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,14 @@ export const typesenseSchemas: TypesenseSchemas = {
134134
fields: [
135135
{ name: 'chainId', type: 'int64' },
136136
{ name: 'contractAddress', type: 'string' },
137-
{ name: 'factoryDeployed', type: 'bool' },
137+
{ name: 'name', type: 'string', optional: true },
138+
{ name: 'symbol', type: 'string', optional: true },
138139
{ name: 'transferable', type: 'bool' },
139140
{ name: 'users', type: 'object[]', optional: true },
140141
{ name: 'users.wallet', type: 'string[]', optional: true, facet: true },
141142
{ name: 'users.tokenId', type: 'int64[]', optional: true },
142-
{ name: 'lastUpdatedBlock', type: 'int64' },
143-
{ name: 'lastTxId', type: 'string' }
143+
{ name: 'deploymentBlock', type: 'int64', optional: true },
144+
{ name: 'deploymentTxId', type: 'string', optional: true }
144145
]
145146
}
146147
}

src/test/integration/accessListEvents.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ describe('********** AccessList event indexing', function () {
124124

125125
expect(doc, 'document was not indexed in time').to.not.equal(null)
126126
expect(doc.contractAddress).to.equal(deployedAddr!.toLowerCase())
127-
expect(doc.factoryDeployed).to.equal(true)
128127
expect(doc.transferable).to.equal(false)
129128
expect(Array.isArray(doc.users)).to.equal(true)
130129
expect(doc.users.length).to.equal(0)
@@ -353,7 +352,6 @@ describe('********** AccessList event indexing', function () {
353352
expect(result.stream).to.not.equal(null)
354353
const doc = JSON.parse(await streamToString(result.stream as Readable))
355354
expect(doc.contractAddress).to.equal(deployedAddr!.toLowerCase())
356-
expect(doc.factoryDeployed).to.equal(true)
357355
})
358356

359357
it('GetAccessListHandler returns 404 for an unknown contract', async () => {

0 commit comments

Comments
 (0)