@sentio/sdk 1.25.3 → 1.26.0
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/aptos/aptos-processor.d.ts +23 -3
- package/lib/aptos/aptos-processor.js +69 -20
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +9 -3
- package/lib/aptos/context.js +32 -2
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/network.d.ts +1 -2
- package/lib/aptos/network.js +1 -1
- package/lib/aptos/network.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +22 -9
- package/lib/gen/processor/protos/processor.js +113 -24
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/processor-state.d.ts +2 -0
- package/lib/processor-state.js +1 -0
- package/lib/processor-state.js.map +1 -1
- package/lib/service.d.ts +3 -0
- package/lib/service.js +40 -2
- package/lib/service.js.map +1 -1
- package/lib/tests/aptos.test.js +25 -0
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/souffl3.js +5 -1
- package/lib/tests/souffl3.js.map +1 -1
- package/package.json +1 -1
- package/src/aptos/aptos-processor.ts +92 -19
- package/src/aptos/context.ts +31 -3
- package/src/aptos/network.ts +2 -4
- package/src/gen/processor/protos/processor.ts +153 -37
- package/src/processor-state.ts +2 -0
- package/src/service.ts +45 -2
- package/src/tests/aptos.test.ts +28 -0
- package/src/tests/souffl3.ts +6 -1
|
@@ -8,14 +8,15 @@ import {
|
|
|
8
8
|
TypeRegistry,
|
|
9
9
|
} from '.'
|
|
10
10
|
|
|
11
|
-
import Long from 'long'
|
|
12
11
|
import { EventInstance, TYPE_REGISTRY } from './types'
|
|
13
12
|
import { getChainId } from './network'
|
|
13
|
+
import { MoveResource } from 'aptos-sdk/src/generated'
|
|
14
|
+
import { AptosResourceContext } from './context'
|
|
14
15
|
|
|
15
16
|
type IndexConfigure = {
|
|
16
17
|
address: string
|
|
17
18
|
network: AptosNetwork
|
|
18
|
-
startVersion:
|
|
19
|
+
startVersion: bigint
|
|
19
20
|
// endSeqNumber?: Long
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -49,6 +50,18 @@ class CallHandler {
|
|
|
49
50
|
handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
export class MoveResourcesWithVersionPayload {
|
|
54
|
+
resources: MoveResource[]
|
|
55
|
+
version: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class ResourceHandlder {
|
|
59
|
+
type?: string
|
|
60
|
+
versionInterval?: number
|
|
61
|
+
timeIntervalInMinutes?: number
|
|
62
|
+
handler: (resource: MoveResourcesWithVersionPayload) => Promise<ProcessResult>
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
export class AptosBaseProcessor {
|
|
53
66
|
readonly moduleName: string
|
|
54
67
|
config: IndexConfigure
|
|
@@ -57,7 +70,7 @@ export class AptosBaseProcessor {
|
|
|
57
70
|
|
|
58
71
|
constructor(moduleName: string, options: AptosBindOptions) {
|
|
59
72
|
this.moduleName = moduleName
|
|
60
|
-
this.configure(options)
|
|
73
|
+
this.config = configure(options)
|
|
61
74
|
global.PROCESSOR_STATE.aptosProcessors.push(this)
|
|
62
75
|
this.loadTypes(TYPE_REGISTRY)
|
|
63
76
|
}
|
|
@@ -79,7 +92,7 @@ export class AptosBaseProcessor {
|
|
|
79
92
|
processor.moduleName,
|
|
80
93
|
processor.config.network,
|
|
81
94
|
processor.config.address,
|
|
82
|
-
|
|
95
|
+
BigInt(tx.version),
|
|
83
96
|
tx
|
|
84
97
|
)
|
|
85
98
|
if (tx) {
|
|
@@ -116,7 +129,7 @@ export class AptosBaseProcessor {
|
|
|
116
129
|
processor.moduleName,
|
|
117
130
|
processor.config.network,
|
|
118
131
|
processor.config.address,
|
|
119
|
-
|
|
132
|
+
BigInt(txn.version),
|
|
120
133
|
txn
|
|
121
134
|
)
|
|
122
135
|
if (txn && txn.events) {
|
|
@@ -158,7 +171,7 @@ export class AptosBaseProcessor {
|
|
|
158
171
|
processor.moduleName,
|
|
159
172
|
processor.config.network,
|
|
160
173
|
processor.config.address,
|
|
161
|
-
|
|
174
|
+
BigInt(tx.version),
|
|
162
175
|
tx
|
|
163
176
|
)
|
|
164
177
|
if (tx) {
|
|
@@ -173,19 +186,6 @@ export class AptosBaseProcessor {
|
|
|
173
186
|
return this
|
|
174
187
|
}
|
|
175
188
|
|
|
176
|
-
private configure(options: AptosBindOptions) {
|
|
177
|
-
let startVersion = Long.ZERO
|
|
178
|
-
if (options.startVersion) {
|
|
179
|
-
startVersion = Long.fromValue(options.startVersion)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
this.config = {
|
|
183
|
-
startVersion: startVersion,
|
|
184
|
-
address: options.address,
|
|
185
|
-
network: options.network || AptosNetwork.MAIN_NET,
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
189
|
getChainId(): string {
|
|
190
190
|
return getChainId(this.config.network)
|
|
191
191
|
}
|
|
@@ -202,3 +202,76 @@ export class AptosBaseProcessor {
|
|
|
202
202
|
console.log('')
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
+
|
|
206
|
+
export class AptosAccountProcessor {
|
|
207
|
+
config: IndexConfigure
|
|
208
|
+
|
|
209
|
+
resourcesHandlers: ResourceHandlder[] = []
|
|
210
|
+
|
|
211
|
+
static bind(options: AptosBindOptions): AptosAccountProcessor {
|
|
212
|
+
return new AptosAccountProcessor(options)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
protected constructor(options: AptosBindOptions) {
|
|
216
|
+
this.config = configure(options)
|
|
217
|
+
global.PROCESSOR_STATE.aptosAccountProcessors.push(this)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
getChainId(): string {
|
|
221
|
+
return getChainId(this.config.network)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private onInterval(
|
|
225
|
+
handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
|
|
226
|
+
timeInterval: number | undefined,
|
|
227
|
+
versionInterval: number | undefined,
|
|
228
|
+
type: string | undefined
|
|
229
|
+
) {
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
231
|
+
const processor = this
|
|
232
|
+
this.resourcesHandlers.push({
|
|
233
|
+
handler: async function (arg) {
|
|
234
|
+
const ctx = new AptosResourceContext(processor.config.network, processor.config.address, BigInt(arg.version))
|
|
235
|
+
await handler(arg.resources, ctx)
|
|
236
|
+
return ctx.getProcessResult()
|
|
237
|
+
},
|
|
238
|
+
timeIntervalInMinutes: timeInterval,
|
|
239
|
+
versionInterval: versionInterval,
|
|
240
|
+
type: type,
|
|
241
|
+
})
|
|
242
|
+
return this
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public onTimeInterval(
|
|
246
|
+
handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
|
|
247
|
+
timeIntervalInMinutes = 60,
|
|
248
|
+
typpe?: string
|
|
249
|
+
) {
|
|
250
|
+
return this.onInterval(handler, timeIntervalInMinutes, undefined, typpe)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
public onVersionInterval(
|
|
254
|
+
handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
|
|
255
|
+
versionInterval = 100000,
|
|
256
|
+
typePrefix?: string
|
|
257
|
+
) {
|
|
258
|
+
return this.onInterval(handler, undefined, versionInterval, typePrefix)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function configure(options: AptosBindOptions): IndexConfigure {
|
|
263
|
+
let startVersion = 0n
|
|
264
|
+
if (options.startVersion !== undefined) {
|
|
265
|
+
if (typeof options.startVersion === 'number') {
|
|
266
|
+
startVersion = BigInt(options.startVersion)
|
|
267
|
+
} else {
|
|
268
|
+
startVersion = options.startVersion
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
startVersion: startVersion,
|
|
274
|
+
address: options.address,
|
|
275
|
+
network: options.network || AptosNetwork.MAIN_NET,
|
|
276
|
+
}
|
|
277
|
+
}
|
package/src/aptos/context.ts
CHANGED
|
@@ -10,14 +10,14 @@ export class AptosContext extends BaseContext {
|
|
|
10
10
|
address: string
|
|
11
11
|
network: AptosNetwork
|
|
12
12
|
moduleName: string
|
|
13
|
-
version:
|
|
13
|
+
version: bigint
|
|
14
14
|
transaction: Transaction_UserTransaction
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
17
|
moduleName: string,
|
|
18
18
|
network: AptosNetwork,
|
|
19
19
|
address: string,
|
|
20
|
-
version:
|
|
20
|
+
version: bigint,
|
|
21
21
|
transaction?: Transaction_UserTransaction
|
|
22
22
|
) {
|
|
23
23
|
super()
|
|
@@ -34,7 +34,7 @@ export class AptosContext extends BaseContext {
|
|
|
34
34
|
return {
|
|
35
35
|
address: this.address,
|
|
36
36
|
contractName: this.moduleName,
|
|
37
|
-
blockNumber: this.version,
|
|
37
|
+
blockNumber: Long.fromString(this.version.toString()),
|
|
38
38
|
transactionIndex: 0,
|
|
39
39
|
transactionHash: this.transaction?.hash || '', // TODO
|
|
40
40
|
logIndex: 0,
|
|
@@ -45,3 +45,31 @@ export class AptosContext extends BaseContext {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
export class AptosResourceContext extends BaseContext {
|
|
50
|
+
address: string
|
|
51
|
+
network: AptosNetwork
|
|
52
|
+
version: bigint
|
|
53
|
+
|
|
54
|
+
constructor(network: AptosNetwork, address: string, version: bigint) {
|
|
55
|
+
super()
|
|
56
|
+
this.address = address
|
|
57
|
+
this.network = network
|
|
58
|
+
this.version = version
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {
|
|
62
|
+
return {
|
|
63
|
+
address: this.address,
|
|
64
|
+
contractName: 'resources',
|
|
65
|
+
blockNumber: Long.fromString(this.version.toString()),
|
|
66
|
+
transactionIndex: 0,
|
|
67
|
+
transactionHash: '',
|
|
68
|
+
logIndex: 0,
|
|
69
|
+
chainId: getChainId(this.network),
|
|
70
|
+
dataDescriptor: descriptor,
|
|
71
|
+
name: descriptor.name,
|
|
72
|
+
labels: normalizeLabels(labels),
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/aptos/network.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Long from 'long'
|
|
2
1
|
import { APTOS_MAINNET_ID, APTOS_TESTNET_ID, CHAIN_MAP } from '../utils/chain'
|
|
3
2
|
import { AptosClient } from 'aptos-sdk'
|
|
4
3
|
|
|
@@ -38,7 +37,6 @@ export function getRpcClient(network: AptosNetwork): AptosClient {
|
|
|
38
37
|
|
|
39
38
|
export class AptosBindOptions {
|
|
40
39
|
address: string
|
|
41
|
-
network?: AptosNetwork = AptosNetwork.
|
|
42
|
-
startVersion?:
|
|
43
|
-
// endBlock?: Long | number
|
|
40
|
+
network?: AptosNetwork = AptosNetwork.MAIN_NET
|
|
41
|
+
startVersion?: bigint | number
|
|
44
42
|
}
|
|
@@ -224,12 +224,19 @@ export interface AccountConfig {
|
|
|
224
224
|
chainId: string;
|
|
225
225
|
address: string;
|
|
226
226
|
startBlock: Long;
|
|
227
|
-
|
|
227
|
+
onIntervalConfigs: OnIntervalConfig[];
|
|
228
|
+
onAptosIntervalConfigs: AptosOnIntervalConfig[];
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
export interface
|
|
231
|
+
export interface OnIntervalConfig {
|
|
231
232
|
handlerId: number;
|
|
232
|
-
|
|
233
|
+
minutes: number;
|
|
234
|
+
slot: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface AptosOnIntervalConfig {
|
|
238
|
+
intervalConfig: OnIntervalConfig | undefined;
|
|
239
|
+
type: string;
|
|
233
240
|
}
|
|
234
241
|
|
|
235
242
|
export interface ContractInfo {
|
|
@@ -1325,7 +1332,8 @@ function createBaseAccountConfig(): AccountConfig {
|
|
|
1325
1332
|
chainId: "",
|
|
1326
1333
|
address: "",
|
|
1327
1334
|
startBlock: Long.UZERO,
|
|
1328
|
-
|
|
1335
|
+
onIntervalConfigs: [],
|
|
1336
|
+
onAptosIntervalConfigs: [],
|
|
1329
1337
|
};
|
|
1330
1338
|
}
|
|
1331
1339
|
|
|
@@ -1343,8 +1351,11 @@ export const AccountConfig = {
|
|
|
1343
1351
|
if (!message.startBlock.isZero()) {
|
|
1344
1352
|
writer.uint32(24).uint64(message.startBlock);
|
|
1345
1353
|
}
|
|
1346
|
-
for (const v of message.
|
|
1347
|
-
|
|
1354
|
+
for (const v of message.onIntervalConfigs) {
|
|
1355
|
+
OnIntervalConfig.encode(v!, writer.uint32(34).fork()).ldelim();
|
|
1356
|
+
}
|
|
1357
|
+
for (const v of message.onAptosIntervalConfigs) {
|
|
1358
|
+
AptosOnIntervalConfig.encode(v!, writer.uint32(42).fork()).ldelim();
|
|
1348
1359
|
}
|
|
1349
1360
|
return writer;
|
|
1350
1361
|
},
|
|
@@ -1366,8 +1377,13 @@ export const AccountConfig = {
|
|
|
1366
1377
|
message.startBlock = reader.uint64() as Long;
|
|
1367
1378
|
break;
|
|
1368
1379
|
case 4:
|
|
1369
|
-
message.
|
|
1370
|
-
|
|
1380
|
+
message.onIntervalConfigs.push(
|
|
1381
|
+
OnIntervalConfig.decode(reader, reader.uint32())
|
|
1382
|
+
);
|
|
1383
|
+
break;
|
|
1384
|
+
case 5:
|
|
1385
|
+
message.onAptosIntervalConfigs.push(
|
|
1386
|
+
AptosOnIntervalConfig.decode(reader, reader.uint32())
|
|
1371
1387
|
);
|
|
1372
1388
|
break;
|
|
1373
1389
|
default:
|
|
@@ -1385,9 +1401,12 @@ export const AccountConfig = {
|
|
|
1385
1401
|
startBlock: isSet(object.startBlock)
|
|
1386
1402
|
? Long.fromValue(object.startBlock)
|
|
1387
1403
|
: Long.UZERO,
|
|
1388
|
-
|
|
1389
|
-
? object.
|
|
1390
|
-
|
|
1404
|
+
onIntervalConfigs: Array.isArray(object?.onIntervalConfigs)
|
|
1405
|
+
? object.onIntervalConfigs.map((e: any) => OnIntervalConfig.fromJSON(e))
|
|
1406
|
+
: [],
|
|
1407
|
+
onAptosIntervalConfigs: Array.isArray(object?.onAptosIntervalConfigs)
|
|
1408
|
+
? object.onAptosIntervalConfigs.map((e: any) =>
|
|
1409
|
+
AptosOnIntervalConfig.fromJSON(e)
|
|
1391
1410
|
)
|
|
1392
1411
|
: [],
|
|
1393
1412
|
};
|
|
@@ -1399,12 +1418,19 @@ export const AccountConfig = {
|
|
|
1399
1418
|
message.address !== undefined && (obj.address = message.address);
|
|
1400
1419
|
message.startBlock !== undefined &&
|
|
1401
1420
|
(obj.startBlock = (message.startBlock || Long.UZERO).toString());
|
|
1402
|
-
if (message.
|
|
1403
|
-
obj.
|
|
1404
|
-
e ?
|
|
1421
|
+
if (message.onIntervalConfigs) {
|
|
1422
|
+
obj.onIntervalConfigs = message.onIntervalConfigs.map((e) =>
|
|
1423
|
+
e ? OnIntervalConfig.toJSON(e) : undefined
|
|
1405
1424
|
);
|
|
1406
1425
|
} else {
|
|
1407
|
-
obj.
|
|
1426
|
+
obj.onIntervalConfigs = [];
|
|
1427
|
+
}
|
|
1428
|
+
if (message.onAptosIntervalConfigs) {
|
|
1429
|
+
obj.onAptosIntervalConfigs = message.onAptosIntervalConfigs.map((e) =>
|
|
1430
|
+
e ? AptosOnIntervalConfig.toJSON(e) : undefined
|
|
1431
|
+
);
|
|
1432
|
+
} else {
|
|
1433
|
+
obj.onAptosIntervalConfigs = [];
|
|
1408
1434
|
}
|
|
1409
1435
|
return obj;
|
|
1410
1436
|
},
|
|
@@ -1417,39 +1443,42 @@ export const AccountConfig = {
|
|
|
1417
1443
|
object.startBlock !== undefined && object.startBlock !== null
|
|
1418
1444
|
? Long.fromValue(object.startBlock)
|
|
1419
1445
|
: Long.UZERO;
|
|
1420
|
-
message.
|
|
1421
|
-
object.
|
|
1422
|
-
|
|
1446
|
+
message.onIntervalConfigs =
|
|
1447
|
+
object.onIntervalConfigs?.map((e) => OnIntervalConfig.fromPartial(e)) ||
|
|
1448
|
+
[];
|
|
1449
|
+
message.onAptosIntervalConfigs =
|
|
1450
|
+
object.onAptosIntervalConfigs?.map((e) =>
|
|
1451
|
+
AptosOnIntervalConfig.fromPartial(e)
|
|
1423
1452
|
) || [];
|
|
1424
1453
|
return message;
|
|
1425
1454
|
},
|
|
1426
1455
|
};
|
|
1427
1456
|
|
|
1428
|
-
function
|
|
1429
|
-
return { handlerId: 0,
|
|
1457
|
+
function createBaseOnIntervalConfig(): OnIntervalConfig {
|
|
1458
|
+
return { handlerId: 0, minutes: 0, slot: 0 };
|
|
1430
1459
|
}
|
|
1431
1460
|
|
|
1432
|
-
export const
|
|
1461
|
+
export const OnIntervalConfig = {
|
|
1433
1462
|
encode(
|
|
1434
|
-
message:
|
|
1463
|
+
message: OnIntervalConfig,
|
|
1435
1464
|
writer: _m0.Writer = _m0.Writer.create()
|
|
1436
1465
|
): _m0.Writer {
|
|
1437
1466
|
if (message.handlerId !== 0) {
|
|
1438
1467
|
writer.uint32(8).int32(message.handlerId);
|
|
1439
1468
|
}
|
|
1440
|
-
if (message.
|
|
1441
|
-
writer.uint32(16).int32(message.
|
|
1469
|
+
if (message.minutes !== 0) {
|
|
1470
|
+
writer.uint32(16).int32(message.minutes);
|
|
1471
|
+
}
|
|
1472
|
+
if (message.slot !== 0) {
|
|
1473
|
+
writer.uint32(24).int32(message.slot);
|
|
1442
1474
|
}
|
|
1443
1475
|
return writer;
|
|
1444
1476
|
},
|
|
1445
1477
|
|
|
1446
|
-
decode(
|
|
1447
|
-
input: _m0.Reader | Uint8Array,
|
|
1448
|
-
length?: number
|
|
1449
|
-
): AptosOnVersionConfig {
|
|
1478
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): OnIntervalConfig {
|
|
1450
1479
|
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
1451
1480
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
1452
|
-
const message =
|
|
1481
|
+
const message = createBaseOnIntervalConfig();
|
|
1453
1482
|
while (reader.pos < end) {
|
|
1454
1483
|
const tag = reader.uint32();
|
|
1455
1484
|
switch (tag >>> 3) {
|
|
@@ -1457,7 +1486,10 @@ export const AptosOnVersionConfig = {
|
|
|
1457
1486
|
message.handlerId = reader.int32();
|
|
1458
1487
|
break;
|
|
1459
1488
|
case 2:
|
|
1460
|
-
message.
|
|
1489
|
+
message.minutes = reader.int32();
|
|
1490
|
+
break;
|
|
1491
|
+
case 3:
|
|
1492
|
+
message.slot = reader.int32();
|
|
1461
1493
|
break;
|
|
1462
1494
|
default:
|
|
1463
1495
|
reader.skipType(tag & 7);
|
|
@@ -1467,25 +1499,109 @@ export const AptosOnVersionConfig = {
|
|
|
1467
1499
|
return message;
|
|
1468
1500
|
},
|
|
1469
1501
|
|
|
1470
|
-
fromJSON(object: any):
|
|
1502
|
+
fromJSON(object: any): OnIntervalConfig {
|
|
1471
1503
|
return {
|
|
1472
1504
|
handlerId: isSet(object.handlerId) ? Number(object.handlerId) : 0,
|
|
1473
|
-
|
|
1505
|
+
minutes: isSet(object.minutes) ? Number(object.minutes) : 0,
|
|
1506
|
+
slot: isSet(object.slot) ? Number(object.slot) : 0,
|
|
1474
1507
|
};
|
|
1475
1508
|
},
|
|
1476
1509
|
|
|
1477
|
-
toJSON(message:
|
|
1510
|
+
toJSON(message: OnIntervalConfig): unknown {
|
|
1478
1511
|
const obj: any = {};
|
|
1479
1512
|
message.handlerId !== undefined &&
|
|
1480
1513
|
(obj.handlerId = Math.round(message.handlerId));
|
|
1481
|
-
message.
|
|
1514
|
+
message.minutes !== undefined &&
|
|
1515
|
+
(obj.minutes = Math.round(message.minutes));
|
|
1516
|
+
message.slot !== undefined && (obj.slot = Math.round(message.slot));
|
|
1482
1517
|
return obj;
|
|
1483
1518
|
},
|
|
1484
1519
|
|
|
1485
|
-
fromPartial(object: DeepPartial<
|
|
1486
|
-
const message =
|
|
1520
|
+
fromPartial(object: DeepPartial<OnIntervalConfig>): OnIntervalConfig {
|
|
1521
|
+
const message = createBaseOnIntervalConfig();
|
|
1487
1522
|
message.handlerId = object.handlerId ?? 0;
|
|
1488
|
-
message.
|
|
1523
|
+
message.minutes = object.minutes ?? 0;
|
|
1524
|
+
message.slot = object.slot ?? 0;
|
|
1525
|
+
return message;
|
|
1526
|
+
},
|
|
1527
|
+
};
|
|
1528
|
+
|
|
1529
|
+
function createBaseAptosOnIntervalConfig(): AptosOnIntervalConfig {
|
|
1530
|
+
return { intervalConfig: undefined, type: "" };
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
export const AptosOnIntervalConfig = {
|
|
1534
|
+
encode(
|
|
1535
|
+
message: AptosOnIntervalConfig,
|
|
1536
|
+
writer: _m0.Writer = _m0.Writer.create()
|
|
1537
|
+
): _m0.Writer {
|
|
1538
|
+
if (message.intervalConfig !== undefined) {
|
|
1539
|
+
OnIntervalConfig.encode(
|
|
1540
|
+
message.intervalConfig,
|
|
1541
|
+
writer.uint32(10).fork()
|
|
1542
|
+
).ldelim();
|
|
1543
|
+
}
|
|
1544
|
+
if (message.type !== "") {
|
|
1545
|
+
writer.uint32(18).string(message.type);
|
|
1546
|
+
}
|
|
1547
|
+
return writer;
|
|
1548
|
+
},
|
|
1549
|
+
|
|
1550
|
+
decode(
|
|
1551
|
+
input: _m0.Reader | Uint8Array,
|
|
1552
|
+
length?: number
|
|
1553
|
+
): AptosOnIntervalConfig {
|
|
1554
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
1555
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
1556
|
+
const message = createBaseAptosOnIntervalConfig();
|
|
1557
|
+
while (reader.pos < end) {
|
|
1558
|
+
const tag = reader.uint32();
|
|
1559
|
+
switch (tag >>> 3) {
|
|
1560
|
+
case 1:
|
|
1561
|
+
message.intervalConfig = OnIntervalConfig.decode(
|
|
1562
|
+
reader,
|
|
1563
|
+
reader.uint32()
|
|
1564
|
+
);
|
|
1565
|
+
break;
|
|
1566
|
+
case 2:
|
|
1567
|
+
message.type = reader.string();
|
|
1568
|
+
break;
|
|
1569
|
+
default:
|
|
1570
|
+
reader.skipType(tag & 7);
|
|
1571
|
+
break;
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
return message;
|
|
1575
|
+
},
|
|
1576
|
+
|
|
1577
|
+
fromJSON(object: any): AptosOnIntervalConfig {
|
|
1578
|
+
return {
|
|
1579
|
+
intervalConfig: isSet(object.intervalConfig)
|
|
1580
|
+
? OnIntervalConfig.fromJSON(object.intervalConfig)
|
|
1581
|
+
: undefined,
|
|
1582
|
+
type: isSet(object.type) ? String(object.type) : "",
|
|
1583
|
+
};
|
|
1584
|
+
},
|
|
1585
|
+
|
|
1586
|
+
toJSON(message: AptosOnIntervalConfig): unknown {
|
|
1587
|
+
const obj: any = {};
|
|
1588
|
+
message.intervalConfig !== undefined &&
|
|
1589
|
+
(obj.intervalConfig = message.intervalConfig
|
|
1590
|
+
? OnIntervalConfig.toJSON(message.intervalConfig)
|
|
1591
|
+
: undefined);
|
|
1592
|
+
message.type !== undefined && (obj.type = message.type);
|
|
1593
|
+
return obj;
|
|
1594
|
+
},
|
|
1595
|
+
|
|
1596
|
+
fromPartial(
|
|
1597
|
+
object: DeepPartial<AptosOnIntervalConfig>
|
|
1598
|
+
): AptosOnIntervalConfig {
|
|
1599
|
+
const message = createBaseAptosOnIntervalConfig();
|
|
1600
|
+
message.intervalConfig =
|
|
1601
|
+
object.intervalConfig !== undefined && object.intervalConfig !== null
|
|
1602
|
+
? OnIntervalConfig.fromPartial(object.intervalConfig)
|
|
1603
|
+
: undefined;
|
|
1604
|
+
message.type = object.type ?? "";
|
|
1489
1605
|
return message;
|
|
1490
1606
|
},
|
|
1491
1607
|
};
|
package/src/processor-state.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { TemplateInstance } from './gen'
|
|
|
14
14
|
import { Provider } from '@ethersproject/providers'
|
|
15
15
|
import { EventTracker } from './core'
|
|
16
16
|
import { Metric } from './core/meter'
|
|
17
|
+
import { AptosAccountProcessor } from './aptos/aptos-processor'
|
|
17
18
|
|
|
18
19
|
export class ProcessorState {
|
|
19
20
|
// from abiName_address_chainId => contract wrapper
|
|
@@ -34,6 +35,7 @@ export class ProcessorState {
|
|
|
34
35
|
suiProcessors: SuiBaseProcessor[] = []
|
|
35
36
|
|
|
36
37
|
aptosProcessors: AptosBaseProcessor[] = []
|
|
38
|
+
aptosAccountProcessors: AptosAccountProcessor[] = []
|
|
37
39
|
|
|
38
40
|
eventTrackers: EventTracker[] = []
|
|
39
41
|
|
package/src/service.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { CallContext, ServerError, Status } from 'nice-grpc'
|
|
|
3
3
|
import { SOL_MAINMET_ID, SUI_DEVNET_ID } from './utils/chain'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
AccountConfig,
|
|
6
7
|
AptosCallHandlerConfig,
|
|
7
8
|
AptosEventHandlerConfig,
|
|
8
9
|
BlockBinding,
|
|
@@ -31,6 +32,7 @@ import Long from 'long'
|
|
|
31
32
|
import { TextDecoder } from 'util'
|
|
32
33
|
import { Trace } from './core'
|
|
33
34
|
import { Instruction } from '@project-serum/anchor'
|
|
35
|
+
import { MoveResourcesWithVersionPayload } from './aptos/aptos-processor'
|
|
34
36
|
|
|
35
37
|
const DEFAULT_MAX_BLOCK = Long.ZERO
|
|
36
38
|
|
|
@@ -42,6 +44,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
42
44
|
private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []
|
|
43
45
|
private aptosEventHandlers: ((event: any) => Promise<ProcessResult>)[] = []
|
|
44
46
|
private aptosCallHandlers: ((func: any) => Promise<ProcessResult>)[] = []
|
|
47
|
+
private aptosResourceHandlers: ((resourceWithVersion: MoveResourcesWithVersionPayload) => Promise<ProcessResult>)[] =
|
|
48
|
+
[]
|
|
45
49
|
|
|
46
50
|
// map from chain id to list of processors
|
|
47
51
|
// private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()
|
|
@@ -49,6 +53,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
49
53
|
|
|
50
54
|
private started = false
|
|
51
55
|
private contractConfigs: ContractConfig[]
|
|
56
|
+
private accountConfigs: AccountConfig[]
|
|
52
57
|
private templateInstances: TemplateInstance[]
|
|
53
58
|
private metricConfigs: MetricConfig[]
|
|
54
59
|
private eventTrackingConfigs: EventTrackingConfig[]
|
|
@@ -72,7 +77,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
72
77
|
templateInstances: this.templateInstances,
|
|
73
78
|
eventTrackingConfigs: this.eventTrackingConfigs,
|
|
74
79
|
metricConfigs: this.metricConfigs,
|
|
75
|
-
accountConfigs:
|
|
80
|
+
accountConfigs: this.accountConfigs,
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
|
|
@@ -81,6 +86,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
81
86
|
this.templateInstances = []
|
|
82
87
|
// this.processorsByChainId.clear()
|
|
83
88
|
this.contractConfigs = []
|
|
89
|
+
this.accountConfigs = []
|
|
84
90
|
|
|
85
91
|
this.templateInstances = [...global.PROCESSOR_STATE.templatesInstances]
|
|
86
92
|
this.eventTrackingConfigs = []
|
|
@@ -247,7 +253,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
247
253
|
blockConfigs: [],
|
|
248
254
|
logConfigs: [],
|
|
249
255
|
traceConfigs: [],
|
|
250
|
-
startBlock: aptosProcessor.config.startVersion,
|
|
256
|
+
startBlock: Long.fromString(aptosProcessor.config.startVersion.toString()),
|
|
251
257
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
252
258
|
instructionConfig: undefined,
|
|
253
259
|
aptosEventConfigs: [],
|
|
@@ -286,6 +292,28 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
286
292
|
}
|
|
287
293
|
this.contractConfigs.push(contractConfig)
|
|
288
294
|
}
|
|
295
|
+
|
|
296
|
+
for (const aptosProcessor of global.PROCESSOR_STATE.aptosAccountProcessors) {
|
|
297
|
+
const accountConfig: AccountConfig = {
|
|
298
|
+
address: aptosProcessor.config.address,
|
|
299
|
+
chainId: aptosProcessor.getChainId(),
|
|
300
|
+
startBlock: Long.fromValue(aptosProcessor.config.startVersion.toString()),
|
|
301
|
+
onAptosIntervalConfigs: [],
|
|
302
|
+
onIntervalConfigs: [],
|
|
303
|
+
}
|
|
304
|
+
for (const handler of aptosProcessor.resourcesHandlers) {
|
|
305
|
+
const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1
|
|
306
|
+
accountConfig.onAptosIntervalConfigs.push({
|
|
307
|
+
intervalConfig: {
|
|
308
|
+
handlerId: handlerId,
|
|
309
|
+
minutes: handler.timeIntervalInMinutes || 0,
|
|
310
|
+
slot: handler.versionInterval || 0,
|
|
311
|
+
},
|
|
312
|
+
type: handler.type || '',
|
|
313
|
+
})
|
|
314
|
+
}
|
|
315
|
+
this.accountConfigs.push(accountConfig)
|
|
316
|
+
}
|
|
289
317
|
}
|
|
290
318
|
|
|
291
319
|
async start(request: StartRequest, context: CallContext): Promise<Empty> {
|
|
@@ -361,6 +389,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
361
389
|
return this.processAptosFunctionCall(request)
|
|
362
390
|
case HandlerType.APT_EVENT:
|
|
363
391
|
return this.processAptosEvent(request)
|
|
392
|
+
case HandlerType.APT_RESOURCE:
|
|
393
|
+
return this.processAptosResource(request)
|
|
364
394
|
default:
|
|
365
395
|
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
366
396
|
}
|
|
@@ -613,6 +643,19 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
613
643
|
return result
|
|
614
644
|
}
|
|
615
645
|
|
|
646
|
+
async processAptosResource(binding: DataBinding): Promise<ProcessResult> {
|
|
647
|
+
if (!binding.data) {
|
|
648
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
|
|
649
|
+
}
|
|
650
|
+
const jsonString = Utf8ArrayToStr(binding.data.raw)
|
|
651
|
+
const json = JSON.parse(jsonString) as MoveResourcesWithVersionPayload
|
|
652
|
+
const result = await this.aptosResourceHandlers[binding.handlerId](json).catch((e) => {
|
|
653
|
+
throw new ServerError(Status.INTERNAL, 'error processing event: ' + jsonString + '\n' + errorString(e))
|
|
654
|
+
})
|
|
655
|
+
recordRuntimeInfo(result, HandlerType.APT_RESOURCE)
|
|
656
|
+
return result
|
|
657
|
+
}
|
|
658
|
+
|
|
616
659
|
async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {
|
|
617
660
|
if (!binding.data) {
|
|
618
661
|
throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
|
package/src/tests/aptos.test.ts
CHANGED
|
@@ -115,6 +115,34 @@ describe('Test Aptos Example', () => {
|
|
|
115
115
|
const res = await service.processBindings(request)
|
|
116
116
|
expect(firstGaugeValue(res.result, 'size')).equal(2n)
|
|
117
117
|
})
|
|
118
|
+
|
|
119
|
+
test('check on timer', async () => {
|
|
120
|
+
const request: ProcessBindingsRequest = {
|
|
121
|
+
bindings: [
|
|
122
|
+
{
|
|
123
|
+
data: {
|
|
124
|
+
raw: new TextEncoder().encode(
|
|
125
|
+
JSON.stringify({
|
|
126
|
+
version: '12345',
|
|
127
|
+
resources: [
|
|
128
|
+
{
|
|
129
|
+
type: '0x1::coin::SupplyConfig',
|
|
130
|
+
data: {
|
|
131
|
+
allow_upgrades: false,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
})
|
|
136
|
+
),
|
|
137
|
+
},
|
|
138
|
+
handlerId: 0,
|
|
139
|
+
handlerType: HandlerType.APT_RESOURCE,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
}
|
|
143
|
+
const res = await service.processBindings(request)
|
|
144
|
+
expect(firstCounterValue(res.result, 'onTimer')).equal(1n)
|
|
145
|
+
})
|
|
118
146
|
})
|
|
119
147
|
|
|
120
148
|
const testData = {
|