@keetanetwork/keetanet-client 0.10.2
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/._version.d.ts +0 -0
- package/LICENSE +35 -0
- package/api/index.d.ts +181 -0
- package/api/node.d.ts +216 -0
- package/api/vote.d.ts +25 -0
- package/client/builder.d.ts +129 -0
- package/client/client_common_tests.d.ts +72 -0
- package/client/index-browser.d.ts +243 -0
- package/client/index-browser.js +141899 -0
- package/client/index.d.ts +243 -0
- package/client/index.js +89118 -0
- package/config/index.d.ts +62 -0
- package/lib/account.d.ts +544 -0
- package/lib/block/index.d.ts +181 -0
- package/lib/block/operations.d.ts +407 -0
- package/lib/bootstrap.d.ts +27 -0
- package/lib/error/account.d.ts +9 -0
- package/lib/error/block.d.ts +9 -0
- package/lib/error/client.d.ts +9 -0
- package/lib/error/index.d.ts +20 -0
- package/lib/error/kv.d.ts +9 -0
- package/lib/error/ledger.d.ts +12 -0
- package/lib/error/permissions.d.ts +9 -0
- package/lib/error/vote.d.ts +9 -0
- package/lib/index.d.ts +39 -0
- package/lib/kv/index.d.ts +22 -0
- package/lib/kv/index.test.data.d.ts +9 -0
- package/lib/kv/kv_dynamodb.d.ts +20 -0
- package/lib/kv/kv_memory.d.ts +17 -0
- package/lib/kv/kv_redis.d.ts +22 -0
- package/lib/kv/providers.d.ts +9 -0
- package/lib/ledger/cache.d.ts +14 -0
- package/lib/ledger/common.d.ts +115 -0
- package/lib/ledger/db_dynamodb.d.ts +129 -0
- package/lib/ledger/db_memory.d.ts +6 -0
- package/lib/ledger/db_postgres.d.ts +70 -0
- package/lib/ledger/db_spanner.d.ts +116 -0
- package/lib/ledger/db_spanner_helper.d.ts +487 -0
- package/lib/ledger/db_sqlite.d.ts +64 -0
- package/lib/ledger/drivers.d.ts +7 -0
- package/lib/ledger/effects.d.ts +78 -0
- package/lib/ledger/index.d.ts +312 -0
- package/lib/ledger/types.d.ts +49 -0
- package/lib/node/index.d.ts +114 -0
- package/lib/node/local.d.ts +30 -0
- package/lib/node/timing.d.ts +12 -0
- package/lib/node/utils.d.ts +4 -0
- package/lib/p2p.d.ts +300 -0
- package/lib/permissions.d.ts +121 -0
- package/lib/pubsub/index.d.ts +7 -0
- package/lib/pubsub/providers.d.ts +7 -0
- package/lib/pubsub/ps_memory.d.ts +9 -0
- package/lib/pubsub/ps_redis.d.ts +10 -0
- package/lib/stats.d.ts +51 -0
- package/lib/utils/asn1.d.ts +205 -0
- package/lib/utils/bitfield.d.ts +13 -0
- package/lib/utils/bloom.d.ts +6 -0
- package/lib/utils/buffer.d.ts +27 -0
- package/lib/utils/certificate.d.ts +340 -0
- package/lib/utils/conversion.d.ts +46 -0
- package/lib/utils/dynamodb.d.ts +17 -0
- package/lib/utils/ed2curve.d.ts +7 -0
- package/lib/utils/hash.d.ts +17 -0
- package/lib/utils/helper.d.ts +67 -0
- package/lib/utils/helper_testing.d.ts +37 -0
- package/lib/utils/initial.d.ts +32 -0
- package/lib/utils/never.d.ts +7 -0
- package/lib/utils/redis.d.ts +11 -0
- package/lib/vote.d.ts +273 -0
- package/package.json +35 -0
- package/version.d.ts +2 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import KeetaNetError from '.';
|
|
2
|
+
declare const LedgerErrorType: "LEDGER";
|
|
3
|
+
declare const LedgerErrorCodes: readonly ["TRANSACTION_ABORTED", "INVALID_CHAIN", "INVALID_NETWORK", "INVALID_SUBNET", "NOT_EMPTY", "NOT_OPENING", "NOT_SUCCESSOR", "INVALID_PERMISSIONS", "INVALID_OWNER_COUNT", "INVALID_BALANCE", "PREVIOUS_ALREADY_USED", "PREVIOUS_NOT_SEEN", "SUCCESSOR_VOTE_EXISTS", "INSUFFICIENT_VOTING_WEIGHT", "INVALID_ACCOUNT_INFO_KEY", "RECEIVE_NOT_MET", "DUPLICATE_VOTE_FOUND", "CANNOT_EXCHANGE_PERM_VOTE", "BLOCKS_DIFFER_FROM_VOTED_ON", "NO_PERM_WITHOUT_SELF_TEMP", "DUPLICATE_VOTE_ISSUER_FOUND", "OTHER"];
|
|
4
|
+
export type LedgerErrorCode = `${typeof LedgerErrorType}_${typeof LedgerErrorCodes[number]}`;
|
|
5
|
+
export declare class KeetaNetLedgerError extends KeetaNetError {
|
|
6
|
+
static isInstance: (obj: any, strict?: boolean) => obj is KeetaNetLedgerError;
|
|
7
|
+
readonly type: "LEDGER";
|
|
8
|
+
readonly shouldRetry: boolean;
|
|
9
|
+
readonly retryDelay?: number;
|
|
10
|
+
constructor(code: LedgerErrorCode, message: string, shouldRetry?: boolean, retryDelay?: number);
|
|
11
|
+
}
|
|
12
|
+
export default KeetaNetLedgerError;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import KeetaNetError from '.';
|
|
2
|
+
declare const PermissionsErrorType: "PERMISSIONS";
|
|
3
|
+
declare const PermissionsErrorCodes: readonly ["CANNOT_MIX_FLAGS_AND_TYPES", "EXTERNAL_OFFSET_TOO_LARGE", "INVALID_EXTERNAL_FLAG", "INVALID_FLAG", "INVALID_FLAG_ASSERTION"];
|
|
4
|
+
export type PermissionsErrorCode = `${typeof PermissionsErrorType}_${typeof PermissionsErrorCodes[number]}`;
|
|
5
|
+
export default class KeetaNetPermissionsError extends KeetaNetError {
|
|
6
|
+
static isInstance: (obj: any, strict?: boolean) => obj is KeetaNetPermissionsError;
|
|
7
|
+
constructor(code: PermissionsErrorCode, message: string);
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import KeetaNetError from '.';
|
|
2
|
+
declare const VoteErrorType: "VOTE";
|
|
3
|
+
declare const VoteErrorCodes: readonly ["SERIAL_MISMATCH", "INVALID_VERSION", "INVALID_CONSTRUCTION", "INVALID_CONSTRUCTION_JSON", "SIGNATURE_INVALID", "EXPIRED", "INVALID_VALIDITY", "MOMENT_BEFORE_VALIDITY_FROM", "STAPLE_INVALID_CONSTRUCTION", "STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_COUNT", "STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_MISSING", "STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_ORDER", "STAPLE_DUPLICATE_VOTE_ISSUER", "STAPLE_PERMANENCE_MISMATCH", "BUILDER_INVALID_CONSTRUCTION", "BUILDER_INVALID_BLOCK_TYPE", "BUILDER_INVALID_SERIAL", "BUILDER_INVALID_VALID_TO_FROM", "MALFORMED_WRAPPER", "MALFORMED_VOTE_WRAPPER", "MALFORMED_VOTE_CONTENT", "MALFORMED_VOTE_CONTENT_EXTRA_DATA", "MALFORMED_VOTE_VERSION", "MALFORMED_VOTE_SERIAL", "MALFORMED_VOTE_SIGNATURE_INFORMATION", "MALFORMED_VOTE_ISSUER_INFORMATION", "MALFORMED_VOTE_SUBJECT_INFORMATION", "MALFORMED_VOTE_VALIDITY_INFORMATION", "MALFORMED_VOTE_SERIAL", "MALFORMED_VOTE_EXTENSIONS", "MALFORMED_VOTE_EXTENSIONS_VALUE", "MALFORMED_VOTE_EXTENSIONS_VALUE_OID", "MALFORMED_VOTE_EXTENSIONS_VALUE_CRITICAL", "MALFORMED_VOTE_EXTENSIONS_VALUE_CRITICAL_TYPE", "MALFORMED_VOTE_EXTENSIONS_VALUE_HASH_DATA", "MALFORMED_VOTE_SIGNATURE_SCHEME_DOES_NOT_MATCH_ISSUER", "MALFORMED_VOTE_SIGNATURE_SCHEME_DOES_NOT_MATCH_WRAPPER", "MALFORMED_VOTE_SIGNATURE_SCHEME_ECDSA_INVALID_CURVE", "MALFORMED_VOTE_SIGNATURE_UNSUPPORTED_SCHEME", "MALFORMED_VOTE_SUBJECT_PUBLIC_KEY_INFORMATION", "MALFORMED_VOTE_SIGNATURE_VALUE", "MALFORMED_VOTE_NO_BLOCKS_FOUND", "MALFORMED_STAPLE", "MALFORMED_STAPLE_BLOCKS", "MALFORMED_STAPLE_BLOCKS_AT_LEAST_ONE", "MALFORMED_STAPLE_VOTES", "MALFORMED_STAPLE_VOTES_AT_LEAST_ONE", "MALFORMED_FIND_RDN_INVALID_TYPE", "MALFORMED_FIND_RDN_MUST_HAVE_ONE", "MALFORMED_FIND_RDN_PART_WELL_FORMED", "MALFORMED_FIND_RDN_MUST_BE_SET", "MALFORMED_FIND_RDN_TYPE_MUST_BE_OID", "MALFORMED_HASHES_FROM_VOTE_INVALID_INPUT", "MALFORMED_HASHES_FROM_VOTE_INVALID_TYPE", "MALFORMED_HASHES_FROM_VOTE_INVALID_CONTEXT_SPECIFIC", "MALFORMED_HASHES_FROM_VOTE_DATA_NEEDS_OID", "MALFORMED_HASHES_FROM_VOTE_DATA_HASH_DATA_MUST_BE_SEQUENCE", "MALFORMED_HASHES_FROM_VOTE_DATA_NOT_TWO_ITEMS", "MALFORMED_HASHES_FROM_VOTE_DATA_UNSUPPORTED_HASH_FUNC", "MALFORMED_HASHES_FROM_VOTE_DATA_UNSUPPORTED_HASH_TYPE", "MALFORMED_HASHES_FROM_VOTE_DATA_SECOND_MUST_BE_SEQUENCE"];
|
|
4
|
+
export type VoteErrorCode = `${typeof VoteErrorType}_${typeof VoteErrorCodes[number]}`;
|
|
5
|
+
export default class KeetaNetVoteError extends KeetaNetError {
|
|
6
|
+
static isInstance: (obj: any, strict?: boolean) => obj is KeetaNetVoteError;
|
|
7
|
+
constructor(code: VoteErrorCode, message: string);
|
|
8
|
+
}
|
|
9
|
+
export {};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Account from './account';
|
|
2
|
+
import Block from './block';
|
|
3
|
+
import Ledger from './ledger';
|
|
4
|
+
import Node from './node';
|
|
5
|
+
import P2P from './p2p';
|
|
6
|
+
import Stats from './stats';
|
|
7
|
+
import Permissions from './permissions';
|
|
8
|
+
import Vote from './vote';
|
|
9
|
+
import Error from './error';
|
|
10
|
+
import * as ASN1 from './utils/asn1';
|
|
11
|
+
import * as Bloom from './utils/bloom';
|
|
12
|
+
import * as Buffer from './utils/buffer';
|
|
13
|
+
import * as Hash from './utils/hash';
|
|
14
|
+
import * as Helper from './utils/helper';
|
|
15
|
+
import * as Initial from './utils/initial';
|
|
16
|
+
import * as Conversion from './utils/conversion';
|
|
17
|
+
import * as Certificate from './utils/certificate';
|
|
18
|
+
declare const _default: {
|
|
19
|
+
Account: typeof Account;
|
|
20
|
+
Block: typeof Block;
|
|
21
|
+
Error: typeof Error;
|
|
22
|
+
Ledger: typeof Ledger;
|
|
23
|
+
Node: typeof Node;
|
|
24
|
+
P2P: typeof P2P;
|
|
25
|
+
Permissions: typeof Permissions;
|
|
26
|
+
Stats: typeof Stats;
|
|
27
|
+
Vote: typeof Vote;
|
|
28
|
+
Utils: {
|
|
29
|
+
ASN1: typeof ASN1;
|
|
30
|
+
Bloom: typeof Bloom;
|
|
31
|
+
Buffer: typeof Buffer;
|
|
32
|
+
Hash: typeof Hash;
|
|
33
|
+
Helper: typeof Helper;
|
|
34
|
+
Initial: typeof Initial;
|
|
35
|
+
Conversion: typeof Conversion;
|
|
36
|
+
Certificate: typeof Certificate;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export default _default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type BufferStorage from '../utils/buffer';
|
|
2
|
+
import type { JSONSerializable } from '../utils/conversion';
|
|
3
|
+
import type KVStorageProviders from './providers';
|
|
4
|
+
export interface KVSetOptionsType {
|
|
5
|
+
exclusiveCreate?: boolean;
|
|
6
|
+
ttl?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface KVStorageProviderAPI {
|
|
9
|
+
set(arena: string, key: string, value: JSONSerializable | undefined, options?: KVSetOptionsType): Promise<void>;
|
|
10
|
+
get(arena: string | null, key: string): Promise<JSONSerializable | undefined>;
|
|
11
|
+
getAll(arena: string): Promise<{
|
|
12
|
+
[key: string]: JSONSerializable;
|
|
13
|
+
}>;
|
|
14
|
+
list(arena: string): Promise<string[]>;
|
|
15
|
+
incr(arena: string, key: string, change: number): Promise<bigint>;
|
|
16
|
+
xor(arena: null, key: string, change: BufferStorage): Promise<void>;
|
|
17
|
+
destroy?: () => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export type KVStorageProvider = InstanceType<typeof KVStorageProviders[keyof typeof KVStorageProviders]>;
|
|
20
|
+
export declare class KVStorageProviderBase {
|
|
21
|
+
xor(_ignored_arena: null, key: string, _ignored_change: BufferStorage): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Random Values in hex which will be XOR'd together to produce
|
|
3
|
+
* TestHashValuesXOR
|
|
4
|
+
*/
|
|
5
|
+
export declare const TestHashValues: string[];
|
|
6
|
+
/**
|
|
7
|
+
* The result of XORing all the values of TestHashValues
|
|
8
|
+
*/
|
|
9
|
+
export declare const TestHashValuesXOR = "3819BCCE11FF17A70475E7683CE0ADD80525F27134EBDDD880B4208EFECDB771";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KVStorageProviderAPI, KVSetOptionsType } from './';
|
|
2
|
+
import { KVStorageProviderBase } from './';
|
|
3
|
+
import type { JSONSerializable } from '../utils/conversion';
|
|
4
|
+
import BufferStorage from '../utils/buffer';
|
|
5
|
+
import { DynamoDB } from '@aws-sdk/client-dynamodb';
|
|
6
|
+
export declare class KVStorageProviderDynamoDB extends KVStorageProviderBase implements KVStorageProviderAPI {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(table: string, ...dynamodbArgs: ConstructorParameters<typeof DynamoDB>);
|
|
9
|
+
static createTable(table: string, ...dynamodbArgs: ConstructorParameters<typeof DynamoDB>): Promise<void>;
|
|
10
|
+
static deleteTable(table: string, ...dynamodbArgs: ConstructorParameters<typeof DynamoDB>): Promise<void>;
|
|
11
|
+
set(arena: string, key: string, value: JSONSerializable | undefined, options?: KVSetOptionsType): Promise<void>;
|
|
12
|
+
get(arena: string | null, key: string): Promise<JSONSerializable | undefined>;
|
|
13
|
+
getAll(arena: string): Promise<{
|
|
14
|
+
[key: string]: JSONSerializable;
|
|
15
|
+
}>;
|
|
16
|
+
list(arena: string): Promise<string[]>;
|
|
17
|
+
incr(arena: string, key: string, change: number): Promise<bigint>;
|
|
18
|
+
xor(arena: null, key: string, change: BufferStorage): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export default KVStorageProviderDynamoDB;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { KVStorageProviderAPI, KVSetOptionsType } from './';
|
|
2
|
+
import { KVStorageProviderBase } from './';
|
|
3
|
+
import type { JSONSerializable } from '../utils/conversion';
|
|
4
|
+
import BufferStorage from '../utils/buffer';
|
|
5
|
+
export declare class KVStorageProviderMemory extends KVStorageProviderBase implements KVStorageProviderAPI {
|
|
6
|
+
#private;
|
|
7
|
+
constructor();
|
|
8
|
+
set(arena: string, key: string, value: JSONSerializable | undefined, options?: KVSetOptionsType): Promise<void>;
|
|
9
|
+
get(arena: string | null, key: string): Promise<JSONSerializable | undefined>;
|
|
10
|
+
getAll(arena: string): Promise<{
|
|
11
|
+
[key: string]: JSONSerializable;
|
|
12
|
+
}>;
|
|
13
|
+
list(arena: string): Promise<string[]>;
|
|
14
|
+
incr(arena: string, key: string, change: number): Promise<bigint>;
|
|
15
|
+
xor(arena: null, key: string, change: BufferStorage): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export default KVStorageProviderMemory;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { KVStorageProviderAPI, KVSetOptionsType } from './';
|
|
2
|
+
import { KVStorageProviderBase } from './';
|
|
3
|
+
import type { JSONSerializable } from '../utils/conversion';
|
|
4
|
+
import type BufferStorage from '../utils/buffer';
|
|
5
|
+
import { RedisClient } from '../utils/redis';
|
|
6
|
+
export declare class KVStorageProviderRedis extends KVStorageProviderBase implements KVStorageProviderAPI {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(host: string, password: string, port?: number);
|
|
9
|
+
destroy(): Promise<void>;
|
|
10
|
+
private deleteExpiredKeys;
|
|
11
|
+
_testingDeleteExpiredKeys(): Promise<void>;
|
|
12
|
+
set(arena: string, key: string, value: JSONSerializable | undefined, opt?: KVSetOptionsType): Promise<void>;
|
|
13
|
+
get(arena: string | null, key: string): Promise<JSONSerializable | undefined>;
|
|
14
|
+
getAll(arena: string): Promise<{
|
|
15
|
+
[key: string]: JSONSerializable;
|
|
16
|
+
}>;
|
|
17
|
+
list(arena: string): Promise<string[]>;
|
|
18
|
+
incr(arena: string, key: string, change: number): Promise<bigint>;
|
|
19
|
+
xor(arena: null, key: string, change: BufferStorage): Promise<void>;
|
|
20
|
+
get _testingClient(): RedisClient;
|
|
21
|
+
}
|
|
22
|
+
export default KVStorageProviderRedis;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import KVStorageProviderMemory from './kv_memory';
|
|
2
|
+
import KVStorageProviderDynamoDB from './kv_dynamodb';
|
|
3
|
+
import KVStorageProviderRedis from './kv_redis';
|
|
4
|
+
export declare const KV: {
|
|
5
|
+
Memory: typeof KVStorageProviderMemory;
|
|
6
|
+
DynamoDB: typeof KVStorageProviderDynamoDB;
|
|
7
|
+
Redis: typeof KVStorageProviderRedis;
|
|
8
|
+
};
|
|
9
|
+
export default KV;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type Vote from '../vote';
|
|
2
|
+
export declare class LedgerRequestCache {
|
|
3
|
+
#private;
|
|
4
|
+
addVote(vote: null, contents: Buffer | ArrayBuffer): null;
|
|
5
|
+
addVote(vote: Vote): Vote;
|
|
6
|
+
addVote(vote: Vote | null, contents?: Buffer | ArrayBuffer): Vote | null;
|
|
7
|
+
addVotes(votes: Vote[]): Vote[];
|
|
8
|
+
getVote(contents: Buffer | ArrayBuffer): Vote | null;
|
|
9
|
+
getVote(contents: Buffer | ArrayBuffer, lookupVote: () => Vote): Vote;
|
|
10
|
+
getVote(contents: Buffer | ArrayBuffer, lookupVote: () => Vote | null): Vote | null;
|
|
11
|
+
getVoteByUID(uid: string): Vote | null;
|
|
12
|
+
getVoteByContents(contents: Buffer | ArrayBuffer): Vote | null;
|
|
13
|
+
}
|
|
14
|
+
export default LedgerRequestCache;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { VoteStaple } from '../vote';
|
|
2
|
+
import type Vote from '../vote';
|
|
3
|
+
import type { GenericAccount, TokenAddress } from '../account';
|
|
4
|
+
import Account from '../account';
|
|
5
|
+
import { Block, BlockHash } from '../block';
|
|
6
|
+
import type { LedgerConfig, LedgerSelector, LedgerStorage, LedgerStorageAPI } from '.';
|
|
7
|
+
import type { AccountInfo, ACLRow, ACLEntry, ACLUpdate } from './types';
|
|
8
|
+
import type Node from '../node';
|
|
9
|
+
import type Stats from '../stats';
|
|
10
|
+
import type { BaseSet, ExternalSet } from '../permissions';
|
|
11
|
+
import type { ComputedEffectOfBlocksByAccount } from './effects';
|
|
12
|
+
interface NumericEffect {
|
|
13
|
+
change: bigint;
|
|
14
|
+
starting?: bigint;
|
|
15
|
+
fellNegative?: boolean;
|
|
16
|
+
final?: bigint;
|
|
17
|
+
}
|
|
18
|
+
interface NumericEffectFinal extends NumericEffect {
|
|
19
|
+
final: bigint;
|
|
20
|
+
}
|
|
21
|
+
interface BalanceNumericEffect extends NumericEffect {
|
|
22
|
+
fellNegative?: boolean;
|
|
23
|
+
lowestChange: bigint;
|
|
24
|
+
receiveValidated?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface BalanceNumericEffectFinal extends BalanceNumericEffect {
|
|
27
|
+
final: bigint;
|
|
28
|
+
fellNegative: boolean;
|
|
29
|
+
starting: bigint;
|
|
30
|
+
}
|
|
31
|
+
type IfTrue<B, V, E = {
|
|
32
|
+
[key: string]: never;
|
|
33
|
+
}> = B extends true ? V : E;
|
|
34
|
+
type BalanceEffect<T extends boolean> = IfTrue<T, BalanceNumericEffectFinal, BalanceNumericEffect>;
|
|
35
|
+
type CompNumericEffect<T extends boolean> = IfTrue<T, NumericEffectFinal, NumericEffect>;
|
|
36
|
+
type PerAccount<T> = {
|
|
37
|
+
[pubKey: string]: T;
|
|
38
|
+
};
|
|
39
|
+
type NumericEffectPerAccount<T extends boolean> = PerAccount<CompNumericEffect<T>>;
|
|
40
|
+
type BalanceChanges<T extends boolean> = PerAccount<PerAccount<BalanceEffect<T>>>;
|
|
41
|
+
type computeLedgerEffectStorageProvider = Pick<LedgerStorageAPI, 'getAccountInfo' | 'getBalance' | 'listACLsByPrincipal' | 'delegatedWeight' | 'getAccountRep'>;
|
|
42
|
+
type BalanceSupplyChangeRespBase<T extends boolean> = {
|
|
43
|
+
balances: BalanceChanges<T>;
|
|
44
|
+
supplies: NumericEffectPerAccount<T>;
|
|
45
|
+
};
|
|
46
|
+
type BalanceSupplyChangeResp<T extends boolean, P extends boolean, W extends boolean> = BalanceSupplyChangeRespBase<T> & IfTrue<P, {
|
|
47
|
+
permissions: ACLUpdate[];
|
|
48
|
+
}> & IfTrue<W, {
|
|
49
|
+
weights: NumericEffectPerAccount<T>;
|
|
50
|
+
}>;
|
|
51
|
+
export declare function findPermissionMatch(lookingFor: Pick<ACLEntry, 'entity' | 'principal' | 'target'>, entries: ACLRow[]): ACLRow | undefined;
|
|
52
|
+
interface ComputeLedgerEffectOptions<T extends boolean, P extends boolean, W extends boolean> {
|
|
53
|
+
getFinalNumericValues?: T;
|
|
54
|
+
computePermissions?: P;
|
|
55
|
+
computeWeights?: W;
|
|
56
|
+
checkNegative?: boolean;
|
|
57
|
+
baseToken: TokenAddress;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Compute effects on the ledger from block effects
|
|
61
|
+
*/
|
|
62
|
+
export declare function computeLedgerEffect<T extends boolean, P extends boolean, W extends boolean>(options: ComputeLedgerEffectOptions<T, P, W>, effects: ComputedEffectOfBlocksByAccount, storageProvider: computeLedgerEffectStorageProvider, transaction?: any): Promise<BalanceSupplyChangeResp<T, P, W>>;
|
|
63
|
+
/**
|
|
64
|
+
* A partial LedgerStorageAPI which just has the methods for "addTimeStatistics"
|
|
65
|
+
*/
|
|
66
|
+
type LedgerStorageAPILike = Pick<LedgerStorageAPI, 'getVotes'>;
|
|
67
|
+
/**
|
|
68
|
+
* An individual update to statistics
|
|
69
|
+
*/
|
|
70
|
+
type StatsIncreaseRequest = Parameters<Stats['incr']>;
|
|
71
|
+
/**
|
|
72
|
+
* Common method for adding a timing data point during processing of a
|
|
73
|
+
* Vote Staple to a Node Stats
|
|
74
|
+
*
|
|
75
|
+
* @param node - A running node
|
|
76
|
+
* @param blocks - Blocks being processed
|
|
77
|
+
* @param to - Ledger being processed
|
|
78
|
+
* @param storageProvider - storage provider that includes getVotes function
|
|
79
|
+
* @param transaction - Current transaction (if any)
|
|
80
|
+
* @param skipPush - Instead of adding to stats immediately, just return what would be added
|
|
81
|
+
* @returns What was added (or would be added, if skipPush is set to true)
|
|
82
|
+
*/
|
|
83
|
+
export declare function addTimeStatistic(node: Node | undefined, blocks: Block[], to: LedgerStorage, storageProvider: LedgerStorageAPILike, transaction?: any, skipPush?: boolean): Promise<StatsIncreaseRequest[]>;
|
|
84
|
+
type AccountInfoUnparsedRow = {
|
|
85
|
+
name?: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
metadata?: string;
|
|
88
|
+
supply?: bigint | string;
|
|
89
|
+
defaultBasePermission?: string | bigint | BaseSet;
|
|
90
|
+
defaultExternalPermission?: string | bigint | ExternalSet;
|
|
91
|
+
};
|
|
92
|
+
export declare abstract class LedgerStorageBase {
|
|
93
|
+
#private;
|
|
94
|
+
protected config: LedgerConfig | null;
|
|
95
|
+
constructor();
|
|
96
|
+
protected abstract adjustDefer(transaction: any, input: VoteStaple): Promise<void>;
|
|
97
|
+
abstract getBlockHeight(transaction: any, blockHash: BlockHash, account: GenericAccount): Promise<{
|
|
98
|
+
blockHeight: string | null;
|
|
99
|
+
} | null>;
|
|
100
|
+
abstract getHeadBlocks(transaction: any, accounts: GenericAccount[], from: LedgerSelector): Promise<{
|
|
101
|
+
[account: string]: Block | null;
|
|
102
|
+
}>;
|
|
103
|
+
abstract getVotesFromMultiplePrevious(transaction: any, prevBlocks: BlockHash[], from: LedgerSelector, issuer?: Account): Promise<{
|
|
104
|
+
[hash: string]: Vote[] | null;
|
|
105
|
+
}>;
|
|
106
|
+
preAdjust(input: VoteStaple, mayDefer?: boolean, transaction?: any): Promise<{
|
|
107
|
+
[hash: string]: bigint;
|
|
108
|
+
}>;
|
|
109
|
+
_formatAccountInfoFromRow(account: GenericAccount, row?: AccountInfoUnparsedRow | undefined): AccountInfo;
|
|
110
|
+
_validateAccountInfoKeys(account: GenericAccount, info: Partial<AccountInfo>): void;
|
|
111
|
+
getHeadBlock(transaction: any, account: GenericAccount, from: LedgerSelector): Promise<Block | null>;
|
|
112
|
+
getVotesFromPrevious(transaction: any, prevBlock: BlockHash, from: LedgerSelector, issuer?: Account): Promise<Vote[] | null>;
|
|
113
|
+
}
|
|
114
|
+
export declare function assertLedgerStorage(value: string): LedgerStorage;
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { VoteStaple, Vote } from '../vote';
|
|
2
|
+
import { Block, BlockHash } from '../block';
|
|
3
|
+
import type { VoteBlockHash, VoteBlockHashMap } from '../vote';
|
|
4
|
+
import type { GenericAccount, IdentifierAddress, TokenAddress } from '../account';
|
|
5
|
+
import Account from '../account';
|
|
6
|
+
import type { Ledger, LedgerConfig, LedgerStorageAPI, LedgerSelector, PaginatedVotes, GetVotesAfterOptions } from '../ledger';
|
|
7
|
+
import type { AccountInfo, ACLRow, GetAllBalancesResponse, LedgerStatistics } from './types';
|
|
8
|
+
import { LedgerStorageBase } from './common';
|
|
9
|
+
import type { ComputedEffectOfBlocks } from './effects';
|
|
10
|
+
declare const dynamoDBTableNames: readonly ["votes", "voteUIDs", "permissions", "accountInfo", "accountOwners", "blocks", "balances", "weight", "heapBlocks", "heapStorage", "chain", "delegation", "serial", "kv"];
|
|
11
|
+
declare const optionalDynamoDbTables: readonly ["kv"];
|
|
12
|
+
type TableName = typeof dynamoDBTableNames[number];
|
|
13
|
+
type OptionalTableName = typeof optionalDynamoDbTables[number];
|
|
14
|
+
type DynamoDbTables = {
|
|
15
|
+
[K in TableName]: string;
|
|
16
|
+
};
|
|
17
|
+
type DynamoDbTablesWithOptional = Omit<DynamoDbTables, OptionalTableName> & Partial<Pick<DynamoDbTables, OptionalTableName>>;
|
|
18
|
+
export interface DynamoDBConfig {
|
|
19
|
+
tables: DynamoDbTablesWithOptional;
|
|
20
|
+
transactionSize?: number;
|
|
21
|
+
batchUpdateSize?: number;
|
|
22
|
+
}
|
|
23
|
+
declare class DynamoDBTransaction {
|
|
24
|
+
#private;
|
|
25
|
+
readonly moment: Date;
|
|
26
|
+
constructor(config: DynamoDBConfig, ledger: Ledger, log: LedgerConfig['log'], dbDynamoDB: DBDynamoDB);
|
|
27
|
+
commit(): Promise<void>;
|
|
28
|
+
abort(): Promise<void>;
|
|
29
|
+
delegatedWeight(rep?: Account): Promise<bigint>;
|
|
30
|
+
getBalance(account: GenericAccount, token: TokenAddress): Promise<bigint>;
|
|
31
|
+
getAllBalances(account: GenericAccount): Promise<GetAllBalancesResponse>;
|
|
32
|
+
adjustDefer(input: VoteStaple): Promise<void>;
|
|
33
|
+
adjust(input: VoteStaple, changes: ComputedEffectOfBlocks, mayDefer?: boolean): Promise<BlockHash[]>;
|
|
34
|
+
addPendingVote(blocksAndVotes: VoteStaple): Promise<void>;
|
|
35
|
+
getBlock(block: BlockHash, from: LedgerSelector): Promise<Block | null>;
|
|
36
|
+
getBlockHeight(blockHash: BlockHash, account: GenericAccount): Promise<{
|
|
37
|
+
blockHeight: string | null;
|
|
38
|
+
} | null>;
|
|
39
|
+
getVotes(block: BlockHash, from: LedgerSelector, issuer?: Account, transactionAlreadyVerifiedActiveByCaller?: boolean): Promise<Vote[] | null>;
|
|
40
|
+
getVoteStaple(stapleBlockHashes: VoteBlockHash[], from?: LedgerSelector): Promise<VoteBlockHashMap<VoteStaple | null>>;
|
|
41
|
+
getHistory(account: GenericAccount, start: VoteBlockHash | null, limit: number): Promise<VoteBlockHash[]>;
|
|
42
|
+
getVotesFromMultiplePrevious(prevBlocks: BlockHash[], from: LedgerSelector, issuer?: Account): Promise<{
|
|
43
|
+
[hash: string]: Vote[] | null;
|
|
44
|
+
}>;
|
|
45
|
+
getBlockHashFromPrevious(prevBlock: BlockHash, from: LedgerSelector): Promise<BlockHash | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Find a block whose "previous" is the value "prevBlock" -- that is,
|
|
48
|
+
* blocks that succeed this block in a chain
|
|
49
|
+
*/
|
|
50
|
+
getBlockFromPrevious(prevBlock: BlockHash, from: LedgerSelector, transactionAlreadyVerifiedActiveByCaller?: boolean): Promise<Block | null>;
|
|
51
|
+
getHeadBlocks(accounts: GenericAccount[], from: LedgerSelector): Promise<{
|
|
52
|
+
[publicKey: string]: Block | null;
|
|
53
|
+
}>;
|
|
54
|
+
getAccountRep(userAccount: Account | string): Promise<Account | null>;
|
|
55
|
+
getAccountInfo(account: GenericAccount | string): Promise<AccountInfo>;
|
|
56
|
+
listOwners(identifier: IdentifierAddress): Promise<Account[]>;
|
|
57
|
+
listACLsByEntity(entity: GenericAccount): Promise<ACLRow[]>;
|
|
58
|
+
listACLsByPrincipal(principal: GenericAccount, entityList?: GenericAccount[]): Promise<ACLRow[]>;
|
|
59
|
+
getVotesAfter(moment: Date, startKey?: string, options?: GetVotesAfterOptions): Promise<PaginatedVotes>;
|
|
60
|
+
gc(): Promise<true>;
|
|
61
|
+
}
|
|
62
|
+
export declare class DBDynamoDB extends LedgerStorageBase implements LedgerStorageAPI {
|
|
63
|
+
#private;
|
|
64
|
+
static Testing: {
|
|
65
|
+
deleteTables: (config: DynamoDBConfig) => Promise<void>;
|
|
66
|
+
createTables: (config: DynamoDBConfig) => Promise<void>;
|
|
67
|
+
};
|
|
68
|
+
init(config: LedgerConfig, ledger: Ledger): void;
|
|
69
|
+
beginTransaction(): Promise<DynamoDBTransaction>;
|
|
70
|
+
commitTransaction(transaction: DynamoDBTransaction): Promise<void>;
|
|
71
|
+
abortTransaction(transaction: DynamoDBTransaction): Promise<void>;
|
|
72
|
+
evaluateError(error: any): Promise<any>;
|
|
73
|
+
delegatedWeight(transaction: DynamoDBTransaction, rep?: Account): Promise<bigint>;
|
|
74
|
+
getBalance(transaction: DynamoDBTransaction, account: GenericAccount, token: TokenAddress): Promise<bigint>;
|
|
75
|
+
getAllBalances(transaction: DynamoDBTransaction, account: GenericAccount): Promise<GetAllBalancesResponse>;
|
|
76
|
+
protected adjustDefer(transaction: DynamoDBTransaction, input: VoteStaple): Promise<void>;
|
|
77
|
+
adjust(transaction: DynamoDBTransaction, input: VoteStaple, changes: ComputedEffectOfBlocks, mayDefer?: boolean): Promise<BlockHash[]>;
|
|
78
|
+
addPendingVote(transaction: DynamoDBTransaction, blocksAndVote: VoteStaple): Promise<void>;
|
|
79
|
+
getBlock(transaction: DynamoDBTransaction, block: BlockHash, from: LedgerSelector): Promise<Block | null>;
|
|
80
|
+
getBlockHeight(transaction: DynamoDBTransaction, blockHash: BlockHash, account: GenericAccount): Promise<{
|
|
81
|
+
blockHeight: string | null;
|
|
82
|
+
} | null>;
|
|
83
|
+
getVotes(transaction: DynamoDBTransaction, block: BlockHash, from: LedgerSelector): Promise<Vote[] | null>;
|
|
84
|
+
getVoteStaples(transaction: DynamoDBTransaction, stapleBlockHashes: VoteBlockHash[], from?: LedgerSelector): Promise<VoteBlockHashMap<VoteStaple | null>>;
|
|
85
|
+
getHistory(transaction: DynamoDBTransaction, account: GenericAccount, start: VoteBlockHash | null, limit?: number): Promise<VoteBlockHash[]>;
|
|
86
|
+
getVotesFromMultiplePrevious(transaction: DynamoDBTransaction, prevBlocks: BlockHash[], from: LedgerSelector, issuer?: Account): Promise<{
|
|
87
|
+
[hash: string]: Vote[] | null;
|
|
88
|
+
}>;
|
|
89
|
+
getBlockFromPrevious(transaction: DynamoDBTransaction, block: BlockHash, from: LedgerSelector): Promise<Block | null>;
|
|
90
|
+
getHeadBlocks(transaction: DynamoDBTransaction, accounts: GenericAccount[], from: LedgerSelector): Promise<{
|
|
91
|
+
[publicKey: string]: Block | null;
|
|
92
|
+
}>;
|
|
93
|
+
getAccountRep(transaction: DynamoDBTransaction, account: Account | string): Promise<Account | null>;
|
|
94
|
+
getAccountInfo(transaction: DynamoDBTransaction, account: GenericAccount | string): Promise<AccountInfo>;
|
|
95
|
+
listOwners(transaction: DynamoDBTransaction, identifier: IdentifierAddress): Promise<Account[]>;
|
|
96
|
+
listACLsByPrincipal(transaction: DynamoDBTransaction, principal: GenericAccount, entityList?: GenericAccount[]): Promise<ACLRow[]>;
|
|
97
|
+
listACLsByEntity(transaction: DynamoDBTransaction, entity: GenericAccount): Promise<ACLRow[]>;
|
|
98
|
+
getVotesAfter(transaction: DynamoDBTransaction, moment: Date, startKey?: string): Promise<PaginatedVotes>;
|
|
99
|
+
getNextSerialNumber(): Promise<bigint>;
|
|
100
|
+
gc(transaction: DynamoDBTransaction): Promise<true>;
|
|
101
|
+
stats(): Promise<LedgerStatistics>;
|
|
102
|
+
}
|
|
103
|
+
export default DBDynamoDB;
|
|
104
|
+
type DynamoDBAttrTypes = 'S' | 'N' | 'B';
|
|
105
|
+
type DynamoDBKey = {
|
|
106
|
+
type: DynamoDBAttrTypes;
|
|
107
|
+
name: string;
|
|
108
|
+
};
|
|
109
|
+
type DynamoDBKeys = {
|
|
110
|
+
hashKey: DynamoDBKey;
|
|
111
|
+
rangeKey?: DynamoDBKey;
|
|
112
|
+
gsi?: (Omit<DynamoDBKeys, 'gsi' | 'lsi'> & {
|
|
113
|
+
name: string;
|
|
114
|
+
})[];
|
|
115
|
+
lsi?: (Required<Omit<DynamoDBKeys, 'gsi' | 'lsi' | 'hashKey'>> & {
|
|
116
|
+
name: string;
|
|
117
|
+
})[];
|
|
118
|
+
};
|
|
119
|
+
type DynamoDBSchema = {
|
|
120
|
+
[name: string]: DynamoDBKeys;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Testing routines
|
|
124
|
+
*/
|
|
125
|
+
export declare const Testing: {
|
|
126
|
+
deleteTables(config: DynamoDBConfig): Promise<void>;
|
|
127
|
+
getSchema(names: DynamoDBConfig["tables"]): DynamoDBSchema;
|
|
128
|
+
createTables(config: DynamoDBConfig): Promise<void>;
|
|
129
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { VoteStaple, Vote } from '../vote';
|
|
2
|
+
import { Block, BlockHash } from '../block';
|
|
3
|
+
import type { VoteBlockHash, VoteBlockHashMap } from '../vote';
|
|
4
|
+
import type { GenericAccount, IdentifierAddress, TokenAddress } from '../account';
|
|
5
|
+
import Account, { AccountKeyAlgorithm } from '../account';
|
|
6
|
+
import type { Ledger, LedgerConfig, LedgerStorageAPI, LedgerSelector, PaginatedVotes, GetVotesAfterOptions } from '../ledger';
|
|
7
|
+
import type { AccountInfo, ACLRow, GetAllBalancesResponse, LedgerStatistics } from './types';
|
|
8
|
+
import { LedgerStorageBase } from './common';
|
|
9
|
+
import type { PoolClient as PostgresPoolClient } from 'pg';
|
|
10
|
+
import { Pool as PostgresPool } from 'pg';
|
|
11
|
+
import type { ComputedEffectOfBlocks } from './effects';
|
|
12
|
+
import LedgerRequestCache from './cache';
|
|
13
|
+
interface PostgresTransaction {
|
|
14
|
+
client: PostgresPoolClient;
|
|
15
|
+
moment: Date;
|
|
16
|
+
cache: LedgerRequestCache;
|
|
17
|
+
}
|
|
18
|
+
interface PostgresSelectOptions {
|
|
19
|
+
forUpdate?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export type PostgresConfig = NonNullable<ConstructorParameters<typeof PostgresPool>[0]>;
|
|
22
|
+
export declare class DBPostgres extends LedgerStorageBase implements LedgerStorageAPI {
|
|
23
|
+
#private;
|
|
24
|
+
constructor();
|
|
25
|
+
init(config: LedgerConfig, ledger: Ledger): void;
|
|
26
|
+
destroy(): Promise<void>;
|
|
27
|
+
beginTransaction(): Promise<PostgresTransaction>;
|
|
28
|
+
commitTransaction(transaction: PostgresTransaction): Promise<void>;
|
|
29
|
+
abortTransaction(transaction: PostgresTransaction): Promise<void>;
|
|
30
|
+
cache(transaction: PostgresTransaction): LedgerRequestCache;
|
|
31
|
+
evaluateError(error: any): Promise<any>;
|
|
32
|
+
delegatedWeight(transaction: PostgresTransaction, rep?: Account, options?: PostgresSelectOptions): Promise<bigint>;
|
|
33
|
+
getBalance(transaction: PostgresTransaction, account: GenericAccount, token: TokenAddress, options?: PostgresSelectOptions): Promise<bigint>;
|
|
34
|
+
getAllBalances(transaction: PostgresTransaction, account: GenericAccount): Promise<GetAllBalancesResponse>;
|
|
35
|
+
addPendingVote(transaction: PostgresTransaction, votesAndBlocks: VoteStaple): Promise<void>;
|
|
36
|
+
getAccountRep(transaction: PostgresTransaction, userAccount: Account | string): Promise<Account | null>;
|
|
37
|
+
/**
|
|
38
|
+
* If an adjustment cannot be made right now, defer it for follow-up
|
|
39
|
+
*/
|
|
40
|
+
protected adjustDefer(transaction: PostgresTransaction, input: VoteStaple): Promise<void>;
|
|
41
|
+
listOwners(transaction: PostgresTransaction, entity: IdentifierAddress): Promise<Account<AccountKeyAlgorithm.TOKEN>[]>;
|
|
42
|
+
listACLsByEntity(transaction: PostgresTransaction, entity: GenericAccount): Promise<ACLRow[]>;
|
|
43
|
+
listACLsByPrincipal(transaction: PostgresTransaction, principal: GenericAccount, entityList?: GenericAccount[]): Promise<ACLRow[]>;
|
|
44
|
+
getAccountInfo(transaction: PostgresTransaction, account: GenericAccount | string): Promise<AccountInfo>;
|
|
45
|
+
adjust(transaction: PostgresTransaction, input: VoteStaple, changes: ComputedEffectOfBlocks, mayDefer?: boolean): Promise<BlockHash[]>;
|
|
46
|
+
getBlock(transaction: PostgresTransaction, block: BlockHash, from: LedgerSelector): Promise<Block | null>;
|
|
47
|
+
getBlockHeight(transaction: PostgresTransaction, blockHash: BlockHash, account: GenericAccount): Promise<{
|
|
48
|
+
blockHeight: string | null;
|
|
49
|
+
} | null>;
|
|
50
|
+
getVotes(transaction: PostgresTransaction, block: BlockHash, from: LedgerSelector, issuer?: GenericAccount): Promise<Vote[] | null>;
|
|
51
|
+
getVoteStaples(transaction: PostgresTransaction, stapleBlockHashes: VoteBlockHash[], from?: LedgerSelector): Promise<VoteBlockHashMap<VoteStaple | null>>;
|
|
52
|
+
getHistory(transaction: PostgresTransaction, account: GenericAccount, start: VoteBlockHash | null, limit?: number): Promise<VoteBlockHash[]>;
|
|
53
|
+
getBlockFromPrevious(transaction: PostgresTransaction, prevBlock: BlockHash, from: LedgerSelector): Promise<Block | null>;
|
|
54
|
+
getVotesFromMultiplePrevious(transaction: PostgresTransaction, prevBlocks: BlockHash[], from: LedgerSelector, issuer?: Account): Promise<{
|
|
55
|
+
[hash: string]: Vote[] | null;
|
|
56
|
+
}>;
|
|
57
|
+
getHeadBlocks(transaction: PostgresTransaction, accounts: GenericAccount[], from: LedgerSelector): Promise<{
|
|
58
|
+
[publicKey: string]: Block | null;
|
|
59
|
+
}>;
|
|
60
|
+
getVoteStaplesFromBlockHash(transaction: PostgresTransaction, blocks: BlockHash[], onLedger: LedgerSelector): Promise<VoteStaple[]>;
|
|
61
|
+
getVotesAfter(transaction: PostgresTransaction, moment: Date, startKey?: string, options?: GetVotesAfterOptions): Promise<PaginatedVotes>;
|
|
62
|
+
gc(transaction: PostgresTransaction): Promise<true>;
|
|
63
|
+
getNextSerialNumber(): Promise<bigint>;
|
|
64
|
+
stats(): Promise<LedgerStatistics>;
|
|
65
|
+
}
|
|
66
|
+
export declare const Testing: {
|
|
67
|
+
createDatabase: (config: PostgresConfig) => Promise<void>;
|
|
68
|
+
deleteDatabase: (config: PostgresConfig) => Promise<void>;
|
|
69
|
+
};
|
|
70
|
+
export default DBPostgres;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Vote, VoteStaple } from '../vote';
|
|
2
|
+
import type { Block } from '../block';
|
|
3
|
+
import { BlockHash } from '../block';
|
|
4
|
+
import type { VoteBlockHash, VoteBlockHashMap } from '../vote';
|
|
5
|
+
import type { GenericAccount, IdentifierAddress, TokenAddress } from '../account';
|
|
6
|
+
import Account from '../account';
|
|
7
|
+
import type { Ledger, LedgerConfig, LedgerStorageAPI, LedgerSelector, PaginatedVotes, GetVotesAfterOptions } from '../ledger';
|
|
8
|
+
import type { AccountInfo, ACLRow, GetAllBalancesResponse, LedgerStatistics } from './types';
|
|
9
|
+
import type { KVStorageProviderAPI } from '../kv';
|
|
10
|
+
import { LedgerStorageBase } from './common';
|
|
11
|
+
import Stats from '../stats';
|
|
12
|
+
import { KeetaNetLedgerError } from '../error/ledger';
|
|
13
|
+
import type { Database as GoogleSpannerDatabase } from '@google-cloud/spanner';
|
|
14
|
+
import type { TableColumn, FilteredResponseRow, IndexName, TableName, QueryRow as HelperQueryRow, QueryRows } from './db_spanner_helper';
|
|
15
|
+
import type { ComputedEffectOfBlocks } from './effects';
|
|
16
|
+
type QueryRow<T extends TableName> = HelperQueryRow<T> | QueryRows<T>;
|
|
17
|
+
type ReadOptions = {
|
|
18
|
+
limit?: number;
|
|
19
|
+
skipLocalRead?: boolean;
|
|
20
|
+
all?: boolean;
|
|
21
|
+
range?: boolean;
|
|
22
|
+
};
|
|
23
|
+
interface ReadQueryWithOptions<T extends TableName> extends ReadOptions {
|
|
24
|
+
query: QueryRow<T>;
|
|
25
|
+
}
|
|
26
|
+
type ReadRequest<T extends TableName> = QueryRow<T> | ReadQueryWithOptions<T>;
|
|
27
|
+
type SpannerReadResponse<T extends TableName, C extends TableColumn<T>[]> = {
|
|
28
|
+
count: number;
|
|
29
|
+
rows: FilteredResponseRow<T, C>[];
|
|
30
|
+
moment: Date;
|
|
31
|
+
};
|
|
32
|
+
interface SpannerTransactionOptions {
|
|
33
|
+
readOnly?: boolean;
|
|
34
|
+
strongRead?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare class SpannerTransaction {
|
|
37
|
+
#private;
|
|
38
|
+
readonly moment: Date;
|
|
39
|
+
readonly options: SpannerTransactionOptions;
|
|
40
|
+
readonly statsChanges: Parameters<Stats['incr']>[];
|
|
41
|
+
constructor(database: GoogleSpannerDatabase, options?: SpannerTransactionOptions);
|
|
42
|
+
evaluateError(error: any): KeetaNetLedgerError;
|
|
43
|
+
beginTransaction(strongRead?: boolean): Promise<void>;
|
|
44
|
+
endTransaction(mode: 'COMMIT' | 'ROLLBACK'): Promise<void>;
|
|
45
|
+
insert<T extends TableName, R extends QueryRow<T>>(table: T, query: R): void;
|
|
46
|
+
upsert<T extends TableName, R extends QueryRow<T>>(table: T, query: R): void;
|
|
47
|
+
delete<T extends TableName, R extends QueryRow<T>>(table: T, query: R): void;
|
|
48
|
+
read<T extends TableName, I extends IndexName | undefined, C extends TableColumn<T>[], X extends ReadRequest<T>>(table: T, index: I, columns: C, request: X): Promise<SpannerReadResponse<T, C>>;
|
|
49
|
+
addStatsChange(...changes: Parameters<Stats['incr']>[]): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Ledger Configuration for Google Spanner
|
|
53
|
+
*/
|
|
54
|
+
export type SpannerConfig = {
|
|
55
|
+
projectId: string;
|
|
56
|
+
instanceId: string;
|
|
57
|
+
databaseId: string;
|
|
58
|
+
kv: KVStorageProviderAPI;
|
|
59
|
+
strongRead?: boolean;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Ledger Storage for Google Spanner
|
|
63
|
+
*/
|
|
64
|
+
export declare class DBSpanner extends LedgerStorageBase implements LedgerStorageAPI {
|
|
65
|
+
#private;
|
|
66
|
+
constructor();
|
|
67
|
+
init(config: LedgerConfig, ledger: Ledger): void;
|
|
68
|
+
destroy(): Promise<void>;
|
|
69
|
+
beginTransaction(readOnly?: boolean): Promise<SpannerTransaction>;
|
|
70
|
+
commitTransaction(transaction: SpannerTransaction): Promise<void>;
|
|
71
|
+
abortTransaction(transaction: SpannerTransaction): Promise<void>;
|
|
72
|
+
evaluateError(error: any): Promise<KeetaNetLedgerError>;
|
|
73
|
+
delegatedWeight(transaction: SpannerTransaction, rep?: Account): Promise<bigint>;
|
|
74
|
+
getBalance(transaction: SpannerTransaction, account: GenericAccount | string, token: TokenAddress | string): Promise<bigint>;
|
|
75
|
+
getAllBalances(transaction: SpannerTransaction, account: GenericAccount): Promise<GetAllBalancesResponse>;
|
|
76
|
+
addPendingVote(transaction: SpannerTransaction, votesAndBlocks: VoteStaple): Promise<void>;
|
|
77
|
+
getAccountRep(transaction: SpannerTransaction, userAccount: Account | string): Promise<Account | null>;
|
|
78
|
+
/**
|
|
79
|
+
* If an adjustment cannot be made right now, defer it for follow-up
|
|
80
|
+
*/
|
|
81
|
+
protected adjustDefer(transaction: SpannerTransaction, input: VoteStaple): Promise<void>;
|
|
82
|
+
adjust(transaction: SpannerTransaction, input: VoteStaple, changes: ComputedEffectOfBlocks, mayDefer?: boolean): Promise<BlockHash[]>;
|
|
83
|
+
getBlock(transaction: SpannerTransaction, blockHash: BlockHash, from: LedgerSelector): Promise<Block | null>;
|
|
84
|
+
getBlockHeight(transaction: SpannerTransaction, blockHash: BlockHash, account: GenericAccount): Promise<{
|
|
85
|
+
blockHeight: string | null;
|
|
86
|
+
} | null>;
|
|
87
|
+
getVotes(transaction: SpannerTransaction, blockHash: BlockHash, from: LedgerSelector): Promise<Vote[] | null>;
|
|
88
|
+
getVoteStaples(transaction: SpannerTransaction, stapleBlockHashes: VoteBlockHash[], from?: LedgerSelector): Promise<VoteBlockHashMap<VoteStaple | null>>;
|
|
89
|
+
getHistory(transaction: SpannerTransaction, account: GenericAccount, start: VoteBlockHash | null, limit?: number): Promise<VoteBlockHash[]>;
|
|
90
|
+
getBlockFromPrevious(transaction: SpannerTransaction, prevBlock: BlockHash, from: LedgerSelector): Promise<Block | null>;
|
|
91
|
+
getVotesFromMultiplePrevious(transaction: SpannerTransaction, prevBlocks: BlockHash[], from: LedgerSelector, issuer?: Account): Promise<{
|
|
92
|
+
[hash: string]: Vote[] | null;
|
|
93
|
+
}>;
|
|
94
|
+
getHeadBlocks(transaction: SpannerTransaction, accounts: GenericAccount[], from: LedgerSelector): Promise<{
|
|
95
|
+
[publicKey: string]: Block | null;
|
|
96
|
+
}>;
|
|
97
|
+
getAccountInfo(transaction: SpannerTransaction, account: GenericAccount | string): Promise<AccountInfo>;
|
|
98
|
+
listOwners(transaction: SpannerTransaction, entity: IdentifierAddress): Promise<GenericAccount[]>;
|
|
99
|
+
listACLsByEntity(transaction: SpannerTransaction, entity: GenericAccount): Promise<ACLRow[]>;
|
|
100
|
+
listACLsByPrincipal(transaction: SpannerTransaction, principal: GenericAccount, entityList?: GenericAccount[]): Promise<ACLRow[]>;
|
|
101
|
+
getVotesAfter(transaction: SpannerTransaction, moment: Date, _ignore_startKey?: string, _ignored_options?: GetVotesAfterOptions): Promise<PaginatedVotes>;
|
|
102
|
+
gc(transaction: SpannerTransaction): Promise<true>;
|
|
103
|
+
getNextSerialNumber(): Promise<bigint>;
|
|
104
|
+
stats(): Promise<LedgerStatistics>;
|
|
105
|
+
}
|
|
106
|
+
export declare const Testing: {
|
|
107
|
+
/**
|
|
108
|
+
* Create a new Spanner Instance (if first call), new Spanner Database, and all the tables needed to use this ledger
|
|
109
|
+
*/
|
|
110
|
+
createDatabase: (config: SpannerConfig, createInstance: boolean) => Promise<GoogleSpannerDatabase>;
|
|
111
|
+
/**
|
|
112
|
+
* Clean-up a Spanner Database (and if deleteInstance) delete the Spanner Instance
|
|
113
|
+
*/
|
|
114
|
+
deleteDatabase: (config: SpannerConfig, deleteInstance: boolean, database: GoogleSpannerDatabase) => Promise<void>;
|
|
115
|
+
};
|
|
116
|
+
export default DBSpanner;
|