@atomiqlabs/chain-solana 13.2.2 → 13.2.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/dist/solana/chain/modules/SolanaBlocks.d.ts +2 -2
- package/dist/solana/chain/modules/SolanaBlocks.js +2 -2
- package/dist/solana/chain/modules/SolanaSlots.d.ts +2 -0
- package/dist/solana/chain/modules/SolanaSlots.js +4 -0
- package/package.json +1 -1
- package/src/solana/chain/modules/SolanaBlocks.ts +4 -4
- package/src/solana/chain/modules/SolanaSlots.ts +3 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SolanaModule } from "../SolanaModule";
|
|
2
|
-
import {
|
|
2
|
+
import { Finality, ParsedAccountsModeBlockResponse } from "@solana/web3.js";
|
|
3
3
|
export type BlockChecked = ParsedAccountsModeBlockResponse & {
|
|
4
4
|
blockTime: number;
|
|
5
5
|
blockHeight: number;
|
|
@@ -19,7 +19,7 @@ export declare class SolanaBlocks extends SolanaModule {
|
|
|
19
19
|
*
|
|
20
20
|
* @param commitment
|
|
21
21
|
*/
|
|
22
|
-
findLatestParsedBlock(commitment:
|
|
22
|
+
findLatestParsedBlock(commitment: Finality): Promise<{
|
|
23
23
|
block: BlockChecked;
|
|
24
24
|
slot: number;
|
|
25
25
|
}>;
|
|
@@ -40,7 +40,7 @@ class SolanaBlocks extends SolanaModule_1.SolanaModule {
|
|
|
40
40
|
*/
|
|
41
41
|
async findLatestParsedBlock(commitment) {
|
|
42
42
|
let slot = await this.root.Slots.getSlot(commitment);
|
|
43
|
-
for (let i = 0; i <
|
|
43
|
+
for (let i = 0; i < 16; i++) {
|
|
44
44
|
const block = await this.getParsedBlock(slot).catch(e => {
|
|
45
45
|
const errorStr = e.toString();
|
|
46
46
|
if (errorStr.startsWith("SolanaJSONRPCError: failed to get block:") && (errorStr.includes("Block not available for slot") ||
|
|
@@ -60,7 +60,7 @@ class SolanaBlocks extends SolanaModule_1.SolanaModule {
|
|
|
60
60
|
}
|
|
61
61
|
slot--;
|
|
62
62
|
}
|
|
63
|
-
throw new Error(
|
|
63
|
+
throw new Error(`Ran out of tries trying to find a parsedBlock, last attempted slot: ${slot + 1}`);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Gets parsed block for a given slot, uses block cache if the block was already fetched before
|
|
@@ -25,6 +25,8 @@ export declare class SolanaSlots extends SolanaModule {
|
|
|
25
25
|
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
26
26
|
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
27
27
|
*
|
|
28
|
+
* @remarks Doesn't try to extrapolate the slot number for `finalized` commitment level
|
|
29
|
+
*
|
|
28
30
|
* @param commitment
|
|
29
31
|
*/
|
|
30
32
|
getSlot(commitment: Commitment): Promise<number>;
|
|
@@ -54,11 +54,15 @@ class SolanaSlots extends SolanaModule_1.SolanaModule {
|
|
|
54
54
|
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
55
55
|
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
56
56
|
*
|
|
57
|
+
* @remarks Doesn't try to extrapolate the slot number for `finalized` commitment level
|
|
58
|
+
*
|
|
57
59
|
* @param commitment
|
|
58
60
|
*/
|
|
59
61
|
async getSlot(commitment) {
|
|
60
62
|
let cachedSlotData = this.slotCache[commitment];
|
|
61
63
|
if (cachedSlotData != null && Date.now() - cachedSlotData.timestamp < this.SLOT_CACHE_TIME) {
|
|
64
|
+
if (commitment === "finalized")
|
|
65
|
+
return await cachedSlotData.slot;
|
|
62
66
|
return (await cachedSlotData.slot) + Math.floor((Date.now() - cachedSlotData.timestamp) / this.root._SLOT_TIME);
|
|
63
67
|
}
|
|
64
68
|
cachedSlotData = this.fetchAndSaveSlot(commitment);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {SolanaModule} from "../SolanaModule";
|
|
2
|
-
import {Commitment, ParsedAccountsModeBlockResponse} from "@solana/web3.js";
|
|
2
|
+
import {Commitment, Finality, ParsedAccountsModeBlockResponse} from "@solana/web3.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export type BlockChecked = ParsedAccountsModeBlockResponse & {blockTime: number, blockHeight: number};
|
|
@@ -38,13 +38,13 @@ export class SolanaBlocks extends SolanaModule {
|
|
|
38
38
|
*
|
|
39
39
|
* @param commitment
|
|
40
40
|
*/
|
|
41
|
-
public async findLatestParsedBlock(commitment:
|
|
41
|
+
public async findLatestParsedBlock(commitment: Finality): Promise<{
|
|
42
42
|
block: BlockChecked,
|
|
43
43
|
slot: number
|
|
44
44
|
}> {
|
|
45
45
|
let slot = await this.root.Slots.getSlot(commitment);
|
|
46
46
|
|
|
47
|
-
for(let i=0;i<
|
|
47
|
+
for(let i=0;i<16;i++) {
|
|
48
48
|
const block = await this.getParsedBlock(slot).catch(e => {
|
|
49
49
|
const errorStr = e.toString();
|
|
50
50
|
if(
|
|
@@ -71,7 +71,7 @@ export class SolanaBlocks extends SolanaModule {
|
|
|
71
71
|
slot--;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
throw new Error(
|
|
74
|
+
throw new Error(`Ran out of tries trying to find a parsedBlock, last attempted slot: ${slot + 1}`);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -65,12 +65,15 @@ export class SolanaSlots extends SolanaModule {
|
|
|
65
65
|
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
66
66
|
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
67
67
|
*
|
|
68
|
+
* @remarks Doesn't try to extrapolate the slot number for `finalized` commitment level
|
|
69
|
+
*
|
|
68
70
|
* @param commitment
|
|
69
71
|
*/
|
|
70
72
|
public async getSlot(commitment: Commitment): Promise<number> {
|
|
71
73
|
let cachedSlotData = this.slotCache[commitment];
|
|
72
74
|
|
|
73
75
|
if(cachedSlotData!=null && Date.now()-cachedSlotData.timestamp<this.SLOT_CACHE_TIME) {
|
|
76
|
+
if(commitment==="finalized") return await cachedSlotData.slot;
|
|
74
77
|
return (await cachedSlotData.slot) + Math.floor((Date.now()-cachedSlotData.timestamp)/this.root._SLOT_TIME);
|
|
75
78
|
}
|
|
76
79
|
|