UNPKG

@neo-one/node-blockchain-esnext-esm

Version:

NEO•ONE NEO blockchain implementation.

237 lines (236 loc) 12.5 kB
import { UInt256 } from '@neo-one/client-common-esnext-esm'; import { AddChange, Block, ChangeSet, DeleteChange, Output, OutputKey, ReadAllStorage, ReadGetAllStorage, ReadMetadataStorage, ReadStorage } from '@neo-one/node-core-esnext-esm'; import { Observable } from 'rxjs'; declare type TrackedChange<Key, AddValue, Value> = { readonly type: 'add'; readonly addValue: AddValue; readonly value: Value; readonly subType: 'add' | 'update'; } | { readonly type: 'delete'; readonly key: Key; }; declare type GetFunc<Key, Value> = (key: Key) => Promise<Value>; declare type TryGetFunc<Key, Value> = (key: Key) => Promise<Value | undefined>; export interface TrackedChangeWithKey<Key, AddValue, Value> { readonly type: string; readonly key: string; readonly value: TrackedChange<Key, AddValue, Value>; } export declare type TrackedChangeSet<Key, AddValue, Value> = ReadonlyArray<TrackedChangeWithKey<Key, AddValue, Value>>; interface BaseReadStorageCacheOptions<Key, AddValue, Value> { readonly readStorage: () => ReadStorage<Key, Value>; readonly name: string; readonly createAddChange: (value: AddValue) => AddChange; readonly createDeleteChange?: (key: Key) => DeleteChange; readonly onAdd?: (value: AddValue) => Promise<void>; } export declare class BaseReadStorageCache<Key, AddValue, Value> { readonly get: GetFunc<Key, Value>; readonly tryGet: TryGetFunc<Key, Value>; readonly tryGetValue: TryGetFunc<Key, Value>; readonly onAdd: ((value: AddValue) => Promise<void>) | undefined; readonly name: string; readonly mutableValues: { [key: string]: TrackedChange<Key, AddValue, Value>; }; protected readonly readStorage: () => ReadStorage<Key, Value>; protected readonly createAddChange: (value: AddValue) => AddChange; protected readonly createDeleteChange: ((key: Key) => DeleteChange) | undefined; constructor(options: BaseReadStorageCacheOptions<Key, AddValue, Value>); getChangeSet(): ChangeSet; getTrackedChangeSet(): TrackedChangeSet<Key, AddValue, Value>; tryGetTracked(_key: Key): TrackedChange<Key, AddValue, Value> | undefined; } interface ReadStorageCacheOptions<Key, AddValue, Value> extends BaseReadStorageCacheOptions<Key, AddValue, Value> { readonly getKeyString: (key: Key) => string; } declare class ReadStorageCache<Key, AddValue, Value> extends BaseReadStorageCache<Key, AddValue, Value> { readonly getKeyString: (key: Key) => string; constructor(options: ReadStorageCacheOptions<Key, AddValue, Value>); tryGetTracked(key: Key): TrackedChange<Key, AddValue, Value> | undefined; addTrackedChange(key: string, value: TrackedChange<Key, AddValue, Value>): void; } interface ReadAllStorageCacheOptions<Key, Value> { readonly readAllStorage: () => ReadAllStorage<Key, Value>; readonly name: string; readonly createAddChange: (value: Value) => AddChange; readonly createDeleteChange?: (key: Key) => DeleteChange; readonly onAdd?: (value: Value) => Promise<void>; readonly getKeyString: (key: Key) => string; readonly getKeyFromValue: (value: Value) => Key; } declare class ReadAllStorageCache<Key, Value> extends ReadStorageCache<Key, Value, Value> { readonly all$: Observable<Value>; protected readonly readAllStorage: () => ReadAllStorage<Key, Value>; protected readonly getKeyFromValue: (value: Value) => Key; constructor(options: ReadAllStorageCacheOptions<Key, Value>); } interface ReadGetAllStorageCacheOptions<Key, PartialKey, Value> { readonly readGetAllStorage: () => ReadGetAllStorage<Key, PartialKey, Value>; readonly name: string; readonly createAddChange: (value: Value) => AddChange; readonly createDeleteChange?: (key: Key) => DeleteChange; readonly onAdd?: (value: Value) => Promise<void>; readonly getKeyString: (key: Key) => string; readonly getKeyFromValue: (value: Value) => Key; readonly matchesPartialKey: (value: Value, key: PartialKey) => boolean; } declare class ReadGetAllStorageCache<Key, PartialKey, Value> extends ReadStorageCache<Key, Value, Value> { readonly getAll$: (key: PartialKey) => Observable<Value>; protected readonly readGetAllStorage: () => ReadGetAllStorage<Key, PartialKey, Value>; protected readonly getKeyFromValue: (value: Value) => Key; protected readonly matchesPartialKey: (value: Value, key: PartialKey) => boolean; constructor(options: ReadGetAllStorageCacheOptions<Key, PartialKey, Value>); } declare type AddFunc<Value> = (value: Value) => Promise<void>; declare type UpdateFunc<Value, Update> = (value: Value, update: Update) => Promise<Value>; declare type DeleteFunc<Key> = (key: Key) => Promise<void>; interface ReadAddUpdateDeleteStorageCacheOptions<Key, Value, Update> extends ReadStorageCacheOptions<Key, Value, Value> { readonly update: (value: Value, update: Update) => Value; readonly getKeyFromValue: (value: Value) => Key; } export declare class ReadAddUpdateDeleteStorageCache<Key, Value, Update> extends ReadStorageCache<Key, Value, Value> { readonly add: AddFunc<Value>; readonly update: UpdateFunc<Value, Update>; readonly delete: DeleteFunc<Key>; constructor(options: ReadAddUpdateDeleteStorageCacheOptions<Key, Value, Update>); } interface ReadAddUpdateStorageCacheOptions<Key, Value, Update> extends ReadStorageCacheOptions<Key, Value, Value> { readonly update: (value: Value, update: Update) => Value; readonly getKeyFromValue: (value: Value) => Key; readonly allowDupes?: boolean; } export declare class ReadAddUpdateStorageCache<Key, Value, Update> extends ReadStorageCache<Key, Value, Value> { readonly add: AddFunc<Value>; readonly update: UpdateFunc<Value, Update>; constructor(options: ReadAddUpdateStorageCacheOptions<Key, Value, Update>); } interface ReadAddDeleteStorageCacheOptions<Key, Value> extends ReadStorageCacheOptions<Key, Value, Value> { readonly getKeyFromValue: (value: Value) => Key; } export declare class ReadAddDeleteStorageCache<Key, Value> extends ReadStorageCache<Key, Value, Value> { readonly add: AddFunc<Value>; readonly delete: DeleteFunc<Key>; constructor(options: ReadAddDeleteStorageCacheOptions<Key, Value>); } interface ReadAddStorageCacheOptions<Key, Value> extends ReadStorageCacheOptions<Key, Value, Value> { readonly getKeyFromValue: (value: Value) => Key; readonly allowDupes?: boolean; } export declare class ReadAddStorageCache<Key, Value> extends ReadStorageCache<Key, Value, Value> { readonly add: AddFunc<Value>; constructor(options: ReadAddStorageCacheOptions<Key, Value>); } interface ReadGetAllAddDeleteStorageCacheOptions<Key, PartialKey, Value> extends ReadGetAllStorageCacheOptions<Key, PartialKey, Value> { readonly getKeyFromValue: (value: Value) => Key; } export declare class ReadGetAllAddDeleteStorageCache<Key, PartialKey, Value> extends ReadGetAllStorageCache<Key, PartialKey, Value> { readonly add: AddFunc<Value>; readonly delete: DeleteFunc<Key>; constructor(options: ReadGetAllAddDeleteStorageCacheOptions<Key, PartialKey, Value>); } interface ReadGetAllAddUpdateDeleteStorageCacheOptions<Key, PartialKey, Value, Update> extends ReadGetAllStorageCacheOptions<Key, PartialKey, Value> { readonly update: (value: Value, update: Update) => Value; readonly getKeyFromValue: (value: Value) => Key; } export declare class ReadGetAllAddUpdateDeleteStorageCache<Key, PartialKey, Value, Update> extends ReadGetAllStorageCache<Key, PartialKey, Value> { readonly add: AddFunc<Value>; readonly update: UpdateFunc<Value, Update>; readonly delete: DeleteFunc<Key>; constructor(options: ReadGetAllAddUpdateDeleteStorageCacheOptions<Key, PartialKey, Value, Update>); } interface ReadGetAllAddStorageCacheOptions<Key, PartialKey, Value> extends ReadGetAllStorageCacheOptions<Key, PartialKey, Value> { readonly getKeyFromValue: (value: Value) => Key; } export declare class ReadGetAllAddStorageCache<Key, PartialKey, Value> extends ReadGetAllStorageCache<Key, PartialKey, Value> { readonly add: AddFunc<Value>; constructor(options: ReadGetAllAddStorageCacheOptions<Key, PartialKey, Value>); } interface ReadAllAddUpdateDeleteStorageCacheOptions<Key, Value, Update> extends ReadAllStorageCacheOptions<Key, Value> { readonly update: (value: Value, update: Update) => Value; readonly getKeyFromValue: (value: Value) => Key; } export declare class ReadAllAddUpdateDeleteStorageCache<Key, Value, Update> extends ReadAllStorageCache<Key, Value> { readonly add: AddFunc<Value>; readonly update: UpdateFunc<Value, Update>; readonly delete: DeleteFunc<Key>; constructor(options: ReadAllAddUpdateDeleteStorageCacheOptions<Key, Value, Update>); } interface ReadAllAddStorageCacheOptions<Key, Value> extends ReadAllStorageCacheOptions<Key, Value> { readonly getKeyFromValue: (value: Value) => Key; } export declare class ReadAllAddStorageCache<Key, Value> extends ReadAllStorageCache<Key, Value> { readonly add: AddFunc<Value>; constructor(options: ReadAllAddStorageCacheOptions<Key, Value>); } interface BlockLikeKey { readonly hashOrIndex: Block['hash'] | Block['index']; } interface BlockLike { readonly hash: Block['hash']; readonly index: Block['index']; } interface BlockLikeStorageCacheOptions<Value extends BlockLike> extends BaseReadStorageCacheOptions<BlockLikeKey, Value, Value> { } export declare class BlockLikeStorageCache<Value extends BlockLike> extends BaseReadStorageCache<BlockLikeKey, Value, Value> { protected readonly mutableIndexValues: { [index: string]: TrackedChange<BlockLikeKey, Value, Value>; }; constructor(options: BlockLikeStorageCacheOptions<Value>); add(value: Value): Promise<void>; tryGetTracked(key: BlockLikeKey): TrackedChange<BlockLikeKey, Value, Value> | undefined; addTrackedChange(key: string, value: TrackedChange<BlockLikeKey, Value, Value>): void; } interface OutputValue { readonly hash: UInt256; readonly index: number; readonly output: Output; } export declare class OutputStorageCache extends ReadStorageCache<OutputKey, OutputValue, Output> { readonly add: AddFunc<OutputValue>; constructor(readStorage: () => ReadStorage<OutputKey, Output>); } declare type TrackedMetadataChange<AddValue, Value> = { readonly type: 'add'; readonly addValue: AddValue; readonly value: Value; readonly subType: 'add' | 'update'; } | { readonly type: 'delete'; }; declare type GetMetadataFunc<Value> = (key?: undefined) => Promise<Value>; declare type TryGetMetadataFunc<Value> = (key?: undefined) => Promise<Value | undefined>; interface BaseReadMetadataStorageCacheOptions<AddValue, Value> { readonly readStorage: () => ReadMetadataStorage<Value>; readonly name: string; readonly createAddChange: (value: AddValue) => AddChange; readonly createDeleteChange?: () => DeleteChange; readonly onAdd?: (value: AddValue) => Promise<void>; } export declare class BaseReadMetadataStorageCache<AddValue, Value> { readonly get: GetMetadataFunc<Value>; readonly tryGet: TryGetMetadataFunc<Value>; mutableValue: TrackedMetadataChange<AddValue, Value> | undefined; readonly onAdd: ((value: AddValue) => Promise<void>) | undefined; protected readonly readStorage: () => ReadMetadataStorage<Value>; protected readonly name: string; protected readonly createAddChange: (value: AddValue) => AddChange; protected readonly createDeleteChange: (() => DeleteChange) | undefined; constructor(options: BaseReadMetadataStorageCacheOptions<AddValue, Value>); getChangeSet(): ChangeSet; getTrackedChangeSet(): TrackedChangeSet<string, AddValue, Value>; tryGetTracked(): TrackedMetadataChange<AddValue, Value> | undefined; addTrackedChange(_key: string, value: TrackedMetadataChange<AddValue, Value>): void; } declare class ReadMetadataStorageCache<AddValue, Value> extends BaseReadMetadataStorageCache<AddValue, Value> { } interface ReadAddUpdateMetadataStorageCacheOptions<Value, Update> extends BaseReadMetadataStorageCacheOptions<Value, Value> { readonly update: (value: Value, update: Update) => Value; } export declare class ReadAddUpdateMetadataStorageCache<Value, Update> extends ReadMetadataStorageCache<Value, Value> { readonly add: AddFunc<Value>; readonly update: UpdateFunc<Value, Update>; constructor(options: ReadAddUpdateMetadataStorageCacheOptions<Value, Update>); } export {};