@solana/web3.js 1.78.0 → 2.0.0-development
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/README.md +56 -112
- package/dist/index.browser.cjs +158 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +137 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.development.js +1044 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.js +139 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +158 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +139 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.production.min.js +25 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/rpc-default-config.d.ts +3 -0
- package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
- package/dist/types/rpc-request-coalescer.d.ts +5 -0
- package/dist/types/rpc-request-deduplication.d.ts +2 -0
- package/dist/types/rpc-transport.d.ts +4 -0
- package/dist/types/rpc.d.ts +5 -0
- package/package.json +86 -111
- package/lib/index.browser.cjs.js +0 -10248
- package/lib/index.browser.cjs.js.map +0 -1
- package/lib/index.browser.esm.js +0 -10145
- package/lib/index.browser.esm.js.map +0 -1
- package/lib/index.cjs.js +0 -12748
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.d.ts +0 -3904
- package/lib/index.esm.js +0 -12638
- package/lib/index.esm.js.map +0 -1
- package/lib/index.iife.js +0 -26757
- package/lib/index.iife.js.map +0 -1
- package/lib/index.iife.min.js +0 -20
- package/lib/index.iife.min.js.map +0 -1
- package/lib/index.native.js +0 -10248
- package/lib/index.native.js.map +0 -1
- package/src/__forks__/browser/fetch-impl.ts +0 -4
- package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
- package/src/__forks__/react-native/fetch-impl.ts +0 -4
- package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
- package/src/account-data.ts +0 -39
- package/src/account.ts +0 -55
- package/src/blockhash.ts +0 -4
- package/src/bpf-loader-deprecated.ts +0 -5
- package/src/bpf-loader.ts +0 -45
- package/src/connection.ts +0 -6796
- package/src/epoch-schedule.ts +0 -102
- package/src/errors.ts +0 -50
- package/src/fee-calculator.ts +0 -18
- package/src/fetch-impl.ts +0 -13
- package/src/index.ts +0 -24
- package/src/instruction.ts +0 -58
- package/src/keypair.ts +0 -93
- package/src/layout.ts +0 -188
- package/src/loader.ts +0 -267
- package/src/message/account-keys.ts +0 -79
- package/src/message/compiled-keys.ts +0 -165
- package/src/message/index.ts +0 -47
- package/src/message/legacy.ts +0 -326
- package/src/message/v0.ts +0 -496
- package/src/message/versioned.ts +0 -36
- package/src/nonce-account.ts +0 -82
- package/src/programs/address-lookup-table/index.ts +0 -435
- package/src/programs/address-lookup-table/state.ts +0 -84
- package/src/programs/compute-budget.ts +0 -281
- package/src/programs/ed25519.ts +0 -157
- package/src/programs/index.ts +0 -7
- package/src/programs/secp256k1.ts +0 -228
- package/src/programs/stake.ts +0 -935
- package/src/programs/system.ts +0 -1048
- package/src/programs/vote.ts +0 -543
- package/src/publickey.ts +0 -259
- package/src/rpc-websocket-factory.ts +0 -4
- package/src/rpc-websocket.ts +0 -79
- package/src/sysvar.ts +0 -37
- package/src/timing.ts +0 -23
- package/src/transaction/constants.ts +0 -12
- package/src/transaction/expiry-custom-errors.ts +0 -48
- package/src/transaction/index.ts +0 -5
- package/src/transaction/legacy.ts +0 -918
- package/src/transaction/message.ts +0 -140
- package/src/transaction/versioned.ts +0 -126
- package/src/utils/assert.ts +0 -8
- package/src/utils/bigint.ts +0 -43
- package/src/utils/borsh-schema.ts +0 -38
- package/src/utils/cluster.ts +0 -31
- package/src/utils/ed25519.ts +0 -43
- package/src/utils/index.ts +0 -5
- package/src/utils/makeWebsocketUrl.ts +0 -26
- package/src/utils/promise-timeout.ts +0 -14
- package/src/utils/secp256k1.ts +0 -11
- package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
- package/src/utils/send-and-confirm-transaction.ts +0 -98
- package/src/utils/shortvec-encoding.ts +0 -28
- package/src/utils/sleep.ts +0 -4
- package/src/utils/to-buffer.ts +0 -11
- package/src/validator-info.ts +0 -104
- package/src/vote-account.ts +0 -236
package/src/loader.ts
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import {Buffer} from 'buffer';
|
|
2
|
-
import * as BufferLayout from '@solana/buffer-layout';
|
|
3
|
-
|
|
4
|
-
import {PublicKey} from './publickey';
|
|
5
|
-
import {Transaction, PACKET_DATA_SIZE} from './transaction';
|
|
6
|
-
import {MS_PER_SLOT} from './timing';
|
|
7
|
-
import {SYSVAR_RENT_PUBKEY} from './sysvar';
|
|
8
|
-
import {sendAndConfirmTransaction} from './utils/send-and-confirm-transaction';
|
|
9
|
-
import {sleep} from './utils/sleep';
|
|
10
|
-
import type {Connection} from './connection';
|
|
11
|
-
import type {Signer} from './keypair';
|
|
12
|
-
import {SystemProgram} from './programs/system';
|
|
13
|
-
import {IInstructionInputData} from './instruction';
|
|
14
|
-
|
|
15
|
-
// Keep program chunks under PACKET_DATA_SIZE, leaving enough room for the
|
|
16
|
-
// rest of the Transaction fields
|
|
17
|
-
//
|
|
18
|
-
// TODO: replace 300 with a proper constant for the size of the other
|
|
19
|
-
// Transaction fields
|
|
20
|
-
const CHUNK_SIZE = PACKET_DATA_SIZE - 300;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Program loader interface
|
|
24
|
-
*/
|
|
25
|
-
export class Loader {
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
constructor() {}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Amount of program data placed in each load Transaction
|
|
33
|
-
*/
|
|
34
|
-
static chunkSize: number = CHUNK_SIZE;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Minimum number of signatures required to load a program not including
|
|
38
|
-
* retries
|
|
39
|
-
*
|
|
40
|
-
* Can be used to calculate transaction fees
|
|
41
|
-
*/
|
|
42
|
-
static getMinNumSignatures(dataLength: number): number {
|
|
43
|
-
return (
|
|
44
|
-
2 * // Every transaction requires two signatures (payer + program)
|
|
45
|
-
(Math.ceil(dataLength / Loader.chunkSize) +
|
|
46
|
-
1 + // Add one for Create transaction
|
|
47
|
-
1) // Add one for Finalize transaction
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Loads a generic program
|
|
53
|
-
*
|
|
54
|
-
* @param connection The connection to use
|
|
55
|
-
* @param payer System account that pays to load the program
|
|
56
|
-
* @param program Account to load the program into
|
|
57
|
-
* @param programId Public key that identifies the loader
|
|
58
|
-
* @param data Program octets
|
|
59
|
-
* @return true if program was loaded successfully, false if program was already loaded
|
|
60
|
-
*/
|
|
61
|
-
static async load(
|
|
62
|
-
connection: Connection,
|
|
63
|
-
payer: Signer,
|
|
64
|
-
program: Signer,
|
|
65
|
-
programId: PublicKey,
|
|
66
|
-
data: Buffer | Uint8Array | Array<number>,
|
|
67
|
-
): Promise<boolean> {
|
|
68
|
-
{
|
|
69
|
-
const balanceNeeded = await connection.getMinimumBalanceForRentExemption(
|
|
70
|
-
data.length,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Fetch program account info to check if it has already been created
|
|
74
|
-
const programInfo = await connection.getAccountInfo(
|
|
75
|
-
program.publicKey,
|
|
76
|
-
'confirmed',
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
let transaction: Transaction | null = null;
|
|
80
|
-
if (programInfo !== null) {
|
|
81
|
-
if (programInfo.executable) {
|
|
82
|
-
console.error('Program load failed, account is already executable');
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (programInfo.data.length !== data.length) {
|
|
87
|
-
transaction = transaction || new Transaction();
|
|
88
|
-
transaction.add(
|
|
89
|
-
SystemProgram.allocate({
|
|
90
|
-
accountPubkey: program.publicKey,
|
|
91
|
-
space: data.length,
|
|
92
|
-
}),
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!programInfo.owner.equals(programId)) {
|
|
97
|
-
transaction = transaction || new Transaction();
|
|
98
|
-
transaction.add(
|
|
99
|
-
SystemProgram.assign({
|
|
100
|
-
accountPubkey: program.publicKey,
|
|
101
|
-
programId,
|
|
102
|
-
}),
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (programInfo.lamports < balanceNeeded) {
|
|
107
|
-
transaction = transaction || new Transaction();
|
|
108
|
-
transaction.add(
|
|
109
|
-
SystemProgram.transfer({
|
|
110
|
-
fromPubkey: payer.publicKey,
|
|
111
|
-
toPubkey: program.publicKey,
|
|
112
|
-
lamports: balanceNeeded - programInfo.lamports,
|
|
113
|
-
}),
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
transaction = new Transaction().add(
|
|
118
|
-
SystemProgram.createAccount({
|
|
119
|
-
fromPubkey: payer.publicKey,
|
|
120
|
-
newAccountPubkey: program.publicKey,
|
|
121
|
-
lamports: balanceNeeded > 0 ? balanceNeeded : 1,
|
|
122
|
-
space: data.length,
|
|
123
|
-
programId,
|
|
124
|
-
}),
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// If the account is already created correctly, skip this step
|
|
129
|
-
// and proceed directly to loading instructions
|
|
130
|
-
if (transaction !== null) {
|
|
131
|
-
await sendAndConfirmTransaction(
|
|
132
|
-
connection,
|
|
133
|
-
transaction,
|
|
134
|
-
[payer, program],
|
|
135
|
-
{
|
|
136
|
-
commitment: 'confirmed',
|
|
137
|
-
},
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const dataLayout = BufferLayout.struct<
|
|
143
|
-
Readonly<{
|
|
144
|
-
bytes: number[];
|
|
145
|
-
bytesLength: number;
|
|
146
|
-
bytesLengthPadding: number;
|
|
147
|
-
instruction: number;
|
|
148
|
-
offset: number;
|
|
149
|
-
}>
|
|
150
|
-
>([
|
|
151
|
-
BufferLayout.u32('instruction'),
|
|
152
|
-
BufferLayout.u32('offset'),
|
|
153
|
-
BufferLayout.u32('bytesLength'),
|
|
154
|
-
BufferLayout.u32('bytesLengthPadding'),
|
|
155
|
-
BufferLayout.seq(
|
|
156
|
-
BufferLayout.u8('byte'),
|
|
157
|
-
BufferLayout.offset(BufferLayout.u32(), -8),
|
|
158
|
-
'bytes',
|
|
159
|
-
),
|
|
160
|
-
]);
|
|
161
|
-
|
|
162
|
-
const chunkSize = Loader.chunkSize;
|
|
163
|
-
let offset = 0;
|
|
164
|
-
let array = data;
|
|
165
|
-
let transactions = [];
|
|
166
|
-
while (array.length > 0) {
|
|
167
|
-
const bytes = array.slice(0, chunkSize);
|
|
168
|
-
const data = Buffer.alloc(chunkSize + 16);
|
|
169
|
-
dataLayout.encode(
|
|
170
|
-
{
|
|
171
|
-
instruction: 0, // Load instruction
|
|
172
|
-
offset,
|
|
173
|
-
bytes: bytes as number[],
|
|
174
|
-
bytesLength: 0,
|
|
175
|
-
bytesLengthPadding: 0,
|
|
176
|
-
},
|
|
177
|
-
data,
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
const transaction = new Transaction().add({
|
|
181
|
-
keys: [{pubkey: program.publicKey, isSigner: true, isWritable: true}],
|
|
182
|
-
programId,
|
|
183
|
-
data,
|
|
184
|
-
});
|
|
185
|
-
transactions.push(
|
|
186
|
-
sendAndConfirmTransaction(connection, transaction, [payer, program], {
|
|
187
|
-
commitment: 'confirmed',
|
|
188
|
-
}),
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
// Delay between sends in an attempt to reduce rate limit errors
|
|
192
|
-
if (connection._rpcEndpoint.includes('solana.com')) {
|
|
193
|
-
const REQUESTS_PER_SECOND = 4;
|
|
194
|
-
await sleep(1000 / REQUESTS_PER_SECOND);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
offset += chunkSize;
|
|
198
|
-
array = array.slice(chunkSize);
|
|
199
|
-
}
|
|
200
|
-
await Promise.all(transactions);
|
|
201
|
-
|
|
202
|
-
// Finalize the account loaded with program data for execution
|
|
203
|
-
{
|
|
204
|
-
const dataLayout = BufferLayout.struct<IInstructionInputData>([
|
|
205
|
-
BufferLayout.u32('instruction'),
|
|
206
|
-
]);
|
|
207
|
-
|
|
208
|
-
const data = Buffer.alloc(dataLayout.span);
|
|
209
|
-
dataLayout.encode(
|
|
210
|
-
{
|
|
211
|
-
instruction: 1, // Finalize instruction
|
|
212
|
-
},
|
|
213
|
-
data,
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
const transaction = new Transaction().add({
|
|
217
|
-
keys: [
|
|
218
|
-
{pubkey: program.publicKey, isSigner: true, isWritable: true},
|
|
219
|
-
{pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false},
|
|
220
|
-
],
|
|
221
|
-
programId,
|
|
222
|
-
data,
|
|
223
|
-
});
|
|
224
|
-
const deployCommitment = 'processed';
|
|
225
|
-
const finalizeSignature = await connection.sendTransaction(
|
|
226
|
-
transaction,
|
|
227
|
-
[payer, program],
|
|
228
|
-
{preflightCommitment: deployCommitment},
|
|
229
|
-
);
|
|
230
|
-
const {context, value} = await connection.confirmTransaction(
|
|
231
|
-
{
|
|
232
|
-
signature: finalizeSignature,
|
|
233
|
-
lastValidBlockHeight: transaction.lastValidBlockHeight!,
|
|
234
|
-
blockhash: transaction.recentBlockhash!,
|
|
235
|
-
},
|
|
236
|
-
deployCommitment,
|
|
237
|
-
);
|
|
238
|
-
if (value.err) {
|
|
239
|
-
throw new Error(
|
|
240
|
-
`Transaction ${finalizeSignature} failed (${JSON.stringify(value)})`,
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
// We prevent programs from being usable until the slot after their deployment.
|
|
244
|
-
// See https://github.com/solana-labs/solana/pull/29654
|
|
245
|
-
while (
|
|
246
|
-
true // eslint-disable-line no-constant-condition
|
|
247
|
-
) {
|
|
248
|
-
try {
|
|
249
|
-
const currentSlot = await connection.getSlot({
|
|
250
|
-
commitment: deployCommitment,
|
|
251
|
-
});
|
|
252
|
-
if (currentSlot > context.slot) {
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
} catch {
|
|
256
|
-
/* empty */
|
|
257
|
-
}
|
|
258
|
-
await new Promise(resolve =>
|
|
259
|
-
setTimeout(resolve, Math.round(MS_PER_SLOT / 2)),
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// success
|
|
265
|
-
return true;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import {LoadedAddresses} from '../connection';
|
|
2
|
-
import {PublicKey} from '../publickey';
|
|
3
|
-
import {TransactionInstruction} from '../transaction';
|
|
4
|
-
import {MessageCompiledInstruction} from './index';
|
|
5
|
-
|
|
6
|
-
export type AccountKeysFromLookups = LoadedAddresses;
|
|
7
|
-
|
|
8
|
-
export class MessageAccountKeys {
|
|
9
|
-
staticAccountKeys: Array<PublicKey>;
|
|
10
|
-
accountKeysFromLookups?: AccountKeysFromLookups;
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
staticAccountKeys: Array<PublicKey>,
|
|
14
|
-
accountKeysFromLookups?: AccountKeysFromLookups,
|
|
15
|
-
) {
|
|
16
|
-
this.staticAccountKeys = staticAccountKeys;
|
|
17
|
-
this.accountKeysFromLookups = accountKeysFromLookups;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
keySegments(): Array<Array<PublicKey>> {
|
|
21
|
-
const keySegments = [this.staticAccountKeys];
|
|
22
|
-
if (this.accountKeysFromLookups) {
|
|
23
|
-
keySegments.push(this.accountKeysFromLookups.writable);
|
|
24
|
-
keySegments.push(this.accountKeysFromLookups.readonly);
|
|
25
|
-
}
|
|
26
|
-
return keySegments;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get(index: number): PublicKey | undefined {
|
|
30
|
-
for (const keySegment of this.keySegments()) {
|
|
31
|
-
if (index < keySegment.length) {
|
|
32
|
-
return keySegment[index];
|
|
33
|
-
} else {
|
|
34
|
-
index -= keySegment.length;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get length(): number {
|
|
41
|
-
return this.keySegments().flat().length;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
compileInstructions(
|
|
45
|
-
instructions: Array<TransactionInstruction>,
|
|
46
|
-
): Array<MessageCompiledInstruction> {
|
|
47
|
-
// Bail early if any account indexes would overflow a u8
|
|
48
|
-
const U8_MAX = 255;
|
|
49
|
-
if (this.length > U8_MAX + 1) {
|
|
50
|
-
throw new Error('Account index overflow encountered during compilation');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const keyIndexMap = new Map();
|
|
54
|
-
this.keySegments()
|
|
55
|
-
.flat()
|
|
56
|
-
.forEach((key, index) => {
|
|
57
|
-
keyIndexMap.set(key.toBase58(), index);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const findKeyIndex = (key: PublicKey) => {
|
|
61
|
-
const keyIndex = keyIndexMap.get(key.toBase58());
|
|
62
|
-
if (keyIndex === undefined)
|
|
63
|
-
throw new Error(
|
|
64
|
-
'Encountered an unknown instruction account key during compilation',
|
|
65
|
-
);
|
|
66
|
-
return keyIndex;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return instructions.map((instruction): MessageCompiledInstruction => {
|
|
70
|
-
return {
|
|
71
|
-
programIdIndex: findKeyIndex(instruction.programId),
|
|
72
|
-
accountKeyIndexes: instruction.keys.map(meta =>
|
|
73
|
-
findKeyIndex(meta.pubkey),
|
|
74
|
-
),
|
|
75
|
-
data: instruction.data,
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import {MessageHeader, MessageAddressTableLookup} from './index';
|
|
2
|
-
import {AccountKeysFromLookups} from './account-keys';
|
|
3
|
-
import {AddressLookupTableAccount} from '../programs';
|
|
4
|
-
import {TransactionInstruction} from '../transaction';
|
|
5
|
-
import assert from '../utils/assert';
|
|
6
|
-
import {PublicKey} from '../publickey';
|
|
7
|
-
|
|
8
|
-
export type CompiledKeyMeta = {
|
|
9
|
-
isSigner: boolean;
|
|
10
|
-
isWritable: boolean;
|
|
11
|
-
isInvoked: boolean;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type KeyMetaMap = Map<string, CompiledKeyMeta>;
|
|
15
|
-
|
|
16
|
-
export class CompiledKeys {
|
|
17
|
-
payer: PublicKey;
|
|
18
|
-
keyMetaMap: KeyMetaMap;
|
|
19
|
-
|
|
20
|
-
constructor(payer: PublicKey, keyMetaMap: KeyMetaMap) {
|
|
21
|
-
this.payer = payer;
|
|
22
|
-
this.keyMetaMap = keyMetaMap;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static compile(
|
|
26
|
-
instructions: Array<TransactionInstruction>,
|
|
27
|
-
payer: PublicKey,
|
|
28
|
-
): CompiledKeys {
|
|
29
|
-
const keyMetaMap: KeyMetaMap = new Map();
|
|
30
|
-
const getOrInsertDefault = (pubkey: PublicKey): CompiledKeyMeta => {
|
|
31
|
-
const address = pubkey.toBase58();
|
|
32
|
-
let keyMeta = keyMetaMap.get(address);
|
|
33
|
-
if (keyMeta === undefined) {
|
|
34
|
-
keyMeta = {
|
|
35
|
-
isSigner: false,
|
|
36
|
-
isWritable: false,
|
|
37
|
-
isInvoked: false,
|
|
38
|
-
};
|
|
39
|
-
keyMetaMap.set(address, keyMeta);
|
|
40
|
-
}
|
|
41
|
-
return keyMeta;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
45
|
-
payerKeyMeta.isSigner = true;
|
|
46
|
-
payerKeyMeta.isWritable = true;
|
|
47
|
-
|
|
48
|
-
for (const ix of instructions) {
|
|
49
|
-
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
50
|
-
for (const accountMeta of ix.keys) {
|
|
51
|
-
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
52
|
-
keyMeta.isSigner ||= accountMeta.isSigner;
|
|
53
|
-
keyMeta.isWritable ||= accountMeta.isWritable;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return new CompiledKeys(payer, keyMetaMap);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getMessageComponents(): [MessageHeader, Array<PublicKey>] {
|
|
61
|
-
const mapEntries = [...this.keyMetaMap.entries()];
|
|
62
|
-
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
63
|
-
|
|
64
|
-
const writableSigners = mapEntries.filter(
|
|
65
|
-
([, meta]) => meta.isSigner && meta.isWritable,
|
|
66
|
-
);
|
|
67
|
-
const readonlySigners = mapEntries.filter(
|
|
68
|
-
([, meta]) => meta.isSigner && !meta.isWritable,
|
|
69
|
-
);
|
|
70
|
-
const writableNonSigners = mapEntries.filter(
|
|
71
|
-
([, meta]) => !meta.isSigner && meta.isWritable,
|
|
72
|
-
);
|
|
73
|
-
const readonlyNonSigners = mapEntries.filter(
|
|
74
|
-
([, meta]) => !meta.isSigner && !meta.isWritable,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const header: MessageHeader = {
|
|
78
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
79
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
80
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// sanity checks
|
|
84
|
-
{
|
|
85
|
-
assert(
|
|
86
|
-
writableSigners.length > 0,
|
|
87
|
-
'Expected at least one writable signer key',
|
|
88
|
-
);
|
|
89
|
-
const [payerAddress] = writableSigners[0];
|
|
90
|
-
assert(
|
|
91
|
-
payerAddress === this.payer.toBase58(),
|
|
92
|
-
'Expected first writable signer key to be the fee payer',
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const staticAccountKeys = [
|
|
97
|
-
...writableSigners.map(([address]) => new PublicKey(address)),
|
|
98
|
-
...readonlySigners.map(([address]) => new PublicKey(address)),
|
|
99
|
-
...writableNonSigners.map(([address]) => new PublicKey(address)),
|
|
100
|
-
...readonlyNonSigners.map(([address]) => new PublicKey(address)),
|
|
101
|
-
];
|
|
102
|
-
|
|
103
|
-
return [header, staticAccountKeys];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
extractTableLookup(
|
|
107
|
-
lookupTable: AddressLookupTableAccount,
|
|
108
|
-
): [MessageAddressTableLookup, AccountKeysFromLookups] | undefined {
|
|
109
|
-
const [writableIndexes, drainedWritableKeys] =
|
|
110
|
-
this.drainKeysFoundInLookupTable(
|
|
111
|
-
lookupTable.state.addresses,
|
|
112
|
-
keyMeta =>
|
|
113
|
-
!keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable,
|
|
114
|
-
);
|
|
115
|
-
const [readonlyIndexes, drainedReadonlyKeys] =
|
|
116
|
-
this.drainKeysFoundInLookupTable(
|
|
117
|
-
lookupTable.state.addresses,
|
|
118
|
-
keyMeta =>
|
|
119
|
-
!keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
// Don't extract lookup if no keys were found
|
|
123
|
-
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return [
|
|
128
|
-
{
|
|
129
|
-
accountKey: lookupTable.key,
|
|
130
|
-
writableIndexes,
|
|
131
|
-
readonlyIndexes,
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
writable: drainedWritableKeys,
|
|
135
|
-
readonly: drainedReadonlyKeys,
|
|
136
|
-
},
|
|
137
|
-
];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** @internal */
|
|
141
|
-
private drainKeysFoundInLookupTable(
|
|
142
|
-
lookupTableEntries: Array<PublicKey>,
|
|
143
|
-
keyMetaFilter: (keyMeta: CompiledKeyMeta) => boolean,
|
|
144
|
-
): [Array<number>, Array<PublicKey>] {
|
|
145
|
-
const lookupTableIndexes = new Array();
|
|
146
|
-
const drainedKeys = new Array();
|
|
147
|
-
|
|
148
|
-
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
149
|
-
if (keyMetaFilter(keyMeta)) {
|
|
150
|
-
const key = new PublicKey(address);
|
|
151
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry =>
|
|
152
|
-
entry.equals(key),
|
|
153
|
-
);
|
|
154
|
-
if (lookupTableIndex >= 0) {
|
|
155
|
-
assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
156
|
-
lookupTableIndexes.push(lookupTableIndex);
|
|
157
|
-
drainedKeys.push(key);
|
|
158
|
-
this.keyMetaMap.delete(address);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return [lookupTableIndexes, drainedKeys];
|
|
164
|
-
}
|
|
165
|
-
}
|
package/src/message/index.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {PublicKey} from '../publickey';
|
|
2
|
-
|
|
3
|
-
export * from './account-keys';
|
|
4
|
-
// note: compiled-keys is internal and doesn't need to be exported
|
|
5
|
-
export * from './legacy';
|
|
6
|
-
export * from './versioned';
|
|
7
|
-
export * from './v0';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The message header, identifying signed and read-only account
|
|
11
|
-
*/
|
|
12
|
-
export type MessageHeader = {
|
|
13
|
-
/**
|
|
14
|
-
* The number of signatures required for this message to be considered valid. The
|
|
15
|
-
* signatures must match the first `numRequiredSignatures` of `accountKeys`.
|
|
16
|
-
*/
|
|
17
|
-
numRequiredSignatures: number;
|
|
18
|
-
/** The last `numReadonlySignedAccounts` of the signed keys are read-only accounts */
|
|
19
|
-
numReadonlySignedAccounts: number;
|
|
20
|
-
/** The last `numReadonlySignedAccounts` of the unsigned keys are read-only accounts */
|
|
21
|
-
numReadonlyUnsignedAccounts: number;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* An address table lookup used to load additional accounts
|
|
26
|
-
*/
|
|
27
|
-
export type MessageAddressTableLookup = {
|
|
28
|
-
accountKey: PublicKey;
|
|
29
|
-
writableIndexes: Array<number>;
|
|
30
|
-
readonlyIndexes: Array<number>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* An instruction to execute by a program
|
|
35
|
-
*
|
|
36
|
-
* @property {number} programIdIndex
|
|
37
|
-
* @property {number[]} accountKeyIndexes
|
|
38
|
-
* @property {Uint8Array} data
|
|
39
|
-
*/
|
|
40
|
-
export type MessageCompiledInstruction = {
|
|
41
|
-
/** Index into the transaction keys array indicating the program account that executes this instruction */
|
|
42
|
-
programIdIndex: number;
|
|
43
|
-
/** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
|
|
44
|
-
accountKeyIndexes: number[];
|
|
45
|
-
/** The program input data */
|
|
46
|
-
data: Uint8Array;
|
|
47
|
-
};
|