@atomiqlabs/chain-solana 13.5.13 → 13.5.14
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/LICENSE +201 -201
- package/README.md +73 -73
- package/dist/index.d.ts +81 -81
- package/dist/index.js +102 -102
- package/dist/node/index.d.ts +9 -9
- package/dist/node/index.js +13 -13
- package/dist/solana/SolanaChainType.d.ts +15 -15
- package/dist/solana/SolanaChainType.js +2 -2
- package/dist/solana/SolanaChains.d.ts +12 -12
- package/dist/solana/SolanaChains.js +45 -45
- package/dist/solana/SolanaInitializer.d.ts +94 -94
- package/dist/solana/SolanaInitializer.js +174 -174
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +222 -222
- package/dist/solana/btcrelay/SolanaBtcRelay.js +455 -455
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +84 -84
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +70 -70
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +92 -92
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +109 -109
- package/dist/solana/btcrelay/program/programIdl.json +671 -671
- package/dist/solana/chain/SolanaAction.d.ts +26 -26
- package/dist/solana/chain/SolanaAction.js +87 -87
- package/dist/solana/chain/SolanaChainInterface.d.ts +224 -224
- package/dist/solana/chain/SolanaChainInterface.js +275 -275
- package/dist/solana/chain/SolanaModule.d.ts +14 -14
- package/dist/solana/chain/SolanaModule.js +13 -13
- package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
- package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
- package/dist/solana/chain/modules/SolanaBlocks.d.ts +32 -32
- package/dist/solana/chain/modules/SolanaBlocks.js +78 -78
- package/dist/solana/chain/modules/SolanaEvents.d.ts +68 -68
- package/dist/solana/chain/modules/SolanaEvents.js +238 -238
- package/dist/solana/chain/modules/SolanaFees.d.ts +189 -189
- package/dist/solana/chain/modules/SolanaFees.js +434 -434
- package/dist/solana/chain/modules/SolanaSignatures.d.ts +24 -24
- package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
- package/dist/solana/chain/modules/SolanaSlots.d.ts +33 -33
- package/dist/solana/chain/modules/SolanaSlots.js +72 -72
- package/dist/solana/chain/modules/SolanaTokens.d.ts +123 -123
- package/dist/solana/chain/modules/SolanaTokens.js +242 -242
- package/dist/solana/chain/modules/SolanaTransactions.d.ts +149 -149
- package/dist/solana/chain/modules/SolanaTransactions.js +445 -445
- package/dist/solana/connection/ConnectionWithRetries.d.ts +35 -35
- package/dist/solana/connection/ConnectionWithRetries.js +86 -71
- package/dist/solana/events/SolanaChainEvents.d.ts +45 -45
- package/dist/solana/events/SolanaChainEvents.js +108 -108
- package/dist/solana/events/SolanaChainEventsBrowser.d.ts +205 -205
- package/dist/solana/events/SolanaChainEventsBrowser.js +404 -404
- package/dist/solana/program/SolanaProgramBase.d.ts +73 -73
- package/dist/solana/program/SolanaProgramBase.js +54 -54
- package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
- package/dist/solana/program/SolanaProgramModule.js +11 -11
- package/dist/solana/program/modules/SolanaProgramEvents.d.ts +53 -53
- package/dist/solana/program/modules/SolanaProgramEvents.js +117 -117
- package/dist/solana/swaps/SolanaSwapData.d.ts +333 -333
- package/dist/solana/swaps/SolanaSwapData.js +535 -535
- package/dist/solana/swaps/SolanaSwapModule.d.ts +11 -11
- package/dist/solana/swaps/SolanaSwapModule.js +12 -12
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +376 -376
- package/dist/solana/swaps/SolanaSwapProgram.js +769 -769
- package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
- package/dist/solana/swaps/SwapTypeEnum.js +43 -43
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +95 -95
- package/dist/solana/swaps/modules/SolanaDataAccount.js +232 -232
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +69 -69
- package/dist/solana/swaps/modules/SolanaLpVault.js +171 -171
- package/dist/solana/swaps/modules/SwapClaim.d.ts +126 -126
- package/dist/solana/swaps/modules/SwapClaim.js +294 -294
- package/dist/solana/swaps/modules/SwapInit.d.ts +213 -213
- package/dist/solana/swaps/modules/SwapInit.js +658 -658
- package/dist/solana/swaps/modules/SwapRefund.d.ts +87 -87
- package/dist/solana/swaps/modules/SwapRefund.js +293 -293
- package/dist/solana/swaps/programIdl.json +945 -945
- package/dist/solana/swaps/programTypes.d.ts +943 -943
- package/dist/solana/swaps/programTypes.js +945 -945
- package/dist/solana/swaps/v1/programIdl.json +945 -945
- package/dist/solana/swaps/v1/programTypes.d.ts +943 -943
- package/dist/solana/swaps/v1/programTypes.js +945 -945
- package/dist/solana/swaps/v2/programIdl.json +952 -952
- package/dist/solana/swaps/v2/programTypes.d.ts +950 -950
- package/dist/solana/swaps/v2/programTypes.js +952 -952
- package/dist/solana/wallet/SolanaKeypairWallet.d.ts +29 -29
- package/dist/solana/wallet/SolanaKeypairWallet.js +50 -50
- package/dist/solana/wallet/SolanaSigner.d.ts +30 -30
- package/dist/solana/wallet/SolanaSigner.js +30 -30
- package/dist/utils/Utils.d.ts +58 -58
- package/dist/utils/Utils.js +170 -170
- package/node/index.d.ts +1 -1
- package/node/index.js +3 -3
- package/package.json +46 -46
- package/src/index.ts +87 -87
- package/src/node/index.ts +9 -9
- package/src/solana/SolanaChainType.ts +32 -32
- package/src/solana/SolanaChains.ts +46 -46
- package/src/solana/SolanaInitializer.ts +278 -278
- package/src/solana/btcrelay/SolanaBtcRelay.ts +615 -615
- package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +116 -116
- package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +148 -148
- package/src/solana/btcrelay/program/programIdl.json +670 -670
- package/src/solana/chain/SolanaAction.ts +109 -109
- package/src/solana/chain/SolanaChainInterface.ts +404 -404
- package/src/solana/chain/SolanaModule.ts +20 -20
- package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
- package/src/solana/chain/modules/SolanaBlocks.ts +89 -89
- package/src/solana/chain/modules/SolanaEvents.ts +271 -271
- package/src/solana/chain/modules/SolanaFees.ts +522 -522
- package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
- package/src/solana/chain/modules/SolanaSlots.ts +85 -85
- package/src/solana/chain/modules/SolanaTokens.ts +300 -300
- package/src/solana/chain/modules/SolanaTransactions.ts +503 -503
- package/src/solana/connection/ConnectionWithRetries.ts +113 -96
- package/src/solana/events/SolanaChainEvents.ts +127 -127
- package/src/solana/events/SolanaChainEventsBrowser.ts +495 -495
- package/src/solana/program/SolanaProgramBase.ts +119 -119
- package/src/solana/program/SolanaProgramModule.ts +15 -15
- package/src/solana/program/modules/SolanaProgramEvents.ts +157 -157
- package/src/solana/swaps/SolanaSwapData.ts +735 -735
- package/src/solana/swaps/SolanaSwapModule.ts +19 -19
- package/src/solana/swaps/SolanaSwapProgram.ts +1074 -1074
- package/src/solana/swaps/SwapTypeEnum.ts +30 -30
- package/src/solana/swaps/modules/SolanaDataAccount.ts +302 -302
- package/src/solana/swaps/modules/SolanaLpVault.ts +208 -208
- package/src/solana/swaps/modules/SwapClaim.ts +387 -387
- package/src/solana/swaps/modules/SwapInit.ts +785 -785
- package/src/solana/swaps/modules/SwapRefund.ts +353 -353
- package/src/solana/swaps/v1/programIdl.json +944 -944
- package/src/solana/swaps/v1/programTypes.ts +1885 -1885
- package/src/solana/swaps/v2/programIdl.json +951 -951
- package/src/solana/swaps/v2/programTypes.ts +1899 -1899
- package/src/solana/wallet/SolanaKeypairWallet.ts +56 -56
- package/src/solana/wallet/SolanaSigner.ts +43 -43
- package/src/utils/Utils.ts +194 -194
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Commitment, Connection, ConnectionConfig } from "@solana/web3.js";
|
|
2
|
-
export type ConnectionWithRetriesConfig = ConnectionConfig & {
|
|
3
|
-
retryPolicy?: {
|
|
4
|
-
maxRetries?: number;
|
|
5
|
-
delay?: number;
|
|
6
|
-
exponential?: boolean;
|
|
7
|
-
};
|
|
8
|
-
requestTimeout?: number;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Solana connection with retry logic and request timeout handling for RPC calls.
|
|
12
|
-
*
|
|
13
|
-
* @category Providers
|
|
14
|
-
*/
|
|
15
|
-
export declare class ConnectionWithRetries extends Connection {
|
|
16
|
-
/**
|
|
17
|
-
* Retry policy used for RPC requests.
|
|
18
|
-
*/
|
|
19
|
-
readonly retryPolicy?: {
|
|
20
|
-
maxRetries?: number;
|
|
21
|
-
delay?: number;
|
|
22
|
-
exponential?: boolean;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Per-request timeout in milliseconds.
|
|
26
|
-
*/
|
|
27
|
-
readonly requestTimeout: number;
|
|
28
|
-
/**
|
|
29
|
-
* Constructs a retry-enabled Solana connection.
|
|
30
|
-
*
|
|
31
|
-
* @param endpoint RPC endpoint URL
|
|
32
|
-
* @param commitmentOrConfig Commitment level or full connection configuration
|
|
33
|
-
*/
|
|
34
|
-
constructor(endpoint: string, commitmentOrConfig?: Commitment | ConnectionWithRetriesConfig);
|
|
35
|
-
}
|
|
1
|
+
import { Commitment, Connection, ConnectionConfig } from "@solana/web3.js";
|
|
2
|
+
export type ConnectionWithRetriesConfig = ConnectionConfig & {
|
|
3
|
+
retryPolicy?: {
|
|
4
|
+
maxRetries?: number;
|
|
5
|
+
delay?: number;
|
|
6
|
+
exponential?: boolean;
|
|
7
|
+
};
|
|
8
|
+
requestTimeout?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Solana connection with retry logic and request timeout handling for RPC calls.
|
|
12
|
+
*
|
|
13
|
+
* @category Providers
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConnectionWithRetries extends Connection {
|
|
16
|
+
/**
|
|
17
|
+
* Retry policy used for RPC requests.
|
|
18
|
+
*/
|
|
19
|
+
readonly retryPolicy?: {
|
|
20
|
+
maxRetries?: number;
|
|
21
|
+
delay?: number;
|
|
22
|
+
exponential?: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Per-request timeout in milliseconds.
|
|
26
|
+
*/
|
|
27
|
+
readonly requestTimeout: number;
|
|
28
|
+
/**
|
|
29
|
+
* Constructs a retry-enabled Solana connection.
|
|
30
|
+
*
|
|
31
|
+
* @param endpoint RPC endpoint URL
|
|
32
|
+
* @param commitmentOrConfig Commitment level or full connection configuration
|
|
33
|
+
*/
|
|
34
|
+
constructor(endpoint: string, commitmentOrConfig?: Commitment | ConnectionWithRetriesConfig);
|
|
35
|
+
}
|
|
@@ -1,71 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConnectionWithRetries = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
const Utils_1 = require("../../utils/Utils");
|
|
6
|
-
/**
|
|
7
|
-
* Solana connection with retry logic and request timeout handling for RPC calls.
|
|
8
|
-
*
|
|
9
|
-
* @category Providers
|
|
10
|
-
*/
|
|
11
|
-
class ConnectionWithRetries extends web3_js_1.Connection {
|
|
12
|
-
/**
|
|
13
|
-
* Constructs a retry-enabled Solana connection.
|
|
14
|
-
*
|
|
15
|
-
* @param endpoint RPC endpoint URL
|
|
16
|
-
* @param commitmentOrConfig Commitment level or full connection configuration
|
|
17
|
-
*/
|
|
18
|
-
constructor(endpoint, commitmentOrConfig) {
|
|
19
|
-
let config;
|
|
20
|
-
if (typeof (commitmentOrConfig) === "string") {
|
|
21
|
-
config = { commitment: commitmentOrConfig };
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
config = commitmentOrConfig ?? {};
|
|
25
|
-
}
|
|
26
|
-
config.fetch = (input, init) => (0, Utils_1.tryWithRetries)(async () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionWithRetries = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const Utils_1 = require("../../utils/Utils");
|
|
6
|
+
/**
|
|
7
|
+
* Solana connection with retry logic and request timeout handling for RPC calls.
|
|
8
|
+
*
|
|
9
|
+
* @category Providers
|
|
10
|
+
*/
|
|
11
|
+
class ConnectionWithRetries extends web3_js_1.Connection {
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a retry-enabled Solana connection.
|
|
14
|
+
*
|
|
15
|
+
* @param endpoint RPC endpoint URL
|
|
16
|
+
* @param commitmentOrConfig Commitment level or full connection configuration
|
|
17
|
+
*/
|
|
18
|
+
constructor(endpoint, commitmentOrConfig) {
|
|
19
|
+
let config;
|
|
20
|
+
if (typeof (commitmentOrConfig) === "string") {
|
|
21
|
+
config = { commitment: commitmentOrConfig };
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
config = commitmentOrConfig ?? {};
|
|
25
|
+
}
|
|
26
|
+
config.fetch = (input, init) => (0, Utils_1.tryWithRetries)(async () => {
|
|
27
|
+
if (init?.signal?.aborted) {
|
|
28
|
+
throw init.signal.reason instanceof Error
|
|
29
|
+
? init.signal.reason
|
|
30
|
+
: new Error("Aborted");
|
|
31
|
+
}
|
|
32
|
+
const abortController = new AbortController();
|
|
33
|
+
const timeoutHandle = setTimeout(() => {
|
|
34
|
+
abortController.abort(new Error('Network request timed out'));
|
|
35
|
+
}, this.requestTimeout);
|
|
36
|
+
let originalSignal;
|
|
37
|
+
let originalSignalListener;
|
|
38
|
+
if (init?.signal != null) {
|
|
39
|
+
originalSignal = init.signal;
|
|
40
|
+
originalSignal.addEventListener('abort', originalSignalListener = () => {
|
|
41
|
+
clearTimeout(timeoutHandle);
|
|
42
|
+
abortController.abort(originalSignal?.reason instanceof Error
|
|
43
|
+
? originalSignal?.reason
|
|
44
|
+
: new Error("Aborted"));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const result = await fetch(input, {
|
|
49
|
+
...init,
|
|
50
|
+
signal: abortController.signal
|
|
51
|
+
});
|
|
52
|
+
if (Math.floor(result.status / 100) === 5) {
|
|
53
|
+
throw new Error(`Internal server error: ${result.status}`);
|
|
54
|
+
}
|
|
55
|
+
if (result.status === 429) {
|
|
56
|
+
throw new Error(`Too many requests (429)`);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const textResult = await result.text();
|
|
60
|
+
return new Response(textResult, {
|
|
61
|
+
status: result.status,
|
|
62
|
+
statusText: result.statusText,
|
|
63
|
+
headers: result.headers,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
console.error(`ConnectionWithRetries: fetch(): Failed to read response body: `, e);
|
|
68
|
+
throw new Error("Error reading response body");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
clearTimeout(timeoutHandle);
|
|
73
|
+
if (originalSignal != null && originalSignalListener != null)
|
|
74
|
+
originalSignal.removeEventListener("abort", originalSignalListener);
|
|
75
|
+
}
|
|
76
|
+
}, this.retryPolicy, (e) => !e?.message?.startsWith?.("Internal server error: ") &&
|
|
77
|
+
e?.message !== "Network request timed out" &&
|
|
78
|
+
e?.message !== "Too many requests (429)" &&
|
|
79
|
+
e?.message !== "Error reading response body", init?.signal ?? undefined);
|
|
80
|
+
config.disableRetryOnRateLimit = true;
|
|
81
|
+
super(endpoint, config);
|
|
82
|
+
this.retryPolicy = config?.retryPolicy;
|
|
83
|
+
this.requestTimeout = config?.requestTimeout ?? 15 * 1000;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.ConnectionWithRetries = ConnectionWithRetries;
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Connection } from "@solana/web3.js";
|
|
2
|
-
import { SolanaSwapProgram } from "../swaps/SolanaSwapProgram";
|
|
3
|
-
import { SolanaChainEventsBrowser } from "./SolanaChainEventsBrowser";
|
|
4
|
-
/**
|
|
5
|
-
* Event handler for backend Node.js systems with access to fs, uses HTTP polling in combination with WS to not miss
|
|
6
|
-
* any events
|
|
7
|
-
*/
|
|
8
|
-
export declare class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
9
|
-
private readonly directory;
|
|
10
|
-
private readonly logFetchInterval;
|
|
11
|
-
private stopped;
|
|
12
|
-
private timeout?;
|
|
13
|
-
constructor(directory: string, connection: Connection, contractVersions: SolanaSwapProgram | {
|
|
14
|
-
[version: string]: {
|
|
15
|
-
swapContract: SolanaSwapProgram;
|
|
16
|
-
};
|
|
17
|
-
}, logFetchInterval?: number);
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves last signature & slot from filesystem
|
|
20
|
-
*
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
private getLastSignature;
|
|
24
|
-
/**
|
|
25
|
-
* Saves last signature & slot to the filesystem
|
|
26
|
-
*
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
private saveLastSignature;
|
|
30
|
-
/**
|
|
31
|
-
* Polls for new events & processes them
|
|
32
|
-
*
|
|
33
|
-
* @private
|
|
34
|
-
*/
|
|
35
|
-
private checkEvents;
|
|
36
|
-
private setupHttpPolling;
|
|
37
|
-
/**
|
|
38
|
-
* @inheritDoc
|
|
39
|
-
*/
|
|
40
|
-
init(noAutomaticPoll?: boolean): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* @inheritDoc
|
|
43
|
-
*/
|
|
44
|
-
stop(): Promise<void>;
|
|
45
|
-
}
|
|
1
|
+
import { Connection } from "@solana/web3.js";
|
|
2
|
+
import { SolanaSwapProgram } from "../swaps/SolanaSwapProgram";
|
|
3
|
+
import { SolanaChainEventsBrowser } from "./SolanaChainEventsBrowser";
|
|
4
|
+
/**
|
|
5
|
+
* Event handler for backend Node.js systems with access to fs, uses HTTP polling in combination with WS to not miss
|
|
6
|
+
* any events
|
|
7
|
+
*/
|
|
8
|
+
export declare class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
9
|
+
private readonly directory;
|
|
10
|
+
private readonly logFetchInterval;
|
|
11
|
+
private stopped;
|
|
12
|
+
private timeout?;
|
|
13
|
+
constructor(directory: string, connection: Connection, contractVersions: SolanaSwapProgram | {
|
|
14
|
+
[version: string]: {
|
|
15
|
+
swapContract: SolanaSwapProgram;
|
|
16
|
+
};
|
|
17
|
+
}, logFetchInterval?: number);
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves last signature & slot from filesystem
|
|
20
|
+
*
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private getLastSignature;
|
|
24
|
+
/**
|
|
25
|
+
* Saves last signature & slot to the filesystem
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
private saveLastSignature;
|
|
30
|
+
/**
|
|
31
|
+
* Polls for new events & processes them
|
|
32
|
+
*
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
private checkEvents;
|
|
36
|
+
private setupHttpPolling;
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
init(noAutomaticPoll?: boolean): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
stop(): Promise<void>;
|
|
45
|
+
}
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaChainEvents = void 0;
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
const SolanaChainEventsBrowser_1 = require("./SolanaChainEventsBrowser");
|
|
6
|
-
const BLOCKHEIGHT_FILENAME = "/blockheight.txt";
|
|
7
|
-
const LOG_FETCH_INTERVAL = 5 * 1000;
|
|
8
|
-
/**
|
|
9
|
-
* Event handler for backend Node.js systems with access to fs, uses HTTP polling in combination with WS to not miss
|
|
10
|
-
* any events
|
|
11
|
-
*/
|
|
12
|
-
class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrowser {
|
|
13
|
-
constructor(directory, connection, contractVersions, logFetchInterval) {
|
|
14
|
-
super(connection, contractVersions);
|
|
15
|
-
this.stopped = true;
|
|
16
|
-
this.directory = directory;
|
|
17
|
-
this.logFetchInterval = logFetchInterval || LOG_FETCH_INTERVAL;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves last signature & slot from filesystem
|
|
21
|
-
*
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
|
-
async getLastSignature() {
|
|
25
|
-
let txt;
|
|
26
|
-
try {
|
|
27
|
-
txt = (await fs.readFile(this.directory + BLOCKHEIGHT_FILENAME)).toString();
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
return JSON.parse(txt);
|
|
34
|
-
}
|
|
35
|
-
catch (e) { }
|
|
36
|
-
try {
|
|
37
|
-
const arr = txt.split(";");
|
|
38
|
-
if (arr.length < 2)
|
|
39
|
-
return {
|
|
40
|
-
signature: txt,
|
|
41
|
-
slot: 0
|
|
42
|
-
};
|
|
43
|
-
return {
|
|
44
|
-
signature: arr[0],
|
|
45
|
-
slot: parseInt(arr[1])
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Saves last signature & slot to the filesystem
|
|
54
|
-
*
|
|
55
|
-
* @private
|
|
56
|
-
*/
|
|
57
|
-
saveLastSignature(lastState) {
|
|
58
|
-
return fs.writeFile(this.directory + BLOCKHEIGHT_FILENAME, JSON.stringify(lastState));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Polls for new events & processes them
|
|
62
|
-
*
|
|
63
|
-
* @private
|
|
64
|
-
*/
|
|
65
|
-
async checkEvents() {
|
|
66
|
-
const lastSignature = await this.getLastSignature();
|
|
67
|
-
const result = await this.poll(lastSignature ?? undefined);
|
|
68
|
-
if (result != null) {
|
|
69
|
-
await this.saveLastSignature(result);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async setupHttpPolling() {
|
|
73
|
-
this.stopped = false;
|
|
74
|
-
let func;
|
|
75
|
-
func = async () => {
|
|
76
|
-
await this.checkEvents().catch(e => {
|
|
77
|
-
this.logger.error("setupHttpPolling(): Failed to fetch Solana log: ", e);
|
|
78
|
-
});
|
|
79
|
-
if (this.stopped)
|
|
80
|
-
return;
|
|
81
|
-
this.timeout = setTimeout(func, this.logFetchInterval);
|
|
82
|
-
};
|
|
83
|
-
await func();
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* @inheritDoc
|
|
87
|
-
*/
|
|
88
|
-
async init(noAutomaticPoll) {
|
|
89
|
-
if (noAutomaticPoll)
|
|
90
|
-
return;
|
|
91
|
-
try {
|
|
92
|
-
await fs.mkdir(this.directory);
|
|
93
|
-
}
|
|
94
|
-
catch (e) { }
|
|
95
|
-
await this.setupHttpPolling();
|
|
96
|
-
this.setupWebsocket();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* @inheritDoc
|
|
100
|
-
*/
|
|
101
|
-
stop() {
|
|
102
|
-
this.stopped = true;
|
|
103
|
-
if (this.timeout != null)
|
|
104
|
-
clearTimeout(this.timeout);
|
|
105
|
-
return super.stop();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.SolanaChainEvents = SolanaChainEvents;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaChainEvents = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const SolanaChainEventsBrowser_1 = require("./SolanaChainEventsBrowser");
|
|
6
|
+
const BLOCKHEIGHT_FILENAME = "/blockheight.txt";
|
|
7
|
+
const LOG_FETCH_INTERVAL = 5 * 1000;
|
|
8
|
+
/**
|
|
9
|
+
* Event handler for backend Node.js systems with access to fs, uses HTTP polling in combination with WS to not miss
|
|
10
|
+
* any events
|
|
11
|
+
*/
|
|
12
|
+
class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrowser {
|
|
13
|
+
constructor(directory, connection, contractVersions, logFetchInterval) {
|
|
14
|
+
super(connection, contractVersions);
|
|
15
|
+
this.stopped = true;
|
|
16
|
+
this.directory = directory;
|
|
17
|
+
this.logFetchInterval = logFetchInterval || LOG_FETCH_INTERVAL;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves last signature & slot from filesystem
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
async getLastSignature() {
|
|
25
|
+
let txt;
|
|
26
|
+
try {
|
|
27
|
+
txt = (await fs.readFile(this.directory + BLOCKHEIGHT_FILENAME)).toString();
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(txt);
|
|
34
|
+
}
|
|
35
|
+
catch (e) { }
|
|
36
|
+
try {
|
|
37
|
+
const arr = txt.split(";");
|
|
38
|
+
if (arr.length < 2)
|
|
39
|
+
return {
|
|
40
|
+
signature: txt,
|
|
41
|
+
slot: 0
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
signature: arr[0],
|
|
45
|
+
slot: parseInt(arr[1])
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Saves last signature & slot to the filesystem
|
|
54
|
+
*
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
saveLastSignature(lastState) {
|
|
58
|
+
return fs.writeFile(this.directory + BLOCKHEIGHT_FILENAME, JSON.stringify(lastState));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Polls for new events & processes them
|
|
62
|
+
*
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
async checkEvents() {
|
|
66
|
+
const lastSignature = await this.getLastSignature();
|
|
67
|
+
const result = await this.poll(lastSignature ?? undefined);
|
|
68
|
+
if (result != null) {
|
|
69
|
+
await this.saveLastSignature(result);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async setupHttpPolling() {
|
|
73
|
+
this.stopped = false;
|
|
74
|
+
let func;
|
|
75
|
+
func = async () => {
|
|
76
|
+
await this.checkEvents().catch(e => {
|
|
77
|
+
this.logger.error("setupHttpPolling(): Failed to fetch Solana log: ", e);
|
|
78
|
+
});
|
|
79
|
+
if (this.stopped)
|
|
80
|
+
return;
|
|
81
|
+
this.timeout = setTimeout(func, this.logFetchInterval);
|
|
82
|
+
};
|
|
83
|
+
await func();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @inheritDoc
|
|
87
|
+
*/
|
|
88
|
+
async init(noAutomaticPoll) {
|
|
89
|
+
if (noAutomaticPoll)
|
|
90
|
+
return;
|
|
91
|
+
try {
|
|
92
|
+
await fs.mkdir(this.directory);
|
|
93
|
+
}
|
|
94
|
+
catch (e) { }
|
|
95
|
+
await this.setupHttpPolling();
|
|
96
|
+
this.setupWebsocket();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @inheritDoc
|
|
100
|
+
*/
|
|
101
|
+
stop() {
|
|
102
|
+
this.stopped = true;
|
|
103
|
+
if (this.timeout != null)
|
|
104
|
+
clearTimeout(this.timeout);
|
|
105
|
+
return super.stop();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.SolanaChainEvents = SolanaChainEvents;
|