@solana/web3.js 2.0.0-experimental.d0412ab → 2.0.0-experimental.d085c72
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 +1 -1
- package/README.md +1155 -43
- package/dist/index.browser.cjs +766 -8
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +749 -13
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +2772 -811
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +738 -13
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +755 -10
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +738 -13
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +80 -30
- package/dist/types/airdrop-confirmer.d.ts +20 -0
- package/dist/types/airdrop.d.ts +23 -0
- package/dist/types/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
- package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
- package/dist/types/rpc-websocket-transport.d.ts +13 -0
- package/dist/types/rpc.d.ts +5 -3
- package/dist/types/send-transaction.d.ts +38 -0
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +10 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +15 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts +14 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +13 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
- package/dist/types/transaction-confirmation.d.ts +37 -0
- package/package.json +22 -18
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/rpc-default-config.d.ts.map +0 -1
- package/dist/types/rpc-integer-overflow-error.d.ts.map +0 -1
- package/dist/types/rpc-request-coalescer.d.ts.map +0 -1
- package/dist/types/rpc-request-deduplication.d.ts.map +0 -1
- package/dist/types/rpc-transport.d.ts.map +0 -1
- package/dist/types/rpc.d.ts.map +0 -1
|
@@ -125,125 +125,269 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
125
125
|
// ../addresses/dist/index.browser.js
|
|
126
126
|
init_env_shim();
|
|
127
127
|
|
|
128
|
-
//
|
|
128
|
+
// ../codecs-core/dist/index.browser.js
|
|
129
129
|
init_env_shim();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
|
|
131
|
+
if (bytes.length - offset <= 0) {
|
|
132
|
+
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
|
|
136
|
+
const bytesLength = bytes.length - offset;
|
|
137
|
+
if (bytesLength < expected) {
|
|
138
|
+
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
var mergeBytes = (byteArrays) => {
|
|
142
|
+
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
143
|
+
if (nonEmptyByteArrays.length === 0) {
|
|
144
|
+
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
145
|
+
}
|
|
146
|
+
if (nonEmptyByteArrays.length === 1) {
|
|
147
|
+
return nonEmptyByteArrays[0];
|
|
148
|
+
}
|
|
149
|
+
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
138
150
|
const result = new Uint8Array(totalLength);
|
|
139
151
|
let offset = 0;
|
|
140
|
-
|
|
152
|
+
nonEmptyByteArrays.forEach((arr) => {
|
|
141
153
|
result.set(arr, offset);
|
|
142
154
|
offset += arr.length;
|
|
143
155
|
});
|
|
144
156
|
return result;
|
|
145
157
|
};
|
|
146
|
-
var padBytes = (
|
|
147
|
-
if (
|
|
148
|
-
return
|
|
158
|
+
var padBytes = (bytes, length) => {
|
|
159
|
+
if (bytes.length >= length)
|
|
160
|
+
return bytes;
|
|
149
161
|
const paddedBytes = new Uint8Array(length).fill(0);
|
|
150
|
-
paddedBytes.set(
|
|
162
|
+
paddedBytes.set(bytes);
|
|
151
163
|
return paddedBytes;
|
|
152
164
|
};
|
|
153
|
-
var fixBytes = (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
|
|
160
|
-
__publicField(this, "name", "DeserializingEmptyBufferError");
|
|
165
|
+
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
166
|
+
function combineCodec(encoder, decoder, description) {
|
|
167
|
+
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
170
|
+
);
|
|
161
171
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
__publicField(this, "name", "NotEnoughBytesError");
|
|
172
|
+
if (encoder.maxSize !== decoder.maxSize) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
175
|
+
);
|
|
167
176
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
super(message);
|
|
173
|
-
__publicField(this, "name", "ExpectedFixedSizeSerializerError");
|
|
177
|
+
if (description === void 0 && encoder.description !== decoder.description) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
|
|
180
|
+
);
|
|
174
181
|
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
178
|
-
init_env_shim();
|
|
179
|
-
function fixSerializer(serializer, fixedBytes, description) {
|
|
180
182
|
return {
|
|
181
|
-
|
|
183
|
+
decode: decoder.decode,
|
|
184
|
+
description: description != null ? description : encoder.description,
|
|
185
|
+
encode: encoder.encode,
|
|
186
|
+
fixedSize: encoder.fixedSize,
|
|
187
|
+
maxSize: encoder.maxSize
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function fixCodecHelper(data, fixedBytes, description) {
|
|
191
|
+
return {
|
|
192
|
+
description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
|
|
182
193
|
fixedSize: fixedBytes,
|
|
183
|
-
maxSize: fixedBytes
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
194
|
+
maxSize: fixedBytes
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function fixEncoder(encoder, fixedBytes, description) {
|
|
198
|
+
return {
|
|
199
|
+
...fixCodecHelper(encoder, fixedBytes, description),
|
|
200
|
+
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function fixDecoder(decoder, fixedBytes, description) {
|
|
204
|
+
return {
|
|
205
|
+
...fixCodecHelper(decoder, fixedBytes, description),
|
|
206
|
+
decode: (bytes, offset = 0) => {
|
|
207
|
+
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
208
|
+
if (offset > 0 || bytes.length > fixedBytes) {
|
|
209
|
+
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
189
210
|
}
|
|
190
|
-
if (
|
|
191
|
-
|
|
211
|
+
if (decoder.fixedSize !== null) {
|
|
212
|
+
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
192
213
|
}
|
|
193
|
-
const [value] =
|
|
214
|
+
const [value] = decoder.decode(bytes, 0);
|
|
194
215
|
return [value, offset + fixedBytes];
|
|
195
216
|
}
|
|
196
217
|
};
|
|
197
218
|
}
|
|
198
|
-
|
|
199
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
|
|
200
|
-
init_env_shim();
|
|
201
|
-
function mapSerializer(serializer, unmap, map) {
|
|
219
|
+
function mapEncoder(encoder, unmap) {
|
|
202
220
|
return {
|
|
203
|
-
description:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
221
|
+
description: encoder.description,
|
|
222
|
+
encode: (value) => encoder.encode(unmap(value)),
|
|
223
|
+
fixedSize: encoder.fixedSize,
|
|
224
|
+
maxSize: encoder.maxSize
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function mapDecoder(decoder, map) {
|
|
228
|
+
return {
|
|
229
|
+
decode: (bytes, offset = 0) => {
|
|
230
|
+
const [value, length] = decoder.decode(bytes, offset);
|
|
231
|
+
return [map(value, bytes, offset), length];
|
|
232
|
+
},
|
|
233
|
+
description: decoder.description,
|
|
234
|
+
fixedSize: decoder.fixedSize,
|
|
235
|
+
maxSize: decoder.maxSize
|
|
211
236
|
};
|
|
212
237
|
}
|
|
213
238
|
|
|
214
|
-
//
|
|
215
|
-
init_env_shim();
|
|
216
|
-
|
|
217
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
239
|
+
// ../codecs-strings/dist/index.browser.js
|
|
218
240
|
init_env_shim();
|
|
219
241
|
|
|
220
|
-
//
|
|
242
|
+
// ../codecs-numbers/dist/index.browser.js
|
|
221
243
|
init_env_shim();
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
this.cause = cause;
|
|
244
|
+
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
245
|
+
if (value < min || value > max) {
|
|
246
|
+
throw new Error(
|
|
247
|
+
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
248
|
+
);
|
|
228
249
|
}
|
|
250
|
+
}
|
|
251
|
+
function sharedNumberFactory(input) {
|
|
252
|
+
var _a;
|
|
253
|
+
let littleEndian;
|
|
254
|
+
let defaultDescription = input.name;
|
|
255
|
+
if (input.size > 1) {
|
|
256
|
+
littleEndian = !("endian" in input.config) || input.config.endian === 0;
|
|
257
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
description: (_a = input.config.description) != null ? _a : defaultDescription,
|
|
261
|
+
fixedSize: input.size,
|
|
262
|
+
littleEndian,
|
|
263
|
+
maxSize: input.size
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function numberEncoderFactory(input) {
|
|
267
|
+
const codecData = sharedNumberFactory(input);
|
|
268
|
+
return {
|
|
269
|
+
description: codecData.description,
|
|
270
|
+
encode(value) {
|
|
271
|
+
if (input.range) {
|
|
272
|
+
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
273
|
+
}
|
|
274
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
275
|
+
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
276
|
+
return new Uint8Array(arrayBuffer);
|
|
277
|
+
},
|
|
278
|
+
fixedSize: codecData.fixedSize,
|
|
279
|
+
maxSize: codecData.maxSize
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function numberDecoderFactory(input) {
|
|
283
|
+
const codecData = sharedNumberFactory(input);
|
|
284
|
+
return {
|
|
285
|
+
decode(bytes, offset = 0) {
|
|
286
|
+
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
|
|
287
|
+
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
|
|
288
|
+
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
289
|
+
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
290
|
+
},
|
|
291
|
+
description: codecData.description,
|
|
292
|
+
fixedSize: codecData.fixedSize,
|
|
293
|
+
maxSize: codecData.maxSize
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function toArrayBuffer(bytes, offset, length) {
|
|
297
|
+
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
|
|
298
|
+
const bytesLength = length != null ? length : bytes.byteLength;
|
|
299
|
+
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
300
|
+
}
|
|
301
|
+
var getShortU16Encoder = (config = {}) => {
|
|
302
|
+
var _a;
|
|
303
|
+
return {
|
|
304
|
+
description: (_a = config.description) != null ? _a : "shortU16",
|
|
305
|
+
encode: (value) => {
|
|
306
|
+
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
307
|
+
const bytes = [0];
|
|
308
|
+
for (let ii = 0; ; ii += 1) {
|
|
309
|
+
const alignedValue = value >> ii * 7;
|
|
310
|
+
if (alignedValue === 0) {
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
const nextSevenBits = 127 & alignedValue;
|
|
314
|
+
bytes[ii] = nextSevenBits;
|
|
315
|
+
if (ii > 0) {
|
|
316
|
+
bytes[ii - 1] |= 128;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return new Uint8Array(bytes);
|
|
320
|
+
},
|
|
321
|
+
fixedSize: null,
|
|
322
|
+
maxSize: 3
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
var getShortU16Decoder = (config = {}) => {
|
|
326
|
+
var _a;
|
|
327
|
+
return {
|
|
328
|
+
decode: (bytes, offset = 0) => {
|
|
329
|
+
let value = 0;
|
|
330
|
+
let byteCount = 0;
|
|
331
|
+
while (++byteCount) {
|
|
332
|
+
const byteIndex = byteCount - 1;
|
|
333
|
+
const currentByte = bytes[offset + byteIndex];
|
|
334
|
+
const nextSevenBits = 127 & currentByte;
|
|
335
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
336
|
+
if ((currentByte & 128) === 0) {
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return [value, offset + byteCount];
|
|
341
|
+
},
|
|
342
|
+
description: (_a = config.description) != null ? _a : "shortU16",
|
|
343
|
+
fixedSize: null,
|
|
344
|
+
maxSize: 3
|
|
345
|
+
};
|
|
229
346
|
};
|
|
347
|
+
var getU32Encoder = (config = {}) => numberEncoderFactory({
|
|
348
|
+
config,
|
|
349
|
+
name: "u32",
|
|
350
|
+
range: [0, Number("0xffffffff")],
|
|
351
|
+
set: (view, value, le) => view.setUint32(0, value, le),
|
|
352
|
+
size: 4
|
|
353
|
+
});
|
|
354
|
+
var getU32Decoder = (config = {}) => numberDecoderFactory({
|
|
355
|
+
config,
|
|
356
|
+
get: (view, le) => view.getUint32(0, le),
|
|
357
|
+
name: "u32",
|
|
358
|
+
size: 4
|
|
359
|
+
});
|
|
360
|
+
var getU8Encoder = (config = {}) => numberEncoderFactory({
|
|
361
|
+
config,
|
|
362
|
+
name: "u8",
|
|
363
|
+
range: [0, Number("0xff")],
|
|
364
|
+
set: (view, value) => view.setUint8(0, value),
|
|
365
|
+
size: 1
|
|
366
|
+
});
|
|
367
|
+
var getU8Decoder = (config = {}) => numberDecoderFactory({
|
|
368
|
+
config,
|
|
369
|
+
get: (view) => view.getUint8(0),
|
|
370
|
+
name: "u8",
|
|
371
|
+
size: 1
|
|
372
|
+
});
|
|
230
373
|
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
|
|
374
|
+
// ../codecs-strings/dist/index.browser.js
|
|
375
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
376
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
377
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
381
|
+
const base = alphabet4.length;
|
|
234
382
|
const baseBigInt = BigInt(base);
|
|
235
383
|
return {
|
|
236
384
|
description: `base${base}`,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
serialize(value) {
|
|
240
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
241
|
-
throw new InvalidBaseStringError(value, base);
|
|
242
|
-
}
|
|
385
|
+
encode(value) {
|
|
386
|
+
assertValidBaseString(alphabet4, value);
|
|
243
387
|
if (value === "")
|
|
244
388
|
return new Uint8Array();
|
|
245
389
|
const chars = [...value];
|
|
246
|
-
let trailIndex = chars.findIndex((c) => c !==
|
|
390
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
247
391
|
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
248
392
|
const leadingZeroes = Array(trailIndex).fill(0);
|
|
249
393
|
if (trailIndex === chars.length)
|
|
@@ -252,7 +396,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
252
396
|
let base10Number = 0n;
|
|
253
397
|
let baseXPower = 1n;
|
|
254
398
|
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
255
|
-
base10Number += baseXPower * BigInt(
|
|
399
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
256
400
|
baseXPower *= baseBigInt;
|
|
257
401
|
}
|
|
258
402
|
const tailBytes = [];
|
|
@@ -262,391 +406,149 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
262
406
|
}
|
|
263
407
|
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
264
408
|
},
|
|
265
|
-
|
|
266
|
-
|
|
409
|
+
fixedSize: null,
|
|
410
|
+
maxSize: null
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
414
|
+
const base = alphabet4.length;
|
|
415
|
+
const baseBigInt = BigInt(base);
|
|
416
|
+
return {
|
|
417
|
+
decode(rawBytes, offset = 0) {
|
|
418
|
+
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
419
|
+
if (bytes.length === 0)
|
|
267
420
|
return ["", 0];
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
421
|
+
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
422
|
+
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
423
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
424
|
+
if (trailIndex === bytes.length)
|
|
425
|
+
return [leadingZeroes, rawBytes.length];
|
|
426
|
+
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
275
427
|
const tailChars = [];
|
|
276
428
|
while (base10Number > 0n) {
|
|
277
|
-
tailChars.unshift(
|
|
429
|
+
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
278
430
|
base10Number /= baseBigInt;
|
|
279
431
|
}
|
|
280
|
-
return [leadingZeroes + tailChars.join(""),
|
|
281
|
-
}
|
|
432
|
+
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
433
|
+
},
|
|
434
|
+
description: `base${base}`,
|
|
435
|
+
fixedSize: null,
|
|
436
|
+
maxSize: null
|
|
282
437
|
};
|
|
283
438
|
};
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
var
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
serialize(value) {
|
|
303
|
-
return new TextEncoder().encode(value);
|
|
304
|
-
},
|
|
305
|
-
deserialize(buffer, offset = 0) {
|
|
306
|
-
const value = new TextDecoder().decode(buffer.slice(offset));
|
|
307
|
-
return [removeNullCharacters(value), buffer.length];
|
|
439
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
440
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
441
|
+
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
442
|
+
var getBase64Encoder = () => {
|
|
443
|
+
{
|
|
444
|
+
return {
|
|
445
|
+
description: `base64`,
|
|
446
|
+
encode(value) {
|
|
447
|
+
try {
|
|
448
|
+
const bytes = atob(value).split("").map((c) => c.charCodeAt(0));
|
|
449
|
+
return new Uint8Array(bytes);
|
|
450
|
+
} catch (e23) {
|
|
451
|
+
throw new Error(`Expected a string of base 64, got [${value}].`);
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
fixedSize: null,
|
|
455
|
+
maxSize: null
|
|
456
|
+
};
|
|
308
457
|
}
|
|
309
458
|
};
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
323
|
-
init_env_shim();
|
|
324
|
-
var NumberOutOfRangeError = class extends RangeError {
|
|
325
|
-
constructor(serializer, min, max, actual) {
|
|
326
|
-
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
327
|
-
__publicField(this, "name", "NumberOutOfRangeError");
|
|
459
|
+
var getBase64Decoder = () => {
|
|
460
|
+
{
|
|
461
|
+
return {
|
|
462
|
+
decode(bytes, offset = 0) {
|
|
463
|
+
const slice = bytes.slice(offset);
|
|
464
|
+
const value = btoa(String.fromCharCode(...slice));
|
|
465
|
+
return [value, bytes.length];
|
|
466
|
+
},
|
|
467
|
+
description: `base64`,
|
|
468
|
+
fixedSize: null,
|
|
469
|
+
maxSize: null
|
|
470
|
+
};
|
|
328
471
|
}
|
|
329
472
|
};
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
339
|
-
}
|
|
473
|
+
var removeNullCharacters = (value) => (
|
|
474
|
+
// eslint-disable-next-line no-control-regex
|
|
475
|
+
value.replace(/\u0000/g, "")
|
|
476
|
+
);
|
|
477
|
+
var e = globalThis.TextDecoder;
|
|
478
|
+
var o = globalThis.TextEncoder;
|
|
479
|
+
var getUtf8Encoder = () => {
|
|
480
|
+
let textEncoder;
|
|
340
481
|
return {
|
|
341
|
-
description:
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (input.range) {
|
|
346
|
-
assertRange(input.name, input.range[0], input.range[1], value);
|
|
347
|
-
}
|
|
348
|
-
const buffer = new ArrayBuffer(input.size);
|
|
349
|
-
input.set(new DataView(buffer), value, littleEndian);
|
|
350
|
-
return new Uint8Array(buffer);
|
|
351
|
-
},
|
|
352
|
-
deserialize(bytes2, offset = 0) {
|
|
353
|
-
const slice = bytes2.slice(offset, offset + input.size);
|
|
354
|
-
assertEnoughBytes("i8", slice, input.size);
|
|
355
|
-
const view = toDataView(slice);
|
|
356
|
-
return [input.get(view, littleEndian), offset + input.size];
|
|
357
|
-
}
|
|
482
|
+
description: "utf8",
|
|
483
|
+
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
484
|
+
fixedSize: null,
|
|
485
|
+
maxSize: null
|
|
358
486
|
};
|
|
359
|
-
}
|
|
360
|
-
var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
|
|
361
|
-
var toDataView = (array2) => new DataView(toArrayBuffer(array2));
|
|
362
|
-
var assertRange = (serializer, min, max, value) => {
|
|
363
|
-
if (value < min || value > max) {
|
|
364
|
-
throw new NumberOutOfRangeError(serializer, min, max, value);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
var assertEnoughBytes = (serializer, bytes2, expected) => {
|
|
368
|
-
if (bytes2.length === 0) {
|
|
369
|
-
throw new DeserializingEmptyBufferError(serializer);
|
|
370
|
-
}
|
|
371
|
-
if (bytes2.length < expected) {
|
|
372
|
-
throw new NotEnoughBytesError(serializer, expected, bytes2.length);
|
|
373
|
-
}
|
|
374
487
|
};
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
init_env_shim();
|
|
378
|
-
var u8 = (options = {}) => numberFactory({
|
|
379
|
-
name: "u8",
|
|
380
|
-
size: 1,
|
|
381
|
-
range: [0, Number("0xff")],
|
|
382
|
-
set: (view, value) => view.setUint8(0, Number(value)),
|
|
383
|
-
get: (view) => view.getUint8(0),
|
|
384
|
-
options
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
|
|
388
|
-
init_env_shim();
|
|
389
|
-
var u32 = (options = {}) => numberFactory({
|
|
390
|
-
name: "u32",
|
|
391
|
-
size: 4,
|
|
392
|
-
range: [0, Number("0xffffffff")],
|
|
393
|
-
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
394
|
-
get: (view, le) => view.getUint32(0, le),
|
|
395
|
-
options
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
|
|
399
|
-
init_env_shim();
|
|
400
|
-
var shortU16 = (options = {}) => ({
|
|
401
|
-
description: options.description ?? "shortU16",
|
|
402
|
-
fixedSize: null,
|
|
403
|
-
maxSize: 3,
|
|
404
|
-
serialize: (value) => {
|
|
405
|
-
assertRange("shortU16", 0, 65535, value);
|
|
406
|
-
const bytes2 = [0];
|
|
407
|
-
for (let ii = 0; ; ii += 1) {
|
|
408
|
-
const alignedValue = value >> ii * 7;
|
|
409
|
-
if (alignedValue === 0) {
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
412
|
-
const nextSevenBits = 127 & alignedValue;
|
|
413
|
-
bytes2[ii] = nextSevenBits;
|
|
414
|
-
if (ii > 0) {
|
|
415
|
-
bytes2[ii - 1] |= 128;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return new Uint8Array(bytes2);
|
|
419
|
-
},
|
|
420
|
-
deserialize: (bytes2, offset = 0) => {
|
|
421
|
-
let value = 0;
|
|
422
|
-
let byteCount = 0;
|
|
423
|
-
while (++byteCount) {
|
|
424
|
-
const byteIndex = byteCount - 1;
|
|
425
|
-
const currentByte = bytes2[offset + byteIndex];
|
|
426
|
-
const nextSevenBits = 127 & currentByte;
|
|
427
|
-
value |= nextSevenBits << byteIndex * 7;
|
|
428
|
-
if ((currentByte & 128) === 0) {
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
return [value, offset + byteCount];
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
|
|
437
|
-
init_env_shim();
|
|
438
|
-
|
|
439
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
|
|
440
|
-
init_env_shim();
|
|
441
|
-
var InvalidNumberOfItemsError = class extends Error {
|
|
442
|
-
constructor(serializer, expected, actual) {
|
|
443
|
-
super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
|
|
444
|
-
__publicField(this, "name", "InvalidNumberOfItemsError");
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
var InvalidArrayLikeRemainderSizeError = class extends Error {
|
|
448
|
-
constructor(remainderSize, itemSize) {
|
|
449
|
-
super(`The remainder of the buffer (${remainderSize} bytes) cannot be split into chunks of ${itemSize} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainderSize} modulo ${itemSize} should be equal to zero.`);
|
|
450
|
-
__publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
|
|
454
|
-
constructor(size) {
|
|
455
|
-
super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
|
|
456
|
-
__publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
461
|
-
init_env_shim();
|
|
462
|
-
|
|
463
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
|
|
464
|
-
init_env_shim();
|
|
465
|
-
function sumSerializerSizes(sizes) {
|
|
466
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
470
|
-
function getResolvedSize(size, childrenSizes, bytes2, offset) {
|
|
471
|
-
if (typeof size === "number") {
|
|
472
|
-
return [size, offset];
|
|
473
|
-
}
|
|
474
|
-
if (typeof size === "object") {
|
|
475
|
-
return size.deserialize(bytes2, offset);
|
|
476
|
-
}
|
|
477
|
-
if (size === "remainder") {
|
|
478
|
-
const childrenSize = sumSerializerSizes(childrenSizes);
|
|
479
|
-
if (childrenSize === null) {
|
|
480
|
-
throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
|
|
481
|
-
}
|
|
482
|
-
const remainder = bytes2.slice(offset).length;
|
|
483
|
-
if (remainder % childrenSize !== 0) {
|
|
484
|
-
throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
|
|
485
|
-
}
|
|
486
|
-
return [remainder / childrenSize, offset];
|
|
487
|
-
}
|
|
488
|
-
throw new UnrecognizedArrayLikeSerializerSizeError(size);
|
|
489
|
-
}
|
|
490
|
-
function getSizeDescription(size) {
|
|
491
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
492
|
-
}
|
|
493
|
-
function getSizeFromChildren(size, childrenSizes) {
|
|
494
|
-
if (typeof size !== "number")
|
|
495
|
-
return null;
|
|
496
|
-
if (size === 0)
|
|
497
|
-
return 0;
|
|
498
|
-
const childrenSize = sumSerializerSizes(childrenSizes);
|
|
499
|
-
return childrenSize === null ? null : childrenSize * size;
|
|
500
|
-
}
|
|
501
|
-
function getSizePrefix(size, realSize) {
|
|
502
|
-
return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
|
|
506
|
-
function array(item, options = {}) {
|
|
507
|
-
const size = options.size ?? u32();
|
|
508
|
-
if (size === "remainder" && item.fixedSize === null) {
|
|
509
|
-
throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
|
|
510
|
-
}
|
|
488
|
+
var getUtf8Decoder = () => {
|
|
489
|
+
let textDecoder;
|
|
511
490
|
return {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
serialize: (value) => {
|
|
516
|
-
if (typeof size === "number" && value.length !== size) {
|
|
517
|
-
throw new InvalidNumberOfItemsError("array", size, value.length);
|
|
518
|
-
}
|
|
519
|
-
return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
|
|
491
|
+
decode(bytes, offset = 0) {
|
|
492
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
493
|
+
return [removeNullCharacters(value), bytes.length];
|
|
520
494
|
},
|
|
521
|
-
|
|
522
|
-
if (typeof size === "object" && bytes2.slice(offset).length === 0) {
|
|
523
|
-
return [[], offset];
|
|
524
|
-
}
|
|
525
|
-
const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
|
|
526
|
-
offset = newOffset;
|
|
527
|
-
const values = [];
|
|
528
|
-
for (let i = 0; i < resolvedSize; i += 1) {
|
|
529
|
-
const [value, newOffset2] = item.deserialize(bytes2, offset);
|
|
530
|
-
values.push(value);
|
|
531
|
-
offset = newOffset2;
|
|
532
|
-
}
|
|
533
|
-
return [values, offset];
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
|
|
539
|
-
init_env_shim();
|
|
540
|
-
function bytes(options = {}) {
|
|
541
|
-
const size = options.size ?? "variable";
|
|
542
|
-
const description = options.description ?? `bytes(${getSizeDescription(size)})`;
|
|
543
|
-
const byteSerializer = {
|
|
544
|
-
description,
|
|
495
|
+
description: "utf8",
|
|
545
496
|
fixedSize: null,
|
|
546
|
-
maxSize: null
|
|
547
|
-
serialize: (value) => new Uint8Array(value),
|
|
548
|
-
deserialize: (bytes2, offset = 0) => {
|
|
549
|
-
const slice = bytes2.slice(offset);
|
|
550
|
-
return [slice, offset + slice.length];
|
|
551
|
-
}
|
|
497
|
+
maxSize: null
|
|
552
498
|
};
|
|
499
|
+
};
|
|
500
|
+
var getStringEncoder = (config = {}) => {
|
|
501
|
+
var _a, _b, _c;
|
|
502
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
503
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
|
|
504
|
+
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
553
505
|
if (size === "variable") {
|
|
554
|
-
return
|
|
506
|
+
return { ...encoding, description };
|
|
555
507
|
}
|
|
556
508
|
if (typeof size === "number") {
|
|
557
|
-
return
|
|
509
|
+
return fixEncoder(encoding, size, description);
|
|
558
510
|
}
|
|
559
511
|
return {
|
|
560
512
|
description,
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const contentBytes = byteSerializer.serialize(value);
|
|
565
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
513
|
+
encode: (value) => {
|
|
514
|
+
const contentBytes = encoding.encode(value);
|
|
515
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
566
516
|
return mergeBytes([lengthBytes, contentBytes]);
|
|
567
517
|
},
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
throw new DeserializingEmptyBufferError("bytes");
|
|
571
|
-
}
|
|
572
|
-
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
573
|
-
const length = Number(lengthBigInt);
|
|
574
|
-
offset = lengthOffset;
|
|
575
|
-
const contentBuffer = buffer.slice(offset, offset + length);
|
|
576
|
-
if (contentBuffer.length < length) {
|
|
577
|
-
throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
|
|
578
|
-
}
|
|
579
|
-
const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
|
|
580
|
-
offset += contentOffset;
|
|
581
|
-
return [value, offset];
|
|
582
|
-
}
|
|
518
|
+
fixedSize: null,
|
|
519
|
+
maxSize: null
|
|
583
520
|
};
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
const
|
|
590
|
-
const encoding = options.encoding ?? utf8;
|
|
591
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
521
|
+
};
|
|
522
|
+
var getStringDecoder = (config = {}) => {
|
|
523
|
+
var _a, _b, _c;
|
|
524
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
525
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
|
|
526
|
+
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
592
527
|
if (size === "variable") {
|
|
593
|
-
return {
|
|
594
|
-
...encoding,
|
|
595
|
-
description
|
|
596
|
-
};
|
|
528
|
+
return { ...encoding, description };
|
|
597
529
|
}
|
|
598
530
|
if (typeof size === "number") {
|
|
599
|
-
return
|
|
531
|
+
return fixDecoder(encoding, size, description);
|
|
600
532
|
}
|
|
601
533
|
return {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
serialize: (value) => {
|
|
606
|
-
const contentBytes = encoding.serialize(value);
|
|
607
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
608
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
609
|
-
},
|
|
610
|
-
deserialize: (buffer, offset = 0) => {
|
|
611
|
-
if (buffer.slice(offset).length === 0) {
|
|
612
|
-
throw new DeserializingEmptyBufferError("string");
|
|
613
|
-
}
|
|
614
|
-
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
534
|
+
decode: (bytes, offset = 0) => {
|
|
535
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
536
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
615
537
|
const length = Number(lengthBigInt);
|
|
616
538
|
offset = lengthOffset;
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
621
|
-
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
539
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
540
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
541
|
+
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
622
542
|
offset += contentOffset;
|
|
623
543
|
return [value, offset];
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
|
|
629
|
-
init_env_shim();
|
|
630
|
-
function struct(fields, options = {}) {
|
|
631
|
-
const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
|
|
632
|
-
return {
|
|
633
|
-
description: options.description ?? `struct(${fieldDescriptions})`,
|
|
634
|
-
fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
|
|
635
|
-
maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
|
|
636
|
-
serialize: (struct2) => {
|
|
637
|
-
const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
|
|
638
|
-
return mergeBytes(fieldBytes);
|
|
639
544
|
},
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
const [value, newOffset] = serializer.deserialize(bytes2, offset);
|
|
644
|
-
offset = newOffset;
|
|
645
|
-
struct2[key] = value;
|
|
646
|
-
});
|
|
647
|
-
return [struct2, offset];
|
|
648
|
-
}
|
|
545
|
+
description,
|
|
546
|
+
fixedSize: null,
|
|
547
|
+
maxSize: null
|
|
649
548
|
};
|
|
549
|
+
};
|
|
550
|
+
function getSizeDescription(size) {
|
|
551
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
650
552
|
}
|
|
651
553
|
|
|
652
554
|
// ../assertions/dist/index.browser.js
|
|
@@ -681,14 +583,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
681
583
|
}
|
|
682
584
|
}
|
|
683
585
|
async function assertDigestCapabilityIsAvailable() {
|
|
586
|
+
var _a;
|
|
684
587
|
assertIsSecureContext();
|
|
685
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
588
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.digest) !== "function") {
|
|
686
589
|
throw new Error("No digest implementation could be found");
|
|
687
590
|
}
|
|
688
591
|
}
|
|
689
592
|
async function assertKeyGenerationIsAvailable() {
|
|
593
|
+
var _a;
|
|
690
594
|
assertIsSecureContext();
|
|
691
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
595
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.generateKey) !== "function") {
|
|
692
596
|
throw new Error("No key generation implementation could be found");
|
|
693
597
|
}
|
|
694
598
|
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
@@ -698,51 +602,104 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
698
602
|
}
|
|
699
603
|
}
|
|
700
604
|
async function assertKeyExporterIsAvailable() {
|
|
605
|
+
var _a;
|
|
701
606
|
assertIsSecureContext();
|
|
702
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
607
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
|
|
703
608
|
throw new Error("No key export implementation could be found");
|
|
704
609
|
}
|
|
705
610
|
}
|
|
706
611
|
async function assertSigningCapabilityIsAvailable() {
|
|
612
|
+
var _a;
|
|
707
613
|
assertIsSecureContext();
|
|
708
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
614
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
|
|
709
615
|
throw new Error("No signing implementation could be found");
|
|
710
616
|
}
|
|
711
617
|
}
|
|
712
618
|
async function assertVerificationCapabilityIsAvailable() {
|
|
619
|
+
var _a;
|
|
713
620
|
assertIsSecureContext();
|
|
714
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
621
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.verify) !== "function") {
|
|
715
622
|
throw new Error("No signature verification implementation could be found");
|
|
716
623
|
}
|
|
717
624
|
}
|
|
718
|
-
|
|
625
|
+
|
|
626
|
+
// ../addresses/dist/index.browser.js
|
|
627
|
+
var memoizedBase58Encoder;
|
|
628
|
+
var memoizedBase58Decoder;
|
|
629
|
+
function getMemoizedBase58Encoder() {
|
|
630
|
+
if (!memoizedBase58Encoder)
|
|
631
|
+
memoizedBase58Encoder = getBase58Encoder();
|
|
632
|
+
return memoizedBase58Encoder;
|
|
633
|
+
}
|
|
634
|
+
function getMemoizedBase58Decoder() {
|
|
635
|
+
if (!memoizedBase58Decoder)
|
|
636
|
+
memoizedBase58Decoder = getBase58Decoder();
|
|
637
|
+
return memoizedBase58Decoder;
|
|
638
|
+
}
|
|
639
|
+
function isAddress(putativeAddress) {
|
|
640
|
+
if (
|
|
641
|
+
// Lowest address (32 bytes of zeroes)
|
|
642
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
643
|
+
putativeAddress.length > 44
|
|
644
|
+
) {
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
const base58Encoder3 = getMemoizedBase58Encoder();
|
|
648
|
+
const bytes = base58Encoder3.encode(putativeAddress);
|
|
649
|
+
const numBytes = bytes.byteLength;
|
|
650
|
+
if (numBytes !== 32) {
|
|
651
|
+
return false;
|
|
652
|
+
}
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
function assertIsAddress(putativeAddress) {
|
|
719
656
|
try {
|
|
720
657
|
if (
|
|
721
658
|
// Lowest address (32 bytes of zeroes)
|
|
722
|
-
|
|
723
|
-
|
|
659
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
660
|
+
putativeAddress.length > 44
|
|
724
661
|
) {
|
|
725
662
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
726
663
|
}
|
|
727
|
-
const
|
|
728
|
-
const
|
|
664
|
+
const base58Encoder3 = getMemoizedBase58Encoder();
|
|
665
|
+
const bytes = base58Encoder3.encode(putativeAddress);
|
|
666
|
+
const numBytes = bytes.byteLength;
|
|
729
667
|
if (numBytes !== 32) {
|
|
730
668
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
731
669
|
}
|
|
732
|
-
} catch (
|
|
733
|
-
throw new Error(`\`${
|
|
734
|
-
cause:
|
|
670
|
+
} catch (e3) {
|
|
671
|
+
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
672
|
+
cause: e3
|
|
735
673
|
});
|
|
736
674
|
}
|
|
737
675
|
}
|
|
738
|
-
function
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
676
|
+
function address(putativeAddress) {
|
|
677
|
+
assertIsAddress(putativeAddress);
|
|
678
|
+
return putativeAddress;
|
|
679
|
+
}
|
|
680
|
+
function getAddressEncoder(config) {
|
|
681
|
+
var _a;
|
|
682
|
+
return mapEncoder(
|
|
683
|
+
getStringEncoder({
|
|
684
|
+
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
685
|
+
encoding: getMemoizedBase58Encoder(),
|
|
686
|
+
size: 32
|
|
687
|
+
}),
|
|
688
|
+
(putativeAddress) => address(putativeAddress)
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
function getAddressDecoder(config) {
|
|
692
|
+
var _a;
|
|
693
|
+
return getStringDecoder({
|
|
694
|
+
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
695
|
+
encoding: getMemoizedBase58Decoder(),
|
|
742
696
|
size: 32
|
|
743
697
|
});
|
|
744
698
|
}
|
|
745
|
-
function
|
|
699
|
+
function getAddressCodec(config) {
|
|
700
|
+
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
|
|
701
|
+
}
|
|
702
|
+
function getAddressComparator() {
|
|
746
703
|
return new Intl.Collator("en", {
|
|
747
704
|
caseFirst: "lower",
|
|
748
705
|
ignorePunctuation: false,
|
|
@@ -826,17 +783,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
826
783
|
return hexString;
|
|
827
784
|
}
|
|
828
785
|
}
|
|
829
|
-
function decompressPointBytes(
|
|
830
|
-
const hexString =
|
|
786
|
+
function decompressPointBytes(bytes) {
|
|
787
|
+
const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
|
|
831
788
|
const integerLiteralString = `0x${hexString}`;
|
|
832
789
|
return BigInt(integerLiteralString);
|
|
833
790
|
}
|
|
834
|
-
async function compressedPointBytesAreOnCurve(
|
|
835
|
-
if (
|
|
791
|
+
async function compressedPointBytesAreOnCurve(bytes) {
|
|
792
|
+
if (bytes.byteLength !== 32) {
|
|
836
793
|
return false;
|
|
837
794
|
}
|
|
838
|
-
const y = decompressPointBytes(
|
|
839
|
-
return pointIsOnCurve(y,
|
|
795
|
+
const y = decompressPointBytes(bytes);
|
|
796
|
+
return pointIsOnCurve(y, bytes[31]);
|
|
797
|
+
}
|
|
798
|
+
function isProgramDerivedAddress(value) {
|
|
799
|
+
return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
|
|
800
|
+
}
|
|
801
|
+
function assertIsProgramDerivedAddress(value) {
|
|
802
|
+
const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
|
|
803
|
+
if (!validFormat) {
|
|
804
|
+
throw new Error(
|
|
805
|
+
`Expected given program derived address to have the following format: [Address, ProgramDerivedAddressBump].`
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
if (value[1] < 0 || value[1] > 255) {
|
|
809
|
+
throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${value[1]}.`);
|
|
810
|
+
}
|
|
811
|
+
assertIsAddress(value[0]);
|
|
840
812
|
}
|
|
841
813
|
var MAX_SEED_LENGTH = 32;
|
|
842
814
|
var MAX_SEEDS = 16;
|
|
@@ -873,15 +845,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
873
845
|
}
|
|
874
846
|
let textEncoder;
|
|
875
847
|
const seedBytes = seeds.reduce((acc, seed, ii) => {
|
|
876
|
-
const
|
|
877
|
-
if (
|
|
848
|
+
const bytes = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
|
|
849
|
+
if (bytes.byteLength > MAX_SEED_LENGTH) {
|
|
878
850
|
throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
|
|
879
851
|
}
|
|
880
|
-
acc.push(...
|
|
852
|
+
acc.push(...bytes);
|
|
881
853
|
return acc;
|
|
882
854
|
}, []);
|
|
883
|
-
const base58EncodedAddressCodec =
|
|
884
|
-
const programAddressBytes = base58EncodedAddressCodec.
|
|
855
|
+
const base58EncodedAddressCodec = getAddressCodec();
|
|
856
|
+
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
|
|
885
857
|
const addressBytesBuffer = await crypto.subtle.digest(
|
|
886
858
|
"SHA-256",
|
|
887
859
|
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
@@ -890,36 +862,54 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
890
862
|
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
891
863
|
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
892
864
|
}
|
|
893
|
-
return base58EncodedAddressCodec.
|
|
865
|
+
return base58EncodedAddressCodec.decode(addressBytes)[0];
|
|
894
866
|
}
|
|
895
|
-
async function getProgramDerivedAddress({
|
|
867
|
+
async function getProgramDerivedAddress({
|
|
868
|
+
programAddress,
|
|
869
|
+
seeds
|
|
870
|
+
}) {
|
|
896
871
|
let bumpSeed = 255;
|
|
897
872
|
while (bumpSeed > 0) {
|
|
898
873
|
try {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
} catch (e2) {
|
|
907
|
-
if (e2 instanceof PointOnCurveError) {
|
|
874
|
+
const address2 = await createProgramDerivedAddress({
|
|
875
|
+
programAddress,
|
|
876
|
+
seeds: [...seeds, new Uint8Array([bumpSeed])]
|
|
877
|
+
});
|
|
878
|
+
return [address2, bumpSeed];
|
|
879
|
+
} catch (e3) {
|
|
880
|
+
if (e3 instanceof PointOnCurveError) {
|
|
908
881
|
bumpSeed--;
|
|
909
882
|
} else {
|
|
910
|
-
throw
|
|
883
|
+
throw e3;
|
|
911
884
|
}
|
|
912
885
|
}
|
|
913
886
|
}
|
|
914
887
|
throw new Error("Unable to find a viable program address bump seed");
|
|
915
888
|
}
|
|
889
|
+
async function createAddressWithSeed({ baseAddress, programAddress, seed }) {
|
|
890
|
+
const { encode: encode2, decode: decode2 } = getAddressCodec();
|
|
891
|
+
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
892
|
+
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
893
|
+
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
894
|
+
}
|
|
895
|
+
const programAddressBytes = encode2(programAddress);
|
|
896
|
+
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
897
|
+
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
898
|
+
}
|
|
899
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
900
|
+
"SHA-256",
|
|
901
|
+
new Uint8Array([...encode2(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
902
|
+
);
|
|
903
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
904
|
+
return decode2(addressBytes)[0];
|
|
905
|
+
}
|
|
916
906
|
async function getAddressFromPublicKey(publicKey) {
|
|
917
907
|
await assertKeyExporterIsAvailable();
|
|
918
908
|
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
919
909
|
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
920
910
|
}
|
|
921
911
|
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
922
|
-
const [base58EncodedAddress] =
|
|
912
|
+
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
923
913
|
return base58EncodedAddress;
|
|
924
914
|
}
|
|
925
915
|
|
|
@@ -976,18 +966,344 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
976
966
|
);
|
|
977
967
|
return keyPair;
|
|
978
968
|
}
|
|
969
|
+
var base58Encoder;
|
|
970
|
+
function assertIsSignature(putativeSignature) {
|
|
971
|
+
if (!base58Encoder)
|
|
972
|
+
base58Encoder = getBase58Encoder();
|
|
973
|
+
try {
|
|
974
|
+
if (
|
|
975
|
+
// Lowest value (64 bytes of zeroes)
|
|
976
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
977
|
+
putativeSignature.length > 88
|
|
978
|
+
) {
|
|
979
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
980
|
+
}
|
|
981
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
982
|
+
const numBytes = bytes.byteLength;
|
|
983
|
+
if (numBytes !== 64) {
|
|
984
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
985
|
+
}
|
|
986
|
+
} catch (e3) {
|
|
987
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
988
|
+
cause: e3
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
function isSignature(putativeSignature) {
|
|
993
|
+
if (!base58Encoder)
|
|
994
|
+
base58Encoder = getBase58Encoder();
|
|
995
|
+
if (
|
|
996
|
+
// Lowest value (64 bytes of zeroes)
|
|
997
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
998
|
+
putativeSignature.length > 88
|
|
999
|
+
) {
|
|
1000
|
+
return false;
|
|
1001
|
+
}
|
|
1002
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
1003
|
+
const numBytes = bytes.byteLength;
|
|
1004
|
+
if (numBytes !== 64) {
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
return true;
|
|
1008
|
+
}
|
|
979
1009
|
async function signBytes(key, data) {
|
|
980
1010
|
await assertSigningCapabilityIsAvailable();
|
|
981
1011
|
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
982
1012
|
return new Uint8Array(signedData);
|
|
983
1013
|
}
|
|
984
|
-
|
|
1014
|
+
function signature(putativeSignature) {
|
|
1015
|
+
assertIsSignature(putativeSignature);
|
|
1016
|
+
return putativeSignature;
|
|
1017
|
+
}
|
|
1018
|
+
async function verifySignature(key, signature2, data) {
|
|
985
1019
|
await assertVerificationCapabilityIsAvailable();
|
|
986
|
-
return await crypto.subtle.verify("Ed25519", key,
|
|
1020
|
+
return await crypto.subtle.verify("Ed25519", key, signature2, data);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// ../rpc-types/dist/index.browser.js
|
|
1024
|
+
init_env_shim();
|
|
1025
|
+
function getCommitmentScore(commitment) {
|
|
1026
|
+
switch (commitment) {
|
|
1027
|
+
case "finalized":
|
|
1028
|
+
return 2;
|
|
1029
|
+
case "confirmed":
|
|
1030
|
+
return 1;
|
|
1031
|
+
case "processed":
|
|
1032
|
+
return 0;
|
|
1033
|
+
default:
|
|
1034
|
+
return ((_) => {
|
|
1035
|
+
throw new Error(`Unrecognized commitment \`${commitment}\`.`);
|
|
1036
|
+
})();
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
function commitmentComparator(a, b) {
|
|
1040
|
+
if (a === b) {
|
|
1041
|
+
return 0;
|
|
1042
|
+
}
|
|
1043
|
+
return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
|
|
1044
|
+
}
|
|
1045
|
+
var maxU64Value = 18446744073709551615n;
|
|
1046
|
+
function isLamports(putativeLamports) {
|
|
1047
|
+
return putativeLamports >= 0 && putativeLamports <= maxU64Value;
|
|
1048
|
+
}
|
|
1049
|
+
function assertIsLamports(putativeLamports) {
|
|
1050
|
+
if (putativeLamports < 0) {
|
|
1051
|
+
throw new Error("Input for 64-bit unsigned integer cannot be negative");
|
|
1052
|
+
}
|
|
1053
|
+
if (putativeLamports > maxU64Value) {
|
|
1054
|
+
throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
function lamports(putativeLamports) {
|
|
1058
|
+
assertIsLamports(putativeLamports);
|
|
1059
|
+
return putativeLamports;
|
|
1060
|
+
}
|
|
1061
|
+
function isStringifiedBigInt(putativeBigInt) {
|
|
1062
|
+
try {
|
|
1063
|
+
BigInt(putativeBigInt);
|
|
1064
|
+
return true;
|
|
1065
|
+
} catch (_) {
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
function assertIsStringifiedBigInt(putativeBigInt) {
|
|
1070
|
+
try {
|
|
1071
|
+
BigInt(putativeBigInt);
|
|
1072
|
+
} catch (e3) {
|
|
1073
|
+
throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
|
|
1074
|
+
cause: e3
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
function stringifiedBigInt(putativeBigInt) {
|
|
1079
|
+
assertIsStringifiedBigInt(putativeBigInt);
|
|
1080
|
+
return putativeBigInt;
|
|
1081
|
+
}
|
|
1082
|
+
function isStringifiedNumber(putativeNumber) {
|
|
1083
|
+
return !Number.isNaN(Number(putativeNumber));
|
|
1084
|
+
}
|
|
1085
|
+
function assertIsStringifiedNumber(putativeNumber) {
|
|
1086
|
+
if (Number.isNaN(Number(putativeNumber))) {
|
|
1087
|
+
throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
function stringifiedNumber(putativeNumber) {
|
|
1091
|
+
assertIsStringifiedNumber(putativeNumber);
|
|
1092
|
+
return putativeNumber;
|
|
1093
|
+
}
|
|
1094
|
+
function isUnixTimestamp(putativeTimestamp) {
|
|
1095
|
+
if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
|
|
1096
|
+
return false;
|
|
1097
|
+
}
|
|
1098
|
+
return true;
|
|
1099
|
+
}
|
|
1100
|
+
function assertIsUnixTimestamp(putativeTimestamp) {
|
|
1101
|
+
try {
|
|
1102
|
+
if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
|
|
1103
|
+
throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
|
|
1104
|
+
}
|
|
1105
|
+
} catch (e3) {
|
|
1106
|
+
throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
|
|
1107
|
+
cause: e3
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
function unixTimestamp(putativeTimestamp) {
|
|
1112
|
+
assertIsUnixTimestamp(putativeTimestamp);
|
|
1113
|
+
return putativeTimestamp;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// ../transactions/dist/index.browser.js
|
|
1117
|
+
init_env_shim();
|
|
1118
|
+
|
|
1119
|
+
// ../codecs-data-structures/dist/index.browser.js
|
|
1120
|
+
init_env_shim();
|
|
1121
|
+
function sumCodecSizes(sizes) {
|
|
1122
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
1123
|
+
}
|
|
1124
|
+
function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
|
|
1125
|
+
if (typeof size === "number") {
|
|
1126
|
+
return [size, offset];
|
|
1127
|
+
}
|
|
1128
|
+
if (typeof size === "object") {
|
|
1129
|
+
return size.decode(bytes, offset);
|
|
1130
|
+
}
|
|
1131
|
+
if (size === "remainder") {
|
|
1132
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
1133
|
+
if (childrenSize === null) {
|
|
1134
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1135
|
+
}
|
|
1136
|
+
const remainder = bytes.slice(offset).length;
|
|
1137
|
+
if (remainder % childrenSize !== 0) {
|
|
1138
|
+
throw new Error(
|
|
1139
|
+
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${childrenSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${childrenSize} should be equal to zero.`
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
return [remainder / childrenSize, offset];
|
|
1143
|
+
}
|
|
1144
|
+
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
1145
|
+
}
|
|
1146
|
+
function getArrayLikeCodecSizeDescription(size) {
|
|
1147
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
1148
|
+
}
|
|
1149
|
+
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
|
|
1150
|
+
if (typeof size !== "number")
|
|
1151
|
+
return null;
|
|
1152
|
+
if (size === 0)
|
|
1153
|
+
return 0;
|
|
1154
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
1155
|
+
return childrenSize === null ? null : childrenSize * size;
|
|
1156
|
+
}
|
|
1157
|
+
function getArrayLikeCodecSizePrefix(size, realSize) {
|
|
1158
|
+
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
|
|
1159
|
+
}
|
|
1160
|
+
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
1161
|
+
if (expected !== actual) {
|
|
1162
|
+
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
function arrayCodecHelper(item, size, description) {
|
|
1166
|
+
if (size === "remainder" && item.fixedSize === null) {
|
|
1167
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1168
|
+
}
|
|
1169
|
+
return {
|
|
1170
|
+
description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
1171
|
+
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
1172
|
+
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
function getArrayEncoder(item, config = {}) {
|
|
1176
|
+
var _a;
|
|
1177
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
1178
|
+
return {
|
|
1179
|
+
...arrayCodecHelper(item, size, config.description),
|
|
1180
|
+
encode: (value) => {
|
|
1181
|
+
if (typeof size === "number") {
|
|
1182
|
+
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
1183
|
+
}
|
|
1184
|
+
return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
function getArrayDecoder(item, config = {}) {
|
|
1189
|
+
var _a;
|
|
1190
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
1191
|
+
return {
|
|
1192
|
+
...arrayCodecHelper(item, size, config.description),
|
|
1193
|
+
decode: (bytes, offset = 0) => {
|
|
1194
|
+
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
1195
|
+
return [[], offset];
|
|
1196
|
+
}
|
|
1197
|
+
const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
|
|
1198
|
+
offset = newOffset;
|
|
1199
|
+
const values = [];
|
|
1200
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1201
|
+
const [value, newOffset2] = item.decode(bytes, offset);
|
|
1202
|
+
values.push(value);
|
|
1203
|
+
offset = newOffset2;
|
|
1204
|
+
}
|
|
1205
|
+
return [values, offset];
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
function getBytesEncoder(config = {}) {
|
|
1210
|
+
var _a, _b;
|
|
1211
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1212
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
1213
|
+
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
|
|
1214
|
+
const byteEncoder = {
|
|
1215
|
+
description,
|
|
1216
|
+
encode: (value) => value,
|
|
1217
|
+
fixedSize: null,
|
|
1218
|
+
maxSize: null
|
|
1219
|
+
};
|
|
1220
|
+
if (size === "variable") {
|
|
1221
|
+
return byteEncoder;
|
|
1222
|
+
}
|
|
1223
|
+
if (typeof size === "number") {
|
|
1224
|
+
return fixEncoder(byteEncoder, size, description);
|
|
1225
|
+
}
|
|
1226
|
+
return {
|
|
1227
|
+
...byteEncoder,
|
|
1228
|
+
encode: (value) => {
|
|
1229
|
+
const contentBytes = byteEncoder.encode(value);
|
|
1230
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
1231
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
function getBytesDecoder(config = {}) {
|
|
1236
|
+
var _a, _b;
|
|
1237
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1238
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
1239
|
+
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
|
|
1240
|
+
const byteDecoder = {
|
|
1241
|
+
decode: (bytes, offset = 0) => {
|
|
1242
|
+
const slice = bytes.slice(offset);
|
|
1243
|
+
return [slice, offset + slice.length];
|
|
1244
|
+
},
|
|
1245
|
+
description,
|
|
1246
|
+
fixedSize: null,
|
|
1247
|
+
maxSize: null
|
|
1248
|
+
};
|
|
1249
|
+
if (size === "variable") {
|
|
1250
|
+
return byteDecoder;
|
|
1251
|
+
}
|
|
1252
|
+
if (typeof size === "number") {
|
|
1253
|
+
return fixDecoder(byteDecoder, size, description);
|
|
1254
|
+
}
|
|
1255
|
+
return {
|
|
1256
|
+
...byteDecoder,
|
|
1257
|
+
decode: (bytes, offset = 0) => {
|
|
1258
|
+
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
1259
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
1260
|
+
const length = Number(lengthBigInt);
|
|
1261
|
+
offset = lengthOffset;
|
|
1262
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
1263
|
+
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
1264
|
+
const [value, contentOffset] = byteDecoder.decode(contentBytes);
|
|
1265
|
+
offset += contentOffset;
|
|
1266
|
+
return [value, offset];
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
function structCodecHelper(fields, description) {
|
|
1271
|
+
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
1272
|
+
return {
|
|
1273
|
+
description: description != null ? description : `struct(${fieldDescriptions})`,
|
|
1274
|
+
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
1275
|
+
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
function getStructEncoder(fields, config = {}) {
|
|
1279
|
+
return {
|
|
1280
|
+
...structCodecHelper(fields, config.description),
|
|
1281
|
+
encode: (struct) => {
|
|
1282
|
+
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
1283
|
+
return mergeBytes(fieldBytes);
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
function getStructDecoder(fields, config = {}) {
|
|
1288
|
+
return {
|
|
1289
|
+
...structCodecHelper(fields, config.description),
|
|
1290
|
+
decode: (bytes, offset = 0) => {
|
|
1291
|
+
const struct = {};
|
|
1292
|
+
fields.forEach(([key, codec]) => {
|
|
1293
|
+
const [value, newOffset] = codec.decode(bytes, offset);
|
|
1294
|
+
offset = newOffset;
|
|
1295
|
+
struct[key] = value;
|
|
1296
|
+
});
|
|
1297
|
+
return [struct, offset];
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
987
1300
|
}
|
|
988
1301
|
|
|
989
|
-
// ../
|
|
1302
|
+
// ../functional/dist/index.browser.js
|
|
990
1303
|
init_env_shim();
|
|
1304
|
+
function pipe(init, ...fns) {
|
|
1305
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1306
|
+
}
|
|
991
1307
|
function getUnsignedTransaction(transaction) {
|
|
992
1308
|
if ("signatures" in transaction) {
|
|
993
1309
|
const {
|
|
@@ -1000,7 +1316,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1000
1316
|
return transaction;
|
|
1001
1317
|
}
|
|
1002
1318
|
}
|
|
1319
|
+
var base58Encoder2;
|
|
1003
1320
|
function assertIsBlockhash(putativeBlockhash) {
|
|
1321
|
+
if (!base58Encoder2)
|
|
1322
|
+
base58Encoder2 = getBase58Encoder();
|
|
1004
1323
|
try {
|
|
1005
1324
|
if (
|
|
1006
1325
|
// Lowest value (32 bytes of zeroes)
|
|
@@ -1009,14 +1328,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1009
1328
|
) {
|
|
1010
1329
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
1011
1330
|
}
|
|
1012
|
-
const
|
|
1013
|
-
const numBytes =
|
|
1331
|
+
const bytes = base58Encoder2.encode(putativeBlockhash);
|
|
1332
|
+
const numBytes = bytes.byteLength;
|
|
1014
1333
|
if (numBytes !== 32) {
|
|
1015
1334
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
1016
1335
|
}
|
|
1017
|
-
} catch (
|
|
1336
|
+
} catch (e3) {
|
|
1018
1337
|
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
1019
|
-
cause:
|
|
1338
|
+
cause: e3
|
|
1020
1339
|
});
|
|
1021
1340
|
}
|
|
1022
1341
|
}
|
|
@@ -1084,12 +1403,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1084
1403
|
};
|
|
1085
1404
|
}
|
|
1086
1405
|
function isAdvanceNonceAccountInstruction(instruction) {
|
|
1406
|
+
var _a;
|
|
1087
1407
|
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
1088
1408
|
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
1089
|
-
instruction.accounts
|
|
1409
|
+
((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
|
|
1090
1410
|
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
|
|
1091
1411
|
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
|
|
1092
|
-
instruction.accounts[2].address != null && instruction.accounts[2].role
|
|
1412
|
+
instruction.accounts[2].address != null && isSignerRole2(instruction.accounts[2].role);
|
|
1093
1413
|
}
|
|
1094
1414
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
1095
1415
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
@@ -1097,21 +1417,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1097
1417
|
function isDurableNonceTransaction(transaction) {
|
|
1098
1418
|
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
1099
1419
|
}
|
|
1420
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
1421
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
1422
|
+
}
|
|
1100
1423
|
function setTransactionLifetimeUsingDurableNonce({
|
|
1101
1424
|
nonce,
|
|
1102
1425
|
nonceAccountAddress,
|
|
1103
1426
|
nonceAuthorityAddress
|
|
1104
1427
|
}, transaction) {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1428
|
+
let newInstructions;
|
|
1429
|
+
const firstInstruction = transaction.instructions[0];
|
|
1430
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1431
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
1432
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
1433
|
+
return transaction;
|
|
1434
|
+
} else {
|
|
1435
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
1436
|
+
}
|
|
1437
|
+
} else {
|
|
1438
|
+
newInstructions = [
|
|
1439
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1440
|
+
...transaction.instructions.slice(1)
|
|
1441
|
+
];
|
|
1442
|
+
}
|
|
1443
|
+
} else {
|
|
1444
|
+
newInstructions = [
|
|
1445
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1446
|
+
...transaction.instructions
|
|
1447
|
+
];
|
|
1108
1448
|
}
|
|
1109
1449
|
const out = {
|
|
1110
1450
|
...getUnsignedTransaction(transaction),
|
|
1111
|
-
instructions:
|
|
1112
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1113
|
-
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
1114
|
-
],
|
|
1451
|
+
instructions: newInstructions,
|
|
1115
1452
|
lifetimeConstraint: {
|
|
1116
1453
|
nonce
|
|
1117
1454
|
}
|
|
@@ -1146,8 +1483,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1146
1483
|
Object.freeze(out);
|
|
1147
1484
|
return out;
|
|
1148
1485
|
}
|
|
1149
|
-
function upsert(addressMap,
|
|
1150
|
-
|
|
1486
|
+
function upsert(addressMap, address2, update) {
|
|
1487
|
+
var _a;
|
|
1488
|
+
addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole2.READONLY });
|
|
1151
1489
|
}
|
|
1152
1490
|
var TYPE = Symbol("AddressMapTypeProperty");
|
|
1153
1491
|
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
@@ -1198,7 +1536,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1198
1536
|
const shouldReplaceEntry = (
|
|
1199
1537
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
1200
1538
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
1201
|
-
(addressComparator || (addressComparator =
|
|
1539
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
1202
1540
|
accountMeta.lookupTableAddress,
|
|
1203
1541
|
entry.lookupTableAddress
|
|
1204
1542
|
) < 0
|
|
@@ -1306,14 +1644,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1306
1644
|
if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
|
|
1307
1645
|
return leftIsWritable ? -1 : 1;
|
|
1308
1646
|
}
|
|
1309
|
-
addressComparator || (addressComparator =
|
|
1647
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
1310
1648
|
if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
1311
1649
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
1312
1650
|
} else {
|
|
1313
1651
|
return addressComparator(leftAddress, rightAddress);
|
|
1314
1652
|
}
|
|
1315
|
-
}).map(([
|
|
1316
|
-
address,
|
|
1653
|
+
}).map(([address2, addressMeta]) => ({
|
|
1654
|
+
address: address2,
|
|
1317
1655
|
...addressMeta
|
|
1318
1656
|
}));
|
|
1319
1657
|
return orderedAccounts;
|
|
@@ -1335,7 +1673,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1335
1673
|
entry.readableIndices.push(account.addressIndex);
|
|
1336
1674
|
}
|
|
1337
1675
|
}
|
|
1338
|
-
return Object.keys(index).sort(
|
|
1676
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
1339
1677
|
lookupTableAddress,
|
|
1340
1678
|
...index[lookupTableAddress]
|
|
1341
1679
|
}));
|
|
@@ -1376,7 +1714,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1376
1714
|
return instructions.map(({ accounts, data, programAddress }) => {
|
|
1377
1715
|
return {
|
|
1378
1716
|
programAddressIndex: accountIndex[programAddress],
|
|
1379
|
-
...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[
|
|
1717
|
+
...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
|
|
1380
1718
|
...data ? { data } : null
|
|
1381
1719
|
};
|
|
1382
1720
|
});
|
|
@@ -1390,7 +1728,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1390
1728
|
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1391
1729
|
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1392
1730
|
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1393
|
-
return orderedStaticAccounts.map(({ address }) =>
|
|
1731
|
+
return orderedStaticAccounts.map(({ address: address2 }) => address2);
|
|
1394
1732
|
}
|
|
1395
1733
|
function compileMessage(transaction) {
|
|
1396
1734
|
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
|
|
@@ -1404,138 +1742,181 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1404
1742
|
version: transaction.version
|
|
1405
1743
|
};
|
|
1406
1744
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1745
|
+
var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
|
|
1746
|
+
var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
|
|
1747
|
+
var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
|
|
1748
|
+
var addressTableLookupDescription = "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" ;
|
|
1749
|
+
var memoizedAddressTableLookupEncoder;
|
|
1750
|
+
function getAddressTableLookupEncoder() {
|
|
1751
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
1752
|
+
memoizedAddressTableLookupEncoder = getStructEncoder(
|
|
1410
1753
|
[
|
|
1411
|
-
"lookupTableAddress",
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1754
|
+
["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
1755
|
+
[
|
|
1756
|
+
"writableIndices",
|
|
1757
|
+
getArrayEncoder(getU8Encoder(), {
|
|
1758
|
+
description: writableIndicesDescription,
|
|
1759
|
+
size: getShortU16Encoder()
|
|
1760
|
+
})
|
|
1761
|
+
],
|
|
1762
|
+
[
|
|
1763
|
+
"readableIndices",
|
|
1764
|
+
getArrayEncoder(getU8Encoder(), {
|
|
1765
|
+
description: readableIndicesDescription,
|
|
1766
|
+
size: getShortU16Encoder()
|
|
1767
|
+
})
|
|
1768
|
+
]
|
|
1417
1769
|
],
|
|
1770
|
+
{ description: addressTableLookupDescription }
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
return memoizedAddressTableLookupEncoder;
|
|
1774
|
+
}
|
|
1775
|
+
var memoizedAddressTableLookupDecoder;
|
|
1776
|
+
function getAddressTableLookupDecoder() {
|
|
1777
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
1778
|
+
memoizedAddressTableLookupDecoder = getStructDecoder(
|
|
1418
1779
|
[
|
|
1419
|
-
"
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1780
|
+
["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
|
|
1781
|
+
[
|
|
1782
|
+
"writableIndices",
|
|
1783
|
+
getArrayDecoder(getU8Decoder(), {
|
|
1784
|
+
description: writableIndicesDescription,
|
|
1785
|
+
size: getShortU16Decoder()
|
|
1786
|
+
})
|
|
1787
|
+
],
|
|
1788
|
+
[
|
|
1789
|
+
"readableIndices",
|
|
1790
|
+
getArrayDecoder(getU8Decoder(), {
|
|
1791
|
+
description: readableIndicesDescription,
|
|
1792
|
+
size: getShortU16Decoder()
|
|
1793
|
+
})
|
|
1794
|
+
]
|
|
1426
1795
|
],
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1796
|
+
{ description: addressTableLookupDescription }
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
return memoizedAddressTableLookupDecoder;
|
|
1800
|
+
}
|
|
1801
|
+
var memoizedU8Encoder;
|
|
1802
|
+
function getMemoizedU8Encoder() {
|
|
1803
|
+
if (!memoizedU8Encoder)
|
|
1804
|
+
memoizedU8Encoder = getU8Encoder();
|
|
1805
|
+
return memoizedU8Encoder;
|
|
1806
|
+
}
|
|
1807
|
+
function getMemoizedU8EncoderDescription(description) {
|
|
1808
|
+
const encoder = getMemoizedU8Encoder();
|
|
1809
|
+
return {
|
|
1810
|
+
...encoder,
|
|
1811
|
+
description: description != null ? description : encoder.description
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
var memoizedU8Decoder;
|
|
1815
|
+
function getMemoizedU8Decoder() {
|
|
1816
|
+
if (!memoizedU8Decoder)
|
|
1817
|
+
memoizedU8Decoder = getU8Decoder();
|
|
1818
|
+
return memoizedU8Decoder;
|
|
1819
|
+
}
|
|
1820
|
+
function getMemoizedU8DecoderDescription(description) {
|
|
1821
|
+
const decoder = getMemoizedU8Decoder();
|
|
1822
|
+
return {
|
|
1823
|
+
...decoder,
|
|
1824
|
+
description: description != null ? description : decoder.description
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
1828
|
+
var numReadonlySignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" ;
|
|
1829
|
+
var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
|
|
1830
|
+
var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
|
|
1831
|
+
function getMessageHeaderEncoder() {
|
|
1832
|
+
return getStructEncoder(
|
|
1833
|
+
[
|
|
1834
|
+
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
1835
|
+
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
1836
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
1436
1837
|
],
|
|
1437
1838
|
{
|
|
1438
|
-
description:
|
|
1439
|
-
}
|
|
1839
|
+
description: messageHeaderDescription
|
|
1840
|
+
}
|
|
1440
1841
|
);
|
|
1441
1842
|
}
|
|
1442
|
-
function
|
|
1443
|
-
return
|
|
1843
|
+
function getMessageHeaderDecoder() {
|
|
1844
|
+
return getStructDecoder(
|
|
1444
1845
|
[
|
|
1445
|
-
[
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
{
|
|
1449
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
1450
|
-
}
|
|
1451
|
-
)
|
|
1452
|
-
],
|
|
1453
|
-
[
|
|
1454
|
-
"numReadonlySignerAccounts",
|
|
1455
|
-
u8(
|
|
1456
|
-
{
|
|
1457
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable"
|
|
1458
|
-
}
|
|
1459
|
-
)
|
|
1460
|
-
],
|
|
1461
|
-
[
|
|
1462
|
-
"numReadonlyNonSignerAccounts",
|
|
1463
|
-
u8(
|
|
1464
|
-
{
|
|
1465
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
1466
|
-
}
|
|
1467
|
-
)
|
|
1468
|
-
]
|
|
1846
|
+
["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
|
|
1847
|
+
["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
|
|
1848
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
1469
1849
|
],
|
|
1470
1850
|
{
|
|
1471
|
-
description:
|
|
1472
|
-
}
|
|
1473
|
-
);
|
|
1474
|
-
}
|
|
1475
|
-
function getInstructionCodec() {
|
|
1476
|
-
return mapSerializer(
|
|
1477
|
-
struct([
|
|
1478
|
-
[
|
|
1479
|
-
"programAddressIndex",
|
|
1480
|
-
u8(
|
|
1481
|
-
{
|
|
1482
|
-
description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
|
|
1483
|
-
}
|
|
1484
|
-
)
|
|
1485
|
-
],
|
|
1486
|
-
[
|
|
1487
|
-
"accountIndices",
|
|
1488
|
-
array(
|
|
1489
|
-
u8({
|
|
1490
|
-
description: "The index of an account, according to the well-ordered accounts list for this transaction"
|
|
1491
|
-
}),
|
|
1492
|
-
{
|
|
1493
|
-
description: "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ,
|
|
1494
|
-
size: shortU16()
|
|
1495
|
-
}
|
|
1496
|
-
)
|
|
1497
|
-
],
|
|
1498
|
-
[
|
|
1499
|
-
"data",
|
|
1500
|
-
bytes({
|
|
1501
|
-
description: "An optional buffer of data passed to the instruction" ,
|
|
1502
|
-
size: shortU16()
|
|
1503
|
-
})
|
|
1504
|
-
]
|
|
1505
|
-
]),
|
|
1506
|
-
(value) => {
|
|
1507
|
-
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
1508
|
-
return value;
|
|
1509
|
-
}
|
|
1510
|
-
return {
|
|
1511
|
-
...value,
|
|
1512
|
-
accountIndices: value.accountIndices ?? [],
|
|
1513
|
-
data: value.data ?? new Uint8Array(0)
|
|
1514
|
-
};
|
|
1515
|
-
},
|
|
1516
|
-
(value) => {
|
|
1517
|
-
if (value.accountIndices.length && value.data.byteLength) {
|
|
1518
|
-
return value;
|
|
1519
|
-
}
|
|
1520
|
-
const { accountIndices, data, ...rest } = value;
|
|
1521
|
-
return {
|
|
1522
|
-
...rest,
|
|
1523
|
-
...accountIndices.length ? { accountIndices } : null,
|
|
1524
|
-
...data.byteLength ? { data } : null
|
|
1525
|
-
};
|
|
1851
|
+
description: messageHeaderDescription
|
|
1526
1852
|
}
|
|
1527
1853
|
);
|
|
1528
1854
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1855
|
+
var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
|
|
1856
|
+
var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
|
|
1857
|
+
var accountIndicesDescription = "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ;
|
|
1858
|
+
var dataDescription = "An optional buffer of data passed to the instruction" ;
|
|
1859
|
+
var memoizedGetInstructionEncoder;
|
|
1860
|
+
function getInstructionEncoder() {
|
|
1861
|
+
if (!memoizedGetInstructionEncoder) {
|
|
1862
|
+
memoizedGetInstructionEncoder = mapEncoder(
|
|
1863
|
+
getStructEncoder([
|
|
1864
|
+
["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
|
|
1865
|
+
[
|
|
1866
|
+
"accountIndices",
|
|
1867
|
+
getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
|
|
1868
|
+
description: accountIndicesDescription,
|
|
1869
|
+
size: getShortU16Encoder()
|
|
1870
|
+
})
|
|
1871
|
+
],
|
|
1872
|
+
["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
|
|
1873
|
+
]),
|
|
1874
|
+
// Convert an instruction to have all fields defined
|
|
1875
|
+
(instruction) => {
|
|
1876
|
+
var _a, _b;
|
|
1877
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
1878
|
+
return instruction;
|
|
1879
|
+
}
|
|
1880
|
+
return {
|
|
1881
|
+
...instruction,
|
|
1882
|
+
accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
|
|
1883
|
+
data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
);
|
|
1887
|
+
}
|
|
1888
|
+
return memoizedGetInstructionEncoder;
|
|
1534
1889
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1890
|
+
var memoizedGetInstructionDecoder;
|
|
1891
|
+
function getInstructionDecoder() {
|
|
1892
|
+
if (!memoizedGetInstructionDecoder) {
|
|
1893
|
+
memoizedGetInstructionDecoder = mapDecoder(
|
|
1894
|
+
getStructDecoder([
|
|
1895
|
+
["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
|
|
1896
|
+
[
|
|
1897
|
+
"accountIndices",
|
|
1898
|
+
getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
|
|
1899
|
+
description: accountIndicesDescription,
|
|
1900
|
+
size: getShortU16Decoder()
|
|
1901
|
+
})
|
|
1902
|
+
],
|
|
1903
|
+
["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
|
|
1904
|
+
]),
|
|
1905
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
1906
|
+
(instruction) => {
|
|
1907
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
1908
|
+
return instruction;
|
|
1909
|
+
}
|
|
1910
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
1911
|
+
return {
|
|
1912
|
+
...rest,
|
|
1913
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
1914
|
+
...data.byteLength ? { data } : null
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
);
|
|
1918
|
+
}
|
|
1919
|
+
return memoizedGetInstructionDecoder;
|
|
1539
1920
|
}
|
|
1540
1921
|
var VERSION_FLAG_MASK = 128;
|
|
1541
1922
|
var BASE_CONFIG = {
|
|
@@ -1543,8 +1924,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1543
1924
|
fixedSize: null,
|
|
1544
1925
|
maxSize: 1
|
|
1545
1926
|
};
|
|
1546
|
-
function
|
|
1547
|
-
const firstByte =
|
|
1927
|
+
function decode(bytes, offset = 0) {
|
|
1928
|
+
const firstByte = bytes[offset];
|
|
1548
1929
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1549
1930
|
return ["legacy", offset];
|
|
1550
1931
|
} else {
|
|
@@ -1552,7 +1933,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1552
1933
|
return [version, offset + 1];
|
|
1553
1934
|
}
|
|
1554
1935
|
}
|
|
1555
|
-
function
|
|
1936
|
+
function encode(value) {
|
|
1556
1937
|
if (value === "legacy") {
|
|
1557
1938
|
return new Uint8Array();
|
|
1558
1939
|
}
|
|
@@ -1561,109 +1942,151 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1561
1942
|
}
|
|
1562
1943
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1563
1944
|
}
|
|
1564
|
-
function
|
|
1945
|
+
function getTransactionVersionDecoder() {
|
|
1565
1946
|
return {
|
|
1566
1947
|
...BASE_CONFIG,
|
|
1567
|
-
|
|
1568
|
-
serialize
|
|
1948
|
+
decode
|
|
1569
1949
|
};
|
|
1570
1950
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1951
|
+
function getTransactionVersionEncoder() {
|
|
1952
|
+
return {
|
|
1953
|
+
...BASE_CONFIG,
|
|
1954
|
+
encode
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
|
|
1958
|
+
var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
|
|
1959
|
+
var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
|
|
1960
|
+
var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
|
|
1961
|
+
function getCompiledMessageLegacyEncoder() {
|
|
1962
|
+
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
1963
|
+
}
|
|
1964
|
+
function getCompiledMessageVersionedEncoder() {
|
|
1965
|
+
return mapEncoder(
|
|
1966
|
+
getStructEncoder([
|
|
1967
|
+
...getPreludeStructEncoderTuple(),
|
|
1968
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
1969
|
+
]),
|
|
1970
|
+
(value) => {
|
|
1971
|
+
var _a;
|
|
1972
|
+
if (value.version === "legacy") {
|
|
1973
|
+
return value;
|
|
1593
1974
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1975
|
+
return {
|
|
1976
|
+
...value,
|
|
1977
|
+
addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
|
|
1978
|
+
};
|
|
1979
|
+
}
|
|
1980
|
+
);
|
|
1596
1981
|
}
|
|
1597
|
-
function
|
|
1982
|
+
function getPreludeStructEncoderTuple() {
|
|
1598
1983
|
return [
|
|
1599
|
-
["version",
|
|
1600
|
-
["header",
|
|
1984
|
+
["version", getTransactionVersionEncoder()],
|
|
1985
|
+
["header", getMessageHeaderEncoder()],
|
|
1601
1986
|
[
|
|
1602
1987
|
"staticAccounts",
|
|
1603
|
-
|
|
1604
|
-
description:
|
|
1605
|
-
size:
|
|
1988
|
+
getArrayEncoder(getAddressEncoder(), {
|
|
1989
|
+
description: staticAccountsDescription,
|
|
1990
|
+
size: getShortU16Encoder()
|
|
1606
1991
|
})
|
|
1607
1992
|
],
|
|
1608
1993
|
[
|
|
1609
1994
|
"lifetimeToken",
|
|
1610
|
-
|
|
1611
|
-
description:
|
|
1612
|
-
encoding:
|
|
1995
|
+
getStringEncoder({
|
|
1996
|
+
description: lifetimeTokenDescription,
|
|
1997
|
+
encoding: getBase58Encoder(),
|
|
1613
1998
|
size: 32
|
|
1614
1999
|
})
|
|
1615
2000
|
],
|
|
1616
2001
|
[
|
|
1617
2002
|
"instructions",
|
|
1618
|
-
|
|
1619
|
-
description:
|
|
1620
|
-
size:
|
|
2003
|
+
getArrayEncoder(getInstructionEncoder(), {
|
|
2004
|
+
description: instructionsDescription,
|
|
2005
|
+
size: getShortU16Encoder()
|
|
1621
2006
|
})
|
|
1622
2007
|
]
|
|
1623
2008
|
];
|
|
1624
2009
|
}
|
|
1625
|
-
function
|
|
1626
|
-
return
|
|
1627
|
-
|
|
1628
|
-
|
|
2010
|
+
function getPreludeStructDecoderTuple() {
|
|
2011
|
+
return [
|
|
2012
|
+
["version", getTransactionVersionDecoder()],
|
|
2013
|
+
["header", getMessageHeaderDecoder()],
|
|
2014
|
+
[
|
|
2015
|
+
"staticAccounts",
|
|
2016
|
+
getArrayDecoder(getAddressDecoder(), {
|
|
2017
|
+
description: staticAccountsDescription,
|
|
2018
|
+
size: getShortU16Decoder()
|
|
2019
|
+
})
|
|
2020
|
+
],
|
|
2021
|
+
[
|
|
2022
|
+
"lifetimeToken",
|
|
2023
|
+
getStringDecoder({
|
|
2024
|
+
description: lifetimeTokenDescription,
|
|
2025
|
+
encoding: getBase58Decoder(),
|
|
2026
|
+
size: 32
|
|
2027
|
+
})
|
|
2028
|
+
],
|
|
2029
|
+
[
|
|
2030
|
+
"instructions",
|
|
2031
|
+
getArrayDecoder(getInstructionDecoder(), {
|
|
2032
|
+
description: instructionsDescription,
|
|
2033
|
+
size: getShortU16Decoder()
|
|
2034
|
+
})
|
|
2035
|
+
],
|
|
2036
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
2037
|
+
];
|
|
2038
|
+
}
|
|
2039
|
+
function getAddressTableLookupArrayEncoder() {
|
|
2040
|
+
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
2041
|
+
description: addressTableLookupsDescription,
|
|
2042
|
+
size: getShortU16Encoder()
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
function getAddressTableLookupArrayDecoder() {
|
|
2046
|
+
return getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
2047
|
+
description: addressTableLookupsDescription,
|
|
2048
|
+
size: getShortU16Decoder()
|
|
1629
2049
|
});
|
|
1630
2050
|
}
|
|
2051
|
+
var messageDescription = "The wire format of a Solana transaction message" ;
|
|
1631
2052
|
function getCompiledMessageEncoder() {
|
|
1632
2053
|
return {
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
2054
|
+
description: messageDescription,
|
|
2055
|
+
encode: (compiledMessage) => {
|
|
2056
|
+
if (compiledMessage.version === "legacy") {
|
|
2057
|
+
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
|
|
2058
|
+
} else {
|
|
2059
|
+
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
|
|
2060
|
+
}
|
|
2061
|
+
},
|
|
2062
|
+
fixedSize: null,
|
|
2063
|
+
maxSize: null
|
|
1636
2064
|
};
|
|
1637
2065
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
2066
|
+
function getCompiledMessageDecoder() {
|
|
2067
|
+
return mapDecoder(
|
|
2068
|
+
getStructDecoder(getPreludeStructDecoderTuple(), {
|
|
2069
|
+
description: messageDescription
|
|
2070
|
+
}),
|
|
2071
|
+
({ addressTableLookups, ...restOfMessage }) => {
|
|
2072
|
+
if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
|
|
2073
|
+
return restOfMessage;
|
|
2074
|
+
}
|
|
2075
|
+
return { ...restOfMessage, addressTableLookups };
|
|
2076
|
+
}
|
|
2077
|
+
);
|
|
1642
2078
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
1646
|
-
getAddressFromPublicKey(keyPair.publicKey),
|
|
1647
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1648
|
-
]);
|
|
1649
|
-
const nextSignatures = {
|
|
1650
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
1651
|
-
...{ [signerPublicKey]: signature }
|
|
1652
|
-
};
|
|
1653
|
-
const out = {
|
|
1654
|
-
...transaction,
|
|
1655
|
-
signatures: nextSignatures
|
|
1656
|
-
};
|
|
1657
|
-
Object.freeze(out);
|
|
1658
|
-
return out;
|
|
2079
|
+
function getCompiledMessageCodec() {
|
|
2080
|
+
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
1659
2081
|
}
|
|
1660
2082
|
function getCompiledTransaction(transaction) {
|
|
2083
|
+
var _a;
|
|
1661
2084
|
const compiledMessage = compileMessage(transaction);
|
|
1662
2085
|
let signatures;
|
|
1663
2086
|
if ("signatures" in transaction) {
|
|
1664
2087
|
signatures = [];
|
|
1665
2088
|
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1666
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]]
|
|
2089
|
+
signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
|
|
1667
2090
|
}
|
|
1668
2091
|
} else {
|
|
1669
2092
|
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
@@ -1673,36 +2096,387 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1673
2096
|
signatures
|
|
1674
2097
|
};
|
|
1675
2098
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
2099
|
+
function getAccountMetas(message) {
|
|
2100
|
+
const { header } = message;
|
|
2101
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
2102
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
2103
|
+
const accountMetas = [];
|
|
2104
|
+
let accountIndex = 0;
|
|
2105
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
2106
|
+
accountMetas.push({
|
|
2107
|
+
address: message.staticAccounts[accountIndex],
|
|
2108
|
+
role: AccountRole2.WRITABLE_SIGNER
|
|
2109
|
+
});
|
|
2110
|
+
accountIndex++;
|
|
2111
|
+
}
|
|
2112
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
2113
|
+
accountMetas.push({
|
|
2114
|
+
address: message.staticAccounts[accountIndex],
|
|
2115
|
+
role: AccountRole2.READONLY_SIGNER
|
|
2116
|
+
});
|
|
2117
|
+
accountIndex++;
|
|
2118
|
+
}
|
|
2119
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
2120
|
+
accountMetas.push({
|
|
2121
|
+
address: message.staticAccounts[accountIndex],
|
|
2122
|
+
role: AccountRole2.WRITABLE
|
|
2123
|
+
});
|
|
2124
|
+
accountIndex++;
|
|
2125
|
+
}
|
|
2126
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
2127
|
+
accountMetas.push({
|
|
2128
|
+
address: message.staticAccounts[accountIndex],
|
|
2129
|
+
role: AccountRole2.READONLY
|
|
2130
|
+
});
|
|
2131
|
+
accountIndex++;
|
|
2132
|
+
}
|
|
2133
|
+
return accountMetas;
|
|
2134
|
+
}
|
|
2135
|
+
function convertInstruction(instruction, accountMetas) {
|
|
2136
|
+
var _a, _b;
|
|
2137
|
+
const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
|
|
2138
|
+
if (!programAddress) {
|
|
2139
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
2140
|
+
}
|
|
2141
|
+
const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
|
|
2142
|
+
const { data } = instruction;
|
|
2143
|
+
return {
|
|
2144
|
+
programAddress,
|
|
2145
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
2146
|
+
...data && data.length ? { data } : {}
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
2150
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
2151
|
+
return {
|
|
2152
|
+
blockhash: messageLifetimeToken,
|
|
2153
|
+
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
2154
|
+
// U64 MAX
|
|
2155
|
+
};
|
|
2156
|
+
} else {
|
|
2157
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
2158
|
+
assertIsAddress(nonceAccountAddress);
|
|
2159
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
2160
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
2161
|
+
return {
|
|
2162
|
+
nonce: messageLifetimeToken,
|
|
2163
|
+
nonceAccountAddress,
|
|
2164
|
+
nonceAuthorityAddress
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
function convertSignatures(compiledTransaction) {
|
|
2169
|
+
const {
|
|
2170
|
+
compiledMessage: { staticAccounts },
|
|
2171
|
+
signatures
|
|
2172
|
+
} = compiledTransaction;
|
|
2173
|
+
return signatures.reduce((acc, sig, index) => {
|
|
2174
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
2175
|
+
if (allZeros)
|
|
2176
|
+
return acc;
|
|
2177
|
+
const address2 = staticAccounts[index];
|
|
2178
|
+
return { ...acc, [address2]: sig };
|
|
2179
|
+
}, {});
|
|
2180
|
+
}
|
|
2181
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
2182
|
+
const { compiledMessage } = compiledTransaction;
|
|
2183
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
2184
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
2185
|
+
}
|
|
2186
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
2187
|
+
if (!feePayer)
|
|
2188
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
2189
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
2190
|
+
const instructions = compiledMessage.instructions.map(
|
|
2191
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
2192
|
+
);
|
|
2193
|
+
const firstInstruction = instructions[0];
|
|
2194
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
2195
|
+
compiledMessage.lifetimeToken,
|
|
2196
|
+
firstInstruction,
|
|
2197
|
+
lastValidBlockHeight
|
|
2198
|
+
);
|
|
2199
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
2200
|
+
return pipe(
|
|
2201
|
+
createTransaction({ version: compiledMessage.version }),
|
|
2202
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
2203
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
2204
|
+
return appendTransactionInstruction(instruction, acc);
|
|
2205
|
+
}, tx),
|
|
2206
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
2207
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
2208
|
+
);
|
|
2209
|
+
}
|
|
2210
|
+
var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
|
|
2211
|
+
var transactionDescription = "The wire format of a Solana transaction" ;
|
|
2212
|
+
function getCompiledTransactionEncoder() {
|
|
2213
|
+
return getStructEncoder(
|
|
2214
|
+
[
|
|
2215
|
+
[
|
|
2216
|
+
"signatures",
|
|
2217
|
+
getArrayEncoder(getBytesEncoder({ size: 64 }), {
|
|
2218
|
+
description: signaturesDescription,
|
|
2219
|
+
size: getShortU16Encoder()
|
|
2220
|
+
})
|
|
2221
|
+
],
|
|
2222
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
2223
|
+
],
|
|
2224
|
+
{
|
|
2225
|
+
description: transactionDescription
|
|
2226
|
+
}
|
|
2227
|
+
);
|
|
2228
|
+
}
|
|
2229
|
+
function getSignatureDecoder() {
|
|
2230
|
+
return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
|
|
2231
|
+
}
|
|
2232
|
+
function getCompiledTransactionDecoder() {
|
|
2233
|
+
return getStructDecoder(
|
|
2234
|
+
[
|
|
2235
|
+
[
|
|
2236
|
+
"signatures",
|
|
2237
|
+
getArrayDecoder(getSignatureDecoder(), {
|
|
2238
|
+
description: signaturesDescription,
|
|
2239
|
+
size: getShortU16Decoder()
|
|
2240
|
+
})
|
|
2241
|
+
],
|
|
2242
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
2243
|
+
],
|
|
2244
|
+
{
|
|
2245
|
+
description: transactionDescription
|
|
2246
|
+
}
|
|
2247
|
+
);
|
|
2248
|
+
}
|
|
2249
|
+
function getTransactionEncoder() {
|
|
2250
|
+
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
2251
|
+
}
|
|
2252
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
2253
|
+
return mapDecoder(
|
|
2254
|
+
getCompiledTransactionDecoder(),
|
|
2255
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
2256
|
+
);
|
|
2257
|
+
}
|
|
2258
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
2259
|
+
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
2260
|
+
}
|
|
2261
|
+
var base58Decoder;
|
|
2262
|
+
function getSignatureFromTransaction(transaction) {
|
|
2263
|
+
if (!base58Decoder)
|
|
2264
|
+
base58Decoder = getBase58Decoder();
|
|
2265
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
2266
|
+
if (!signatureBytes) {
|
|
2267
|
+
throw new Error(
|
|
2268
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
2272
|
+
return transactionSignature;
|
|
2273
|
+
}
|
|
2274
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
2275
|
+
const compiledMessage = compileMessage(transaction);
|
|
2276
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
2277
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
2278
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
2279
|
+
keyPairs.map(
|
|
2280
|
+
(keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
2281
|
+
)
|
|
2282
|
+
);
|
|
2283
|
+
for (const [signerPublicKey, signature2] of publicKeySignaturePairs) {
|
|
2284
|
+
nextSignatures[signerPublicKey] = signature2;
|
|
2285
|
+
}
|
|
2286
|
+
const out = {
|
|
2287
|
+
...transaction,
|
|
2288
|
+
signatures: nextSignatures
|
|
2289
|
+
};
|
|
2290
|
+
Object.freeze(out);
|
|
2291
|
+
return out;
|
|
2292
|
+
}
|
|
2293
|
+
async function signTransaction(keyPairs, transaction) {
|
|
2294
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
2295
|
+
assertTransactionIsFullySigned(out);
|
|
2296
|
+
Object.freeze(out);
|
|
2297
|
+
return out;
|
|
2298
|
+
}
|
|
2299
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
2300
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
|
|
2301
|
+
var _a, _b;
|
|
2302
|
+
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole2(a.role))) != null ? _b : [];
|
|
2303
|
+
}).map((a) => a.address);
|
|
2304
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
2305
|
+
requiredSigners.forEach((address2) => {
|
|
2306
|
+
if (!transaction.signatures[address2]) {
|
|
2307
|
+
throw new Error(`Transaction is missing signature for address \`${address2}\``);
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
function getBase64EncodedWireTransaction(transaction) {
|
|
2312
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
2313
|
+
return getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
// src/airdrop.ts
|
|
2317
|
+
init_env_shim();
|
|
2318
|
+
|
|
2319
|
+
// src/airdrop-confirmer.ts
|
|
2320
|
+
init_env_shim();
|
|
2321
|
+
|
|
2322
|
+
// src/transaction-confirmation-strategy-racer.ts
|
|
2323
|
+
init_env_shim();
|
|
2324
|
+
async function raceStrategies(signature2, config, getSpecificStrategiesForRace) {
|
|
2325
|
+
const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
|
|
2326
|
+
callerAbortSignal == null ? void 0 : callerAbortSignal.throwIfAborted();
|
|
2327
|
+
const abortController = new AbortController();
|
|
2328
|
+
if (callerAbortSignal) {
|
|
2329
|
+
const handleAbort = () => {
|
|
2330
|
+
abortController.abort();
|
|
2331
|
+
};
|
|
2332
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
2333
|
+
}
|
|
2334
|
+
try {
|
|
2335
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
2336
|
+
...config,
|
|
2337
|
+
abortSignal: abortController.signal
|
|
2338
|
+
});
|
|
2339
|
+
return await Promise.race([
|
|
2340
|
+
getRecentSignatureConfirmationPromise({
|
|
2341
|
+
abortSignal: abortController.signal,
|
|
2342
|
+
commitment,
|
|
2343
|
+
signature: signature2
|
|
2344
|
+
}),
|
|
2345
|
+
...specificStrategies
|
|
2346
|
+
]);
|
|
2347
|
+
} finally {
|
|
2348
|
+
abortController.abort();
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
// src/transaction-confirmation-strategy-recent-signature.ts
|
|
2353
|
+
init_env_shim();
|
|
2354
|
+
function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
2355
|
+
return async function getRecentSignatureConfirmationPromise({
|
|
2356
|
+
abortSignal: callerAbortSignal,
|
|
2357
|
+
commitment,
|
|
2358
|
+
signature: signature2
|
|
2359
|
+
}) {
|
|
2360
|
+
const abortController = new AbortController();
|
|
2361
|
+
function handleAbort() {
|
|
2362
|
+
abortController.abort();
|
|
2363
|
+
}
|
|
2364
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
2365
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature2, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
2366
|
+
const signatureDidCommitPromise = (async () => {
|
|
2367
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
2368
|
+
if (signatureStatusNotification.value.err) {
|
|
2369
|
+
throw new Error(`The transaction with signature \`${signature2}\` failed.`, {
|
|
2370
|
+
cause: signatureStatusNotification.value.err
|
|
2371
|
+
});
|
|
2372
|
+
} else {
|
|
2373
|
+
return;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
})();
|
|
2377
|
+
const signatureStatusLookupPromise = (async () => {
|
|
2378
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature2]).send({ abortSignal: abortController.signal });
|
|
2379
|
+
const signatureStatus = signatureStatusResults[0];
|
|
2380
|
+
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
2381
|
+
return;
|
|
2382
|
+
} else {
|
|
2383
|
+
await new Promise(() => {
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
})();
|
|
2387
|
+
try {
|
|
2388
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
2389
|
+
} finally {
|
|
2390
|
+
abortController.abort();
|
|
2391
|
+
}
|
|
2392
|
+
};
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
// src/transaction-confirmation-strategy-timeout.ts
|
|
2396
|
+
init_env_shim();
|
|
2397
|
+
async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
|
|
2398
|
+
return await new Promise((_, reject) => {
|
|
2399
|
+
const handleAbort = (e3) => {
|
|
2400
|
+
clearTimeout(timeoutId);
|
|
2401
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
2402
|
+
reject(abortError);
|
|
2403
|
+
};
|
|
2404
|
+
callerAbortSignal.addEventListener("abort", handleAbort);
|
|
2405
|
+
const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
|
|
2406
|
+
const startMs = performance.now();
|
|
2407
|
+
const timeoutId = (
|
|
2408
|
+
// We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
|
|
2409
|
+
// elapsed time instead of active time.
|
|
2410
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
|
|
2411
|
+
setTimeout(() => {
|
|
2412
|
+
const elapsedMs = performance.now() - startMs;
|
|
2413
|
+
reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
|
|
2414
|
+
}, timeoutMs)
|
|
2415
|
+
);
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
// src/airdrop-confirmer.ts
|
|
2420
|
+
function createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
2421
|
+
rpc,
|
|
2422
|
+
rpcSubscriptions
|
|
2423
|
+
}) {
|
|
2424
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
2425
|
+
rpc,
|
|
2426
|
+
rpcSubscriptions
|
|
2427
|
+
);
|
|
2428
|
+
return async function confirmSignatureOnlyRecentTransaction(config) {
|
|
2429
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
2430
|
+
...config,
|
|
2431
|
+
getRecentSignatureConfirmationPromise,
|
|
2432
|
+
getTimeoutPromise
|
|
2433
|
+
});
|
|
2434
|
+
};
|
|
2435
|
+
}
|
|
2436
|
+
async function waitForRecentTransactionConfirmationUntilTimeout(config) {
|
|
2437
|
+
await raceStrategies(
|
|
2438
|
+
config.signature,
|
|
2439
|
+
config,
|
|
2440
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
|
|
2441
|
+
return [
|
|
2442
|
+
getTimeoutPromise2({
|
|
2443
|
+
abortSignal,
|
|
2444
|
+
commitment
|
|
2445
|
+
})
|
|
2446
|
+
];
|
|
2447
|
+
}
|
|
2448
|
+
);
|
|
1693
2449
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
2450
|
+
|
|
2451
|
+
// src/airdrop.ts
|
|
2452
|
+
function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
|
|
2453
|
+
const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
2454
|
+
rpc,
|
|
2455
|
+
rpcSubscriptions
|
|
2456
|
+
});
|
|
2457
|
+
return async function requestAirdrop(config) {
|
|
2458
|
+
return await requestAndConfirmAirdrop({
|
|
2459
|
+
...config,
|
|
2460
|
+
confirmSignatureOnlyTransaction,
|
|
2461
|
+
rpc
|
|
2462
|
+
});
|
|
1699
2463
|
};
|
|
1700
2464
|
}
|
|
1701
|
-
function
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
2465
|
+
async function requestAndConfirmAirdrop({
|
|
2466
|
+
abortSignal,
|
|
2467
|
+
commitment,
|
|
2468
|
+
confirmSignatureOnlyTransaction,
|
|
2469
|
+
lamports: lamports2,
|
|
2470
|
+
recipientAddress,
|
|
2471
|
+
rpc
|
|
2472
|
+
}) {
|
|
2473
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports2, { commitment }).send({ abortSignal });
|
|
2474
|
+
await confirmSignatureOnlyTransaction({
|
|
2475
|
+
abortSignal,
|
|
2476
|
+
commitment,
|
|
2477
|
+
signature: airdropTransactionSignature
|
|
2478
|
+
});
|
|
2479
|
+
return airdropTransactionSignature;
|
|
1706
2480
|
}
|
|
1707
2481
|
|
|
1708
2482
|
// src/rpc.ts
|
|
@@ -1736,63 +2510,306 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1736
2510
|
return visitNode(params, [], onIntegerOverflow);
|
|
1737
2511
|
}
|
|
1738
2512
|
var KEYPATH_WILDCARD = {};
|
|
1739
|
-
var
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
2513
|
+
var jsonParsedTokenAccountsConfigs = [
|
|
2514
|
+
// parsed Token/Token22 token account
|
|
2515
|
+
["data", "parsed", "info", "tokenAmount", "decimals"],
|
|
2516
|
+
["data", "parsed", "info", "tokenAmount", "uiAmount"],
|
|
2517
|
+
["data", "parsed", "info", "rentExemptReserve", "decimals"],
|
|
2518
|
+
["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
|
|
2519
|
+
["data", "parsed", "info", "delegatedAmount", "decimals"],
|
|
2520
|
+
["data", "parsed", "info", "delegatedAmount", "uiAmount"],
|
|
2521
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "olderTransferFee", "transferFeeBasisPoints"],
|
|
2522
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "newerTransferFee", "transferFeeBasisPoints"],
|
|
2523
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
|
|
2524
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
|
|
2525
|
+
];
|
|
2526
|
+
var jsonParsedAccountsConfigs = [
|
|
2527
|
+
...jsonParsedTokenAccountsConfigs,
|
|
2528
|
+
// parsed AddressTableLookup account
|
|
2529
|
+
["data", "parsed", "info", "lastExtendedSlotStartIndex"],
|
|
2530
|
+
// parsed Config account
|
|
2531
|
+
["data", "parsed", "info", "slashPenalty"],
|
|
2532
|
+
["data", "parsed", "info", "warmupCooldownRate"],
|
|
2533
|
+
// parsed Token/Token22 mint account
|
|
2534
|
+
["data", "parsed", "info", "decimals"],
|
|
2535
|
+
// parsed Token/Token22 multisig account
|
|
2536
|
+
["data", "parsed", "info", "numRequiredSigners"],
|
|
2537
|
+
["data", "parsed", "info", "numValidSigners"],
|
|
2538
|
+
// parsed Stake account
|
|
2539
|
+
["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
|
|
2540
|
+
// parsed Sysvar rent account
|
|
2541
|
+
["data", "parsed", "info", "exemptionThreshold"],
|
|
2542
|
+
["data", "parsed", "info", "burnPercent"],
|
|
2543
|
+
// parsed Vote account
|
|
2544
|
+
["data", "parsed", "info", "commission"],
|
|
2545
|
+
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
2546
|
+
];
|
|
2547
|
+
var memoizedNotificationKeypaths;
|
|
2548
|
+
var memoizedResponseKeypaths;
|
|
2549
|
+
function getAllowedNumericKeypathsForNotification() {
|
|
2550
|
+
if (!memoizedNotificationKeypaths) {
|
|
2551
|
+
memoizedNotificationKeypaths = {
|
|
2552
|
+
accountNotifications: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
2553
|
+
blockNotifications: [
|
|
2554
|
+
["value", "block", "blockTime"],
|
|
2555
|
+
[
|
|
2556
|
+
"value",
|
|
2557
|
+
"block",
|
|
2558
|
+
"transactions",
|
|
2559
|
+
KEYPATH_WILDCARD,
|
|
2560
|
+
"meta",
|
|
2561
|
+
"preTokenBalances",
|
|
2562
|
+
KEYPATH_WILDCARD,
|
|
2563
|
+
"accountIndex"
|
|
2564
|
+
],
|
|
2565
|
+
[
|
|
2566
|
+
"value",
|
|
2567
|
+
"block",
|
|
2568
|
+
"transactions",
|
|
2569
|
+
KEYPATH_WILDCARD,
|
|
2570
|
+
"meta",
|
|
2571
|
+
"preTokenBalances",
|
|
2572
|
+
KEYPATH_WILDCARD,
|
|
2573
|
+
"uiTokenAmount",
|
|
2574
|
+
"decimals"
|
|
2575
|
+
],
|
|
2576
|
+
[
|
|
2577
|
+
"value",
|
|
2578
|
+
"block",
|
|
2579
|
+
"transactions",
|
|
2580
|
+
KEYPATH_WILDCARD,
|
|
2581
|
+
"meta",
|
|
2582
|
+
"postTokenBalances",
|
|
2583
|
+
KEYPATH_WILDCARD,
|
|
2584
|
+
"accountIndex"
|
|
2585
|
+
],
|
|
2586
|
+
[
|
|
2587
|
+
"value",
|
|
2588
|
+
"block",
|
|
2589
|
+
"transactions",
|
|
2590
|
+
KEYPATH_WILDCARD,
|
|
2591
|
+
"meta",
|
|
2592
|
+
"postTokenBalances",
|
|
2593
|
+
KEYPATH_WILDCARD,
|
|
2594
|
+
"uiTokenAmount",
|
|
2595
|
+
"decimals"
|
|
2596
|
+
],
|
|
2597
|
+
["value", "block", "transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2598
|
+
[
|
|
2599
|
+
"value",
|
|
2600
|
+
"block",
|
|
2601
|
+
"transactions",
|
|
2602
|
+
KEYPATH_WILDCARD,
|
|
2603
|
+
"meta",
|
|
2604
|
+
"innerInstructions",
|
|
2605
|
+
KEYPATH_WILDCARD,
|
|
2606
|
+
"index"
|
|
2607
|
+
],
|
|
2608
|
+
[
|
|
2609
|
+
"value",
|
|
2610
|
+
"block",
|
|
2611
|
+
"transactions",
|
|
2612
|
+
KEYPATH_WILDCARD,
|
|
2613
|
+
"meta",
|
|
2614
|
+
"innerInstructions",
|
|
2615
|
+
KEYPATH_WILDCARD,
|
|
2616
|
+
"instructions",
|
|
2617
|
+
KEYPATH_WILDCARD,
|
|
2618
|
+
"programIdIndex"
|
|
2619
|
+
],
|
|
2620
|
+
[
|
|
2621
|
+
"value",
|
|
2622
|
+
"block",
|
|
2623
|
+
"transactions",
|
|
2624
|
+
KEYPATH_WILDCARD,
|
|
2625
|
+
"meta",
|
|
2626
|
+
"innerInstructions",
|
|
2627
|
+
KEYPATH_WILDCARD,
|
|
2628
|
+
"instructions",
|
|
2629
|
+
KEYPATH_WILDCARD,
|
|
2630
|
+
"accounts",
|
|
2631
|
+
KEYPATH_WILDCARD
|
|
2632
|
+
],
|
|
2633
|
+
[
|
|
2634
|
+
"value",
|
|
2635
|
+
"block",
|
|
2636
|
+
"transactions",
|
|
2637
|
+
KEYPATH_WILDCARD,
|
|
2638
|
+
"transaction",
|
|
2639
|
+
"message",
|
|
2640
|
+
"addressTableLookups",
|
|
2641
|
+
KEYPATH_WILDCARD,
|
|
2642
|
+
"writableIndexes",
|
|
2643
|
+
KEYPATH_WILDCARD
|
|
2644
|
+
],
|
|
2645
|
+
[
|
|
2646
|
+
"value",
|
|
2647
|
+
"block",
|
|
2648
|
+
"transactions",
|
|
2649
|
+
KEYPATH_WILDCARD,
|
|
2650
|
+
"transaction",
|
|
2651
|
+
"message",
|
|
2652
|
+
"addressTableLookups",
|
|
2653
|
+
KEYPATH_WILDCARD,
|
|
2654
|
+
"readonlyIndexes",
|
|
2655
|
+
KEYPATH_WILDCARD
|
|
2656
|
+
],
|
|
2657
|
+
[
|
|
2658
|
+
"value",
|
|
2659
|
+
"block",
|
|
2660
|
+
"transactions",
|
|
2661
|
+
KEYPATH_WILDCARD,
|
|
2662
|
+
"transaction",
|
|
2663
|
+
"message",
|
|
2664
|
+
"instructions",
|
|
2665
|
+
KEYPATH_WILDCARD,
|
|
2666
|
+
"programIdIndex"
|
|
2667
|
+
],
|
|
2668
|
+
[
|
|
2669
|
+
"value",
|
|
2670
|
+
"block",
|
|
2671
|
+
"transactions",
|
|
2672
|
+
KEYPATH_WILDCARD,
|
|
2673
|
+
"transaction",
|
|
2674
|
+
"message",
|
|
2675
|
+
"instructions",
|
|
2676
|
+
KEYPATH_WILDCARD,
|
|
2677
|
+
"accounts",
|
|
2678
|
+
KEYPATH_WILDCARD
|
|
2679
|
+
],
|
|
2680
|
+
[
|
|
2681
|
+
"value",
|
|
2682
|
+
"block",
|
|
2683
|
+
"transactions",
|
|
2684
|
+
KEYPATH_WILDCARD,
|
|
2685
|
+
"transaction",
|
|
2686
|
+
"message",
|
|
2687
|
+
"header",
|
|
2688
|
+
"numReadonlySignedAccounts"
|
|
2689
|
+
],
|
|
2690
|
+
[
|
|
2691
|
+
"value",
|
|
2692
|
+
"block",
|
|
2693
|
+
"transactions",
|
|
2694
|
+
KEYPATH_WILDCARD,
|
|
2695
|
+
"transaction",
|
|
2696
|
+
"message",
|
|
2697
|
+
"header",
|
|
2698
|
+
"numReadonlyUnsignedAccounts"
|
|
2699
|
+
],
|
|
2700
|
+
[
|
|
2701
|
+
"value",
|
|
2702
|
+
"block",
|
|
2703
|
+
"transactions",
|
|
2704
|
+
KEYPATH_WILDCARD,
|
|
2705
|
+
"transaction",
|
|
2706
|
+
"message",
|
|
2707
|
+
"header",
|
|
2708
|
+
"numRequiredSignatures"
|
|
2709
|
+
],
|
|
2710
|
+
["value", "block", "rewards", KEYPATH_WILDCARD, "commission"]
|
|
1769
2711
|
],
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
["data", "parsed", "info", "decimals"],
|
|
1782
|
-
// parsed Token/Token22 multisig account
|
|
1783
|
-
["data", "parsed", "info", "numRequiredSigners"],
|
|
1784
|
-
["data", "parsed", "info", "numValidSigners"],
|
|
1785
|
-
// parsed Stake account
|
|
1786
|
-
["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
|
|
1787
|
-
// parsed Sysvar rent account
|
|
1788
|
-
["data", "parsed", "info", "exemptionThreshold"],
|
|
1789
|
-
["data", "parsed", "info", "burnPercent"],
|
|
1790
|
-
// parsed Vote account
|
|
1791
|
-
["data", "parsed", "info", "commission"],
|
|
1792
|
-
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
1793
|
-
];
|
|
1794
|
-
memoizedKeypaths = {
|
|
2712
|
+
programNotifications: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
2713
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
2714
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
2715
|
+
])
|
|
2716
|
+
};
|
|
2717
|
+
}
|
|
2718
|
+
return memoizedNotificationKeypaths;
|
|
2719
|
+
}
|
|
2720
|
+
function getAllowedNumericKeypathsForResponse() {
|
|
2721
|
+
if (!memoizedResponseKeypaths) {
|
|
2722
|
+
memoizedResponseKeypaths = {
|
|
1795
2723
|
getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
2724
|
+
getBlock: [
|
|
2725
|
+
["blockTime"],
|
|
2726
|
+
["transactions", KEYPATH_WILDCARD, "meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2727
|
+
[
|
|
2728
|
+
"transactions",
|
|
2729
|
+
KEYPATH_WILDCARD,
|
|
2730
|
+
"meta",
|
|
2731
|
+
"preTokenBalances",
|
|
2732
|
+
KEYPATH_WILDCARD,
|
|
2733
|
+
"uiTokenAmount",
|
|
2734
|
+
"decimals"
|
|
2735
|
+
],
|
|
2736
|
+
["transactions", KEYPATH_WILDCARD, "meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2737
|
+
[
|
|
2738
|
+
"transactions",
|
|
2739
|
+
KEYPATH_WILDCARD,
|
|
2740
|
+
"meta",
|
|
2741
|
+
"postTokenBalances",
|
|
2742
|
+
KEYPATH_WILDCARD,
|
|
2743
|
+
"uiTokenAmount",
|
|
2744
|
+
"decimals"
|
|
2745
|
+
],
|
|
2746
|
+
["transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2747
|
+
["transactions", KEYPATH_WILDCARD, "meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
2748
|
+
[
|
|
2749
|
+
"transactions",
|
|
2750
|
+
KEYPATH_WILDCARD,
|
|
2751
|
+
"meta",
|
|
2752
|
+
"innerInstructions",
|
|
2753
|
+
KEYPATH_WILDCARD,
|
|
2754
|
+
"instructions",
|
|
2755
|
+
KEYPATH_WILDCARD,
|
|
2756
|
+
"programIdIndex"
|
|
2757
|
+
],
|
|
2758
|
+
[
|
|
2759
|
+
"transactions",
|
|
2760
|
+
KEYPATH_WILDCARD,
|
|
2761
|
+
"meta",
|
|
2762
|
+
"innerInstructions",
|
|
2763
|
+
KEYPATH_WILDCARD,
|
|
2764
|
+
"instructions",
|
|
2765
|
+
KEYPATH_WILDCARD,
|
|
2766
|
+
"accounts",
|
|
2767
|
+
KEYPATH_WILDCARD
|
|
2768
|
+
],
|
|
2769
|
+
[
|
|
2770
|
+
"transactions",
|
|
2771
|
+
KEYPATH_WILDCARD,
|
|
2772
|
+
"transaction",
|
|
2773
|
+
"message",
|
|
2774
|
+
"addressTableLookups",
|
|
2775
|
+
KEYPATH_WILDCARD,
|
|
2776
|
+
"writableIndexes",
|
|
2777
|
+
KEYPATH_WILDCARD
|
|
2778
|
+
],
|
|
2779
|
+
[
|
|
2780
|
+
"transactions",
|
|
2781
|
+
KEYPATH_WILDCARD,
|
|
2782
|
+
"transaction",
|
|
2783
|
+
"message",
|
|
2784
|
+
"addressTableLookups",
|
|
2785
|
+
KEYPATH_WILDCARD,
|
|
2786
|
+
"readonlyIndexes",
|
|
2787
|
+
KEYPATH_WILDCARD
|
|
2788
|
+
],
|
|
2789
|
+
[
|
|
2790
|
+
"transactions",
|
|
2791
|
+
KEYPATH_WILDCARD,
|
|
2792
|
+
"transaction",
|
|
2793
|
+
"message",
|
|
2794
|
+
"instructions",
|
|
2795
|
+
KEYPATH_WILDCARD,
|
|
2796
|
+
"programIdIndex"
|
|
2797
|
+
],
|
|
2798
|
+
[
|
|
2799
|
+
"transactions",
|
|
2800
|
+
KEYPATH_WILDCARD,
|
|
2801
|
+
"transaction",
|
|
2802
|
+
"message",
|
|
2803
|
+
"instructions",
|
|
2804
|
+
KEYPATH_WILDCARD,
|
|
2805
|
+
"accounts",
|
|
2806
|
+
KEYPATH_WILDCARD
|
|
2807
|
+
],
|
|
2808
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
2809
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
2810
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numRequiredSignatures"],
|
|
2811
|
+
["rewards", KEYPATH_WILDCARD, "commission"]
|
|
2812
|
+
],
|
|
1796
2813
|
getBlockTime: [[]],
|
|
1797
2814
|
getClusterNodes: [
|
|
1798
2815
|
[KEYPATH_WILDCARD, "featureSet"],
|
|
@@ -1874,10 +2891,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1874
2891
|
getVoteAccounts: [
|
|
1875
2892
|
["current", KEYPATH_WILDCARD, "commission"],
|
|
1876
2893
|
["delinquent", KEYPATH_WILDCARD, "commission"]
|
|
1877
|
-
]
|
|
2894
|
+
],
|
|
2895
|
+
simulateTransaction: jsonParsedAccountsConfigs.map((c) => ["value", "accounts", KEYPATH_WILDCARD, ...c])
|
|
1878
2896
|
};
|
|
1879
2897
|
}
|
|
1880
|
-
return
|
|
2898
|
+
return memoizedResponseKeypaths;
|
|
1881
2899
|
}
|
|
1882
2900
|
function getNextAllowedKeypaths(keyPaths, property) {
|
|
1883
2901
|
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1));
|
|
@@ -1905,8 +2923,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1905
2923
|
}
|
|
1906
2924
|
}
|
|
1907
2925
|
function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
|
|
1908
|
-
const allowedKeypaths = methodName ?
|
|
1909
|
-
return visitNode2(rawResponse, allowedKeypaths
|
|
2926
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
|
|
2927
|
+
return visitNode2(rawResponse, allowedKeypaths != null ? allowedKeypaths : []);
|
|
2928
|
+
}
|
|
2929
|
+
function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
|
|
2930
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
|
|
2931
|
+
return visitNode2(rawResponse, allowedKeypaths != null ? allowedKeypaths : []);
|
|
1910
2932
|
}
|
|
1911
2933
|
function createSolanaRpcApi(config) {
|
|
1912
2934
|
return new Proxy({}, {
|
|
@@ -1920,7 +2942,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1920
2942
|
const [_, p] = args;
|
|
1921
2943
|
const methodName = p.toString();
|
|
1922
2944
|
return function(...rawParams) {
|
|
1923
|
-
const handleIntegerOverflow = config
|
|
2945
|
+
const handleIntegerOverflow = config == null ? void 0 : config.onIntegerOverflow;
|
|
1924
2946
|
const params = patchParamsForSolanaLabsRpc(
|
|
1925
2947
|
rawParams,
|
|
1926
2948
|
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(methodName, keyPath, value) : void 0
|
|
@@ -1934,12 +2956,44 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1934
2956
|
}
|
|
1935
2957
|
});
|
|
1936
2958
|
}
|
|
2959
|
+
function createSolanaRpcSubscriptionsApi(config) {
|
|
2960
|
+
return new Proxy({}, {
|
|
2961
|
+
defineProperty() {
|
|
2962
|
+
return false;
|
|
2963
|
+
},
|
|
2964
|
+
deleteProperty() {
|
|
2965
|
+
return false;
|
|
2966
|
+
},
|
|
2967
|
+
get(...args) {
|
|
2968
|
+
const [_, p] = args;
|
|
2969
|
+
const notificationName = p.toString();
|
|
2970
|
+
return function(...rawParams) {
|
|
2971
|
+
const handleIntegerOverflow = config == null ? void 0 : config.onIntegerOverflow;
|
|
2972
|
+
const params = patchParamsForSolanaLabsRpc(
|
|
2973
|
+
rawParams,
|
|
2974
|
+
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
|
|
2975
|
+
);
|
|
2976
|
+
return {
|
|
2977
|
+
params,
|
|
2978
|
+
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpcSubscriptions(rawResponse, notificationName),
|
|
2979
|
+
subscribeMethodName: notificationName.replace(/Notifications$/, "Subscribe"),
|
|
2980
|
+
unsubscribeMethodName: notificationName.replace(/Notifications$/, "Unsubscribe")
|
|
2981
|
+
};
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
});
|
|
2985
|
+
}
|
|
2986
|
+
function createSolanaRpcSubscriptionsApi_UNSTABLE(config) {
|
|
2987
|
+
return createSolanaRpcSubscriptionsApi(config);
|
|
2988
|
+
}
|
|
1937
2989
|
|
|
1938
2990
|
// ../rpc-transport/dist/index.browser.js
|
|
1939
2991
|
init_env_shim();
|
|
1940
2992
|
var SolanaJsonRpcError = class extends Error {
|
|
1941
2993
|
constructor(details) {
|
|
1942
2994
|
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`);
|
|
2995
|
+
__publicField(this, "code");
|
|
2996
|
+
__publicField(this, "data");
|
|
1943
2997
|
Error.captureStackTrace(this, this.constructor);
|
|
1944
2998
|
this.code = details.code;
|
|
1945
2999
|
this.data = details.data;
|
|
@@ -1962,24 +3016,109 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1962
3016
|
params
|
|
1963
3017
|
};
|
|
1964
3018
|
}
|
|
1965
|
-
function createPendingRpcRequest(rpcConfig, pendingRequest) {
|
|
3019
|
+
function createPendingRpcRequest(rpcConfig, pendingRequest) {
|
|
3020
|
+
return {
|
|
3021
|
+
async send(options) {
|
|
3022
|
+
const { methodName, params, responseProcessor } = pendingRequest;
|
|
3023
|
+
const payload = createJsonRpcMessage(methodName, params);
|
|
3024
|
+
const response = await rpcConfig.transport({
|
|
3025
|
+
payload,
|
|
3026
|
+
signal: options == null ? void 0 : options.abortSignal
|
|
3027
|
+
});
|
|
3028
|
+
if ("error" in response) {
|
|
3029
|
+
throw new SolanaJsonRpcError(response.error);
|
|
3030
|
+
} else {
|
|
3031
|
+
return responseProcessor ? responseProcessor(response.result) : response.result;
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
};
|
|
3035
|
+
}
|
|
3036
|
+
function makeProxy(rpcConfig) {
|
|
3037
|
+
return new Proxy(rpcConfig.api, {
|
|
3038
|
+
defineProperty() {
|
|
3039
|
+
return false;
|
|
3040
|
+
},
|
|
3041
|
+
deleteProperty() {
|
|
3042
|
+
return false;
|
|
3043
|
+
},
|
|
3044
|
+
get(target, p, receiver) {
|
|
3045
|
+
return function(...rawParams) {
|
|
3046
|
+
const methodName = p.toString();
|
|
3047
|
+
const createRpcRequest = Reflect.get(target, methodName, receiver);
|
|
3048
|
+
const newRequest = createRpcRequest ? createRpcRequest(...rawParams) : { methodName, params: rawParams };
|
|
3049
|
+
return createPendingRpcRequest(rpcConfig, newRequest);
|
|
3050
|
+
};
|
|
3051
|
+
}
|
|
3052
|
+
});
|
|
3053
|
+
}
|
|
3054
|
+
function createJsonRpc(rpcConfig) {
|
|
3055
|
+
return makeProxy(rpcConfig);
|
|
3056
|
+
}
|
|
3057
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
3058
|
+
(async () => {
|
|
3059
|
+
try {
|
|
3060
|
+
for await (const _ of iterable)
|
|
3061
|
+
;
|
|
3062
|
+
} catch {
|
|
3063
|
+
} finally {
|
|
3064
|
+
cleanupFn();
|
|
3065
|
+
}
|
|
3066
|
+
})();
|
|
3067
|
+
}
|
|
3068
|
+
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
|
|
1966
3069
|
return {
|
|
1967
|
-
async
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
3070
|
+
async subscribe({ abortSignal }) {
|
|
3071
|
+
abortSignal.throwIfAborted();
|
|
3072
|
+
let subscriptionId;
|
|
3073
|
+
function handleCleanup() {
|
|
3074
|
+
if (subscriptionId !== void 0) {
|
|
3075
|
+
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]);
|
|
3076
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => {
|
|
3077
|
+
connectionAbortController.abort();
|
|
3078
|
+
});
|
|
3079
|
+
} else {
|
|
3080
|
+
connectionAbortController.abort();
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
abortSignal.addEventListener("abort", handleCleanup);
|
|
3084
|
+
const connectionAbortController = new AbortController();
|
|
3085
|
+
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
|
|
3086
|
+
const connection = await rpcConfig.transport({
|
|
3087
|
+
payload: subscribeMessage,
|
|
3088
|
+
signal: connectionAbortController.signal
|
|
1973
3089
|
});
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
}
|
|
1977
|
-
|
|
3090
|
+
function handleConnectionCleanup() {
|
|
3091
|
+
abortSignal.removeEventListener("abort", handleCleanup);
|
|
3092
|
+
}
|
|
3093
|
+
registerIterableCleanup(connection, handleConnectionCleanup);
|
|
3094
|
+
for await (const message of connection) {
|
|
3095
|
+
if ("id" in message && message.id === subscribeMessage.id) {
|
|
3096
|
+
if ("error" in message) {
|
|
3097
|
+
throw new SolanaJsonRpcError(message.error);
|
|
3098
|
+
} else {
|
|
3099
|
+
subscriptionId = message.result;
|
|
3100
|
+
break;
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
if (subscriptionId == null) {
|
|
3105
|
+
throw new Error("Failed to obtain a subscription id from the server");
|
|
1978
3106
|
}
|
|
3107
|
+
return {
|
|
3108
|
+
async *[Symbol.asyncIterator]() {
|
|
3109
|
+
for await (const message of connection) {
|
|
3110
|
+
if (!("params" in message) || message.params.subscription !== subscriptionId) {
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
3113
|
+
const notification = message.params.result;
|
|
3114
|
+
yield responseProcessor ? responseProcessor(notification) : notification;
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
};
|
|
1979
3118
|
}
|
|
1980
3119
|
};
|
|
1981
3120
|
}
|
|
1982
|
-
function
|
|
3121
|
+
function makeProxy2(rpcConfig) {
|
|
1983
3122
|
return new Proxy(rpcConfig.api, {
|
|
1984
3123
|
defineProperty() {
|
|
1985
3124
|
return false;
|
|
@@ -1990,20 +3129,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1990
3129
|
get(target, p, receiver) {
|
|
1991
3130
|
return function(...rawParams) {
|
|
1992
3131
|
const methodName = p.toString();
|
|
1993
|
-
const
|
|
1994
|
-
|
|
1995
|
-
|
|
3132
|
+
const createRpcSubscription = Reflect.get(target, methodName, receiver);
|
|
3133
|
+
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) {
|
|
3134
|
+
throw new Error(
|
|
3135
|
+
"Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names."
|
|
3136
|
+
);
|
|
3137
|
+
}
|
|
3138
|
+
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : {
|
|
3139
|
+
params: rawParams,
|
|
3140
|
+
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"),
|
|
3141
|
+
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe")
|
|
3142
|
+
};
|
|
3143
|
+
return createPendingRpcSubscription(rpcConfig, newRequest);
|
|
1996
3144
|
};
|
|
1997
3145
|
}
|
|
1998
3146
|
});
|
|
1999
3147
|
}
|
|
2000
|
-
function
|
|
2001
|
-
return
|
|
3148
|
+
function createJsonSubscriptionRpc(rpcConfig) {
|
|
3149
|
+
return makeProxy2(rpcConfig);
|
|
2002
3150
|
}
|
|
2003
|
-
var
|
|
3151
|
+
var e2 = globalThis.fetch;
|
|
2004
3152
|
var SolanaHttpError = class extends Error {
|
|
2005
3153
|
constructor(details) {
|
|
2006
3154
|
super(`HTTP error (${details.statusCode}): ${details.message}`);
|
|
3155
|
+
__publicField(this, "statusCode");
|
|
2007
3156
|
Error.captureStackTrace(this, this.constructor);
|
|
2008
3157
|
this.statusCode = details.statusCode;
|
|
2009
3158
|
}
|
|
@@ -2059,16 +3208,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2059
3208
|
}
|
|
2060
3209
|
return out;
|
|
2061
3210
|
}
|
|
2062
|
-
function createHttpTransport({
|
|
3211
|
+
function createHttpTransport({ headers, url }) {
|
|
2063
3212
|
if (headers) {
|
|
2064
3213
|
assertIsAllowedHttpRequestHeaders(headers);
|
|
2065
3214
|
}
|
|
2066
|
-
const agent = void 0;
|
|
2067
|
-
if (httpAgentNodeOnly != null) {
|
|
2068
|
-
console.warn(
|
|
2069
|
-
"createHttpTransport(): The `httpAgentNodeOnly` config you supplied has been ignored; HTTP agents are only usable in Node environments."
|
|
2070
|
-
);
|
|
2071
|
-
}
|
|
2072
3215
|
const customHeaders = headers && normalizeHeaders(headers);
|
|
2073
3216
|
return async function makeHttpRequest({
|
|
2074
3217
|
payload,
|
|
@@ -2076,7 +3219,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2076
3219
|
}) {
|
|
2077
3220
|
const body = JSON.stringify(payload);
|
|
2078
3221
|
const requestInfo = {
|
|
2079
|
-
agent,
|
|
2080
3222
|
body,
|
|
2081
3223
|
headers: {
|
|
2082
3224
|
...customHeaders,
|
|
@@ -2088,7 +3230,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2088
3230
|
method: "POST",
|
|
2089
3231
|
signal
|
|
2090
3232
|
};
|
|
2091
|
-
const response = await
|
|
3233
|
+
const response = await e2(url, requestInfo);
|
|
2092
3234
|
if (!response.ok) {
|
|
2093
3235
|
throw new SolanaHttpError({
|
|
2094
3236
|
message: response.statusText,
|
|
@@ -2098,6 +3240,175 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2098
3240
|
return await response.json();
|
|
2099
3241
|
};
|
|
2100
3242
|
}
|
|
3243
|
+
var e22 = globalThis.WebSocket;
|
|
3244
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
3245
|
+
"This symbol is thrown from a socket's iterator when the connection is explicitly aborted by the user"
|
|
3246
|
+
);
|
|
3247
|
+
async function createWebSocketConnection({
|
|
3248
|
+
sendBufferHighWatermark,
|
|
3249
|
+
signal,
|
|
3250
|
+
url
|
|
3251
|
+
}) {
|
|
3252
|
+
return new Promise((resolve, reject) => {
|
|
3253
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
3254
|
+
const iteratorState = /* @__PURE__ */ new Map();
|
|
3255
|
+
function errorAndClearAllIteratorStates(reason) {
|
|
3256
|
+
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError);
|
|
3257
|
+
iteratorState.clear();
|
|
3258
|
+
errorCallbacks.forEach((cb) => {
|
|
3259
|
+
try {
|
|
3260
|
+
cb(reason);
|
|
3261
|
+
} catch {
|
|
3262
|
+
}
|
|
3263
|
+
});
|
|
3264
|
+
}
|
|
3265
|
+
function handleAbort() {
|
|
3266
|
+
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
|
|
3267
|
+
if (webSocket.readyState !== e22.CLOSED && webSocket.readyState !== e22.CLOSING) {
|
|
3268
|
+
webSocket.close(1e3);
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
function handleClose(ev) {
|
|
3272
|
+
bufferDrainWatcher == null ? void 0 : bufferDrainWatcher.onCancel();
|
|
3273
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3274
|
+
webSocket.removeEventListener("close", handleClose);
|
|
3275
|
+
webSocket.removeEventListener("error", handleError);
|
|
3276
|
+
webSocket.removeEventListener("open", handleOpen);
|
|
3277
|
+
webSocket.removeEventListener("message", handleMessage);
|
|
3278
|
+
errorAndClearAllIteratorStates(ev);
|
|
3279
|
+
}
|
|
3280
|
+
function handleError(ev) {
|
|
3281
|
+
if (!hasConnected) {
|
|
3282
|
+
reject(
|
|
3283
|
+
// TODO: Coded error
|
|
3284
|
+
new Error("WebSocket failed to connect", { cause: ev })
|
|
3285
|
+
);
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
let hasConnected = false;
|
|
3289
|
+
let bufferDrainWatcher;
|
|
3290
|
+
function handleOpen() {
|
|
3291
|
+
hasConnected = true;
|
|
3292
|
+
resolve({
|
|
3293
|
+
async send(payload) {
|
|
3294
|
+
const message = JSON.stringify(payload);
|
|
3295
|
+
if (!bufferDrainWatcher && webSocket.readyState === e22.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
|
|
3296
|
+
let onCancel;
|
|
3297
|
+
const promise = new Promise((resolve2, reject2) => {
|
|
3298
|
+
const intervalId = setInterval(() => {
|
|
3299
|
+
if (webSocket.readyState !== e22.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
|
|
3300
|
+
clearInterval(intervalId);
|
|
3301
|
+
bufferDrainWatcher = void 0;
|
|
3302
|
+
resolve2();
|
|
3303
|
+
}
|
|
3304
|
+
}, 16);
|
|
3305
|
+
onCancel = () => {
|
|
3306
|
+
bufferDrainWatcher = void 0;
|
|
3307
|
+
clearInterval(intervalId);
|
|
3308
|
+
reject2(
|
|
3309
|
+
// TODO: Coded error
|
|
3310
|
+
new Error("WebSocket was closed before payload could be sent")
|
|
3311
|
+
);
|
|
3312
|
+
};
|
|
3313
|
+
});
|
|
3314
|
+
bufferDrainWatcher = {
|
|
3315
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3316
|
+
// @ts-ignore
|
|
3317
|
+
onCancel,
|
|
3318
|
+
promise
|
|
3319
|
+
};
|
|
3320
|
+
}
|
|
3321
|
+
if (bufferDrainWatcher) {
|
|
3322
|
+
await bufferDrainWatcher.promise;
|
|
3323
|
+
}
|
|
3324
|
+
webSocket.send(message);
|
|
3325
|
+
},
|
|
3326
|
+
async *[Symbol.asyncIterator]() {
|
|
3327
|
+
const iteratorKey = Symbol();
|
|
3328
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
3329
|
+
try {
|
|
3330
|
+
while (true) {
|
|
3331
|
+
const state = iteratorState.get(iteratorKey);
|
|
3332
|
+
if (!state) {
|
|
3333
|
+
throw new Error("Invariant: WebSocket message iterator is missing state storage");
|
|
3334
|
+
}
|
|
3335
|
+
if (state.__hasPolled) {
|
|
3336
|
+
throw new Error(
|
|
3337
|
+
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise"
|
|
3338
|
+
);
|
|
3339
|
+
}
|
|
3340
|
+
const queuedMessages = state.queuedMessages;
|
|
3341
|
+
if (queuedMessages.length) {
|
|
3342
|
+
state.queuedMessages = [];
|
|
3343
|
+
yield* queuedMessages;
|
|
3344
|
+
} else {
|
|
3345
|
+
try {
|
|
3346
|
+
yield await new Promise((resolve2, reject2) => {
|
|
3347
|
+
iteratorState.set(iteratorKey, {
|
|
3348
|
+
__hasPolled: true,
|
|
3349
|
+
onError: reject2,
|
|
3350
|
+
onMessage: resolve2
|
|
3351
|
+
});
|
|
3352
|
+
});
|
|
3353
|
+
} catch (e3) {
|
|
3354
|
+
if (e3 === EXPLICIT_ABORT_TOKEN) {
|
|
3355
|
+
return;
|
|
3356
|
+
} else {
|
|
3357
|
+
throw new Error("WebSocket connection closed", { cause: e3 });
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
} finally {
|
|
3363
|
+
iteratorState.delete(iteratorKey);
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
function handleMessage({ data }) {
|
|
3369
|
+
const message = JSON.parse(data);
|
|
3370
|
+
iteratorState.forEach((state, iteratorKey) => {
|
|
3371
|
+
if (state.__hasPolled) {
|
|
3372
|
+
const { onMessage } = state;
|
|
3373
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
3374
|
+
onMessage(message);
|
|
3375
|
+
} else {
|
|
3376
|
+
state.queuedMessages.push(message);
|
|
3377
|
+
}
|
|
3378
|
+
});
|
|
3379
|
+
}
|
|
3380
|
+
const webSocket = new e22(url);
|
|
3381
|
+
webSocket.addEventListener("close", handleClose);
|
|
3382
|
+
webSocket.addEventListener("error", handleError);
|
|
3383
|
+
webSocket.addEventListener("open", handleOpen);
|
|
3384
|
+
webSocket.addEventListener("message", handleMessage);
|
|
3385
|
+
});
|
|
3386
|
+
}
|
|
3387
|
+
function createWebSocketTransport({ sendBufferHighWatermark, url }) {
|
|
3388
|
+
if (/^wss?:/i.test(url) === false) {
|
|
3389
|
+
const protocolMatch = url.match(/^([^:]+):/);
|
|
3390
|
+
throw new DOMException(
|
|
3391
|
+
protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.`
|
|
3392
|
+
);
|
|
3393
|
+
}
|
|
3394
|
+
return async function sendWebSocketMessage({ payload, signal }) {
|
|
3395
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
3396
|
+
const connection = await createWebSocketConnection({
|
|
3397
|
+
sendBufferHighWatermark,
|
|
3398
|
+
signal,
|
|
3399
|
+
url
|
|
3400
|
+
});
|
|
3401
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
3402
|
+
await connection.send(payload);
|
|
3403
|
+
return {
|
|
3404
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
3405
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection)
|
|
3406
|
+
};
|
|
3407
|
+
};
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
// src/rpc.ts
|
|
3411
|
+
var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
|
|
2101
3412
|
|
|
2102
3413
|
// src/rpc-default-config.ts
|
|
2103
3414
|
init_env_shim();
|
|
@@ -2123,6 +3434,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2123
3434
|
super(
|
|
2124
3435
|
`The ${ordinal} argument to the \`${methodName}\` RPC method${path ? ` at path \`${path}\`` : ""} was \`${value}\`. This number is unsafe for use with the Solana JSON-RPC because it exceeds \`Number.MAX_SAFE_INTEGER\`.`
|
|
2125
3436
|
);
|
|
3437
|
+
__publicField(this, "methodName");
|
|
3438
|
+
__publicField(this, "keyPath");
|
|
3439
|
+
__publicField(this, "value");
|
|
2126
3440
|
this.keyPath = keyPath;
|
|
2127
3441
|
this.methodName = methodName;
|
|
2128
3442
|
this.value = value;
|
|
@@ -2139,6 +3453,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2139
3453
|
}
|
|
2140
3454
|
};
|
|
2141
3455
|
|
|
3456
|
+
// src/rpc-subscription-coalescer.ts
|
|
3457
|
+
init_env_shim();
|
|
3458
|
+
|
|
3459
|
+
// src/cached-abortable-iterable.ts
|
|
3460
|
+
init_env_shim();
|
|
3461
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
3462
|
+
(async () => {
|
|
3463
|
+
try {
|
|
3464
|
+
for await (const _ of iterable)
|
|
3465
|
+
;
|
|
3466
|
+
} catch {
|
|
3467
|
+
} finally {
|
|
3468
|
+
cleanupFn();
|
|
3469
|
+
}
|
|
3470
|
+
})();
|
|
3471
|
+
}
|
|
3472
|
+
function getCachedAbortableIterableFactory({
|
|
3473
|
+
getAbortSignalFromInputArgs,
|
|
3474
|
+
getCacheEntryMissingError,
|
|
3475
|
+
getCacheKeyFromInputArgs,
|
|
3476
|
+
onCacheHit,
|
|
3477
|
+
onCreateIterable
|
|
3478
|
+
}) {
|
|
3479
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3480
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
3481
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
3482
|
+
if (!currentCacheEntry) {
|
|
3483
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
3484
|
+
}
|
|
3485
|
+
return currentCacheEntry;
|
|
3486
|
+
}
|
|
3487
|
+
return async (...args) => {
|
|
3488
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
3489
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
3490
|
+
if (cacheKey === void 0) {
|
|
3491
|
+
return await onCreateIterable(signal, ...args);
|
|
3492
|
+
}
|
|
3493
|
+
const cleanup = () => {
|
|
3494
|
+
cache.delete(cacheKey);
|
|
3495
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3496
|
+
};
|
|
3497
|
+
const handleAbort = () => {
|
|
3498
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
3499
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
3500
|
+
cacheEntry.purgeScheduled = true;
|
|
3501
|
+
globalThis.queueMicrotask(() => {
|
|
3502
|
+
cacheEntry.purgeScheduled = false;
|
|
3503
|
+
if (cacheEntry.referenceCount === 0) {
|
|
3504
|
+
cacheEntry.abortController.abort();
|
|
3505
|
+
cleanup();
|
|
3506
|
+
}
|
|
3507
|
+
});
|
|
3508
|
+
}
|
|
3509
|
+
cacheEntry.referenceCount--;
|
|
3510
|
+
};
|
|
3511
|
+
signal.addEventListener("abort", handleAbort);
|
|
3512
|
+
try {
|
|
3513
|
+
const cacheEntry = cache.get(cacheKey);
|
|
3514
|
+
if (!cacheEntry) {
|
|
3515
|
+
const singletonAbortController = new AbortController();
|
|
3516
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
3517
|
+
const newCacheEntry = {
|
|
3518
|
+
abortController: singletonAbortController,
|
|
3519
|
+
iterable: newIterablePromise,
|
|
3520
|
+
purgeScheduled: false,
|
|
3521
|
+
referenceCount: 1
|
|
3522
|
+
};
|
|
3523
|
+
cache.set(cacheKey, newCacheEntry);
|
|
3524
|
+
const newIterable = await newIterablePromise;
|
|
3525
|
+
registerIterableCleanup2(newIterable, cleanup);
|
|
3526
|
+
newCacheEntry.iterable = newIterable;
|
|
3527
|
+
return newIterable;
|
|
3528
|
+
} else {
|
|
3529
|
+
cacheEntry.referenceCount++;
|
|
3530
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
3531
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
3532
|
+
await onCacheHit(cachedIterable, ...args);
|
|
3533
|
+
return cachedIterable;
|
|
3534
|
+
}
|
|
3535
|
+
} catch (e3) {
|
|
3536
|
+
cleanup();
|
|
3537
|
+
throw e3;
|
|
3538
|
+
}
|
|
3539
|
+
};
|
|
3540
|
+
}
|
|
3541
|
+
|
|
3542
|
+
// src/rpc-subscription-coalescer.ts
|
|
3543
|
+
var EXPLICIT_ABORT_TOKEN2 = Symbol(
|
|
3544
|
+
"This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user"
|
|
3545
|
+
);
|
|
3546
|
+
function registerIterableCleanup3(iterable, cleanupFn) {
|
|
3547
|
+
(async () => {
|
|
3548
|
+
try {
|
|
3549
|
+
for await (const _ of iterable)
|
|
3550
|
+
;
|
|
3551
|
+
} catch {
|
|
3552
|
+
} finally {
|
|
3553
|
+
cleanupFn();
|
|
3554
|
+
}
|
|
3555
|
+
})();
|
|
3556
|
+
}
|
|
3557
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
3558
|
+
getDeduplicationKey,
|
|
3559
|
+
rpcSubscriptions
|
|
3560
|
+
}) {
|
|
3561
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3562
|
+
return new Proxy(rpcSubscriptions, {
|
|
3563
|
+
defineProperty() {
|
|
3564
|
+
return false;
|
|
3565
|
+
},
|
|
3566
|
+
deleteProperty() {
|
|
3567
|
+
return false;
|
|
3568
|
+
},
|
|
3569
|
+
get(target, p, receiver) {
|
|
3570
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
3571
|
+
if (typeof subscriptionMethod !== "function") {
|
|
3572
|
+
return subscriptionMethod;
|
|
3573
|
+
}
|
|
3574
|
+
return function(...rawParams) {
|
|
3575
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
3576
|
+
if (deduplicationKey === void 0) {
|
|
3577
|
+
return subscriptionMethod(...rawParams);
|
|
3578
|
+
}
|
|
3579
|
+
if (cache.has(deduplicationKey)) {
|
|
3580
|
+
return cache.get(deduplicationKey);
|
|
3581
|
+
}
|
|
3582
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
3583
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
3584
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
3585
|
+
return new Error(
|
|
3586
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2 == null ? void 0 : deduplicationKey2.toString()}\``
|
|
3587
|
+
);
|
|
3588
|
+
},
|
|
3589
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
3590
|
+
async onCacheHit(_iterable, _config) {
|
|
3591
|
+
},
|
|
3592
|
+
async onCreateIterable(abortSignal, config) {
|
|
3593
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
3594
|
+
...rawParams
|
|
3595
|
+
);
|
|
3596
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
3597
|
+
...config,
|
|
3598
|
+
abortSignal
|
|
3599
|
+
});
|
|
3600
|
+
registerIterableCleanup3(iterable, () => {
|
|
3601
|
+
cache.delete(deduplicationKey);
|
|
3602
|
+
});
|
|
3603
|
+
return iterable;
|
|
3604
|
+
}
|
|
3605
|
+
});
|
|
3606
|
+
const pendingSubscription = {
|
|
3607
|
+
async subscribe(...args) {
|
|
3608
|
+
const iterable = await iterableFactory(...args);
|
|
3609
|
+
const { abortSignal } = args[0];
|
|
3610
|
+
let abortPromise;
|
|
3611
|
+
return {
|
|
3612
|
+
...iterable,
|
|
3613
|
+
async *[Symbol.asyncIterator]() {
|
|
3614
|
+
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN2) : new Promise((_, reject) => {
|
|
3615
|
+
abortSignal.addEventListener("abort", () => {
|
|
3616
|
+
reject(EXPLICIT_ABORT_TOKEN2);
|
|
3617
|
+
});
|
|
3618
|
+
}));
|
|
3619
|
+
try {
|
|
3620
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
3621
|
+
while (true) {
|
|
3622
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
3623
|
+
if (iteratorResult.done) {
|
|
3624
|
+
return;
|
|
3625
|
+
} else {
|
|
3626
|
+
yield iteratorResult.value;
|
|
3627
|
+
}
|
|
3628
|
+
}
|
|
3629
|
+
} catch (e3) {
|
|
3630
|
+
if (e3 === EXPLICIT_ABORT_TOKEN2) {
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3633
|
+
cache.delete(deduplicationKey);
|
|
3634
|
+
throw e3;
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
};
|
|
3638
|
+
}
|
|
3639
|
+
};
|
|
3640
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
3641
|
+
return pendingSubscription;
|
|
3642
|
+
};
|
|
3643
|
+
}
|
|
3644
|
+
});
|
|
3645
|
+
}
|
|
3646
|
+
|
|
2142
3647
|
// src/rpc.ts
|
|
2143
3648
|
function createSolanaRpc(config) {
|
|
2144
3649
|
return createJsonRpc({
|
|
@@ -2146,6 +3651,24 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2146
3651
|
api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
|
|
2147
3652
|
});
|
|
2148
3653
|
}
|
|
3654
|
+
function createSolanaRpcSubscriptions(config) {
|
|
3655
|
+
return pipe(
|
|
3656
|
+
createJsonSubscriptionRpc({
|
|
3657
|
+
...config,
|
|
3658
|
+
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
3659
|
+
}),
|
|
3660
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
3661
|
+
getDeduplicationKey: (...args) => (0, import_fast_stable_stringify.default)(args),
|
|
3662
|
+
rpcSubscriptions
|
|
3663
|
+
})
|
|
3664
|
+
);
|
|
3665
|
+
}
|
|
3666
|
+
function createSolanaRpcSubscriptions_UNSTABLE(config) {
|
|
3667
|
+
return createJsonSubscriptionRpc({
|
|
3668
|
+
...config,
|
|
3669
|
+
api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
|
|
3670
|
+
});
|
|
3671
|
+
}
|
|
2149
3672
|
|
|
2150
3673
|
// src/rpc-transport.ts
|
|
2151
3674
|
init_env_shim();
|
|
@@ -2182,14 +3705,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2182
3705
|
if (signal) {
|
|
2183
3706
|
const responsePromise = coalescedRequest.responsePromise;
|
|
2184
3707
|
return await new Promise((resolve, reject) => {
|
|
2185
|
-
const handleAbort = (
|
|
3708
|
+
const handleAbort = (e3) => {
|
|
2186
3709
|
signal.removeEventListener("abort", handleAbort);
|
|
2187
3710
|
coalescedRequest.numConsumers -= 1;
|
|
2188
3711
|
if (coalescedRequest.numConsumers === 0) {
|
|
2189
3712
|
const abortController = coalescedRequest.abortController;
|
|
2190
3713
|
abortController.abort();
|
|
2191
3714
|
}
|
|
2192
|
-
const abortError = new DOMException(
|
|
3715
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
2193
3716
|
reject(abortError);
|
|
2194
3717
|
};
|
|
2195
3718
|
signal.addEventListener("abort", handleAbort);
|
|
@@ -2205,14 +3728,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2205
3728
|
|
|
2206
3729
|
// src/rpc-request-deduplication.ts
|
|
2207
3730
|
init_env_shim();
|
|
2208
|
-
var
|
|
2209
|
-
function
|
|
3731
|
+
var import_fast_stable_stringify2 = __toESM(require_fast_stable_stringify(), 1);
|
|
3732
|
+
function isJsonRpcPayload(payload) {
|
|
2210
3733
|
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
2211
|
-
return;
|
|
2212
|
-
}
|
|
2213
|
-
if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
|
|
2214
|
-
return (0, import_fast_stable_stringify.default)([payload.method, payload.params]);
|
|
3734
|
+
return false;
|
|
2215
3735
|
}
|
|
3736
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
3737
|
+
}
|
|
3738
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
3739
|
+
return isJsonRpcPayload(payload) ? (0, import_fast_stable_stringify2.default)([payload.method, payload.params]) : void 0;
|
|
2216
3740
|
}
|
|
2217
3741
|
|
|
2218
3742
|
// src/rpc-transport.ts
|
|
@@ -2224,49 +3748,486 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2224
3748
|
return out;
|
|
2225
3749
|
}
|
|
2226
3750
|
function createDefaultRpcTransport(config) {
|
|
2227
|
-
|
|
3751
|
+
var _a;
|
|
3752
|
+
return pipe(
|
|
2228
3753
|
createHttpTransport({
|
|
2229
3754
|
...config,
|
|
2230
3755
|
headers: {
|
|
2231
3756
|
...config.headers ? normalizeHeaders2(config.headers) : void 0,
|
|
2232
3757
|
...{
|
|
2233
3758
|
// Keep these headers lowercase so they will override any user-supplied headers above.
|
|
2234
|
-
"solana-client": `js/${"2.0.0-development"}`
|
|
3759
|
+
"solana-client": (_a = `js/${"2.0.0-development"}`) != null ? _a : "UNKNOWN"
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
}),
|
|
3763
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
3764
|
+
);
|
|
3765
|
+
}
|
|
3766
|
+
|
|
3767
|
+
// src/rpc-websocket-transport.ts
|
|
3768
|
+
init_env_shim();
|
|
3769
|
+
|
|
3770
|
+
// src/rpc-websocket-autopinger.ts
|
|
3771
|
+
init_env_shim();
|
|
3772
|
+
var PING_PAYLOAD = {
|
|
3773
|
+
jsonrpc: "2.0",
|
|
3774
|
+
method: "ping"
|
|
3775
|
+
};
|
|
3776
|
+
function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
3777
|
+
const pingableConnections = /* @__PURE__ */ new Map();
|
|
3778
|
+
return async (...args) => {
|
|
3779
|
+
const connection = await transport(...args);
|
|
3780
|
+
let intervalId;
|
|
3781
|
+
function sendPing() {
|
|
3782
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
3783
|
+
}
|
|
3784
|
+
function restartPingTimer() {
|
|
3785
|
+
clearInterval(intervalId);
|
|
3786
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
3787
|
+
}
|
|
3788
|
+
if (pingableConnections.has(connection) === false) {
|
|
3789
|
+
pingableConnections.set(connection, {
|
|
3790
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
3791
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
3792
|
+
restartPingTimer();
|
|
3793
|
+
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
3794
|
+
}
|
|
3795
|
+
});
|
|
3796
|
+
(async () => {
|
|
3797
|
+
try {
|
|
3798
|
+
for await (const _ of connection) {
|
|
3799
|
+
restartPingTimer();
|
|
3800
|
+
}
|
|
3801
|
+
} catch {
|
|
3802
|
+
} finally {
|
|
3803
|
+
pingableConnections.delete(connection);
|
|
3804
|
+
clearInterval(intervalId);
|
|
3805
|
+
if (handleOffline) {
|
|
3806
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
3807
|
+
}
|
|
3808
|
+
if (handleOnline) {
|
|
3809
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
3810
|
+
}
|
|
2235
3811
|
}
|
|
3812
|
+
})();
|
|
3813
|
+
if (globalThis.navigator.onLine) {
|
|
3814
|
+
restartPingTimer();
|
|
3815
|
+
}
|
|
3816
|
+
let handleOffline;
|
|
3817
|
+
let handleOnline;
|
|
3818
|
+
{
|
|
3819
|
+
handleOffline = () => {
|
|
3820
|
+
clearInterval(intervalId);
|
|
3821
|
+
};
|
|
3822
|
+
handleOnline = () => {
|
|
3823
|
+
sendPing();
|
|
3824
|
+
restartPingTimer();
|
|
3825
|
+
};
|
|
3826
|
+
globalThis.window.addEventListener("offline", handleOffline);
|
|
3827
|
+
globalThis.window.addEventListener("online", handleOnline);
|
|
2236
3828
|
}
|
|
3829
|
+
}
|
|
3830
|
+
return pingableConnections.get(connection);
|
|
3831
|
+
};
|
|
3832
|
+
}
|
|
3833
|
+
|
|
3834
|
+
// src/rpc-websocket-connection-sharding.ts
|
|
3835
|
+
init_env_shim();
|
|
3836
|
+
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
3837
|
+
"Cache key to use when there is no connection sharding strategy"
|
|
3838
|
+
);
|
|
3839
|
+
function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
|
|
3840
|
+
return getCachedAbortableIterableFactory({
|
|
3841
|
+
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
3842
|
+
getCacheEntryMissingError(shardKey) {
|
|
3843
|
+
return new Error(`Found no cache entry for connection with shard key \`${shardKey == null ? void 0 : shardKey.toString()}\``);
|
|
3844
|
+
},
|
|
3845
|
+
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
3846
|
+
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
3847
|
+
onCreateIterable: (abortSignal, config) => transport({
|
|
3848
|
+
...config,
|
|
3849
|
+
signal: abortSignal
|
|
3850
|
+
})
|
|
3851
|
+
});
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3854
|
+
// src/rpc-websocket-transport.ts
|
|
3855
|
+
function createDefaultRpcSubscriptionsTransport(config) {
|
|
3856
|
+
var _a;
|
|
3857
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
3858
|
+
return pipe(
|
|
3859
|
+
createWebSocketTransport({
|
|
3860
|
+
...rest,
|
|
3861
|
+
sendBufferHighWatermark: (_a = config.sendBufferHighWatermark) != null ? _a : (
|
|
3862
|
+
// Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
3863
|
+
131072
|
|
3864
|
+
)
|
|
3865
|
+
}),
|
|
3866
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
3867
|
+
intervalMs: intervalMs != null ? intervalMs : 5e3,
|
|
3868
|
+
transport
|
|
2237
3869
|
}),
|
|
2238
|
-
|
|
3870
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
3871
|
+
getShard,
|
|
3872
|
+
transport
|
|
3873
|
+
})
|
|
3874
|
+
);
|
|
3875
|
+
}
|
|
3876
|
+
|
|
3877
|
+
// src/send-transaction.ts
|
|
3878
|
+
init_env_shim();
|
|
3879
|
+
|
|
3880
|
+
// src/transaction-confirmation.ts
|
|
3881
|
+
init_env_shim();
|
|
3882
|
+
|
|
3883
|
+
// src/transaction-confirmation-strategy-blockheight.ts
|
|
3884
|
+
init_env_shim();
|
|
3885
|
+
function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
|
|
3886
|
+
return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
|
|
3887
|
+
const abortController = new AbortController();
|
|
3888
|
+
function handleAbort() {
|
|
3889
|
+
abortController.abort();
|
|
3890
|
+
}
|
|
3891
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3892
|
+
const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
|
|
3893
|
+
try {
|
|
3894
|
+
for await (const slotNotification of slotNotifications) {
|
|
3895
|
+
if (slotNotification.slot > lastValidBlockHeight) {
|
|
3896
|
+
throw new Error(
|
|
3897
|
+
"The network has progressed past the last block for which this transaction could have committed."
|
|
3898
|
+
);
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
} finally {
|
|
3902
|
+
abortController.abort();
|
|
3903
|
+
}
|
|
3904
|
+
};
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3907
|
+
// src/transaction-confirmation-strategy-nonce.ts
|
|
3908
|
+
init_env_shim();
|
|
3909
|
+
var NONCE_VALUE_OFFSET = 4 + // version(u32)
|
|
3910
|
+
4 + // state(u32)
|
|
3911
|
+
32;
|
|
3912
|
+
function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
3913
|
+
return async function getNonceInvalidationPromise({
|
|
3914
|
+
abortSignal: callerAbortSignal,
|
|
3915
|
+
commitment,
|
|
3916
|
+
currentNonceValue,
|
|
3917
|
+
nonceAccountAddress
|
|
3918
|
+
}) {
|
|
3919
|
+
const abortController = new AbortController();
|
|
3920
|
+
function handleAbort() {
|
|
3921
|
+
abortController.abort();
|
|
3922
|
+
}
|
|
3923
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3924
|
+
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
3925
|
+
const base58Decoder2 = getBase58Decoder();
|
|
3926
|
+
const base64Encoder = getBase64Encoder();
|
|
3927
|
+
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
3928
|
+
const data = base64Encoder.encode(base64EncodedBytes);
|
|
3929
|
+
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
3930
|
+
return base58Decoder2.decode(nonceValueBytes)[0];
|
|
3931
|
+
}
|
|
3932
|
+
const nonceAccountDidAdvancePromise = (async () => {
|
|
3933
|
+
for await (const accountNotification of accountNotifications) {
|
|
3934
|
+
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
3935
|
+
if (nonceValue !== currentNonceValue) {
|
|
3936
|
+
throw new Error(
|
|
3937
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
3938
|
+
);
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
3941
|
+
})();
|
|
3942
|
+
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
3943
|
+
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
3944
|
+
commitment,
|
|
3945
|
+
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
3946
|
+
encoding: "base58"
|
|
3947
|
+
}).send({ abortSignal: abortController.signal });
|
|
3948
|
+
if (!nonceAccount) {
|
|
3949
|
+
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
3950
|
+
}
|
|
3951
|
+
const nonceValue = (
|
|
3952
|
+
// This works because we asked for the exact slice of data representing the nonce
|
|
3953
|
+
// value, and furthermore asked for it in `base58` encoding.
|
|
3954
|
+
nonceAccount.data[0]
|
|
3955
|
+
);
|
|
3956
|
+
if (nonceValue !== currentNonceValue) {
|
|
3957
|
+
throw new Error(
|
|
3958
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
3959
|
+
);
|
|
3960
|
+
} else {
|
|
3961
|
+
await new Promise(() => {
|
|
3962
|
+
});
|
|
3963
|
+
}
|
|
3964
|
+
})();
|
|
3965
|
+
try {
|
|
3966
|
+
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
3967
|
+
} finally {
|
|
3968
|
+
abortController.abort();
|
|
3969
|
+
}
|
|
3970
|
+
};
|
|
3971
|
+
}
|
|
3972
|
+
|
|
3973
|
+
// src/transaction-confirmation.ts
|
|
3974
|
+
function createDefaultDurableNonceTransactionConfirmer({
|
|
3975
|
+
rpc,
|
|
3976
|
+
rpcSubscriptions
|
|
3977
|
+
}) {
|
|
3978
|
+
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
3979
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
3980
|
+
rpc,
|
|
3981
|
+
rpcSubscriptions
|
|
3982
|
+
);
|
|
3983
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
3984
|
+
await waitForDurableNonceTransactionConfirmation({
|
|
3985
|
+
...config,
|
|
3986
|
+
getNonceInvalidationPromise,
|
|
3987
|
+
getRecentSignatureConfirmationPromise
|
|
3988
|
+
});
|
|
3989
|
+
};
|
|
3990
|
+
}
|
|
3991
|
+
function createDefaultRecentTransactionConfirmer({
|
|
3992
|
+
rpc,
|
|
3993
|
+
rpcSubscriptions
|
|
3994
|
+
}) {
|
|
3995
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
|
|
3996
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
3997
|
+
rpc,
|
|
3998
|
+
rpcSubscriptions
|
|
3999
|
+
);
|
|
4000
|
+
return async function confirmRecentTransaction(config) {
|
|
4001
|
+
await waitForRecentTransactionConfirmation({
|
|
4002
|
+
...config,
|
|
4003
|
+
getBlockHeightExceedencePromise,
|
|
4004
|
+
getRecentSignatureConfirmationPromise
|
|
4005
|
+
});
|
|
4006
|
+
};
|
|
4007
|
+
}
|
|
4008
|
+
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
4009
|
+
await raceStrategies(
|
|
4010
|
+
getSignatureFromTransaction(config.transaction),
|
|
4011
|
+
config,
|
|
4012
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
4013
|
+
return [
|
|
4014
|
+
getNonceInvalidationPromise({
|
|
4015
|
+
abortSignal,
|
|
4016
|
+
commitment,
|
|
4017
|
+
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
4018
|
+
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
4019
|
+
})
|
|
4020
|
+
];
|
|
4021
|
+
}
|
|
2239
4022
|
);
|
|
2240
4023
|
}
|
|
4024
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
4025
|
+
await raceStrategies(
|
|
4026
|
+
getSignatureFromTransaction(config.transaction),
|
|
4027
|
+
config,
|
|
4028
|
+
function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
|
|
4029
|
+
return [
|
|
4030
|
+
getBlockHeightExceedencePromise({
|
|
4031
|
+
abortSignal,
|
|
4032
|
+
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
4033
|
+
})
|
|
4034
|
+
];
|
|
4035
|
+
}
|
|
4036
|
+
);
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
// src/send-transaction.ts
|
|
4040
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
4041
|
+
if (
|
|
4042
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
4043
|
+
!(config == null ? void 0 : config.preflightCommitment) && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
4044
|
+
commitmentComparator(
|
|
4045
|
+
commitment,
|
|
4046
|
+
"finalized"
|
|
4047
|
+
/* default value of `preflightCommitment` */
|
|
4048
|
+
) < 0
|
|
4049
|
+
) {
|
|
4050
|
+
return {
|
|
4051
|
+
...config,
|
|
4052
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
4053
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
4054
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
4055
|
+
// confirmation commitment.
|
|
4056
|
+
preflightCommitment: commitment
|
|
4057
|
+
};
|
|
4058
|
+
}
|
|
4059
|
+
return config;
|
|
4060
|
+
}
|
|
4061
|
+
async function sendTransaction_INTERNAL({
|
|
4062
|
+
abortSignal,
|
|
4063
|
+
commitment,
|
|
4064
|
+
rpc,
|
|
4065
|
+
transaction,
|
|
4066
|
+
...sendTransactionConfig
|
|
4067
|
+
}) {
|
|
4068
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
4069
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
4070
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
4071
|
+
encoding: "base64"
|
|
4072
|
+
}).send({ abortSignal });
|
|
4073
|
+
}
|
|
4074
|
+
function createDefaultDurableNonceTransactionSender({
|
|
4075
|
+
rpc,
|
|
4076
|
+
rpcSubscriptions
|
|
4077
|
+
}) {
|
|
4078
|
+
const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
|
|
4079
|
+
rpc,
|
|
4080
|
+
rpcSubscriptions
|
|
4081
|
+
});
|
|
4082
|
+
return async function sendDurableNonceTransaction(transaction, config) {
|
|
4083
|
+
await sendAndConfirmDurableNonceTransaction({
|
|
4084
|
+
...config,
|
|
4085
|
+
confirmDurableNonceTransaction,
|
|
4086
|
+
rpc,
|
|
4087
|
+
transaction
|
|
4088
|
+
});
|
|
4089
|
+
};
|
|
4090
|
+
}
|
|
4091
|
+
function createDefaultTransactionSender({
|
|
4092
|
+
rpc,
|
|
4093
|
+
rpcSubscriptions
|
|
4094
|
+
}) {
|
|
4095
|
+
const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
|
|
4096
|
+
rpc,
|
|
4097
|
+
rpcSubscriptions
|
|
4098
|
+
});
|
|
4099
|
+
return async function sendTransaction(transaction, config) {
|
|
4100
|
+
await sendAndConfirmTransaction({
|
|
4101
|
+
...config,
|
|
4102
|
+
confirmRecentTransaction,
|
|
4103
|
+
rpc,
|
|
4104
|
+
transaction
|
|
4105
|
+
});
|
|
4106
|
+
};
|
|
4107
|
+
}
|
|
4108
|
+
async function sendAndConfirmDurableNonceTransaction({
|
|
4109
|
+
abortSignal,
|
|
4110
|
+
commitment,
|
|
4111
|
+
confirmDurableNonceTransaction,
|
|
4112
|
+
rpc,
|
|
4113
|
+
transaction,
|
|
4114
|
+
...sendTransactionConfig
|
|
4115
|
+
}) {
|
|
4116
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
4117
|
+
...sendTransactionConfig,
|
|
4118
|
+
abortSignal,
|
|
4119
|
+
commitment,
|
|
4120
|
+
rpc,
|
|
4121
|
+
transaction
|
|
4122
|
+
});
|
|
4123
|
+
await confirmDurableNonceTransaction({
|
|
4124
|
+
abortSignal,
|
|
4125
|
+
commitment,
|
|
4126
|
+
transaction
|
|
4127
|
+
});
|
|
4128
|
+
return transactionSignature;
|
|
4129
|
+
}
|
|
4130
|
+
async function sendAndConfirmTransaction({
|
|
4131
|
+
abortSignal,
|
|
4132
|
+
commitment,
|
|
4133
|
+
confirmRecentTransaction,
|
|
4134
|
+
rpc,
|
|
4135
|
+
transaction,
|
|
4136
|
+
...sendTransactionConfig
|
|
4137
|
+
}) {
|
|
4138
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
4139
|
+
...sendTransactionConfig,
|
|
4140
|
+
abortSignal,
|
|
4141
|
+
commitment,
|
|
4142
|
+
rpc,
|
|
4143
|
+
transaction
|
|
4144
|
+
});
|
|
4145
|
+
await confirmRecentTransaction({
|
|
4146
|
+
abortSignal,
|
|
4147
|
+
commitment,
|
|
4148
|
+
transaction
|
|
4149
|
+
});
|
|
4150
|
+
return transactionSignature;
|
|
4151
|
+
}
|
|
2241
4152
|
|
|
2242
4153
|
exports.AccountRole = AccountRole;
|
|
4154
|
+
exports.address = address;
|
|
2243
4155
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
2244
|
-
exports.
|
|
4156
|
+
exports.assertIsAddress = assertIsAddress;
|
|
2245
4157
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
2246
4158
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
4159
|
+
exports.assertIsLamports = assertIsLamports;
|
|
4160
|
+
exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
|
|
4161
|
+
exports.assertIsSignature = assertIsSignature;
|
|
4162
|
+
exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
|
|
4163
|
+
exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
|
|
4164
|
+
exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
|
|
4165
|
+
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
4166
|
+
exports.commitmentComparator = commitmentComparator;
|
|
4167
|
+
exports.compileMessage = compileMessage;
|
|
4168
|
+
exports.createAddressWithSeed = createAddressWithSeed;
|
|
4169
|
+
exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
|
|
4170
|
+
exports.createDefaultAirdropRequester = createDefaultAirdropRequester;
|
|
4171
|
+
exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
|
|
4172
|
+
exports.createDefaultDurableNonceTransactionSender = createDefaultDurableNonceTransactionSender;
|
|
4173
|
+
exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
|
|
4174
|
+
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
2247
4175
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
4176
|
+
exports.createDefaultTransactionSender = createDefaultTransactionSender;
|
|
4177
|
+
exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
|
|
4178
|
+
exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
|
|
2248
4179
|
exports.createSolanaRpc = createSolanaRpc;
|
|
4180
|
+
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
4181
|
+
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
2249
4182
|
exports.createTransaction = createTransaction;
|
|
2250
4183
|
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
2251
4184
|
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
2252
4185
|
exports.generateKeyPair = generateKeyPair;
|
|
4186
|
+
exports.getAddressCodec = getAddressCodec;
|
|
4187
|
+
exports.getAddressComparator = getAddressComparator;
|
|
4188
|
+
exports.getAddressDecoder = getAddressDecoder;
|
|
4189
|
+
exports.getAddressEncoder = getAddressEncoder;
|
|
2253
4190
|
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
2254
|
-
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
|
|
2255
|
-
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
2256
4191
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
4192
|
+
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
4193
|
+
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
4194
|
+
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
2257
4195
|
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
4196
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
4197
|
+
exports.getTransactionCodec = getTransactionCodec;
|
|
4198
|
+
exports.getTransactionDecoder = getTransactionDecoder;
|
|
4199
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
4200
|
+
exports.isAddress = isAddress;
|
|
4201
|
+
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
4202
|
+
exports.isLamports = isLamports;
|
|
4203
|
+
exports.isProgramDerivedAddress = isProgramDerivedAddress;
|
|
4204
|
+
exports.isSignature = isSignature;
|
|
2258
4205
|
exports.isSignerRole = isSignerRole;
|
|
4206
|
+
exports.isStringifiedBigInt = isStringifiedBigInt;
|
|
4207
|
+
exports.isStringifiedNumber = isStringifiedNumber;
|
|
4208
|
+
exports.isUnixTimestamp = isUnixTimestamp;
|
|
2259
4209
|
exports.isWritableRole = isWritableRole;
|
|
4210
|
+
exports.lamports = lamports;
|
|
2260
4211
|
exports.mergeRoles = mergeRoles;
|
|
4212
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
2261
4213
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
4214
|
+
exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
|
|
4215
|
+
exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
|
|
4216
|
+
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|
|
2262
4217
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
2263
4218
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
2264
4219
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
2265
4220
|
exports.signBytes = signBytes;
|
|
2266
4221
|
exports.signTransaction = signTransaction;
|
|
4222
|
+
exports.signature = signature;
|
|
4223
|
+
exports.stringifiedBigInt = stringifiedBigInt;
|
|
4224
|
+
exports.stringifiedNumber = stringifiedNumber;
|
|
4225
|
+
exports.unixTimestamp = unixTimestamp;
|
|
2267
4226
|
exports.upgradeRoleToSigner = upgradeRoleToSigner;
|
|
2268
4227
|
exports.upgradeRoleToWritable = upgradeRoleToWritable;
|
|
2269
4228
|
exports.verifySignature = verifySignature;
|
|
4229
|
+
exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
|
|
4230
|
+
exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
|
|
2270
4231
|
|
|
2271
4232
|
return exports;
|
|
2272
4233
|
|