@triton-one/yellowstone-grpc 0.1.0
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/.prettierrc.json +1 -0
- package/README.md +26 -0
- package/dist/grpc/geyser.d.ts +8450 -0
- package/dist/grpc/geyser.js +2868 -0
- package/dist/grpc/solana-storage.d.ts +3773 -0
- package/dist/grpc/solana-storage.js +1856 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +265 -0
- package/package.json +35 -0
- package/src/grpc/geyser.ts +3477 -0
- package/src/grpc/solana-storage.ts +2141 -0
- package/src/index.ts +190 -0
- package/tsconfig.json +7 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript/JavaScript client for gRPC Geyser.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Import generated gRPC client and types.
|
|
6
|
+
import {
|
|
7
|
+
CommitmentLevel,
|
|
8
|
+
GetLatestBlockhashResponse,
|
|
9
|
+
GeyserClient,
|
|
10
|
+
IsBlockhashValidResponse,
|
|
11
|
+
SubscribeRequestFilterAccounts,
|
|
12
|
+
SubscribeRequestFilterBlocks,
|
|
13
|
+
SubscribeRequestFilterBlocksMeta,
|
|
14
|
+
SubscribeRequestFilterSlots,
|
|
15
|
+
SubscribeRequestFilterTransactions,
|
|
16
|
+
} from "./grpc/geyser";
|
|
17
|
+
|
|
18
|
+
import { ChannelCredentials, credentials, Metadata } from "@grpc/grpc-js";
|
|
19
|
+
|
|
20
|
+
// Reexport automatically generated types
|
|
21
|
+
export {
|
|
22
|
+
SubscribeRequest,
|
|
23
|
+
SubscribeRequest_AccountsEntry,
|
|
24
|
+
SubscribeRequest_SlotsEntry,
|
|
25
|
+
SubscribeRequestFilterSlots,
|
|
26
|
+
SubscribeRequest_TransactionsEntry,
|
|
27
|
+
SubscribeRequestFilterTransactions,
|
|
28
|
+
SubscribeRequest_BlocksEntry,
|
|
29
|
+
SubscribeRequest_BlocksMetaEntry,
|
|
30
|
+
SubscribeRequestFilterAccounts,
|
|
31
|
+
SubscribeRequestFilterAccountsFilter,
|
|
32
|
+
SubscribeRequestFilterAccountsFilterMemcmp,
|
|
33
|
+
SubscribeRequestFilterBlocks,
|
|
34
|
+
SubscribeRequestFilterBlocksMeta,
|
|
35
|
+
SubscribeUpdate,
|
|
36
|
+
SubscribeUpdateAccount,
|
|
37
|
+
SubscribeUpdateAccountInfo,
|
|
38
|
+
SubscribeUpdateSlot,
|
|
39
|
+
CommitmentLevel,
|
|
40
|
+
SubscribeUpdateTransaction,
|
|
41
|
+
SubscribeUpdateTransactionInfo,
|
|
42
|
+
SubscribeUpdateBlock,
|
|
43
|
+
SubscribeUpdatePing,
|
|
44
|
+
SubscribeUpdateBlockMeta,
|
|
45
|
+
} from "./grpc/geyser";
|
|
46
|
+
|
|
47
|
+
export default class Client {
|
|
48
|
+
_client: GeyserClient;
|
|
49
|
+
|
|
50
|
+
constructor(endpoint: string, xToken: string | undefined) {
|
|
51
|
+
let creds: ChannelCredentials;
|
|
52
|
+
|
|
53
|
+
const endpointURL = new URL(endpoint);
|
|
54
|
+
|
|
55
|
+
// Check if we need to use TLS.
|
|
56
|
+
if (endpointURL.protocol === "https:") {
|
|
57
|
+
creds = credentials.combineChannelCredentials(
|
|
58
|
+
credentials.createSsl(),
|
|
59
|
+
credentials.createFromMetadataGenerator((_params, callback) => {
|
|
60
|
+
const metadata = new Metadata();
|
|
61
|
+
if (xToken !== undefined) {
|
|
62
|
+
metadata.add("x-token", xToken);
|
|
63
|
+
}
|
|
64
|
+
return callback(null, metadata);
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
} else {
|
|
68
|
+
creds = ChannelCredentials.createInsecure();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this._client = new GeyserClient(endpointURL.host, creds);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async subscribe() {
|
|
75
|
+
return await this._client.subscribe();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async subscribe_once(
|
|
79
|
+
accounts: { [key: string]: SubscribeRequestFilterAccounts },
|
|
80
|
+
slots: { [key: string]: SubscribeRequestFilterSlots },
|
|
81
|
+
transactions: { [key: string]: SubscribeRequestFilterTransactions },
|
|
82
|
+
blocks: { [key: string]: SubscribeRequestFilterBlocks },
|
|
83
|
+
blocksMeta: { [key: string]: SubscribeRequestFilterBlocksMeta },
|
|
84
|
+
commitment?: CommitmentLevel | undefined
|
|
85
|
+
) {
|
|
86
|
+
const stream = await this._client.subscribe();
|
|
87
|
+
|
|
88
|
+
await new Promise<void>((resolve, reject) => {
|
|
89
|
+
stream.write(
|
|
90
|
+
{
|
|
91
|
+
accounts,
|
|
92
|
+
slots,
|
|
93
|
+
transactions,
|
|
94
|
+
blocks,
|
|
95
|
+
blocksMeta,
|
|
96
|
+
commitment,
|
|
97
|
+
},
|
|
98
|
+
(err) => {
|
|
99
|
+
if (err === null || err === undefined) {
|
|
100
|
+
resolve();
|
|
101
|
+
} else {
|
|
102
|
+
reject(err);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return stream;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async ping(count: number): Promise<number> {
|
|
112
|
+
return await new Promise<number>((resolve, reject) => {
|
|
113
|
+
this._client.ping({ count }, (err, response) => {
|
|
114
|
+
if (err === null || err === undefined) {
|
|
115
|
+
resolve(response.count);
|
|
116
|
+
} else {
|
|
117
|
+
reject(err);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async getLatestBlockhash(
|
|
124
|
+
commitment?: CommitmentLevel
|
|
125
|
+
): Promise<GetLatestBlockhashResponse> {
|
|
126
|
+
return await new Promise<GetLatestBlockhashResponse>((resolve, reject) => {
|
|
127
|
+
this._client.getLatestBlockhash({ commitment }, (err, response) => {
|
|
128
|
+
if (err === null || err === undefined) {
|
|
129
|
+
resolve(response);
|
|
130
|
+
} else {
|
|
131
|
+
reject(err);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getBlockHeight(commitment?: CommitmentLevel): Promise<number> {
|
|
138
|
+
return await new Promise<number>((resolve, reject) => {
|
|
139
|
+
this._client.getBlockHeight({ commitment }, (err, response) => {
|
|
140
|
+
if (err === null || err === undefined) {
|
|
141
|
+
resolve(response.blockHeight);
|
|
142
|
+
} else {
|
|
143
|
+
reject(err);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async getSlot(commitment?: CommitmentLevel): Promise<number> {
|
|
150
|
+
return await new Promise<number>((resolve, reject) => {
|
|
151
|
+
this._client.getSlot({ commitment }, (err, response) => {
|
|
152
|
+
if (err === null || err === undefined) {
|
|
153
|
+
resolve(response.slot);
|
|
154
|
+
} else {
|
|
155
|
+
reject(err);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async isBlockhashValid(
|
|
162
|
+
blockhash: string,
|
|
163
|
+
commitment?: CommitmentLevel
|
|
164
|
+
): Promise<IsBlockhashValidResponse> {
|
|
165
|
+
return await new Promise<IsBlockhashValidResponse>((resolve, reject) => {
|
|
166
|
+
this._client.isBlockhashValid(
|
|
167
|
+
{ blockhash, commitment },
|
|
168
|
+
(err, response) => {
|
|
169
|
+
if (err === null || err === undefined) {
|
|
170
|
+
resolve(response);
|
|
171
|
+
} else {
|
|
172
|
+
reject(err);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async getVersion(): Promise<string> {
|
|
180
|
+
return await new Promise<string>((resolve, reject) => {
|
|
181
|
+
this._client.getVersion({}, (err, response) => {
|
|
182
|
+
if (err === null || err === undefined) {
|
|
183
|
+
resolve(response.version);
|
|
184
|
+
} else {
|
|
185
|
+
reject(err);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|