@xyo-network/xl1-protocol-sdk 1.18.21 → 1.18.23
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/dist/neutral/index.mjs +83 -79
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/summary/model/summary.d.ts +4 -4
- package/dist/neutral/summary/model/summary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/balances/balancesStepSummaryFromRange.d.ts +2 -2
- package/dist/neutral/summary/primitives/balances/balancesStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/schemas/schemasStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/transfers/transfersStepSummaryFromRange.d.ts +2 -2
- package/dist/neutral/summary/primitives/transfers/transfersStepSummaryFromRange.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/summary/model/summary.ts +4 -4
- package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +64 -60
- package/src/summary/primitives/schemas/schemasStepSummaryFromRange.ts +7 -9
- package/src/summary/primitives/transfers/transfersStepSummaryFromRange.ts +9 -10
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { Payload } from '@xyo-network/payload-model';
|
|
1
|
+
import type { Payload, WithHashMeta } from '@xyo-network/payload-model';
|
|
2
2
|
import type { Semaphore } from 'async-mutex';
|
|
3
3
|
import type { MapType, MapTypeRead } from '../../map/index.ts';
|
|
4
4
|
import type { CachingBaseContext, ChainContext, ChainContextRead } from '../../model/index.ts';
|
|
5
5
|
import type { BalancesStepSummary } from './BalancesStepSummary.ts';
|
|
6
6
|
import type { SchemasStepSummary } from './SchemasStepSummary.ts';
|
|
7
7
|
import type { TransfersStepSummary } from './TransfersSummary.ts';
|
|
8
|
-
export interface ChainSummaryContextBase<TPayload extends Payload, T extends (MapTypeRead<string, TPayload
|
|
8
|
+
export interface ChainSummaryContextBase<TPayload extends Payload, T extends (MapTypeRead<string, WithHashMeta<TPayload>>)> extends CachingBaseContext {
|
|
9
9
|
stepSemaphores: Semaphore[];
|
|
10
10
|
summaryMap: T;
|
|
11
11
|
}
|
|
12
|
-
export interface ChainSummaryContextRead<T extends Payload> extends ChainSummaryContextBase<T, MapTypeRead<string, T
|
|
12
|
+
export interface ChainSummaryContextRead<T extends Payload> extends ChainSummaryContextBase<T, MapTypeRead<string, WithHashMeta<T>>>, ChainContextRead {
|
|
13
13
|
}
|
|
14
|
-
export interface ChainSummaryContextWrite<T extends Payload> extends ChainSummaryContextBase<T, MapType<string, T
|
|
14
|
+
export interface ChainSummaryContextWrite<T extends Payload> extends ChainSummaryContextBase<T, MapType<string, WithHashMeta<T>>>, ChainContext {
|
|
15
15
|
}
|
|
16
16
|
export type ChainSummaryContext<T extends Payload> = ChainSummaryContextRead<T> & ChainSummaryContextWrite<T>;
|
|
17
17
|
export interface BalanceStepSummaryContextRead extends ChainSummaryContextRead<BalancesStepSummary> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../../src/summary/model/summary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../../src/summary/model/summary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,KAAK,EACV,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EACnD,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,MAAM,WAAW,uBAAuB,CAAC,QAAQ,SAAS,OAAO,EAC/D,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IACnF,cAAc,EAAE,SAAS,EAAE,CAAA;IAC3B,UAAU,EAAE,CAAC,CAAA;CACd;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,OAAO,CAAE,SAAQ,uBAAuB,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,gBAAgB;CAAG;AAEzJ,MAAM,WAAW,wBAAwB,CAAC,CAAC,SAAS,OAAO,CAAE,SAAQ,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY;CAAG;AAElJ,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,OAAO,IAAI,uBAAuB,CAAC,CAAC,CAAC,GAAG,wBAAwB,CAAC,CAAC,CAAC,CAAA;AAE7G,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB,CAAC,mBAAmB,CAAC;CAAG;AAEtG,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB,CAAC,mBAAmB,CAAC;CAAG;AAE9F,MAAM,WAAW,+BAAgC,SAAQ,uBAAuB,CAAC,oBAAoB,CAAC;CAAG;AAEzG,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB,CAAC,oBAAoB,CAAC;CAAG;AAEjG,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB,CAAC,kBAAkB,CAAC;CAAG;AAErG,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB,CAAC,kBAAkB,CAAC;CAAG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WithHashMeta } from '@xyo-network/payload-model';
|
|
2
2
|
import type { XL1BlockRange } from '@xyo-network/xl1-protocol';
|
|
3
3
|
import type { BalancesStepSummary, BalanceStepSummaryContext } from '../../model/index.ts';
|
|
4
|
-
export declare function balancesStepSummaryFromRange(context: BalanceStepSummaryContext, range: XL1BlockRange): Promise<
|
|
4
|
+
export declare function balancesStepSummaryFromRange(context: BalanceStepSummaryContext, range: XL1BlockRange): Promise<WithHashMeta<BalancesStepSummary>>;
|
|
5
5
|
//# sourceMappingURL=balancesStepSummaryFromRange.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balancesStepSummaryFromRange.d.ts","sourceRoot":"","sources":["../../../../../src/summary/primitives/balances/balancesStepSummaryFromRange.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"balancesStepSummaryFromRange.d.ts","sourceRoot":"","sources":["../../../../../src/summary/primitives/balances/balancesStepSummaryFromRange.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAY9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAG1F,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAmE5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemasStepSummaryFromRange.d.ts","sourceRoot":"","sources":["../../../../../src/summary/primitives/schemas/schemasStepSummaryFromRange.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"schemasStepSummaryFromRange.d.ts","sourceRoot":"","sources":["../../../../../src/summary/primitives/schemas/schemasStepSummaryFromRange.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAO9D,OAAO,EACL,KAAK,kBAAkB,EAAE,KAAK,yBAAyB,EACxD,MAAM,sBAAsB,CAAA;AAE7B,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CA6D3C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WithHashMeta } from '@xyo-network/payload-model';
|
|
2
2
|
import type { XL1BlockRange } from '@xyo-network/xl1-protocol';
|
|
3
3
|
import { type TransfersStepSummary, type TransfersStepSummaryContext } from '../../model/index.ts';
|
|
4
|
-
export declare function transfersStepSummaryFromRange(context: TransfersStepSummaryContext, range: XL1BlockRange): Promise<
|
|
4
|
+
export declare function transfersStepSummaryFromRange(context: TransfersStepSummaryContext, range: XL1BlockRange): Promise<WithHashMeta<TransfersStepSummary>>;
|
|
5
5
|
//# sourceMappingURL=transfersStepSummaryFromRange.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfersStepSummaryFromRange.d.ts","sourceRoot":"","sources":["../../../../../src/summary/primitives/transfers/transfersStepSummaryFromRange.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"transfersStepSummaryFromRange.d.ts","sourceRoot":"","sources":["../../../../../src/summary/primitives/transfers/transfersStepSummaryFromRange.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAU9D,OAAO,EACL,KAAK,oBAAoB,EAAE,KAAK,2BAA2B,EAC5D,MAAM,sBAAsB,CAAA;AAG7B,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,2BAA2B,EACpC,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,CAyE7C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/xl1-protocol-sdk",
|
|
4
|
-
"version": "1.18.
|
|
4
|
+
"version": "1.18.23",
|
|
5
5
|
"description": "XYO Layer One SDK Protocol",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@xyo-network/payload-model": "~5.2.24",
|
|
53
53
|
"@xyo-network/wallet": "~5.2.24",
|
|
54
54
|
"@xyo-network/wallet-model": "~5.2.24",
|
|
55
|
-
"@xyo-network/xl1-protocol": "~1.18.
|
|
55
|
+
"@xyo-network/xl1-protocol": "~1.18.23",
|
|
56
56
|
"async-mutex": "~0.5.0",
|
|
57
57
|
"ethers": "^6.16.0",
|
|
58
58
|
"lru-cache": "^11.2.4",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
1
|
+
import type { Payload, WithHashMeta } from '@xyo-network/payload-model'
|
|
2
2
|
import type { Semaphore } from 'async-mutex'
|
|
3
3
|
|
|
4
4
|
import type { MapType, MapTypeRead } from '../../map/index.ts'
|
|
@@ -10,14 +10,14 @@ import type { SchemasStepSummary } from './SchemasStepSummary.ts'
|
|
|
10
10
|
import type { TransfersStepSummary } from './TransfersSummary.ts'
|
|
11
11
|
|
|
12
12
|
export interface ChainSummaryContextBase<TPayload extends Payload,
|
|
13
|
-
T extends (MapTypeRead<string, TPayload
|
|
13
|
+
T extends (MapTypeRead<string, WithHashMeta<TPayload>>)> extends CachingBaseContext {
|
|
14
14
|
stepSemaphores: Semaphore[]
|
|
15
15
|
summaryMap: T
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export interface ChainSummaryContextRead<T extends Payload> extends ChainSummaryContextBase<T, MapTypeRead<string, T
|
|
18
|
+
export interface ChainSummaryContextRead<T extends Payload> extends ChainSummaryContextBase<T, MapTypeRead<string, WithHashMeta<T>>>, ChainContextRead {}
|
|
19
19
|
|
|
20
|
-
export interface ChainSummaryContextWrite<T extends Payload> extends ChainSummaryContextBase<T, MapType<string, T
|
|
20
|
+
export interface ChainSummaryContextWrite<T extends Payload> extends ChainSummaryContextBase<T, MapType<string, WithHashMeta<T>>>, ChainContext {}
|
|
21
21
|
|
|
22
22
|
export type ChainSummaryContext<T extends Payload> = ChainSummaryContextRead<T> & ChainSummaryContextWrite<T>
|
|
23
23
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import { type Address } from '@xylabs/sdk-js'
|
|
1
|
+
import { type Address, spanRootAsync } from '@xylabs/sdk-js'
|
|
3
2
|
import { assertEx } from '@xylabs/sdk-js'
|
|
4
3
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
|
-
import type {
|
|
4
|
+
import type { WithHashMeta } from '@xyo-network/payload-model'
|
|
6
5
|
import { isAnyPayload } from '@xyo-network/payload-model'
|
|
7
6
|
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
8
|
-
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
7
|
+
import { asXL1BlockNumber, StepSizes } from '@xyo-network/xl1-protocol'
|
|
9
8
|
|
|
10
9
|
import {
|
|
11
10
|
deepCalculateFramesFromRange, hashFromBlockNumber,
|
|
12
11
|
hydrateBlock,
|
|
13
12
|
} from '../../../block/index.ts'
|
|
13
|
+
import { withContextCacheResponse } from '../../../model/index.ts'
|
|
14
14
|
import { netBalancesForPayloads } from '../../../payloads/index.ts'
|
|
15
15
|
import {
|
|
16
16
|
parseSignedBigInt, type SignedBigInt, toSignedBigInt,
|
|
@@ -21,67 +21,71 @@ import { BalancesStepSummarySchema } from '../../model/index.ts'
|
|
|
21
21
|
export async function balancesStepSummaryFromRange(
|
|
22
22
|
context: BalanceStepSummaryContext,
|
|
23
23
|
range: XL1BlockRange,
|
|
24
|
-
): Promise<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
): Promise<WithHashMeta<BalancesStepSummary>> {
|
|
25
|
+
const cacheKey = `${range[0]}|${range[1]}`
|
|
26
|
+
return await withContextCacheResponse(context, 'balancesStepSummaryFromRange', cacheKey, async () => {
|
|
27
|
+
return await spanRootAsync('balancesStepSummaryFromRange', async () => {
|
|
28
|
+
// console.log(`balanceStepSummaryFromRange: head=${head}, range=${range[0]}-${range[1]}`)
|
|
29
|
+
const frameHeadHash = await hashFromBlockNumber(context, range[1])
|
|
30
|
+
const frameSize = range[1] - range[0] + 1
|
|
31
|
+
const [headHash] = await context.head()
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
const key = `${frameHeadHash}|${frameSize}`
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
return (frameSize === 1)
|
|
36
|
+
? await spanRootAsync(`balancesStepSummaryFromRange.frameSize=1[${key}]`, async () => {
|
|
37
|
+
const hash = await hashFromBlockNumber(context, range[0])
|
|
38
|
+
const [, payloads] = await hydrateBlock(context.store, hash)
|
|
39
|
+
const balances: Record<Address, SignedBigInt> = {}
|
|
40
|
+
for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
|
|
41
|
+
balances[address as Address] = toSignedBigInt(balance)
|
|
42
|
+
}
|
|
43
|
+
return await PayloadBuilder.addHashMeta({
|
|
44
|
+
schema: BalancesStepSummarySchema, hash: headHash, stepSize: -1, balances,
|
|
45
|
+
})
|
|
46
|
+
}, { timeBudgetLimit: 100 })
|
|
47
|
+
: await spanRootAsync(`balancesStepSummaryFromRange.frameSize>1[${key}]`, async () => {
|
|
48
|
+
const step = StepSizes.indexOf(asXL1BlockNumber(frameSize, true))
|
|
49
|
+
assertEx(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes.join(', ')}`)
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
const summaryResult = await context.summaryMap.get(key)
|
|
52
|
+
if (isAnyPayload(summaryResult)) {
|
|
53
|
+
return summaryResult as WithHashMeta<BalancesStepSummary>
|
|
54
|
+
} else {
|
|
55
|
+
// We do not have it, so lets build it
|
|
56
|
+
await context.stepSemaphores[step].acquire()
|
|
57
|
+
try {
|
|
58
|
+
const subRanges = deepCalculateFramesFromRange(range, step - 1)
|
|
59
|
+
const promises = subRanges.map(subRange => balancesStepSummaryFromRange(
|
|
60
|
+
context,
|
|
61
|
+
subRange,
|
|
62
|
+
))
|
|
63
|
+
const subResults = await Promise.all(promises)
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
// add them all up
|
|
66
|
+
const bigIntBalances: Record<Address, bigint> = {}
|
|
67
|
+
for (const subResult of subResults) {
|
|
68
|
+
for (const [address, balance] of Object.entries(subResult.balances)) {
|
|
69
|
+
bigIntBalances[address as Address] = (bigIntBalances[address as Address] ?? 0n) + parseSignedBigInt(balance)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
const balances: Record<Address, SignedBigInt> = {}
|
|
74
|
+
for (const [address, balance] of Object.entries(bigIntBalances)) {
|
|
75
|
+
balances[address as Address] = toSignedBigInt(balance)
|
|
76
|
+
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
const result = await PayloadBuilder.addHashMeta({
|
|
79
|
+
schema: BalancesStepSummarySchema, hash: frameHeadHash, stepSize: frameSize, balances,
|
|
80
|
+
})
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
await context.summaryMap.set(key, result)
|
|
83
|
+
return result
|
|
84
|
+
} finally {
|
|
85
|
+
context.stepSemaphores[step].release()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, { timeBudgetLimit: 100 })
|
|
89
|
+
}, { timeBudgetLimit: 200 })
|
|
90
|
+
}, { max: 100_000, timeBudgetMs: 200 })
|
|
87
91
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/sdk-js'
|
|
2
2
|
import { isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
3
3
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
4
|
-
import type {
|
|
5
|
-
Schema, WithHashMeta, WithStorageMeta,
|
|
6
|
-
} from '@xyo-network/payload-model'
|
|
4
|
+
import type { Schema, WithHashMeta } from '@xyo-network/payload-model'
|
|
7
5
|
import { isAnyPayload, isHashMeta } from '@xyo-network/payload-model'
|
|
8
6
|
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
9
7
|
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
@@ -25,7 +23,7 @@ export async function schemasStepSummaryFromRange(
|
|
|
25
23
|
const frameSize = range[1] - range[0] + 1
|
|
26
24
|
const [headHash] = await context.head()
|
|
27
25
|
|
|
28
|
-
let result: SchemasStepSummary | undefined = undefined
|
|
26
|
+
let result: WithHashMeta<SchemasStepSummary> | undefined = undefined
|
|
29
27
|
|
|
30
28
|
if (frameSize === 1) {
|
|
31
29
|
const hash = await hashFromBlockNumber(context, range[0])
|
|
@@ -38,9 +36,9 @@ export async function schemasStepSummaryFromRange(
|
|
|
38
36
|
schemas[schema] = (schemas[schema] ?? 0) + 1
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
result = {
|
|
39
|
+
result = await PayloadBuilder.addHashMeta({
|
|
42
40
|
schema: SchemasStepSummarySchema, hash: headHash, stepSize: -1, schemas,
|
|
43
|
-
}
|
|
41
|
+
})
|
|
44
42
|
} else {
|
|
45
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
44
|
const step = (StepSizes as any).indexOf(frameSize)
|
|
@@ -48,7 +46,7 @@ export async function schemasStepSummaryFromRange(
|
|
|
48
46
|
|
|
49
47
|
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`)
|
|
50
48
|
if (isAnyPayload(summaryResult)) {
|
|
51
|
-
result = summaryResult as
|
|
49
|
+
result = summaryResult as WithHashMeta<SchemasStepSummary>
|
|
52
50
|
} else {
|
|
53
51
|
// We do not have it, so lets build it
|
|
54
52
|
await context.stepSemaphores[step].acquire()
|
|
@@ -68,9 +66,9 @@ export async function schemasStepSummaryFromRange(
|
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
result = {
|
|
69
|
+
result = await PayloadBuilder.addHashMeta({
|
|
72
70
|
schema: SchemasStepSummarySchema, hash: frameHeadHash, stepSize: frameSize, schemas: schemas,
|
|
73
|
-
}
|
|
71
|
+
})
|
|
74
72
|
|
|
75
73
|
await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result)
|
|
76
74
|
} finally {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { type Address } from '@xylabs/sdk-js'
|
|
3
3
|
import { assertEx } from '@xylabs/sdk-js'
|
|
4
4
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
|
-
import type {
|
|
5
|
+
import type { WithHashMeta } from '@xyo-network/payload-model'
|
|
6
6
|
import { isAnyPayload } from '@xyo-network/payload-model'
|
|
7
7
|
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
8
8
|
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
@@ -22,13 +22,13 @@ import { transfersSummaryKey } from './transfersSummary.ts'
|
|
|
22
22
|
export async function transfersStepSummaryFromRange(
|
|
23
23
|
context: TransfersStepSummaryContext,
|
|
24
24
|
range: XL1BlockRange,
|
|
25
|
-
): Promise<
|
|
25
|
+
): Promise<WithHashMeta<TransfersStepSummary>> {
|
|
26
26
|
// console.log(`transfersStepSummaryFromRange: head=${context.head}, range=${range[0]}-${range[1]}`)
|
|
27
27
|
const frameHeadHash = await hashFromBlockNumber(context, range[1])
|
|
28
28
|
const frameSize = range[1] - range[0] + 1
|
|
29
29
|
const [headHash] = await context.head()
|
|
30
30
|
|
|
31
|
-
let result: TransfersStepSummary | undefined = undefined
|
|
31
|
+
let result: WithHashMeta<TransfersStepSummary> | undefined = undefined
|
|
32
32
|
|
|
33
33
|
if (frameSize === 1) {
|
|
34
34
|
const hash = await hashFromBlockNumber(context, range[0])
|
|
@@ -40,9 +40,9 @@ export async function transfersStepSummaryFromRange(
|
|
|
40
40
|
transfers[from as Address][to as Address] = toSignedBigInt(amount)
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
result = {
|
|
43
|
+
result = await PayloadBuilder.addHashMeta({
|
|
44
44
|
schema: TransfersStepSummarySchema, hash: headHash, stepSize: -1, transfers,
|
|
45
|
-
}
|
|
45
|
+
})
|
|
46
46
|
} else {
|
|
47
47
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
48
|
const step = (StepSizes as any).indexOf(frameSize)
|
|
@@ -52,7 +52,7 @@ export async function transfersStepSummaryFromRange(
|
|
|
52
52
|
|
|
53
53
|
const summaryResult = await context.summaryMap.get(key)
|
|
54
54
|
if (isAnyPayload(summaryResult)) {
|
|
55
|
-
result = summaryResult as
|
|
55
|
+
result = summaryResult as WithHashMeta<TransfersStepSummary>
|
|
56
56
|
} else {
|
|
57
57
|
await context.stepSemaphores[step].acquire()
|
|
58
58
|
// We do not have it, so lets build it
|
|
@@ -83,9 +83,9 @@ export async function transfersStepSummaryFromRange(
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
result = {
|
|
86
|
+
result = await PayloadBuilder.addHashMeta({
|
|
87
87
|
schema: TransfersStepSummarySchema, hash: frameHeadHash, stepSize: frameSize, transfers,
|
|
88
|
-
}
|
|
88
|
+
})
|
|
89
89
|
|
|
90
90
|
await context.summaryMap.set(key, result)
|
|
91
91
|
} finally {
|
|
@@ -94,6 +94,5 @@ export async function transfersStepSummaryFromRange(
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
// console.log(`transfersStepSummaryFromRange-result: head=${context.head}, range=${range[0]}-${range[1]}: ${toSafeJsonString(result, 10)}`)
|
|
97
|
-
|
|
98
|
-
return finalResult
|
|
97
|
+
return result
|
|
99
98
|
}
|