@keetanetwork/keetanet-client 0.10.2 → 0.10.3
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/api/node.d.ts +2 -0
- package/client/client_common_tests.d.ts +5 -4
- package/client/index-browser.d.ts +25 -9
- package/client/index-browser.js +576 -423
- package/client/index.d.ts +25 -9
- package/client/index.js +120 -22
- package/lib/ledger/common.d.ts +2 -0
- package/lib/ledger/db_dynamodb.d.ts +2 -2
- package/lib/ledger/db_postgres.d.ts +1 -1
- package/lib/ledger/db_spanner.d.ts +5 -4
- package/lib/ledger/db_spanner_helper.d.ts +0 -1
- package/lib/ledger/db_sqlite.d.ts +1 -1
- package/lib/ledger/index.d.ts +6 -5
- package/package.json +1 -1
- package/version.d.ts +1 -1
- package/._version.d.ts +0 -0
package/client/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import KeetaNetError from '../lib/error';
|
|
|
11
11
|
import type { AccountInfo, GetAllBalancesResponse, ACLRow, LedgerStatistics } from '../lib/ledger/types';
|
|
12
12
|
import type { LedgerSelector, LedgerStorage } from '../lib/ledger';
|
|
13
13
|
import type { AcceptedPermissionTypes } from '../lib/permissions';
|
|
14
|
+
import { type BlockOperations } from '../lib/block/operations';
|
|
14
15
|
type Vote = InstanceType<typeof KeetaNet['Vote']>;
|
|
15
16
|
type VoteStaple = InstanceType<typeof KeetaNet['Vote']['Staple']>;
|
|
16
17
|
type VoteBlocksHash = Vote['blocksHash'];
|
|
@@ -50,6 +51,9 @@ interface UserClientConfig extends UserClientOptions {
|
|
|
50
51
|
network: bigint;
|
|
51
52
|
networkAlias: Config.Networks;
|
|
52
53
|
}
|
|
54
|
+
type ClientRepresentative = Config.Representative & {
|
|
55
|
+
weight?: bigint;
|
|
56
|
+
};
|
|
53
57
|
export declare class Client {
|
|
54
58
|
#private;
|
|
55
59
|
static readonly Builder: typeof UserClientBuilder;
|
|
@@ -64,13 +68,13 @@ export declare class Client {
|
|
|
64
68
|
};
|
|
65
69
|
static fromNetwork(network: Config.Networks): Client;
|
|
66
70
|
static isInstance: (obj: any, strict?: boolean) => obj is Client;
|
|
67
|
-
constructor(reps:
|
|
71
|
+
constructor(reps: ClientRepresentative[]);
|
|
68
72
|
destroy(): Promise<void>;
|
|
69
73
|
makeBuilder(options: BuilderOptions): UserClientBuilder;
|
|
70
74
|
computeBuilderBlocks(network: bigint, builder: UserClientBuilder): Promise<import("./builder").ComputeBlocksResponse>;
|
|
71
75
|
transmit(blocks: Block[]): ReturnType<Client['transmitStaple']>;
|
|
72
76
|
transmit(blocks: UserClientBuilder, network: bigint): ReturnType<Client['transmitStaple']>;
|
|
73
|
-
transmitStaple(votesAndBlocks: VoteStaple, reps?:
|
|
77
|
+
transmitStaple(votesAndBlocks: VoteStaple, reps?: ClientRepresentative[]): Promise<any>;
|
|
74
78
|
getNodeStats(): Promise<{
|
|
75
79
|
ledger: LedgerStatistics;
|
|
76
80
|
switch: P2PSwitchStatistics;
|
|
@@ -87,7 +91,7 @@ export declare class Client {
|
|
|
87
91
|
getAllBalances(account: GenericAccount | string): Promise<GetAllBalancesResponse>;
|
|
88
92
|
getHeadBlock(account: GenericAccount | string): Promise<Block | null>;
|
|
89
93
|
getBlock(blockhash: BlockHash | string): Promise<Block | null>;
|
|
90
|
-
getBlock(blockhash: BlockHash | string, side?: LedgerSelector, rep?:
|
|
94
|
+
getBlock(blockhash: BlockHash | string, side?: LedgerSelector, rep?: ClientRepresentative | 'ANY'): Promise<Block | null>;
|
|
91
95
|
getVoteStaple(blockhash: BlockHash | string): Promise<VoteStaple | null>;
|
|
92
96
|
getVoteStaple(blockhash: BlockHash | string, side?: LedgerStorage): Promise<VoteStaple | null>;
|
|
93
97
|
getChain(account: GenericAccount | string, options?: {
|
|
@@ -103,17 +107,17 @@ export declare class Client {
|
|
|
103
107
|
getSingleRepresentativeInfo(rep?: Account | string): Promise<RepresentativeInfo>;
|
|
104
108
|
getPeers(): Promise<GetPeersAPIResponse>;
|
|
105
109
|
getAllRepresentativeInfo(): Promise<RepresentativeInfo[]>;
|
|
106
|
-
get representatives():
|
|
110
|
+
get representatives(): ClientRepresentative[];
|
|
107
111
|
/**
|
|
108
112
|
* Get the network status of all representatives
|
|
109
113
|
*
|
|
110
114
|
* @param timeout Maximum time to wait for a response from a representative in milliseconds
|
|
111
115
|
*/
|
|
112
116
|
getNetworkStatus(timeout?: number): Promise<({
|
|
113
|
-
rep:
|
|
117
|
+
rep: ClientRepresentative;
|
|
114
118
|
online: false;
|
|
115
119
|
} | {
|
|
116
|
-
rep:
|
|
120
|
+
rep: ClientRepresentative;
|
|
117
121
|
online: true;
|
|
118
122
|
ledger: {
|
|
119
123
|
moment: string;
|
|
@@ -131,7 +135,7 @@ export declare class Client {
|
|
|
131
135
|
outgoingMessagesPeerFailureUngreeted: number;
|
|
132
136
|
};
|
|
133
137
|
})[]>;
|
|
134
|
-
updateReps(): Promise<void>;
|
|
138
|
+
updateReps(addNewReps?: boolean): Promise<void>;
|
|
135
139
|
getVoteStaplesAfter(moment: Date, limit?: number, bloomFilter?: string): Promise<VoteStaple[]>;
|
|
136
140
|
getPendingBlock(account: GenericAccount): Promise<Block | null>;
|
|
137
141
|
/**
|
|
@@ -141,12 +145,12 @@ export declare class Client {
|
|
|
141
145
|
* @param publish Publish the recovered staple to the network (default is true)
|
|
142
146
|
*/
|
|
143
147
|
recoverAccount(account: GenericAccount, publish?: boolean): Promise<VoteStaple | null>;
|
|
144
|
-
getLedgerChecksum(rep?:
|
|
148
|
+
getLedgerChecksum(rep?: ClientRepresentative | 'ANY'): Promise<{
|
|
145
149
|
moment: string;
|
|
146
150
|
momentRange: number;
|
|
147
151
|
checksum: string;
|
|
148
152
|
}>;
|
|
149
|
-
getVersion(rep?:
|
|
153
|
+
getVersion(rep?: ClientRepresentative | 'ANY'): Promise<{
|
|
150
154
|
node: string;
|
|
151
155
|
}>;
|
|
152
156
|
}
|
|
@@ -163,6 +167,12 @@ export declare class UserClient {
|
|
|
163
167
|
static getConfigFromNetwork(network: Config.Networks, options?: UserClientOptions): Omit<UserClientConfig, 'signer'>;
|
|
164
168
|
static fromNetwork(network: Config.Networks, signer: Account | null, options?: UserClientOptions): UserClient;
|
|
165
169
|
static isInstance: (obj: any, strict?: boolean) => obj is UserClient;
|
|
170
|
+
static filterStapleOperations(voteStaples: VoteStaple[], account: GenericAccount): {
|
|
171
|
+
[stapleHash: string]: {
|
|
172
|
+
block: Block;
|
|
173
|
+
filteredOperations: BlockOperations[];
|
|
174
|
+
}[];
|
|
175
|
+
};
|
|
166
176
|
constructor(config: UserClientConfig);
|
|
167
177
|
initializeChain(initOpts: {
|
|
168
178
|
addSupplyAmount: bigint;
|
|
@@ -186,6 +196,12 @@ export declare class UserClient {
|
|
|
186
196
|
voteStaple: import("../lib/vote").VoteStaple;
|
|
187
197
|
effects: import("../lib/ledger/effects").ComputedEffectOfBlocks;
|
|
188
198
|
}[]>;
|
|
199
|
+
filterStapleOperations(voteStaples: VoteStaple[], options?: UserClientOptions): {
|
|
200
|
+
[stapleHash: string]: {
|
|
201
|
+
block: Block;
|
|
202
|
+
filteredOperations: BlockOperations[];
|
|
203
|
+
}[];
|
|
204
|
+
};
|
|
189
205
|
state(options?: UserClientOptions): ReturnType<Client['getAccountInfo']>;
|
|
190
206
|
listACLsByPrincipal(entity?: (GenericAccount | string)[], options?: UserClientOptions): ReturnType<Client['listACLsByPrincipal']>;
|
|
191
207
|
listACLsByEntity(options?: UserClientOptions): ReturnType<Client['listACLsByEntity']>;
|
package/client/index.js
CHANGED
|
@@ -79838,6 +79838,17 @@ class client_LedgerStorageBase {
|
|
|
79838
79838
|
}
|
|
79839
79839
|
return (null);
|
|
79840
79840
|
}
|
|
79841
|
+
async gc(transaction) {
|
|
79842
|
+
let lastGCResult = false;
|
|
79843
|
+
for (const startTime = Date.now(); Date.now() - startTime < 280000;) {
|
|
79844
|
+
const gcResult = await this.gcBatch(transaction);
|
|
79845
|
+
lastGCResult = gcResult;
|
|
79846
|
+
if (!gcResult) {
|
|
79847
|
+
return (false);
|
|
79848
|
+
}
|
|
79849
|
+
}
|
|
79850
|
+
return (lastGCResult);
|
|
79851
|
+
}
|
|
79841
79852
|
}
|
|
79842
79853
|
client_LedgerStorageBase_instances = new WeakSet(), client_LedgerStorageBase_log = function _LedgerStorageBase_log(...args) {
|
|
79843
79854
|
if (this.config !== null) {
|
|
@@ -80586,7 +80597,7 @@ class client_LedgerAtomicInterface {
|
|
|
80586
80597
|
async vote(blocks, otherVotes) {
|
|
80587
80598
|
client_ledger_classPrivateFieldGet(this, client_LedgerAtomicInterface_instances, "m", client_LedgerAtomicInterface_assertTransaction).call(this);
|
|
80588
80599
|
if (client_ledger_classPrivateFieldGet(this, client_LedgerAtomicInterface_ledger, "f").ledgerWriteMode !== 'read-write') {
|
|
80589
|
-
throw (new Error(
|
|
80600
|
+
throw (new Error(`May not issue votes in read-only mode, in ${client_ledger_classPrivateFieldGet(this, client_LedgerAtomicInterface_ledger, "f").ledgerWriteMode} mode`));
|
|
80590
80601
|
}
|
|
80591
80602
|
if (!client_ledger_classPrivateFieldGet(this, client_LedgerAtomicInterface_privateKey, "f")) {
|
|
80592
80603
|
throw (new Error('Cannot vote on block, no private key loaded'));
|
|
@@ -80798,6 +80809,7 @@ class client_LedgerAtomicInterface {
|
|
|
80798
80809
|
}
|
|
80799
80810
|
throw (new Error('Cannot add blocks to a read-only ledger (except for bootstrapping)'));
|
|
80800
80811
|
case 'read-write':
|
|
80812
|
+
case 'no-voting':
|
|
80801
80813
|
break;
|
|
80802
80814
|
default:
|
|
80803
80815
|
throw (new Error(`internal error: invalid ledger write mode: ${client_ledger_classPrivateFieldGet(this, client_LedgerAtomicInterface_ledger, "f").ledgerWriteMode}`));
|
|
@@ -81356,6 +81368,7 @@ class client_Ledger {
|
|
|
81356
81368
|
* @returns The return value from "code"
|
|
81357
81369
|
*/
|
|
81358
81370
|
async run(identifier, code, readOnly) {
|
|
81371
|
+
const txnIdentifier = identifier;
|
|
81359
81372
|
if (this.node !== undefined) {
|
|
81360
81373
|
identifier = `${identifier}-${this.node.timing.counter()}`;
|
|
81361
81374
|
this.node.timing.startTime(identifier);
|
|
@@ -81365,7 +81378,7 @@ class client_Ledger {
|
|
|
81365
81378
|
try {
|
|
81366
81379
|
let runError;
|
|
81367
81380
|
let threw = false;
|
|
81368
|
-
const transaction = await this.beginTransaction(readOnly);
|
|
81381
|
+
const transaction = await this.beginTransaction(txnIdentifier, readOnly);
|
|
81369
81382
|
try {
|
|
81370
81383
|
retval = await code(transaction);
|
|
81371
81384
|
}
|
|
@@ -81414,8 +81427,8 @@ class client_Ledger {
|
|
|
81414
81427
|
async runReadOnly(identifier, code) {
|
|
81415
81428
|
return (await this.run(identifier, code, true));
|
|
81416
81429
|
}
|
|
81417
|
-
async beginTransaction(readOnly) {
|
|
81418
|
-
const transaction = await client_ledger_classPrivateFieldGet(this, client_Ledger_storage, "f").beginTransaction(readOnly);
|
|
81430
|
+
async beginTransaction(identifier, readOnly) {
|
|
81431
|
+
const transaction = await client_ledger_classPrivateFieldGet(this, client_Ledger_storage, "f").beginTransaction(identifier, readOnly);
|
|
81419
81432
|
return (new client_LedgerAtomicInterface(transaction, client_ledger_classPrivateFieldGet(this, client_Ledger_storage, "f"), client_ledger_classPrivateFieldGet(this, client_Ledger_config, "f"), this));
|
|
81420
81433
|
}
|
|
81421
81434
|
async vote(...args) {
|
|
@@ -82747,7 +82760,7 @@ class client_P2PSwitch {
|
|
|
82747
82760
|
for (const conn of client_p2p_classPrivateFieldGet(this, client_P2PSwitch_connectedPeersLocal, "f")) {
|
|
82748
82761
|
closePromises.push(conn.close());
|
|
82749
82762
|
}
|
|
82750
|
-
await Promise.
|
|
82763
|
+
await Promise.allSettled(closePromises);
|
|
82751
82764
|
await this.wait();
|
|
82752
82765
|
}
|
|
82753
82766
|
/**
|
|
@@ -82758,7 +82771,7 @@ class client_P2PSwitch {
|
|
|
82758
82771
|
if (promises.length === 0) {
|
|
82759
82772
|
return;
|
|
82760
82773
|
}
|
|
82761
|
-
await Promise.
|
|
82774
|
+
await Promise.allSettled(promises);
|
|
82762
82775
|
}
|
|
82763
82776
|
async stats() {
|
|
82764
82777
|
return ({
|
|
@@ -83592,7 +83605,7 @@ async function _P2PSwitch_relayActiveState(conn) {
|
|
|
83592
83605
|
* Perform peer exchange
|
|
83593
83606
|
*/
|
|
83594
83607
|
promises.push(client_p2p_classPrivateFieldGet(this, client_P2PSwitch_instances, "m", client_P2PSwitch_relayActiveState).call(this, from));
|
|
83595
|
-
await Promise.
|
|
83608
|
+
await Promise.allSettled(promises);
|
|
83596
83609
|
return (true);
|
|
83597
83610
|
}, client_P2PSwitch_updateConnTimeout = function _P2PSwitch_updateConnTimeout(conn) {
|
|
83598
83611
|
if (conn.peer) {
|
|
@@ -87571,7 +87584,8 @@ var client_client_classPrivateFieldGet = (undefined && undefined.__classPrivateF
|
|
|
87571
87584
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
87572
87585
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
87573
87586
|
};
|
|
87574
|
-
var client_Client_instances, client_Client_reps, client_Client_agent, client_Client_intervals, client_Client_updateRepsPromise, client_Client_apiRaw, client_Client_api, client_Client_requestVotes, client_Client_getVotes, client_Client_getBuilderRenderOptions, client_Client_urlSeparatedAccounts, client_Client_formatAllBalances, client_Client_parseResponsePermissions, client_Client_formatAccountInfo, client_Client_parseAccountInfo, client_Client_parsePermissionEntries, client_Client_parseRepInfo, client_UserClient_instances, client_UserClient_config, client_UserClient_client, client_UserClient_listeners, client_UserClient_intervals, client_UserClient_previousAccountChangeData, client_UserClient_socketPromise, client_UserClient_filteredWebSocket, client_UserClient_changePromise, client_UserClient_reconnectAttempts, client_UserClient_RECONNECT_TIMEOUT, client_UserClient_getAccount, client_UserClient_publishAidURL_get, client_UserClient_publishWithPublishAid, client_UserClient_reconnectWebSocket, client_UserClient_setupFilteredWebSocket, client_UserClient_emit, client_UserClient_emitAccountInfoIfChanged;
|
|
87587
|
+
var client_Client_instances, client_Client_reps, client_Client_weightOrderedReps, client_Client_agent, client_Client_intervals, client_Client_updateRepsPromise, client_Client_apiRaw, client_Client_api, client_Client_requestVotes, client_Client_getVotes, client_Client_getBuilderRenderOptions, client_Client_urlSeparatedAccounts, client_Client_formatAllBalances, client_Client_parseResponsePermissions, client_Client_formatAccountInfo, client_Client_parseAccountInfo, client_Client_parsePermissionEntries, client_Client_parseRepInfo, client_UserClient_instances, client_UserClient_config, client_UserClient_client, client_UserClient_listeners, client_UserClient_intervals, client_UserClient_previousAccountChangeData, client_UserClient_socketPromise, client_UserClient_filteredWebSocket, client_UserClient_changePromise, client_UserClient_reconnectAttempts, client_UserClient_RECONNECT_TIMEOUT, client_UserClient_getAccount, client_UserClient_publishAidURL_get, client_UserClient_publishWithPublishAid, client_UserClient_reconnectWebSocket, client_UserClient_setupFilteredWebSocket, client_UserClient_emit, client_UserClient_emitAccountInfoIfChanged;
|
|
87588
|
+
|
|
87575
87589
|
|
|
87576
87590
|
|
|
87577
87591
|
|
|
@@ -87628,6 +87642,7 @@ class client_Client {
|
|
|
87628
87642
|
client_Client_instances.add(this);
|
|
87629
87643
|
this.logger = client_Client.DefaultLogger;
|
|
87630
87644
|
client_Client_reps.set(this, void 0);
|
|
87645
|
+
client_Client_weightOrderedReps.set(this, []);
|
|
87631
87646
|
client_Client_agent.set(this, void 0);
|
|
87632
87647
|
client_Client_intervals.set(this, void 0);
|
|
87633
87648
|
client_Client_updateRepsPromise.set(this, void 0);
|
|
@@ -87656,13 +87671,12 @@ class client_Client {
|
|
|
87656
87671
|
client_client_classPrivateFieldSet(this, client_Client_updateRepsPromise, undefined, "f");
|
|
87657
87672
|
client_client_classPrivateFieldSet(this, client_Client_intervals, {}, "f");
|
|
87658
87673
|
// Update Reps immediately and then every 5 minutes
|
|
87659
|
-
|
|
87660
|
-
|
|
87661
|
-
|
|
87662
|
-
|
|
87663
|
-
|
|
87664
|
-
|
|
87665
|
-
// }
|
|
87674
|
+
client_client_classPrivateFieldSet(this, client_Client_updateRepsPromise, this.updateReps(), "f");
|
|
87675
|
+
if (client_client_classPrivateFieldGet(this, client_Client_intervals, "f").updateReps === undefined) {
|
|
87676
|
+
client_client_classPrivateFieldGet(this, client_Client_intervals, "f").updateReps = setInterval(() => {
|
|
87677
|
+
client_client_classPrivateFieldSet(this, client_Client_updateRepsPromise, this.updateReps(), "f");
|
|
87678
|
+
}, 5 * 60 * 1000);
|
|
87679
|
+
}
|
|
87666
87680
|
}
|
|
87667
87681
|
async destroy() {
|
|
87668
87682
|
if (client_client_classPrivateFieldGet(this, client_Client_updateRepsPromise, "f") !== undefined) {
|
|
@@ -87695,7 +87709,12 @@ class client_Client {
|
|
|
87695
87709
|
const votesAndBlocks = src_client_lib.Vote.Staple.fromVotesAndBlocks(permVotes, blocks);
|
|
87696
87710
|
return (await this.transmitStaple(votesAndBlocks));
|
|
87697
87711
|
}
|
|
87698
|
-
async transmitStaple(votesAndBlocks, reps
|
|
87712
|
+
async transmitStaple(votesAndBlocks, reps) {
|
|
87713
|
+
// If reps are not defined then publish to the highest weight rep
|
|
87714
|
+
if (!reps || reps.length === 0) {
|
|
87715
|
+
await client_client_classPrivateFieldGet(this, client_Client_updateRepsPromise, "f");
|
|
87716
|
+
reps = [client_client_classPrivateFieldGet(this, client_Client_weightOrderedReps, "f")[0]];
|
|
87717
|
+
}
|
|
87699
87718
|
const publishPromises = [];
|
|
87700
87719
|
for (const rep of reps) {
|
|
87701
87720
|
publishPromises.push((async () => {
|
|
@@ -88056,8 +88075,9 @@ class client_Client {
|
|
|
88056
88075
|
const retval = await Promise.all(repsInfo);
|
|
88057
88076
|
return (retval);
|
|
88058
88077
|
}
|
|
88059
|
-
async updateReps() {
|
|
88078
|
+
async updateReps(addNewReps = false) {
|
|
88060
88079
|
const repsResponse = await client_client_classPrivateFieldGet(this, client_Client_instances, "m", client_Client_api).call(this, 'ANY', 'GET /node/ledger/representatives');
|
|
88080
|
+
const weightedReps = [];
|
|
88061
88081
|
for (const rep of repsResponse.representatives) {
|
|
88062
88082
|
const repAccount = src_client_lib.Account.fromPublicKeyString(rep.representative).assertAccount();
|
|
88063
88083
|
const repIndex = client_client_classPrivateFieldGet(this, client_Client_reps, "f").findIndex(repInfo => {
|
|
@@ -88065,15 +88085,31 @@ class client_Client {
|
|
|
88065
88085
|
});
|
|
88066
88086
|
const repInfo = {
|
|
88067
88087
|
key: repAccount,
|
|
88088
|
+
weight: BigInt(rep.weight),
|
|
88068
88089
|
endpoints: rep.endpoints
|
|
88069
88090
|
};
|
|
88070
88091
|
if (repIndex === -1) {
|
|
88071
|
-
|
|
88092
|
+
if (addNewReps) {
|
|
88093
|
+
// TODO - make addNewReps default true when rep tracking is stable
|
|
88094
|
+
// If we are adding new reps, also add them to weight sorted reps
|
|
88095
|
+
client_client_classPrivateFieldGet(this, client_Client_reps, "f").push(repInfo);
|
|
88096
|
+
weightedReps.push(repInfo);
|
|
88097
|
+
}
|
|
88072
88098
|
}
|
|
88073
88099
|
else {
|
|
88074
|
-
|
|
88100
|
+
weightedReps.push(repInfo);
|
|
88075
88101
|
}
|
|
88076
88102
|
}
|
|
88103
|
+
weightedReps.sort((rep1, rep2) => {
|
|
88104
|
+
if (rep2.weight > rep1.weight) {
|
|
88105
|
+
return (1);
|
|
88106
|
+
}
|
|
88107
|
+
if (rep2.weight < rep1.weight) {
|
|
88108
|
+
return (-1);
|
|
88109
|
+
}
|
|
88110
|
+
return (0);
|
|
88111
|
+
});
|
|
88112
|
+
client_client_classPrivateFieldSet(this, client_Client_weightOrderedReps, weightedReps, "f");
|
|
88077
88113
|
}
|
|
88078
88114
|
async getVoteStaplesAfter(moment, limit, bloomFilter) {
|
|
88079
88115
|
const query = {
|
|
@@ -88274,18 +88310,22 @@ class client_Client {
|
|
|
88274
88310
|
return (version);
|
|
88275
88311
|
}
|
|
88276
88312
|
}
|
|
88277
|
-
client_Client_reps = new WeakMap(), client_Client_agent = new WeakMap(), client_Client_intervals = new WeakMap(), client_Client_updateRepsPromise = new WeakMap(), client_Client_instances = new WeakSet(), client_Client_apiRaw =
|
|
88313
|
+
client_Client_reps = new WeakMap(), client_Client_weightOrderedReps = new WeakMap(), client_Client_agent = new WeakMap(), client_Client_intervals = new WeakMap(), client_Client_updateRepsPromise = new WeakMap(), client_Client_instances = new WeakSet(), client_Client_apiRaw =
|
|
88278
88314
|
/**
|
|
88279
88315
|
* API dispatching routine
|
|
88280
88316
|
*/
|
|
88281
88317
|
async function _Client_apiRaw(rep, api, method, options = {}) {
|
|
88318
|
+
var _a;
|
|
88282
88319
|
const startTime = Date.now();
|
|
88283
88320
|
options = Object.assign({ maxRetries: 32 }, options);
|
|
88284
88321
|
let delay = 1;
|
|
88285
88322
|
let result, resultThrow;
|
|
88286
88323
|
for (let retry = 0; retry < Number.MAX_SAFE_INTEGER; retry++) {
|
|
88287
88324
|
if (rep === 'ANY') {
|
|
88288
|
-
|
|
88325
|
+
if (client_client_classPrivateFieldGet(this, client_Client_weightOrderedReps, "f").length === 0) {
|
|
88326
|
+
await client_client_classPrivateFieldGet(this, client_Client_updateRepsPromise, "f");
|
|
88327
|
+
}
|
|
88328
|
+
rep = (_a = client_client_classPrivateFieldGet(this, client_Client_weightOrderedReps, "f")[0]) !== null && _a !== void 0 ? _a : client_client_classPrivateFieldGet(this, client_Client_reps, "f")[0];
|
|
88289
88329
|
}
|
|
88290
88330
|
const repURL = rep.endpoints.api;
|
|
88291
88331
|
let fetchURL = `${repURL}${api}`;
|
|
@@ -88357,7 +88397,7 @@ async function _Client_apiRaw(rep, api, method, options = {}) {
|
|
|
88357
88397
|
try {
|
|
88358
88398
|
errorMessage = `${errorMessage}: ${await response.text()}`;
|
|
88359
88399
|
}
|
|
88360
|
-
catch (
|
|
88400
|
+
catch (_b) {
|
|
88361
88401
|
/* Ignore any errors, we will just have an incomplete error message */
|
|
88362
88402
|
}
|
|
88363
88403
|
throw (new Error(errorMessage));
|
|
@@ -88656,6 +88696,60 @@ class client_UserClient {
|
|
|
88656
88696
|
const config = Object.assign(Object.assign({}, client_UserClient.getConfigFromNetwork(network, options)), { signer: signer });
|
|
88657
88697
|
return (new client_UserClient(config));
|
|
88658
88698
|
}
|
|
88699
|
+
static filterStapleOperations(voteStaples, account) {
|
|
88700
|
+
const filteredOperations = {};
|
|
88701
|
+
// For each staple
|
|
88702
|
+
for (const staple of voteStaples) {
|
|
88703
|
+
const stapleHash = staple.blocksHash.toString();
|
|
88704
|
+
filteredOperations[stapleHash] = [];
|
|
88705
|
+
// For each block
|
|
88706
|
+
for (const block of staple.blocks) {
|
|
88707
|
+
const blockOperations = [];
|
|
88708
|
+
// If block is produced by the account being filtered, included all operations
|
|
88709
|
+
if (block.account.comparePublicKey(account)) {
|
|
88710
|
+
blockOperations.push(...block.operations);
|
|
88711
|
+
}
|
|
88712
|
+
else {
|
|
88713
|
+
// If the block is for another account then filter the operations for the given account
|
|
88714
|
+
for (const ops in block.operations) {
|
|
88715
|
+
const operation = block.operations[ops];
|
|
88716
|
+
const principals = [];
|
|
88717
|
+
switch (operation.type) {
|
|
88718
|
+
case client_OperationType.SEND:
|
|
88719
|
+
case client_OperationType.SET_REP:
|
|
88720
|
+
principals.push(operation.to);
|
|
88721
|
+
break;
|
|
88722
|
+
case client_OperationType.MODIFY_PERMISSIONS:
|
|
88723
|
+
principals.push(operation.principal);
|
|
88724
|
+
break;
|
|
88725
|
+
case client_OperationType.CREATE_IDENTIFIER:
|
|
88726
|
+
principals.push(operation.identifier);
|
|
88727
|
+
break;
|
|
88728
|
+
case client_OperationType.TOKEN_ADMIN_MODIFY_BALANCE:
|
|
88729
|
+
case client_OperationType.SET_INFO:
|
|
88730
|
+
case client_OperationType.TOKEN_ADMIN_SUPPLY:
|
|
88731
|
+
// Do nothing for these, they don't reference an account directly
|
|
88732
|
+
break;
|
|
88733
|
+
case client_OperationType.RECEIVE:
|
|
88734
|
+
principals.push(operation.from);
|
|
88735
|
+
if (operation.forward) {
|
|
88736
|
+
principals.push(operation.forward);
|
|
88737
|
+
}
|
|
88738
|
+
break;
|
|
88739
|
+
}
|
|
88740
|
+
if (principals.length > 0 && principals.some(principal => principal.comparePublicKey(account))) {
|
|
88741
|
+
blockOperations.push(operation);
|
|
88742
|
+
}
|
|
88743
|
+
}
|
|
88744
|
+
}
|
|
88745
|
+
filteredOperations[stapleHash].push({
|
|
88746
|
+
block,
|
|
88747
|
+
filteredOperations: blockOperations
|
|
88748
|
+
});
|
|
88749
|
+
}
|
|
88750
|
+
}
|
|
88751
|
+
return (filteredOperations);
|
|
88752
|
+
}
|
|
88659
88753
|
constructor(config) {
|
|
88660
88754
|
client_UserClient_instances.add(this);
|
|
88661
88755
|
client_UserClient_config.set(this, void 0);
|
|
@@ -88806,6 +88900,10 @@ class client_UserClient {
|
|
|
88806
88900
|
});
|
|
88807
88901
|
return (retval);
|
|
88808
88902
|
}
|
|
88903
|
+
filterStapleOperations(voteStaples, options = {}) {
|
|
88904
|
+
const account = client_client_classPrivateFieldGet(this, client_UserClient_instances, "m", client_UserClient_getAccount).call(this, options);
|
|
88905
|
+
return (client_UserClient.filterStapleOperations(voteStaples, account));
|
|
88906
|
+
}
|
|
88809
88907
|
state(options = {}) {
|
|
88810
88908
|
return (client_client_classPrivateFieldGet(this, client_UserClient_client, "f").getAccountInfo(client_client_classPrivateFieldGet(this, client_UserClient_instances, "m", client_UserClient_getAccount).call(this, options)));
|
|
88811
88909
|
}
|
package/lib/ledger/common.d.ts
CHANGED
|
@@ -110,6 +110,8 @@ export declare abstract class LedgerStorageBase {
|
|
|
110
110
|
_validateAccountInfoKeys(account: GenericAccount, info: Partial<AccountInfo>): void;
|
|
111
111
|
getHeadBlock(transaction: any, account: GenericAccount, from: LedgerSelector): Promise<Block | null>;
|
|
112
112
|
getVotesFromPrevious(transaction: any, prevBlock: BlockHash, from: LedgerSelector, issuer?: Account): Promise<Vote[] | null>;
|
|
113
|
+
protected abstract gcBatch(transaction: any): Promise<boolean>;
|
|
114
|
+
gc(transaction: any): Promise<boolean>;
|
|
113
115
|
}
|
|
114
116
|
export declare function assertLedgerStorage(value: string): LedgerStorage;
|
|
115
117
|
export {};
|
|
@@ -57,7 +57,7 @@ declare class DynamoDBTransaction {
|
|
|
57
57
|
listACLsByEntity(entity: GenericAccount): Promise<ACLRow[]>;
|
|
58
58
|
listACLsByPrincipal(principal: GenericAccount, entityList?: GenericAccount[]): Promise<ACLRow[]>;
|
|
59
59
|
getVotesAfter(moment: Date, startKey?: string, options?: GetVotesAfterOptions): Promise<PaginatedVotes>;
|
|
60
|
-
|
|
60
|
+
gcBatch(): Promise<boolean>;
|
|
61
61
|
}
|
|
62
62
|
export declare class DBDynamoDB extends LedgerStorageBase implements LedgerStorageAPI {
|
|
63
63
|
#private;
|
|
@@ -97,7 +97,7 @@ export declare class DBDynamoDB extends LedgerStorageBase implements LedgerStora
|
|
|
97
97
|
listACLsByEntity(transaction: DynamoDBTransaction, entity: GenericAccount): Promise<ACLRow[]>;
|
|
98
98
|
getVotesAfter(transaction: DynamoDBTransaction, moment: Date, startKey?: string): Promise<PaginatedVotes>;
|
|
99
99
|
getNextSerialNumber(): Promise<bigint>;
|
|
100
|
-
|
|
100
|
+
gcBatch(transaction: DynamoDBTransaction): Promise<boolean>;
|
|
101
101
|
stats(): Promise<LedgerStatistics>;
|
|
102
102
|
}
|
|
103
103
|
export default DBDynamoDB;
|
|
@@ -59,7 +59,7 @@ export declare class DBPostgres extends LedgerStorageBase implements LedgerStora
|
|
|
59
59
|
}>;
|
|
60
60
|
getVoteStaplesFromBlockHash(transaction: PostgresTransaction, blocks: BlockHash[], onLedger: LedgerSelector): Promise<VoteStaple[]>;
|
|
61
61
|
getVotesAfter(transaction: PostgresTransaction, moment: Date, startKey?: string, options?: GetVotesAfterOptions): Promise<PaginatedVotes>;
|
|
62
|
-
|
|
62
|
+
protected gcBatch(transaction: PostgresTransaction): Promise<boolean>;
|
|
63
63
|
getNextSerialNumber(): Promise<bigint>;
|
|
64
64
|
stats(): Promise<LedgerStatistics>;
|
|
65
65
|
}
|
|
@@ -40,7 +40,7 @@ export declare class SpannerTransaction {
|
|
|
40
40
|
readonly statsChanges: Parameters<Stats['incr']>[];
|
|
41
41
|
constructor(database: GoogleSpannerDatabase, options?: SpannerTransactionOptions);
|
|
42
42
|
evaluateError(error: any): KeetaNetLedgerError;
|
|
43
|
-
beginTransaction(strongRead?: boolean): Promise<void>;
|
|
43
|
+
beginTransaction(identifier: string, strongRead?: boolean): Promise<void>;
|
|
44
44
|
endTransaction(mode: 'COMMIT' | 'ROLLBACK'): Promise<void>;
|
|
45
45
|
insert<T extends TableName, R extends QueryRow<T>>(table: T, query: R): void;
|
|
46
46
|
upsert<T extends TableName, R extends QueryRow<T>>(table: T, query: R): void;
|
|
@@ -66,7 +66,7 @@ export declare class DBSpanner extends LedgerStorageBase implements LedgerStorag
|
|
|
66
66
|
constructor();
|
|
67
67
|
init(config: LedgerConfig, ledger: Ledger): void;
|
|
68
68
|
destroy(): Promise<void>;
|
|
69
|
-
beginTransaction(readOnly?: boolean): Promise<SpannerTransaction>;
|
|
69
|
+
beginTransaction(identifier: string, readOnly?: boolean): Promise<SpannerTransaction>;
|
|
70
70
|
commitTransaction(transaction: SpannerTransaction): Promise<void>;
|
|
71
71
|
abortTransaction(transaction: SpannerTransaction): Promise<void>;
|
|
72
72
|
evaluateError(error: any): Promise<KeetaNetLedgerError>;
|
|
@@ -98,8 +98,9 @@ export declare class DBSpanner extends LedgerStorageBase implements LedgerStorag
|
|
|
98
98
|
listOwners(transaction: SpannerTransaction, entity: IdentifierAddress): Promise<GenericAccount[]>;
|
|
99
99
|
listACLsByEntity(transaction: SpannerTransaction, entity: GenericAccount): Promise<ACLRow[]>;
|
|
100
100
|
listACLsByPrincipal(transaction: SpannerTransaction, principal: GenericAccount, entityList?: GenericAccount[]): Promise<ACLRow[]>;
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
getVoteStaplesFromBlockHash(transaction: SpannerTransaction, blocks: BlockHash[], from: LedgerSelector): Promise<VoteStaple[]>;
|
|
102
|
+
getVotesAfter(transaction: SpannerTransaction, moment: Date, startKey?: string, options?: GetVotesAfterOptions): Promise<PaginatedVotes>;
|
|
103
|
+
protected gcBatch(transaction: SpannerTransaction): Promise<boolean>;
|
|
103
104
|
getNextSerialNumber(): Promise<bigint>;
|
|
104
105
|
stats(): Promise<LedgerStatistics>;
|
|
105
106
|
}
|
|
@@ -57,7 +57,7 @@ export declare class DBSqlite extends LedgerStorageBase implements LedgerStorage
|
|
|
57
57
|
[publicKey: string]: Block | null;
|
|
58
58
|
}>;
|
|
59
59
|
getVotesAfter(transaction: DBSqliteTransaction, moment: Date, startKey?: string, options?: GetVotesAfterOptions): Promise<PaginatedVotes>;
|
|
60
|
-
|
|
60
|
+
protected gcBatch(transaction: DBSqliteTransaction): Promise<boolean>;
|
|
61
61
|
getNextSerialNumber(transaction: DBSqliteTransaction): Promise<bigint>;
|
|
62
62
|
stats(): Promise<LedgerStatistics>;
|
|
63
63
|
}
|
package/lib/ledger/index.d.ts
CHANGED
|
@@ -44,8 +44,9 @@ export interface LedgerConfig {
|
|
|
44
44
|
* bootstrap-only: Bootstrapping can still occur
|
|
45
45
|
* read-only: No bootstrapping, no voting
|
|
46
46
|
* read-write: Normal mode (read-write enabled)
|
|
47
|
+
* no-voting: Normal mode (read-write enabled), but no voting
|
|
47
48
|
*/
|
|
48
|
-
ledgerWriteMode?: 'bootstrap-only' | 'read-only' | 'read-write';
|
|
49
|
+
ledgerWriteMode?: 'bootstrap-only' | 'read-only' | 'read-write' | 'no-voting';
|
|
49
50
|
/**
|
|
50
51
|
* Logging method
|
|
51
52
|
*/
|
|
@@ -98,7 +99,7 @@ export interface LedgerStorageAPI {
|
|
|
98
99
|
/**
|
|
99
100
|
* Begin a transaction
|
|
100
101
|
*/
|
|
101
|
-
beginTransaction: (readOnly?: boolean) => Promise<any>;
|
|
102
|
+
beginTransaction: (identifier: string, readOnly?: boolean) => Promise<any>;
|
|
102
103
|
/**
|
|
103
104
|
* Commit an active transaction
|
|
104
105
|
*/
|
|
@@ -216,7 +217,7 @@ export interface LedgerStorageAPI {
|
|
|
216
217
|
/**
|
|
217
218
|
* Perform Garbage Collection
|
|
218
219
|
*/
|
|
219
|
-
gc: (transaction: any) => Promise<
|
|
220
|
+
gc: (transaction: any) => Promise<boolean>;
|
|
220
221
|
/**
|
|
221
222
|
* Get the next serial number for a representative
|
|
222
223
|
*/
|
|
@@ -258,7 +259,7 @@ declare class LedgerAtomicInterface {
|
|
|
258
259
|
getHistory(account: GenericAccount, start: VoteBlockHash | null, limit?: number): Promise<VoteStaple[]>;
|
|
259
260
|
getStaplesFromBlockHashes(hashes: BlockHash[]): Promise<VoteStaple[]>;
|
|
260
261
|
getVoteStaplesAfter(moment: Date, limit?: number, options?: GetVotesAfterOptions): Promise<VoteStaple[]>;
|
|
261
|
-
gc(): Promise<
|
|
262
|
+
gc(): Promise<boolean>;
|
|
262
263
|
_testingRunStorageFunction<T>(code: (storage: LedgerStorageAPI, transaction: any) => Promise<T>): Promise<T>;
|
|
263
264
|
}
|
|
264
265
|
/**
|
|
@@ -284,7 +285,7 @@ export declare class Ledger implements Omit<LedgerAtomicInterface, 'commit' | 'a
|
|
|
284
285
|
*/
|
|
285
286
|
run<T>(identifier: string, code: (transaction: LedgerAtomicInterface) => Promise<T>, readOnly?: boolean): Promise<T>;
|
|
286
287
|
runReadOnly<T>(identifier: string, code: (transaction: LedgerAtomicInterface) => Promise<T>): ReturnType<typeof code>;
|
|
287
|
-
beginTransaction(readOnly?: boolean): Promise<LedgerAtomicInterface>;
|
|
288
|
+
beginTransaction(identifier: string, readOnly?: boolean): Promise<LedgerAtomicInterface>;
|
|
288
289
|
vote(...args: Parameters<LedgerAtomicInterface['vote']>): ReturnType<LedgerAtomicInterface['vote']>;
|
|
289
290
|
add(...args: Parameters<LedgerAtomicInterface['add']>): ReturnType<LedgerAtomicInterface['add']>;
|
|
290
291
|
listACLsByPrincipal(...args: Parameters<LedgerAtomicInterface['listACLsByPrincipal']>): ReturnType<LedgerAtomicInterface['listACLsByPrincipal']>;
|
package/package.json
CHANGED
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "0.10.
|
|
1
|
+
export declare const version = "0.10.3";
|
|
2
2
|
export default version;
|
package/._version.d.ts
DELETED
|
Binary file
|