@sentio/sdk 1.30.3 → 1.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/builtin/erc1155/index.d.ts +2 -0
- package/lib/builtin/erc1155/index.js +22 -0
- package/lib/builtin/erc1155/index.js.map +1 -0
- package/lib/builtin/erc1155/test-utils.d.ts +6 -0
- package/lib/builtin/erc1155/test-utils.js +57 -0
- package/lib/builtin/erc1155/test-utils.js.map +1 -0
- package/lib/builtin/erc721/index.d.ts +2 -0
- package/lib/builtin/erc721/index.js +22 -0
- package/lib/builtin/erc721/index.js.map +1 -0
- package/lib/builtin/erc721/test-utils.d.ts +5 -0
- package/lib/builtin/erc721/test-utils.js +46 -0
- package/lib/builtin/erc721/test-utils.js.map +1 -0
- package/lib/builtin/internal/ERC1155.d.ts +199 -0
- package/lib/builtin/internal/ERC1155.js +3 -0
- package/lib/builtin/internal/ERC1155.js.map +1 -0
- package/lib/builtin/internal/ERC721.d.ts +252 -0
- package/lib/builtin/internal/ERC721.js +3 -0
- package/lib/builtin/internal/ERC721.js.map +1 -0
- package/lib/builtin/internal/erc1155_processor.d.ts +134 -0
- package/lib/builtin/internal/erc1155_processor.js +337 -0
- package/lib/builtin/internal/erc1155_processor.js.map +1 -0
- package/lib/builtin/internal/erc721_processor.d.ts +169 -0
- package/lib/builtin/internal/erc721_processor.js +479 -0
- package/lib/builtin/internal/erc721_processor.js.map +1 -0
- package/lib/builtin/internal/factories/ERC1155__factory.d.ts +35 -0
- package/lib/builtin/internal/factories/ERC1155__factory.js +332 -0
- package/lib/builtin/internal/factories/ERC1155__factory.js.map +1 -0
- package/lib/builtin/internal/factories/ERC721__factory.d.ts +51 -0
- package/lib/builtin/internal/factories/ERC721__factory.js +364 -0
- package/lib/builtin/internal/factories/ERC721__factory.js.map +1 -0
- package/lib/builtin/internal/factories/index.d.ts +2 -0
- package/lib/builtin/internal/factories/index.js +5 -1
- package/lib/builtin/internal/factories/index.js.map +1 -1
- package/lib/builtin/internal/index.d.ts +4 -0
- package/lib/builtin/internal/index.js +5 -1
- package/lib/builtin/internal/index.js.map +1 -1
- package/lib/core/account-processor.d.ts +58 -0
- package/lib/core/account-processor.js +147 -0
- package/lib/core/account-processor.js.map +1 -0
- package/lib/core/base-processor.d.ts +5 -2
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/bind-options.d.ts +5 -0
- package/lib/core/bind-options.js +7 -1
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +7 -1
- package/lib/core/context.js +30 -18
- package/lib/core/context.js.map +1 -1
- package/lib/core/meter.js +9 -0
- package/lib/core/meter.js.map +1 -1
- package/lib/gen/chainquery/protos/chainquery.d.ts +1 -0
- package/lib/gen/chainquery/protos/chainquery.js +17 -1
- package/lib/gen/chainquery/protos/chainquery.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +12 -1
- package/lib/gen/processor/protos/processor.js +108 -13
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/service.d.ts +1 -0
- package/lib/service.js +67 -42
- package/lib/service.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +6 -2
- package/lib/testing/test-processor-server.js +66 -5
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +1 -1
- package/src/abis/ERC1155.json +314 -0
- package/src/abis/ERC721.json +346 -0
- package/src/builtin/erc1155/index.ts +6 -0
- package/src/builtin/erc1155/test-utils.ts +89 -0
- package/src/builtin/erc721/index.ts +6 -0
- package/src/builtin/erc721/test-utils.ts +71 -0
- package/src/builtin/internal/ERC1155.ts +529 -0
- package/src/builtin/internal/ERC721.ts +639 -0
- package/src/builtin/internal/erc1155_processor.ts +580 -0
- package/src/builtin/internal/erc721_processor.ts +768 -0
- package/src/builtin/internal/factories/ERC1155__factory.ts +335 -0
- package/src/builtin/internal/factories/ERC721__factory.ts +364 -0
- package/src/builtin/internal/factories/index.ts +2 -0
- package/src/builtin/internal/index.ts +4 -0
- package/src/core/account-processor.ts +217 -0
- package/src/core/base-processor.ts +6 -2
- package/src/core/bind-options.ts +6 -0
- package/src/core/context.ts +42 -27
- package/src/core/meter.ts +11 -2
- package/src/gen/chainquery/protos/chainquery.ts +18 -1
- package/src/gen/processor/protos/processor.ts +113 -12
- package/src/service.ts +71 -44
- package/src/testing/test-processor-server.ts +71 -5
|
@@ -37,6 +37,45 @@ export function aggregationTypeToJSON(object: AggregationType): string {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export enum AddressType {
|
|
41
|
+
ERC20 = 0,
|
|
42
|
+
ERC721 = 1,
|
|
43
|
+
ERC1155 = 2,
|
|
44
|
+
UNRECOGNIZED = -1,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function addressTypeFromJSON(object: any): AddressType {
|
|
48
|
+
switch (object) {
|
|
49
|
+
case 0:
|
|
50
|
+
case "ERC20":
|
|
51
|
+
return AddressType.ERC20;
|
|
52
|
+
case 1:
|
|
53
|
+
case "ERC721":
|
|
54
|
+
return AddressType.ERC721;
|
|
55
|
+
case 2:
|
|
56
|
+
case "ERC1155":
|
|
57
|
+
return AddressType.ERC1155;
|
|
58
|
+
case -1:
|
|
59
|
+
case "UNRECOGNIZED":
|
|
60
|
+
default:
|
|
61
|
+
return AddressType.UNRECOGNIZED;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function addressTypeToJSON(object: AddressType): string {
|
|
66
|
+
switch (object) {
|
|
67
|
+
case AddressType.ERC20:
|
|
68
|
+
return "ERC20";
|
|
69
|
+
case AddressType.ERC721:
|
|
70
|
+
return "ERC721";
|
|
71
|
+
case AddressType.ERC1155:
|
|
72
|
+
return "ERC1155";
|
|
73
|
+
case AddressType.UNRECOGNIZED:
|
|
74
|
+
default:
|
|
75
|
+
return "UNRECOGNIZED";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
40
79
|
export enum HandlerType {
|
|
41
80
|
UNKNOWN = 0,
|
|
42
81
|
ETH_LOG = 1,
|
|
@@ -262,7 +301,7 @@ export interface MetricConfig {
|
|
|
262
301
|
}
|
|
263
302
|
|
|
264
303
|
export interface AggregationConfig {
|
|
265
|
-
intervalInMinutes: number;
|
|
304
|
+
intervalInMinutes: number[];
|
|
266
305
|
types: AggregationType[];
|
|
267
306
|
discardOrigin: boolean;
|
|
268
307
|
}
|
|
@@ -273,6 +312,7 @@ export interface AccountConfig {
|
|
|
273
312
|
startBlock: Long;
|
|
274
313
|
intervalConfigs: OnIntervalConfig[];
|
|
275
314
|
aptosIntervalConfigs: AptosOnIntervalConfig[];
|
|
315
|
+
logConfigs: LogHandlerConfig[];
|
|
276
316
|
}
|
|
277
317
|
|
|
278
318
|
export interface OnIntervalConfig {
|
|
@@ -320,6 +360,8 @@ export interface LogHandlerConfig {
|
|
|
320
360
|
|
|
321
361
|
export interface LogFilter {
|
|
322
362
|
topics: Topic[];
|
|
363
|
+
address: string | undefined;
|
|
364
|
+
addressType: AddressType | undefined;
|
|
323
365
|
}
|
|
324
366
|
|
|
325
367
|
export interface InstructionHandlerConfig {
|
|
@@ -1510,7 +1552,7 @@ export const MetricConfig = {
|
|
|
1510
1552
|
};
|
|
1511
1553
|
|
|
1512
1554
|
function createBaseAggregationConfig(): AggregationConfig {
|
|
1513
|
-
return { intervalInMinutes:
|
|
1555
|
+
return { intervalInMinutes: [], types: [], discardOrigin: false };
|
|
1514
1556
|
}
|
|
1515
1557
|
|
|
1516
1558
|
export const AggregationConfig = {
|
|
@@ -1518,9 +1560,11 @@ export const AggregationConfig = {
|
|
|
1518
1560
|
message: AggregationConfig,
|
|
1519
1561
|
writer: _m0.Writer = _m0.Writer.create()
|
|
1520
1562
|
): _m0.Writer {
|
|
1521
|
-
|
|
1522
|
-
|
|
1563
|
+
writer.uint32(10).fork();
|
|
1564
|
+
for (const v of message.intervalInMinutes) {
|
|
1565
|
+
writer.int32(v);
|
|
1523
1566
|
}
|
|
1567
|
+
writer.ldelim();
|
|
1524
1568
|
writer.uint32(18).fork();
|
|
1525
1569
|
for (const v of message.types) {
|
|
1526
1570
|
writer.int32(v);
|
|
@@ -1540,7 +1584,14 @@ export const AggregationConfig = {
|
|
|
1540
1584
|
const tag = reader.uint32();
|
|
1541
1585
|
switch (tag >>> 3) {
|
|
1542
1586
|
case 1:
|
|
1543
|
-
|
|
1587
|
+
if ((tag & 7) === 2) {
|
|
1588
|
+
const end2 = reader.uint32() + reader.pos;
|
|
1589
|
+
while (reader.pos < end2) {
|
|
1590
|
+
message.intervalInMinutes.push(reader.int32());
|
|
1591
|
+
}
|
|
1592
|
+
} else {
|
|
1593
|
+
message.intervalInMinutes.push(reader.int32());
|
|
1594
|
+
}
|
|
1544
1595
|
break;
|
|
1545
1596
|
case 2:
|
|
1546
1597
|
if ((tag & 7) === 2) {
|
|
@@ -1565,9 +1616,9 @@ export const AggregationConfig = {
|
|
|
1565
1616
|
|
|
1566
1617
|
fromJSON(object: any): AggregationConfig {
|
|
1567
1618
|
return {
|
|
1568
|
-
intervalInMinutes:
|
|
1569
|
-
?
|
|
1570
|
-
:
|
|
1619
|
+
intervalInMinutes: Array.isArray(object?.intervalInMinutes)
|
|
1620
|
+
? object.intervalInMinutes.map((e: any) => Number(e))
|
|
1621
|
+
: [],
|
|
1571
1622
|
types: Array.isArray(object?.types)
|
|
1572
1623
|
? object.types.map((e: any) => aggregationTypeFromJSON(e))
|
|
1573
1624
|
: [],
|
|
@@ -1579,8 +1630,13 @@ export const AggregationConfig = {
|
|
|
1579
1630
|
|
|
1580
1631
|
toJSON(message: AggregationConfig): unknown {
|
|
1581
1632
|
const obj: any = {};
|
|
1582
|
-
message.intervalInMinutes
|
|
1583
|
-
|
|
1633
|
+
if (message.intervalInMinutes) {
|
|
1634
|
+
obj.intervalInMinutes = message.intervalInMinutes.map((e) =>
|
|
1635
|
+
Math.round(e)
|
|
1636
|
+
);
|
|
1637
|
+
} else {
|
|
1638
|
+
obj.intervalInMinutes = [];
|
|
1639
|
+
}
|
|
1584
1640
|
if (message.types) {
|
|
1585
1641
|
obj.types = message.types.map((e) => aggregationTypeToJSON(e));
|
|
1586
1642
|
} else {
|
|
@@ -1593,7 +1649,7 @@ export const AggregationConfig = {
|
|
|
1593
1649
|
|
|
1594
1650
|
fromPartial(object: DeepPartial<AggregationConfig>): AggregationConfig {
|
|
1595
1651
|
const message = createBaseAggregationConfig();
|
|
1596
|
-
message.intervalInMinutes = object.intervalInMinutes
|
|
1652
|
+
message.intervalInMinutes = object.intervalInMinutes?.map((e) => e) || [];
|
|
1597
1653
|
message.types = object.types?.map((e) => e) || [];
|
|
1598
1654
|
message.discardOrigin = object.discardOrigin ?? false;
|
|
1599
1655
|
return message;
|
|
@@ -1607,6 +1663,7 @@ function createBaseAccountConfig(): AccountConfig {
|
|
|
1607
1663
|
startBlock: Long.UZERO,
|
|
1608
1664
|
intervalConfigs: [],
|
|
1609
1665
|
aptosIntervalConfigs: [],
|
|
1666
|
+
logConfigs: [],
|
|
1610
1667
|
};
|
|
1611
1668
|
}
|
|
1612
1669
|
|
|
@@ -1630,6 +1687,9 @@ export const AccountConfig = {
|
|
|
1630
1687
|
for (const v of message.aptosIntervalConfigs) {
|
|
1631
1688
|
AptosOnIntervalConfig.encode(v!, writer.uint32(42).fork()).ldelim();
|
|
1632
1689
|
}
|
|
1690
|
+
for (const v of message.logConfigs) {
|
|
1691
|
+
LogHandlerConfig.encode(v!, writer.uint32(50).fork()).ldelim();
|
|
1692
|
+
}
|
|
1633
1693
|
return writer;
|
|
1634
1694
|
},
|
|
1635
1695
|
|
|
@@ -1659,6 +1719,11 @@ export const AccountConfig = {
|
|
|
1659
1719
|
AptosOnIntervalConfig.decode(reader, reader.uint32())
|
|
1660
1720
|
);
|
|
1661
1721
|
break;
|
|
1722
|
+
case 6:
|
|
1723
|
+
message.logConfigs.push(
|
|
1724
|
+
LogHandlerConfig.decode(reader, reader.uint32())
|
|
1725
|
+
);
|
|
1726
|
+
break;
|
|
1662
1727
|
default:
|
|
1663
1728
|
reader.skipType(tag & 7);
|
|
1664
1729
|
break;
|
|
@@ -1682,6 +1747,9 @@ export const AccountConfig = {
|
|
|
1682
1747
|
AptosOnIntervalConfig.fromJSON(e)
|
|
1683
1748
|
)
|
|
1684
1749
|
: [],
|
|
1750
|
+
logConfigs: Array.isArray(object?.logConfigs)
|
|
1751
|
+
? object.logConfigs.map((e: any) => LogHandlerConfig.fromJSON(e))
|
|
1752
|
+
: [],
|
|
1685
1753
|
};
|
|
1686
1754
|
},
|
|
1687
1755
|
|
|
@@ -1705,6 +1773,13 @@ export const AccountConfig = {
|
|
|
1705
1773
|
} else {
|
|
1706
1774
|
obj.aptosIntervalConfigs = [];
|
|
1707
1775
|
}
|
|
1776
|
+
if (message.logConfigs) {
|
|
1777
|
+
obj.logConfigs = message.logConfigs.map((e) =>
|
|
1778
|
+
e ? LogHandlerConfig.toJSON(e) : undefined
|
|
1779
|
+
);
|
|
1780
|
+
} else {
|
|
1781
|
+
obj.logConfigs = [];
|
|
1782
|
+
}
|
|
1708
1783
|
return obj;
|
|
1709
1784
|
},
|
|
1710
1785
|
|
|
@@ -1722,6 +1797,8 @@ export const AccountConfig = {
|
|
|
1722
1797
|
object.aptosIntervalConfigs?.map((e) =>
|
|
1723
1798
|
AptosOnIntervalConfig.fromPartial(e)
|
|
1724
1799
|
) || [];
|
|
1800
|
+
message.logConfigs =
|
|
1801
|
+
object.logConfigs?.map((e) => LogHandlerConfig.fromPartial(e)) || [];
|
|
1725
1802
|
return message;
|
|
1726
1803
|
},
|
|
1727
1804
|
};
|
|
@@ -2313,7 +2390,7 @@ export const LogHandlerConfig = {
|
|
|
2313
2390
|
};
|
|
2314
2391
|
|
|
2315
2392
|
function createBaseLogFilter(): LogFilter {
|
|
2316
|
-
return { topics: [] };
|
|
2393
|
+
return { topics: [], address: undefined, addressType: undefined };
|
|
2317
2394
|
}
|
|
2318
2395
|
|
|
2319
2396
|
export const LogFilter = {
|
|
@@ -2324,6 +2401,12 @@ export const LogFilter = {
|
|
|
2324
2401
|
for (const v of message.topics) {
|
|
2325
2402
|
Topic.encode(v!, writer.uint32(10).fork()).ldelim();
|
|
2326
2403
|
}
|
|
2404
|
+
if (message.address !== undefined) {
|
|
2405
|
+
writer.uint32(18).string(message.address);
|
|
2406
|
+
}
|
|
2407
|
+
if (message.addressType !== undefined) {
|
|
2408
|
+
writer.uint32(24).int32(message.addressType);
|
|
2409
|
+
}
|
|
2327
2410
|
return writer;
|
|
2328
2411
|
},
|
|
2329
2412
|
|
|
@@ -2337,6 +2420,12 @@ export const LogFilter = {
|
|
|
2337
2420
|
case 1:
|
|
2338
2421
|
message.topics.push(Topic.decode(reader, reader.uint32()));
|
|
2339
2422
|
break;
|
|
2423
|
+
case 2:
|
|
2424
|
+
message.address = reader.string();
|
|
2425
|
+
break;
|
|
2426
|
+
case 3:
|
|
2427
|
+
message.addressType = reader.int32() as any;
|
|
2428
|
+
break;
|
|
2340
2429
|
default:
|
|
2341
2430
|
reader.skipType(tag & 7);
|
|
2342
2431
|
break;
|
|
@@ -2350,6 +2439,10 @@ export const LogFilter = {
|
|
|
2350
2439
|
topics: Array.isArray(object?.topics)
|
|
2351
2440
|
? object.topics.map((e: any) => Topic.fromJSON(e))
|
|
2352
2441
|
: [],
|
|
2442
|
+
address: isSet(object.address) ? String(object.address) : undefined,
|
|
2443
|
+
addressType: isSet(object.addressType)
|
|
2444
|
+
? addressTypeFromJSON(object.addressType)
|
|
2445
|
+
: undefined,
|
|
2353
2446
|
};
|
|
2354
2447
|
},
|
|
2355
2448
|
|
|
@@ -2360,12 +2453,20 @@ export const LogFilter = {
|
|
|
2360
2453
|
} else {
|
|
2361
2454
|
obj.topics = [];
|
|
2362
2455
|
}
|
|
2456
|
+
message.address !== undefined && (obj.address = message.address);
|
|
2457
|
+
message.addressType !== undefined &&
|
|
2458
|
+
(obj.addressType =
|
|
2459
|
+
message.addressType !== undefined
|
|
2460
|
+
? addressTypeToJSON(message.addressType)
|
|
2461
|
+
: undefined);
|
|
2363
2462
|
return obj;
|
|
2364
2463
|
},
|
|
2365
2464
|
|
|
2366
2465
|
fromPartial(object: DeepPartial<LogFilter>): LogFilter {
|
|
2367
2466
|
const message = createBaseLogFilter();
|
|
2368
2467
|
message.topics = object.topics?.map((e) => Topic.fromPartial(e)) || [];
|
|
2468
|
+
message.address = object.address ?? undefined;
|
|
2469
|
+
message.addressType = object.addressType ?? undefined;
|
|
2369
2470
|
return message;
|
|
2370
2471
|
},
|
|
2371
2472
|
};
|
package/src/service.ts
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
AptosProcessorState,
|
|
42
42
|
MoveResourcesWithVersionPayload,
|
|
43
43
|
} from './aptos/aptos-processor'
|
|
44
|
+
import { AccountProcessorState } from './core/account-processor'
|
|
44
45
|
;(BigInt.prototype as any).toJSON = function () {
|
|
45
46
|
return this.toString()
|
|
46
47
|
}
|
|
@@ -131,7 +132,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
131
132
|
})
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
// Part 1, prepare EVM processors
|
|
135
|
+
// Part 1.a, prepare EVM processors
|
|
135
136
|
for (const processor of global.PROCESSOR_STATE.processors) {
|
|
136
137
|
// If server favor incremental update this need to change
|
|
137
138
|
// Start basic config for contract
|
|
@@ -195,6 +196,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
195
196
|
throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
|
|
196
197
|
}
|
|
197
198
|
const logFilter: LogFilter = {
|
|
199
|
+
addressType: undefined,
|
|
200
|
+
address: contractConfig.contract?.address,
|
|
198
201
|
topics: [],
|
|
199
202
|
}
|
|
200
203
|
|
|
@@ -216,6 +219,52 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
216
219
|
this.contractConfigs.push(contractConfig)
|
|
217
220
|
}
|
|
218
221
|
|
|
222
|
+
// part 1.b prepare EVM account processors
|
|
223
|
+
for (const processor of AccountProcessorState.INSTANCE.getValues()) {
|
|
224
|
+
const accountConfig: AccountConfig = {
|
|
225
|
+
address: processor.config.address,
|
|
226
|
+
chainId: processor.getChainId().toString(),
|
|
227
|
+
startBlock: processor.config.startBlock ? Long.fromValue(processor.config.startBlock) : Long.ZERO,
|
|
228
|
+
aptosIntervalConfigs: [],
|
|
229
|
+
intervalConfigs: [],
|
|
230
|
+
logConfigs: [],
|
|
231
|
+
}
|
|
232
|
+
// TODO add interval
|
|
233
|
+
for (const eventsHandler of processor.eventHandlers) {
|
|
234
|
+
// associate id with filter
|
|
235
|
+
const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1
|
|
236
|
+
const logConfig: LogHandlerConfig = {
|
|
237
|
+
handlerId: handlerId,
|
|
238
|
+
filters: [],
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
for (const filter of eventsHandler.filters) {
|
|
242
|
+
if (!filter.topics) {
|
|
243
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
|
|
244
|
+
}
|
|
245
|
+
const logFilter: LogFilter = {
|
|
246
|
+
addressType: filter.addressType,
|
|
247
|
+
address: filter.address,
|
|
248
|
+
topics: [],
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
for (const ts of filter.topics) {
|
|
252
|
+
let hashes: string[] = []
|
|
253
|
+
if (Array.isArray(ts)) {
|
|
254
|
+
hashes = hashes.concat(ts)
|
|
255
|
+
} else if (ts) {
|
|
256
|
+
hashes.push(ts)
|
|
257
|
+
}
|
|
258
|
+
logFilter.topics.push({ hashes: hashes })
|
|
259
|
+
}
|
|
260
|
+
logConfig.filters.push(logFilter)
|
|
261
|
+
}
|
|
262
|
+
accountConfig.logConfigs.push(logConfig)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
this.accountConfigs.push(accountConfig)
|
|
266
|
+
}
|
|
267
|
+
|
|
219
268
|
// Part 2, prepare solana constractors
|
|
220
269
|
for (const solanaProcessor of global.PROCESSOR_STATE.solanaProcessors) {
|
|
221
270
|
const contractConfig: ContractConfig = {
|
|
@@ -327,6 +376,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
327
376
|
startBlock: Long.fromValue(aptosProcessor.config.startVersion.toString()),
|
|
328
377
|
aptosIntervalConfigs: [],
|
|
329
378
|
intervalConfigs: [],
|
|
379
|
+
logConfigs: [],
|
|
330
380
|
}
|
|
331
381
|
for (const handler of aptosProcessor.resourcesHandlers) {
|
|
332
382
|
const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1
|
|
@@ -418,6 +468,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
418
468
|
return this.processAptosEvent(request)
|
|
419
469
|
case HandlerType.APT_RESOURCE:
|
|
420
470
|
return this.processAptosResource(request)
|
|
471
|
+
case HandlerType.ETH_LOG:
|
|
472
|
+
return this.processLog(request)
|
|
421
473
|
default:
|
|
422
474
|
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
423
475
|
}
|
|
@@ -430,24 +482,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
430
482
|
|
|
431
483
|
const promises: Promise<ProcessResult>[] = []
|
|
432
484
|
for (const l of request.bindings) {
|
|
433
|
-
|
|
434
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
435
|
-
}
|
|
436
|
-
// const jsonString = Buffer.from(l.log.raw.buffer).toString("utf-8")
|
|
437
|
-
// const jsonString = String.fromCharCode.apply(null, l.log.raw)
|
|
438
|
-
|
|
439
|
-
try {
|
|
440
|
-
const jsonString = Utf8ArrayToStr(l.data.raw)
|
|
441
|
-
const log: Log = JSON.parse(jsonString)
|
|
442
|
-
const handler = this.eventHandlers[l.handlerId]
|
|
443
|
-
const promise = handler(log).catch((e) => {
|
|
444
|
-
throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\n' + errorString(e))
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
promises.push(promise)
|
|
448
|
-
} catch (e) {
|
|
449
|
-
throw new ServerError(Status.INTERNAL, 'error parse log: ' + l)
|
|
450
|
-
}
|
|
485
|
+
promises.push(this.processLog(l))
|
|
451
486
|
}
|
|
452
487
|
|
|
453
488
|
const result = mergeProcessResults(await Promise.all(promises))
|
|
@@ -468,6 +503,23 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
468
503
|
}
|
|
469
504
|
}
|
|
470
505
|
|
|
506
|
+
async processLog(l: DataBinding): Promise<ProcessResult> {
|
|
507
|
+
if (!l.data) {
|
|
508
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
try {
|
|
512
|
+
const jsonString = Utf8ArrayToStr(l.data.raw)
|
|
513
|
+
const log: Log = JSON.parse(jsonString)
|
|
514
|
+
const handler = this.eventHandlers[l.handlerId]
|
|
515
|
+
return handler(log).catch((e) => {
|
|
516
|
+
throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\n' + errorString(e))
|
|
517
|
+
})
|
|
518
|
+
} catch (e) {
|
|
519
|
+
throw new ServerError(Status.INTERNAL, 'error parse log: ' + l)
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
471
523
|
async processTransactions(
|
|
472
524
|
request: ProcessTransactionsRequest,
|
|
473
525
|
context: CallContext
|
|
@@ -501,31 +553,6 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
501
553
|
await Promise.all(processorPromises)
|
|
502
554
|
}
|
|
503
555
|
|
|
504
|
-
// if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {
|
|
505
|
-
// const processorPromises: Promise<void>[] = []
|
|
506
|
-
// for (const txn of request.transactions) {
|
|
507
|
-
// processorPromises.push(
|
|
508
|
-
// new Promise((resolve, _) => {
|
|
509
|
-
// for (const processor of global.PROCESSOR_STATE.aptosProcessors) {
|
|
510
|
-
// if (processor.address === txn.programAccountId!) {
|
|
511
|
-
// const res = processor.handleTransaction(
|
|
512
|
-
// JSON.parse(new TextDecoder().decode(txn.raw)),
|
|
513
|
-
// txn.slot ?? Long.fromNumber(0)
|
|
514
|
-
// )
|
|
515
|
-
// if (res) {
|
|
516
|
-
// res.gauges.forEach((g) => result.gauges.push(g))
|
|
517
|
-
// res.counters.forEach((c) => result.counters.push(c))
|
|
518
|
-
// res.logs.forEach((l) => result.logs.push(l))
|
|
519
|
-
// }
|
|
520
|
-
// }
|
|
521
|
-
// }
|
|
522
|
-
// resolve()
|
|
523
|
-
// })
|
|
524
|
-
// )
|
|
525
|
-
// }
|
|
526
|
-
// await Promise.all(processorPromises)
|
|
527
|
-
// }
|
|
528
|
-
|
|
529
556
|
recordRuntimeInfo(result, HandlerType.TRANSACTION)
|
|
530
557
|
return {
|
|
531
558
|
result,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AccountConfig,
|
|
2
3
|
BlockBinding,
|
|
3
4
|
ContractConfig,
|
|
4
5
|
DataBinding,
|
|
@@ -25,6 +26,7 @@ import { ProcessorState } from '../state/processor-state'
|
|
|
25
26
|
import { ProcessorServiceImpl } from '../service'
|
|
26
27
|
import { Trace } from '../core/trace'
|
|
27
28
|
import { setProvider } from '../provider'
|
|
29
|
+
import { account } from '../builtin/aptos/0x1'
|
|
28
30
|
|
|
29
31
|
export const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
30
32
|
|
|
@@ -37,7 +39,8 @@ export function cleanTest() {
|
|
|
37
39
|
|
|
38
40
|
export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
39
41
|
service: ProcessorServiceImpl
|
|
40
|
-
|
|
42
|
+
contractConfigs: ContractConfig[]
|
|
43
|
+
accountConfigs: AccountConfig[]
|
|
41
44
|
|
|
42
45
|
constructor(loader: () => void, httpEndpoints: Record<string, string> = {}) {
|
|
43
46
|
cleanTest()
|
|
@@ -58,7 +61,9 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
58
61
|
|
|
59
62
|
async start(request: StartRequest = { templateInstances: [] }, context = TEST_CONTEXT): Promise<Empty> {
|
|
60
63
|
const res = await this.service.start(request, context)
|
|
61
|
-
|
|
64
|
+
const config = await this.getConfig({})
|
|
65
|
+
this.contractConfigs = config.contractConfigs
|
|
66
|
+
this.accountConfigs = config.accountConfigs
|
|
62
67
|
return res
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -114,7 +119,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
114
119
|
}
|
|
115
120
|
const signature = trace.action.input.slice(0, 10)
|
|
116
121
|
|
|
117
|
-
for (const contract of this.
|
|
122
|
+
for (const contract of this.contractConfigs) {
|
|
118
123
|
if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {
|
|
119
124
|
continue
|
|
120
125
|
}
|
|
@@ -155,7 +160,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
buildLogBinding(log: Log, network: Networkish = 1): DataBinding | undefined {
|
|
158
|
-
for (const contract of this.
|
|
163
|
+
for (const contract of this.contractConfigs) {
|
|
159
164
|
if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {
|
|
160
165
|
continue
|
|
161
166
|
}
|
|
@@ -197,6 +202,67 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
197
202
|
}
|
|
198
203
|
return undefined
|
|
199
204
|
}
|
|
205
|
+
testAccountLog(address: string, log: Log, network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
206
|
+
return this.testAccountLogs(address, [log], network)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
testAccountLogs(address: string, logs: Log[], network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
210
|
+
const bindings = []
|
|
211
|
+
for (const log of logs) {
|
|
212
|
+
const binding = this.buildAccountLogBinding(address, log, network)
|
|
213
|
+
if (!binding) {
|
|
214
|
+
throw Error('Invalid test log: ' + JSON.stringify(log))
|
|
215
|
+
}
|
|
216
|
+
bindings.push(binding)
|
|
217
|
+
}
|
|
218
|
+
return this.processLogs({
|
|
219
|
+
bindings: bindings,
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
buildAccountLogBinding(address: string, log: Log, network: Networkish = 1): DataBinding | undefined {
|
|
224
|
+
for (const account of this.accountConfigs) {
|
|
225
|
+
if (account.chainId !== getNetwork(network).chainId.toString()) {
|
|
226
|
+
continue
|
|
227
|
+
}
|
|
228
|
+
if (address.toLowerCase() !== account.address.toLowerCase()) {
|
|
229
|
+
continue
|
|
230
|
+
}
|
|
231
|
+
for (const config of account.logConfigs) {
|
|
232
|
+
for (const filter of config.filters) {
|
|
233
|
+
// if (filter.topics.length != log.topics.length) {
|
|
234
|
+
// continue
|
|
235
|
+
// }
|
|
236
|
+
|
|
237
|
+
let match = true
|
|
238
|
+
for (const topicIdx in filter.topics) {
|
|
239
|
+
const logTopic = log.topics[topicIdx]
|
|
240
|
+
const possibleTopic = filter.topics[topicIdx].hashes
|
|
241
|
+
if (possibleTopic.length === 0) {
|
|
242
|
+
// match all
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
if (possibleTopic.find((e) => e.toLowerCase() === logTopic.toLowerCase())) {
|
|
246
|
+
// find one
|
|
247
|
+
continue
|
|
248
|
+
}
|
|
249
|
+
match = false
|
|
250
|
+
break
|
|
251
|
+
}
|
|
252
|
+
if (match) {
|
|
253
|
+
return {
|
|
254
|
+
data: {
|
|
255
|
+
raw: toBytes(log),
|
|
256
|
+
},
|
|
257
|
+
handlerId: config.handlerId,
|
|
258
|
+
handlerType: HandlerType.ETH_LOG,
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return undefined
|
|
265
|
+
}
|
|
200
266
|
|
|
201
267
|
testBlock(block: Partial<Block> & { number: number }, network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
202
268
|
return this.testBlocks([block], network)
|
|
@@ -223,7 +289,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
223
289
|
},
|
|
224
290
|
handlerIds: [],
|
|
225
291
|
}
|
|
226
|
-
for (const contract of this.
|
|
292
|
+
for (const contract of this.contractConfigs) {
|
|
227
293
|
if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {
|
|
228
294
|
continue
|
|
229
295
|
}
|