@xyo-network/xl1-protocol-sdk 1.18.0-rc.1 → 1.18.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/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts +6 -5
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts +5 -5
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactory.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +2 -2
- package/dist/neutral/config/Services.d.ts +2 -2
- package/dist/neutral/config/Services.d.ts.map +1 -1
- package/dist/neutral/index.mjs +537 -211
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/ChainQualification.d.ts +42 -0
- package/dist/neutral/model/ChainQualification.d.ts.map +1 -0
- package/dist/neutral/model/index.d.ts +1 -1
- package/dist/neutral/model/index.d.ts.map +1 -1
- package/dist/neutral/primitives/chain/getWindowedChain.d.ts +26 -0
- package/dist/neutral/primitives/chain/getWindowedChain.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/index.d.ts +1 -0
- package/dist/neutral/primitives/chain/index.d.ts.map +1 -1
- package/dist/neutral/primitives/index.d.ts +1 -0
- package/dist/neutral/primitives/index.d.ts.map +1 -1
- package/dist/neutral/primitives/rewards/networkStakeStepRewardPositionWeight.d.ts +1 -1
- package/dist/neutral/primitives/uncle/findBestUncle.d.ts +24 -0
- package/dist/neutral/primitives/uncle/findBestUncle.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/findUncles.d.ts +26 -0
- package/dist/neutral/primitives/uncle/findUncles.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/index.d.ts +4 -0
- package/dist/neutral/primitives/uncle/index.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/scoreUncle.d.ts +3 -0
- package/dist/neutral/primitives/uncle/scoreUncle.d.ts.map +1 -0
- package/dist/neutral/provider/viewer/XyoViewer.d.ts +7 -5
- package/dist/neutral/provider/viewer/XyoViewer.d.ts.map +1 -1
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +61 -10
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts +31 -0
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts.map +1 -0
- package/dist/neutral/simple/blockValidation/index.d.ts +2 -0
- package/dist/neutral/simple/blockValidation/index.d.ts.map +1 -0
- package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts +1 -1
- package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/index.d.ts +1 -0
- package/dist/neutral/simple/index.d.ts.map +1 -1
- package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts.map +1 -1
- package/dist/neutral/summary/model/summary.d.ts +0 -1
- package/dist/neutral/summary/model/summary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts.map +1 -1
- package/dist/neutral/viewers/AccountBalance.d.ts +35 -15
- package/dist/neutral/viewers/AccountBalance.d.ts.map +1 -1
- package/dist/neutral/viewers/BlockValidation.d.ts +54 -0
- package/dist/neutral/viewers/BlockValidation.d.ts.map +1 -0
- package/dist/neutral/viewers/StakeIntent.d.ts +2 -2
- package/dist/neutral/viewers/StakeIntent.d.ts.map +1 -1
- package/dist/neutral/viewers/TransactionValidation.d.ts +35 -0
- package/dist/neutral/viewers/TransactionValidation.d.ts.map +1 -0
- package/dist/neutral/viewers/index.d.ts +2 -0
- package/dist/neutral/viewers/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/CreatableProvider/AbstractCreatableProvider.ts +22 -6
- package/src/CreatableProvider/CreatableProvider.ts +5 -5
- package/src/CreatableProvider/CreatableProviderRegistry.ts +1 -0
- package/src/CreatableProvider/ProviderFactory.ts +3 -2
- package/src/CreatableProvider/ProviderFactoryLocator.ts +2 -1
- package/src/config/Services.ts +4 -2
- package/src/model/ChainQualification.ts +33 -0
- package/src/model/index.ts +1 -1
- package/src/primitives/chain/getWindowedChain.ts +23 -0
- package/src/primitives/chain/index.ts +1 -0
- package/src/primitives/index.ts +1 -0
- package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +1 -1
- package/src/primitives/uncle/findBestUncle.ts +8 -0
- package/src/primitives/uncle/findUncles.ts +75 -0
- package/src/primitives/uncle/index.ts +3 -0
- package/src/primitives/uncle/scoreUncle.ts +6 -0
- package/src/provider/viewer/XyoViewer.ts +7 -7
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +46 -30
- package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +126 -0
- package/src/simple/blockValidation/index.ts +1 -0
- package/src/simple/datalake/AbstractSimpleDataLake.ts +2 -1
- package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -1
- package/src/simple/index.ts +1 -0
- package/src/simple/timesync/SimpleTimeSyncViewer.ts +1 -1
- package/src/summary/model/summary.ts +0 -1
- package/src/summary/primitives/balances/balancesSummary.ts +12 -12
- package/src/summary/primitives/schemas/schemasSummary.ts +12 -10
- package/src/summary/primitives/transfers/transfersSummary.ts +14 -16
- package/src/viewers/AccountBalance.ts +22 -14
- package/src/viewers/BlockValidation.ts +47 -0
- package/src/viewers/StakeIntent.ts +2 -2
- package/src/viewers/TransactionValidation.ts +35 -0
- package/src/viewers/index.ts +2 -0
- package/dist/neutral/model/Qualified.d.ts +0 -6
- package/dist/neutral/model/Qualified.d.ts.map +0 -1
- package/src/model/Qualified.ts +0 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountBalance.d.ts","sourceRoot":"","sources":["../../../src/viewers/AccountBalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"AccountBalance.d.ts","sourceRoot":"","sources":["../../../src/viewers/AccountBalance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAG9D,OAAO,EACL,KAAK,OAAO,EAEb,MAAM,2BAA2B,CAAA;AAElC,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAA;AAE1B,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAIvC,CAAA;AAEF,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAA;AAEpF,eAAO,MAAM,8BAA8B;;;mBAAwB,CAAA;AACnE,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AACxF,eAAO,MAAM,6BAA6B;;;CAA+C,CAAA;AAEzF,eAAO,MAAM,uBAAuB;;;;uDAA0B,CAAA;AAC9D,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAC1E,eAAO,MAAM,sBAAsB;;;;0BAAwC,CAAA;AAE3E,MAAM,WAAW,2BAA2B;IAC1C,gCAAgC,CAC9B,OAAO,EAAE,OAAO,EAAE,EAClB,MAAM,EAAE,oBAAoB,GAC3B,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,yBAAyB,EAAE,CAAC,CAAC,CAAC,CAAA;IAC3E,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,oBAAoB,GAAG,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;CACjI;AAED,MAAM,WAAW,oBAAqB,SAAQ,2BAA2B,EAAE,QAAQ,CAAC,2BAA2B,CAAC;IAC9G,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,oBAAoB,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IACpF,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,CAAC,EAAE,oBAAoB,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,yBAAyB,EAAE,CAAC,CAAC,CAAA;IACpI,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,oBAAoB,GAAG,UAAU,CAAC,yBAAyB,EAAE,CAAC,CAAA;IAC/G,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,CAAC,EAAE,oBAAoB,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;CACzG;AAED,eAAO,MAAM,2BAA2B,EAAG,sBAA+B,CAAA;AAC1E,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Promisable } from '@xylabs/sdk-js';
|
|
2
|
+
import type { HydratedBlock, SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol';
|
|
3
|
+
import z from 'zod';
|
|
4
|
+
import { type Provider } from '../model/index.ts';
|
|
5
|
+
import type { HydratedBlockValidationError } from '../validation/index.ts';
|
|
6
|
+
export declare const BlockValidationQualificationZod: z.ZodObject<{
|
|
7
|
+
head: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").Hash, string>>;
|
|
8
|
+
range: z.ZodTuple<[z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-protocol").XL1BlockNumber, number>>, z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-protocol").XL1BlockNumber, number>>], null>;
|
|
9
|
+
}, z.z.core.$strip>;
|
|
10
|
+
export type BlockValidationQualification = z.infer<typeof BlockValidationQualificationZod>;
|
|
11
|
+
export declare const isBlockValidationQualification: <T>(value: T) => value is T & {
|
|
12
|
+
head: import("@xylabs/sdk-js").Hash;
|
|
13
|
+
range: [import("@xyo-network/xl1-protocol").XL1BlockNumber, import("@xyo-network/xl1-protocol").XL1BlockNumber];
|
|
14
|
+
};
|
|
15
|
+
export declare const BlockValidationConfigFieldsZod: z.ZodObject<{
|
|
16
|
+
value: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
state: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
}, z.z.core.$strip>;
|
|
19
|
+
export declare const BlockValidationConfigZod: z.ZodUnion<readonly [z.ZodObject<{
|
|
20
|
+
value: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
state: z.ZodOptional<z.ZodBoolean>;
|
|
22
|
+
head: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").Hash, string>>;
|
|
23
|
+
}, z.z.core.$strip>, z.ZodObject<{
|
|
24
|
+
value: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
state: z.ZodOptional<z.ZodBoolean>;
|
|
26
|
+
range: z.ZodTuple<[z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-protocol").XL1BlockNumber, number>>, z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-protocol").XL1BlockNumber, number>>], null>;
|
|
27
|
+
}, z.z.core.$strip>, z.ZodObject<{
|
|
28
|
+
value: z.ZodOptional<z.ZodBoolean>;
|
|
29
|
+
state: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
}, z.z.core.$strip>, z.ZodObject<{}, z.z.core.$strip>]>;
|
|
31
|
+
export type BlockValidationConfig = z.infer<typeof BlockValidationConfigZod>;
|
|
32
|
+
export declare const isBlockValidationConfig: <T>(value: T) => value is T & (Record<string, never> | {
|
|
33
|
+
value?: boolean | undefined;
|
|
34
|
+
state?: boolean | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
head: import("@xylabs/sdk-js").Hash;
|
|
37
|
+
value?: boolean | undefined;
|
|
38
|
+
state?: boolean | undefined;
|
|
39
|
+
} | {
|
|
40
|
+
range: [import("@xyo-network/xl1-protocol").XL1BlockNumber, import("@xyo-network/xl1-protocol").XL1BlockNumber];
|
|
41
|
+
value?: boolean | undefined;
|
|
42
|
+
state?: boolean | undefined;
|
|
43
|
+
});
|
|
44
|
+
export interface BlockValidationViewerMethods {
|
|
45
|
+
qualifiedValidateBlocks(blocks: HydratedBlock[], config?: BlockValidationConfig): Promisable<[HydratedBlockValidationError[], BlockValidationQualification]>;
|
|
46
|
+
}
|
|
47
|
+
export declare const BlockValidationViewerMoniker: "BlockValidationViewer";
|
|
48
|
+
export type BlockValidationViewerMoniker = typeof BlockValidationViewerMoniker;
|
|
49
|
+
export interface BlockValidationViewer extends BlockValidationViewerMethods, Provider<BlockValidationViewerMoniker> {
|
|
50
|
+
qualifiedValidateBlock(block: SignedHydratedBlockWithHashMeta, config?: BlockValidationConfig): Promisable<[HydratedBlockValidationError[], BlockValidationQualification]>;
|
|
51
|
+
validateBlock(block: SignedHydratedBlockWithHashMeta, config?: BlockValidationConfig): Promisable<HydratedBlockValidationError[]>;
|
|
52
|
+
validateBlocks(blocks: SignedHydratedBlockWithHashMeta[], config?: BlockValidationConfig): Promisable<HydratedBlockValidationError[]>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=BlockValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockValidation.d.ts","sourceRoot":"","sources":["../../../src/viewers/BlockValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAA;AAC/F,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,EAC6E,KAAK,QAAQ,EAChG,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAE1E,eAAO,MAAM,+BAA+B;;;mBAAwB,CAAA;AACpE,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAA;AAC1F,eAAO,MAAM,8BAA8B;;;CAAgD,CAAA;AAE3F,eAAO,MAAM,8BAA8B;;;mBAGzC,CAAA;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;;;uDAKnC,CAAA;AAEF,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAC5E,eAAO,MAAM,uBAAuB;;;;;;;;;;;EAAyC,CAAA;AAE7E,MAAM,WAAW,4BAA4B;IAC3C,uBAAuB,CACrB,MAAM,EAAE,aAAa,EAAE,EACvB,MAAM,CAAC,EAAE,qBAAqB,GAC7B,UAAU,CAAC,CAAC,4BAA4B,EAAE,EAAE,4BAA4B,CAAC,CAAC,CAAA;CAC9E;AAED,eAAO,MAAM,4BAA4B,EAAG,uBAAgC,CAAA;AAC5E,MAAM,MAAM,4BAA4B,GAAG,OAAO,4BAA4B,CAAA;AAE9E,MAAM,WAAW,qBAAsB,SAAQ,4BAA4B,EAAE,QAAQ,CAAC,4BAA4B,CAAC;IACjH,sBAAsB,CACpB,KAAK,EAAE,+BAA+B,EACtC,MAAM,CAAC,EAAE,qBAAqB,GAC7B,UAAU,CAAC,CAAC,4BAA4B,EAAE,EAAE,4BAA4B,CAAC,CAAC,CAAA;IAC7E,aAAa,CAAC,KAAK,EAAE,+BAA+B,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAAC,4BAA4B,EAAE,CAAC,CAAA;IACjI,cAAc,CAAC,MAAM,EAAE,+BAA+B,EAAE,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAAC,4BAA4B,EAAE,CAAC,CAAA;CACtI"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Address, Hash, Promisable } from '@xylabs/sdk-js';
|
|
2
2
|
import type { ChainStakeIntent, XL1BlockRange } from '@xyo-network/xl1-protocol';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ChainQualified, Provider } from '../model/index.ts';
|
|
4
4
|
export interface StakeIntentViewerMethods {
|
|
5
|
-
qualifiedIntentByAddress(address: Address, headOrRange?: Hash | XL1BlockRange): Promisable<
|
|
5
|
+
qualifiedIntentByAddress(address: Address, headOrRange?: Hash | XL1BlockRange): Promisable<ChainQualified<ChainStakeIntent | null>>;
|
|
6
6
|
}
|
|
7
7
|
export declare const StakeIntentViewerMoniker: "StakeIntentViewer";
|
|
8
8
|
export type StakeIntentViewerMoniker = typeof StakeIntentViewerMoniker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StakeIntent.d.ts","sourceRoot":"","sources":["../../../src/viewers/StakeIntent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAAE,IAAI,EAAE,UAAU,EAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAEhF,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"StakeIntent.d.ts","sourceRoot":"","sources":["../../../src/viewers/StakeIntent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAAE,IAAI,EAAE,UAAU,EAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAEhF,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjE,MAAM,WAAW,wBAAwB;IACvC,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,IAAI,GAAG,aAAa,GAAG,UAAU,CAAC,cAAc,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,CAAA;CACpI;AAED,eAAO,MAAM,wBAAwB,EAAG,mBAA4B,CAAA;AACpE,MAAM,MAAM,wBAAwB,GAAG,OAAO,wBAAwB,CAAA;AAEtE,MAAM,WAAW,iBAAkB,SAAQ,wBAAwB,EAAE,QAAQ,CAAC,wBAAwB,CAAC;IACrG,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,IAAI,GAAG,aAAa,GAAG,UAAU,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAA;CAC3G"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Promisable } from '@xylabs/sdk-js';
|
|
2
|
+
import { type HydratedTransaction, type ValidationError } from '@xyo-network/xl1-protocol';
|
|
3
|
+
import type z from 'zod';
|
|
4
|
+
import { type Provider } from '../model/index.ts';
|
|
5
|
+
export declare const TransactionValidationQualificationZod: z.ZodObject<{
|
|
6
|
+
head: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").Hash, string>>;
|
|
7
|
+
range: z.ZodTuple<[z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-protocol").XL1BlockNumber, number>>, z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-protocol").XL1BlockNumber, number>>], null>;
|
|
8
|
+
}, z.z.core.$strip>;
|
|
9
|
+
export type TransactionValidationQualification = z.infer<typeof TransactionValidationQualificationZod>;
|
|
10
|
+
export declare const isTransactionValidationQualification: <T>(value: T) => value is T & {
|
|
11
|
+
head: import("@xylabs/sdk-js").Hash;
|
|
12
|
+
range: [import("@xyo-network/xl1-protocol").XL1BlockNumber, import("@xyo-network/xl1-protocol").XL1BlockNumber];
|
|
13
|
+
};
|
|
14
|
+
export declare const TransactionValidationConfigZod: z.ZodUnion<readonly [z.ZodObject<{
|
|
15
|
+
range: z.ZodTuple<[z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-protocol").XL1BlockNumber, number>>, z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-protocol").XL1BlockNumber, number>>], null>;
|
|
16
|
+
}, z.z.core.$strip>, z.ZodObject<{
|
|
17
|
+
head: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").Hash, string>>;
|
|
18
|
+
}, z.z.core.$strip>, z.ZodObject<{}, z.z.core.$strip>]>;
|
|
19
|
+
export type TransactionValidationConfig = z.infer<typeof TransactionValidationConfigZod>;
|
|
20
|
+
export declare const isTransactionValidationConfig: <T>(value: T) => value is T & ({
|
|
21
|
+
range: [import("@xyo-network/xl1-protocol").XL1BlockNumber, import("@xyo-network/xl1-protocol").XL1BlockNumber];
|
|
22
|
+
} | {
|
|
23
|
+
head: import("@xylabs/sdk-js").Hash;
|
|
24
|
+
} | Record<string, never>);
|
|
25
|
+
export interface TransactionValidationViewerMethods {
|
|
26
|
+
qualifiedValidateTransactions(transactions: HydratedTransaction[], config?: TransactionValidationConfig): Promisable<[ValidationError[][], TransactionValidationQualification]>;
|
|
27
|
+
}
|
|
28
|
+
export declare const TransactionValidationViewerMoniker: "TransactionValidationViewer";
|
|
29
|
+
export type TransactionValidationViewerMoniker = typeof TransactionValidationViewerMoniker;
|
|
30
|
+
export interface TransactionValidationViewer extends TransactionValidationViewerMethods, Provider<TransactionValidationViewerMoniker> {
|
|
31
|
+
qualifiedValidateTransaction(transaction: HydratedTransaction, config?: TransactionValidationConfig): Promisable<[ValidationError[], TransactionValidationQualification]>;
|
|
32
|
+
validateTransaction(transaction: HydratedTransaction[], config?: TransactionValidationConfig): Promisable<ValidationError[]>;
|
|
33
|
+
validateTransactions(transactions: HydratedTransaction[], config?: TransactionValidationConfig): Promisable<ValidationError[][]>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=TransactionValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionValidation.d.ts","sourceRoot":"","sources":["../../../src/viewers/TransactionValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC1F,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAC2C,KAAK,QAAQ,EAC9D,MAAM,mBAAmB,CAAA;AAE1B,eAAO,MAAM,qCAAqC;;;mBAAwB,CAAA;AAC1E,MAAM,MAAM,kCAAkC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qCAAqC,CAAC,CAAA;AACtG,eAAO,MAAM,oCAAoC;;;CAAsD,CAAA;AAEvG,eAAO,MAAM,8BAA8B;;;;uDAA0B,CAAA;AACrE,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AACxF,eAAO,MAAM,6BAA6B;;;;0BAA+C,CAAA;AAEzF,MAAM,WAAW,kCAAkC;IACjD,6BAA6B,CAC3B,YAAY,EAAE,mBAAmB,EAAE,EACnC,MAAM,CAAC,EAAE,2BAA2B,GACnC,UAAU,CAAC,CAAC,eAAe,EAAE,EAAE,EAAE,kCAAkC,CAAC,CAAC,CAAA;CACzE;AAED,eAAO,MAAM,kCAAkC,EAAG,6BAAsC,CAAA;AACxF,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA;AAE1F,MAAM,WAAW,2BAA4B,SAAQ,kCAAkC,EAAE,QAAQ,CAAC,kCAAkC,CAAC;IACnI,4BAA4B,CAC1B,WAAW,EAAE,mBAAmB,EAChC,MAAM,CAAC,EAAE,2BAA2B,GACnC,UAAU,CAAC,CAAC,eAAe,EAAE,EAAE,kCAAkC,CAAC,CAAC,CAAA;IACtE,mBAAmB,CAAC,WAAW,EAAE,mBAAmB,EAAE,EAAE,MAAM,CAAC,EAAE,2BAA2B,GAAG,UAAU,CAAC,eAAe,EAAE,CAAC,CAAA;IAC5H,oBAAoB,CAAC,YAAY,EAAE,mBAAmB,EAAE,EAAE,MAAM,CAAC,EAAE,2BAA2B,GAAG,UAAU,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;CACjI"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './AccountBalance.ts';
|
|
2
2
|
export * from './Block.ts';
|
|
3
3
|
export * from './BlockReward.ts';
|
|
4
|
+
export * from './BlockValidation.ts';
|
|
4
5
|
export * from './ChainContract.ts';
|
|
5
6
|
export * from './ChainStakeViewer.ts';
|
|
6
7
|
export * from './Fork.ts';
|
|
@@ -13,5 +14,6 @@ export * from './StepStake.ts';
|
|
|
13
14
|
export * from './StepViewer.ts';
|
|
14
15
|
export * from './TimeSync.ts';
|
|
15
16
|
export * from './Transaction.ts';
|
|
17
|
+
export * from './TransactionValidation.ts';
|
|
16
18
|
export * from './TransferBalance.ts';
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/viewers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/viewers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA"}
|
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.0
|
|
4
|
+
"version": "1.18.0",
|
|
5
5
|
"description": "XYO Layer One SDK Protocol",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"@opentelemetry/api": "^1.9.0",
|
|
43
43
|
"@xylabs/hex": "~5.0.51",
|
|
44
44
|
"@xylabs/sdk-js": "~5.0.51",
|
|
45
|
+
"@xylabs/zod": "~5.0.51",
|
|
45
46
|
"@xyo-network/account": "~5.2.17",
|
|
46
47
|
"@xyo-network/account-model": "~5.2.17",
|
|
47
48
|
"@xyo-network/archivist-model": "~5.2.17",
|
|
@@ -80,6 +81,5 @@
|
|
|
80
81
|
"engineStrict": true,
|
|
81
82
|
"publishConfig": {
|
|
82
83
|
"access": "public"
|
|
83
|
-
}
|
|
84
|
-
"stableVersion": "1.17.7"
|
|
84
|
+
}
|
|
85
85
|
}
|
|
@@ -12,16 +12,16 @@ export abstract class AbstractCreatableProvider<TParams extends CreatableProvide
|
|
|
12
12
|
implements Omit<CreatableProviderInstance, 'moniker'> {
|
|
13
13
|
protected _contextCache: TParams['context'] | undefined
|
|
14
14
|
|
|
15
|
-
get config() {
|
|
16
|
-
return
|
|
15
|
+
protected get config() {
|
|
16
|
+
return this.context.config!
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
get context() {
|
|
20
|
-
return
|
|
19
|
+
protected get context() {
|
|
20
|
+
return this.params.context!
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
get locator() {
|
|
24
|
-
return
|
|
23
|
+
protected get locator() {
|
|
24
|
+
return this.context.locator!
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
static factory<TModule extends CreatableProviderInstance>(
|
|
@@ -40,6 +40,22 @@ export abstract class AbstractCreatableProvider<TParams extends CreatableProvide
|
|
|
40
40
|
return instance
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
static override async paramsHandler<T extends CreatableProviderInstance>(
|
|
44
|
+
params: Partial<T['params']> = {},
|
|
45
|
+
) {
|
|
46
|
+
const context = assertEx(params.context, () => new Error('Context is required'))
|
|
47
|
+
const config = assertEx(context.config, () => new Error('Context config is required'))
|
|
48
|
+
const locator = assertEx(context.locator, () => new Error('Context locator is required'))
|
|
49
|
+
return await super.paramsHandler<T>({
|
|
50
|
+
...params,
|
|
51
|
+
statusReporter: params.statusReporter ?? context.statusReporter,
|
|
52
|
+
context: {
|
|
53
|
+
...context, config, locator,
|
|
54
|
+
},
|
|
55
|
+
name: params.name ?? (this as unknown as CreatableProvider<T>).defaultMoniker,
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
static async tryGetInstance<T extends CreatableProviderInstance>(
|
|
44
60
|
this: CreatableProvider<T>,
|
|
45
61
|
inParams: T['params'],
|
|
@@ -46,26 +46,26 @@ export interface CreatableProviderFactory<T extends CreatableProviderInstance =
|
|
|
46
46
|
/** @deprecated use getInstance instead */
|
|
47
47
|
create(
|
|
48
48
|
this: CreatableProviderFactory<T>,
|
|
49
|
-
params?: Partial<T['params']>, start?: boolean): Promise<T>
|
|
49
|
+
params?: Partial<T['params'] & CreatableProviderParams>, start?: boolean): Promise<T>
|
|
50
50
|
|
|
51
51
|
getInstance(
|
|
52
52
|
this: CreatableProviderFactory<T>,
|
|
53
|
-
params: T['params'], start?: boolean): Promise<T>
|
|
53
|
+
params: T['params'] & CreatableProviderParams, start?: boolean): Promise<T>
|
|
54
54
|
|
|
55
55
|
tryGetInstance(
|
|
56
56
|
this: CreatableProviderFactory<T>,
|
|
57
|
-
params: T['params'], start?: boolean): Promise<T | undefined>
|
|
57
|
+
params: T['params'] & CreatableProviderParams, start?: boolean): Promise<T | undefined>
|
|
58
58
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export interface LabeledCreatableProvider<T extends CreatableProviderInstance = CreatableProviderInstance> extends CreatableProvider<T>, WithOptionalLabels {
|
|
62
|
-
factory(params?: Partial<T['params']>): LabeledCreatableProviderFactory<T>
|
|
62
|
+
factory(params?: Partial<T['params'] & CreatableProviderParams>): LabeledCreatableProviderFactory<T>
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export interface CreatableProvider<T extends CreatableProviderInstance = CreatableProviderInstance> extends Creatable<T> {
|
|
66
66
|
defaultMoniker: ProviderMoniker
|
|
67
67
|
monikers: ProviderMoniker[]
|
|
68
|
-
factory(params?: Partial<T['params']>): CreatableProviderFactory<T>
|
|
68
|
+
factory(params?: Partial<T['params'] & CreatableProviderParams>): CreatableProviderFactory<T>
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
@@ -16,6 +16,7 @@ const buildProviderFactory = <TProvider extends CreatableProviderInstance>(
|
|
|
16
16
|
const factory = {
|
|
17
17
|
monikers: provider.monikers,
|
|
18
18
|
// Copy static methods
|
|
19
|
+
// eslint-disable-next-line sonarjs/deprecation
|
|
19
20
|
create: provider.create.bind(provider) as LabeledCreatableProviderFactory<TProvider>['create'],
|
|
20
21
|
|
|
21
22
|
// Merge module & supplied labels
|
|
@@ -103,11 +103,12 @@ export class ProviderFactory<TProvider extends CreatableProviderInstance> implem
|
|
|
103
103
|
},
|
|
104
104
|
},
|
|
105
105
|
} as TProvider['params']
|
|
106
|
-
const
|
|
106
|
+
const resultPromise = scopeObject[this.resolvedMoniker] as Promise<TProvider> ?? this.creatableProvider.create<TProvider>(mergedParams)
|
|
107
|
+
scopeObject[this.resolvedMoniker] = resultPromise
|
|
108
|
+
const result = await resultPromise
|
|
107
109
|
if (start) {
|
|
108
110
|
assertEx(await result.start(), () => 'Failed to start provider instance')
|
|
109
111
|
}
|
|
110
|
-
scopeObject[this.resolvedMoniker] = result
|
|
111
112
|
return result
|
|
112
113
|
}
|
|
113
114
|
|
|
@@ -68,7 +68,8 @@ export class ProviderFactoryLocator implements ProviderFactoryLocatorInstance {
|
|
|
68
68
|
} as CreatableProviderInstance<TProvider>['params']['context'],
|
|
69
69
|
} as CreatableProviderInstance<TProvider>['params']
|
|
70
70
|
const factory = this.locate<TProvider>(moniker, labels)
|
|
71
|
-
|
|
71
|
+
const result = await factory.getInstance(resolvedParams)
|
|
72
|
+
return result
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
/**
|
package/src/config/Services.ts
CHANGED
|
@@ -2,12 +2,14 @@ import { globalRegistry } from 'zod'
|
|
|
2
2
|
import * as z from 'zod'
|
|
3
3
|
|
|
4
4
|
export const ServicesConfigZod = z.object({
|
|
5
|
-
accountBalanceViewerEndpoint: z.string().
|
|
5
|
+
accountBalanceViewerEndpoint: z.string().default('http://localhost:8080/rpc').register(globalRegistry, {
|
|
6
|
+
default: 'http://localhost:8080/rpc',
|
|
6
7
|
description: 'Endpoint of the API to use for instantiating an external AccountBalanceViewer',
|
|
7
8
|
title: 'services.accountBalanceViewerEndpoint',
|
|
8
9
|
type: 'string',
|
|
9
10
|
}),
|
|
10
|
-
apiEndpoint: z.string().
|
|
11
|
+
apiEndpoint: z.string().default('http://localhost:8080/rpc').register(globalRegistry, {
|
|
12
|
+
default: 'http://localhost:8080/rpc',
|
|
11
13
|
description: 'Endpoint of the API to use for instantiating an external Viewers',
|
|
12
14
|
title: 'services.apiEndpoint',
|
|
13
15
|
type: 'string',
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { HashZod } from '@xylabs/hex'
|
|
2
|
+
import { zodIsFactory } from '@xylabs/zod'
|
|
3
|
+
import { XL1BlockRangeZod } from '@xyo-network/xl1-protocol'
|
|
4
|
+
import z from 'zod'
|
|
5
|
+
|
|
6
|
+
export const ChainQualificationZod = z.object({ head: HashZod, range: XL1BlockRangeZod })
|
|
7
|
+
export type ChainQualification = z.infer<typeof ChainQualificationZod>
|
|
8
|
+
export const isChainQualification = zodIsFactory(ChainQualificationZod)
|
|
9
|
+
|
|
10
|
+
export const ChainQualifiedRangeConfigZod = z.object({ range: XL1BlockRangeZod })
|
|
11
|
+
export type ChainQualifiedRangeConfig = z.infer<typeof ChainQualifiedRangeConfigZod>
|
|
12
|
+
export const isChainQualifiedRangeConfig = zodIsFactory(ChainQualifiedRangeConfigZod)
|
|
13
|
+
|
|
14
|
+
export const ChainQualifiedHeadConfigZod = z.object({ head: HashZod })
|
|
15
|
+
export type ChainQualifiedHeadConfig = z.infer<typeof ChainQualifiedHeadConfigZod>
|
|
16
|
+
export const isChainQualifiedHeadConfig = zodIsFactory(ChainQualifiedHeadConfigZod)
|
|
17
|
+
|
|
18
|
+
export const ChainQualifiedConfigZod = z.union([ChainQualifiedRangeConfigZod, ChainQualifiedHeadConfigZod, z.object({})])
|
|
19
|
+
export type ChainQualifiedConfig = z.infer<typeof ChainQualifiedConfigZod>
|
|
20
|
+
export const isChainQualifiedConfig = zodIsFactory(ChainQualifiedConfigZod)
|
|
21
|
+
|
|
22
|
+
export const ExtendChainQualifiedConfigZod = (<T>(zodType: z.ZodType<T>) => {
|
|
23
|
+
return z.union([
|
|
24
|
+
ChainQualifiedRangeConfigZod.extend(zodType),
|
|
25
|
+
ChainQualifiedHeadConfigZod.extend(zodType),
|
|
26
|
+
zodType,
|
|
27
|
+
])
|
|
28
|
+
}) as <T>(zodType: z.ZodType<T>) => z.ZodType<T & ChainQualifiedConfig>
|
|
29
|
+
|
|
30
|
+
export type ChainQualified<T> = [T, ChainQualification]
|
|
31
|
+
export const ChainQualifiedZod = <T>(zodType: z.ZodType<T>) => {
|
|
32
|
+
return z.tuple([zodType, ChainQualificationZod])
|
|
33
|
+
}
|
package/src/model/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export * from './ChainContext/index.ts'
|
|
2
2
|
export * from './ChainFork/index.ts'
|
|
3
3
|
export * from './ChainIdentity.ts'
|
|
4
|
+
export * from './ChainQualification.ts'
|
|
4
5
|
export * from './ChainStore.ts'
|
|
5
6
|
export * from './PayloadBundle/index.ts'
|
|
6
7
|
export * from './PayloadMap.ts'
|
|
7
8
|
export * from './Position.ts'
|
|
8
9
|
export * from './Provider.ts'
|
|
9
|
-
export * from './Qualified.ts'
|
|
10
10
|
export * from './RecordKeyType.ts'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
+
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
3
|
+
|
|
4
|
+
import type { BlockViewer } from '../../viewers/index.ts'
|
|
5
|
+
|
|
6
|
+
export async function getWindowedChain(blockViewer: BlockViewer, maxWindowSize: number, previousChain: SignedHydratedBlockWithHashMeta[] = []) {
|
|
7
|
+
const newBlocks: SignedHydratedBlockWithHashMeta[] = []
|
|
8
|
+
let currentBlock: SignedHydratedBlockWithHashMeta | null = await blockViewer.currentBlock()
|
|
9
|
+
console.log('[getWindowedChain] Current Block:', currentBlock?.[0]._hash)
|
|
10
|
+
const head = currentBlock
|
|
11
|
+
while (currentBlock !== null && currentBlock[0].block >= head[0].block) {
|
|
12
|
+
newBlocks.unshift(currentBlock)
|
|
13
|
+
const previousBlockHash: Hash | null = currentBlock[0].previous
|
|
14
|
+
currentBlock = (previousBlockHash === null ? null : await blockViewer.blockByHash(previousBlockHash))
|
|
15
|
+
}
|
|
16
|
+
const newChain = [...previousChain, ...newBlocks].slice(-maxWindowSize)
|
|
17
|
+
while (newChain.length > 0 && newChain.length < maxWindowSize && newChain[0][0].previous !== null) {
|
|
18
|
+
const block = await blockViewer.blockByHash(newChain[0][0].previous!)
|
|
19
|
+
if (block === null) break
|
|
20
|
+
newChain.unshift(block)
|
|
21
|
+
}
|
|
22
|
+
return newChain
|
|
23
|
+
}
|
package/src/primitives/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type StepIdentity } from '@xyo-network/xl1-protocol'
|
|
2
2
|
|
|
3
3
|
import type { StakedChainContextRead } from '../../model/index.ts'
|
|
4
|
-
import type { BlockViewer } from '../../viewers/
|
|
4
|
+
import type { BlockViewer } from '../../viewers/index.ts'
|
|
5
5
|
import { externalBlockRangeFromStep } from '../chain/time/index.ts'
|
|
6
6
|
import { weightedStakeForRangeByPosition } from '../stake/index.ts'
|
|
7
7
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
2
|
+
|
|
3
|
+
import { scoreUncle } from './scoreUncle.ts'
|
|
4
|
+
|
|
5
|
+
export function findBestUncle(finalizedWindowedChain: SignedHydratedBlockWithHashMeta[], uncles: SignedHydratedBlockWithHashMeta[][]) {
|
|
6
|
+
const scores = uncles.map(uncle => ([scoreUncle(finalizedWindowedChain, uncle), uncle] as const)).toSorted((a, b) => b[0] - a[0])
|
|
7
|
+
return scores[0]?.[1] ?? finalizedWindowedChain
|
|
8
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertEx,
|
|
3
|
+
exists, type Hash,
|
|
4
|
+
} from '@xylabs/sdk-js'
|
|
5
|
+
import { isTransactionBoundWitness, type SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
6
|
+
|
|
7
|
+
import type { BaseContext } from '../../model/index.ts'
|
|
8
|
+
|
|
9
|
+
function blocksToChains(blocks: SignedHydratedBlockWithHashMeta[]) {
|
|
10
|
+
const chains: SignedHydratedBlockWithHashMeta[][] = []
|
|
11
|
+
const map = new Map<Hash, SignedHydratedBlockWithHashMeta>()
|
|
12
|
+
for (const block of blocks) {
|
|
13
|
+
map.set(block[0]._hash, block)
|
|
14
|
+
}
|
|
15
|
+
for (const block of blocks) {
|
|
16
|
+
let uncle: SignedHydratedBlockWithHashMeta[] = [block]
|
|
17
|
+
let previous = block[0].previous ? map.get(block[0].previous) : undefined
|
|
18
|
+
while (previous) {
|
|
19
|
+
if (previous[0].block === (uncle[0][0].block - 1)) {
|
|
20
|
+
uncle.unshift(previous)
|
|
21
|
+
previous = previous[0].previous ? map.get(previous[0].previous) : undefined
|
|
22
|
+
} else {
|
|
23
|
+
// block number sequence is off
|
|
24
|
+
uncle = []
|
|
25
|
+
break
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (uncle.length > 0) {
|
|
29
|
+
chains.push(uncle)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return chains
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toValidUncle(
|
|
36
|
+
_context: BaseContext,
|
|
37
|
+
finalizedWindowedChain: SignedHydratedBlockWithHashMeta[],
|
|
38
|
+
possibleUncle: SignedHydratedBlockWithHashMeta[],
|
|
39
|
+
) {
|
|
40
|
+
const finalizedWindowStartBlockNumber = finalizedWindowedChain.at(0)?.[0].block ?? -1
|
|
41
|
+
const finalizedHead = assertEx(finalizedWindowedChain.at(-1), () => 'finalizedWindowedChain is empty')
|
|
42
|
+
// prune the chain to match the finalized head
|
|
43
|
+
|
|
44
|
+
const prunedPossibleUncle = possibleUncle.filter(b => b[0].block > finalizedHead[0].block)
|
|
45
|
+
|
|
46
|
+
if (prunedPossibleUncle.length === 0) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (prunedPossibleUncle[0][0].block !== finalizedHead[0].block + 1) {
|
|
51
|
+
// uncle does not build on finalized head (block number mismatch)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
if (prunedPossibleUncle[0][0].previous !== finalizedHead[0]._hash) {
|
|
55
|
+
// uncle does not build on finalized head (previous hash mismatch)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
const allUncleTransactions = prunedPossibleUncle.flatMap(b => b[1]).filter(isTransactionBoundWitness)
|
|
59
|
+
const allFinalizedTransactions = finalizedWindowedChain.flatMap(b => b[1]).filter(isTransactionBoundWitness)
|
|
60
|
+
const txPossiblyBeforeWindow = allUncleTransactions.find(tx => tx.nbf < finalizedWindowStartBlockNumber)
|
|
61
|
+
if (txPossiblyBeforeWindow) {
|
|
62
|
+
// uncle has a transaction that is valid before the finalized window
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
const txExistsInWindow = allUncleTransactions.find(tx => allFinalizedTransactions.find(finalTx => finalTx._hash === tx._hash))
|
|
66
|
+
if (txExistsInWindow) {
|
|
67
|
+
// uncle has a transaction that is already in the finalized window
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
return prunedPossibleUncle
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function findUncles(context: BaseContext, finalizedWindowedChain: SignedHydratedBlockWithHashMeta[], blocks: SignedHydratedBlockWithHashMeta[]) {
|
|
74
|
+
return blocksToChains(blocks).map(chain => toValidUncle(context, finalizedWindowedChain, chain)).filter(exists)
|
|
75
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
2
|
+
|
|
3
|
+
export function scoreUncle(finalizedWindowedChain: SignedHydratedBlockWithHashMeta[], blocks: SignedHydratedBlockWithHashMeta[]) {
|
|
4
|
+
// TODO: More than length check
|
|
5
|
+
return blocks.length
|
|
6
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { AttoXL1, XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
1
|
+
import type { Address, Promisable } from '@xylabs/sdk-js'
|
|
2
|
+
import type { AttoXL1 } from '@xyo-network/xl1-protocol'
|
|
5
3
|
|
|
6
|
-
import type { Provider } from '../../model/index.ts'
|
|
4
|
+
import type { ChainQualifiedConfig, Provider } from '../../model/index.ts'
|
|
7
5
|
import type {
|
|
8
6
|
AccountBalanceHistoryItem,
|
|
9
7
|
AccountBalanceViewer,
|
|
@@ -22,8 +20,10 @@ import type { NetworkStakeViewer } from './NetworkStake/index.ts'
|
|
|
22
20
|
export interface XyoViewerMethods extends
|
|
23
21
|
NetworkStakeStepRewardViewerMethods, BlockViewerMethods,
|
|
24
22
|
TransactionViewerMethods, StakeViewerMethods, ForkViewerMethods {
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
/** @deprecated Use .account.balance.accountBalance instead */
|
|
24
|
+
accountBalance(address: Address, config?: ChainQualifiedConfig): Promisable<AttoXL1>
|
|
25
|
+
/** @deprecated Use .account.balance.accountBalanceHistory instead */
|
|
26
|
+
accountBalanceHistory(address: Address, config?: ChainQualifiedConfig): Promisable<AccountBalanceHistoryItem[]>
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const XyoViewerMoniker = 'XyoViewer' as const
|