@solana/web3.js 0.98.0 → 1.0.1
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 +10 -55
- package/lib/index.browser.esm.js +48 -24
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +101 -56
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +88 -64
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +42 -25
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +27 -45
- package/src/message.ts +9 -12
- package/src/transaction.ts +2 -2
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/validator-info.ts +5 -4
- package/bin/bpf-sdk-install.sh +0 -38
- package/bin/localnet.sh +0 -161
- package/bpf-sdk/LICENSE +0 -13
- package/bpf-sdk/c/README.md +0 -44
- package/bpf-sdk/c/bpf.ld +0 -20
- package/bpf-sdk/c/bpf.mk +0 -249
- package/bpf-sdk/c/inc/deserialize_deprecated.h +0 -115
- package/bpf-sdk/c/inc/solana_sdk.h +0 -669
- package/bpf-sdk/c/inc/stdio.h +0 -4
- package/bpf-sdk/c/inc/stdlib.h +0 -2
- package/bpf-sdk/c/inc/string.h +0 -7
- package/bpf-sdk/c/inc/sys/param.h +0 -1
- package/bpf-sdk/c/inc/wchar.h +0 -1
- package/bpf-sdk/env.sh +0 -39
- package/bpf-sdk/rust/bpf.ld +0 -20
- package/bpf-sdk/rust/build.sh +0 -21
- package/bpf-sdk/rust/clean.sh +0 -17
- package/bpf-sdk/rust/xargo-build.sh +0 -29
- package/bpf-sdk/scripts/dump.sh +0 -45
- package/bpf-sdk/scripts/install.sh +0 -178
- package/bpf-sdk/scripts/objcopy.sh +0 -6
- package/bpf-sdk/scripts/package.sh +0 -19
- package/bpf-sdk/scripts/strip.sh +0 -23
- package/bpf-sdk/version.txt +0 -2
- package/doc/assets/css/main.css +0 -2660
- package/doc/assets/images/icons.png +0 -0
- package/doc/assets/images/icons@2x.png +0 -0
- package/doc/assets/images/widgets.png +0 -0
- package/doc/assets/images/widgets@2x.png +0 -0
- package/doc/assets/js/main.js +0 -248
- package/doc/assets/js/search.js +0 -1
- package/doc/classes/account.html +0 -244
- package/doc/classes/authorized.html +0 -234
- package/doc/classes/bpfloader.html +0 -267
- package/doc/classes/connection.html +0 -2354
- package/doc/classes/loader.html +0 -275
- package/doc/classes/lockup.html +0 -250
- package/doc/classes/message.html +0 -326
- package/doc/classes/nonceaccount.html +0 -233
- package/doc/classes/publickey.html +0 -411
- package/doc/classes/secp256k1program.html +0 -308
- package/doc/classes/stakeinstruction.html +0 -403
- package/doc/classes/stakeprogram.html +0 -503
- package/doc/classes/systeminstruction.html +0 -563
- package/doc/classes/systemprogram.html +0 -503
- package/doc/classes/transaction.html +0 -688
- package/doc/classes/transactioninstruction.html +0 -240
- package/doc/classes/validatorinfo.html +0 -279
- package/doc/classes/voteaccount.html +0 -331
- package/doc/index.html +0 -640
- package/doc/interfaces/feecalculator.html +0 -166
- package/doc/modules.html +0 -4682
- package/examples/README.md +0 -10
- package/examples/account.html +0 -24
- package/examples/account.js +0 -10
- package/examples/bpf-c-noop/.gitignore +0 -1
- package/examples/bpf-c-noop/makefile +0 -1
- package/examples/bpf-c-noop/src/noop/noop.c +0 -19
- package/examples/bpf-rust-noop/.gitignore +0 -3
- package/examples/bpf-rust-noop/Cargo.toml +0 -23
- package/examples/bpf-rust-noop/Xargo.toml +0 -2
- package/examples/bpf-rust-noop/src/lib.rs +0 -70
- package/examples/get-balance.html +0 -37
- package/examples/get-balance.js +0 -18
|
@@ -1,669 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
/**
|
|
3
|
-
* @brief Solana C-based BPF program utility functions and types
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
#ifdef __cplusplus
|
|
7
|
-
extern "C" {
|
|
8
|
-
#endif
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Pick up static_assert if C11 or greater
|
|
12
|
-
*
|
|
13
|
-
* Inlined here until <assert.h> is available
|
|
14
|
-
*/
|
|
15
|
-
#if (defined _ISOC11_SOURCE || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)) && !defined (__cplusplus)
|
|
16
|
-
#undef static_assert
|
|
17
|
-
#define static_assert _Static_assert
|
|
18
|
-
#endif
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Numeric types
|
|
22
|
-
*/
|
|
23
|
-
#ifndef __LP64__
|
|
24
|
-
#error LP64 data model required
|
|
25
|
-
#endif
|
|
26
|
-
|
|
27
|
-
typedef signed char int8_t;
|
|
28
|
-
typedef unsigned char uint8_t;
|
|
29
|
-
typedef signed short int16_t;
|
|
30
|
-
typedef unsigned short uint16_t;
|
|
31
|
-
typedef signed int int32_t;
|
|
32
|
-
typedef unsigned int uint32_t;
|
|
33
|
-
typedef signed long int int64_t;
|
|
34
|
-
typedef unsigned long int uint64_t;
|
|
35
|
-
typedef int64_t ssize_t;
|
|
36
|
-
typedef uint64_t size_t;
|
|
37
|
-
|
|
38
|
-
#if defined (__cplusplus) || defined(static_assert)
|
|
39
|
-
static_assert(sizeof(int8_t) == 1);
|
|
40
|
-
static_assert(sizeof(uint8_t) == 1);
|
|
41
|
-
static_assert(sizeof(int16_t) == 2);
|
|
42
|
-
static_assert(sizeof(uint16_t) == 2);
|
|
43
|
-
static_assert(sizeof(int32_t) == 4);
|
|
44
|
-
static_assert(sizeof(uint32_t) == 4);
|
|
45
|
-
static_assert(sizeof(int64_t) == 8);
|
|
46
|
-
static_assert(sizeof(uint64_t) == 8);
|
|
47
|
-
#endif
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Minimum of signed integral types
|
|
51
|
-
*/
|
|
52
|
-
#define INT8_MIN (-128)
|
|
53
|
-
#define INT16_MIN (-32767-1)
|
|
54
|
-
#define INT32_MIN (-2147483647-1)
|
|
55
|
-
#define INT64_MIN (-9223372036854775807L-1)
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Maximum of signed integral types
|
|
59
|
-
*/
|
|
60
|
-
#define INT8_MAX (127)
|
|
61
|
-
#define INT16_MAX (32767)
|
|
62
|
-
#define INT32_MAX (2147483647)
|
|
63
|
-
#define INT64_MAX (9223372036854775807L)
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Maximum of unsigned integral types
|
|
67
|
-
*/
|
|
68
|
-
#define UINT8_MAX (255)
|
|
69
|
-
#define UINT16_MAX (65535)
|
|
70
|
-
#define UINT32_MAX (4294967295U)
|
|
71
|
-
#define UINT64_MAX (18446744073709551615UL)
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* NULL
|
|
75
|
-
*/
|
|
76
|
-
#define NULL 0
|
|
77
|
-
|
|
78
|
-
/** Indicates the instruction was processed successfully */
|
|
79
|
-
#define SUCCESS 0
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Builtin program status values occupy the upper 32 bits of the program return
|
|
83
|
-
* value. Programs may define their own error values but they must be confined
|
|
84
|
-
* to the lower 32 bits.
|
|
85
|
-
*/
|
|
86
|
-
#define TO_BUILTIN(error) ((uint64_t)(error) << 32)
|
|
87
|
-
|
|
88
|
-
/** Note: Not applicable to program written in C */
|
|
89
|
-
#define ERROR_CUSTOM_ZERO TO_BUILTIN(1)
|
|
90
|
-
/** The arguments provided to a program instruction where invalid */
|
|
91
|
-
#define ERROR_INVALID_ARGUMENT TO_BUILTIN(2)
|
|
92
|
-
/** An instruction's data contents was invalid */
|
|
93
|
-
#define ERROR_INVALID_INSTRUCTION_DATA TO_BUILTIN(3)
|
|
94
|
-
/** An account's data contents was invalid */
|
|
95
|
-
#define ERROR_INVALID_ACCOUNT_DATA TO_BUILTIN(4)
|
|
96
|
-
/** An account's data was too small */
|
|
97
|
-
#define ERROR_ACCOUNT_DATA_TOO_SMALL TO_BUILTIN(5)
|
|
98
|
-
/** An account's balance was too small to complete the instruction */
|
|
99
|
-
#define ERROR_INSUFFICIENT_FUNDS TO_BUILTIN(6)
|
|
100
|
-
/** The account did not have the expected program id */
|
|
101
|
-
#define ERROR_INCORRECT_PROGRAM_ID TO_BUILTIN(7)
|
|
102
|
-
/** A signature was required but not found */
|
|
103
|
-
#define ERROR_MISSING_REQUIRED_SIGNATURES TO_BUILTIN(8)
|
|
104
|
-
/** An initialize instruction was sent to an account that has already been initialized */
|
|
105
|
-
#define ERROR_ACCOUNT_ALREADY_INITIALIZED TO_BUILTIN(9)
|
|
106
|
-
/** An attempt to operate on an account that hasn't been initialized */
|
|
107
|
-
#define ERROR_UNINITIALIZED_ACCOUNT TO_BUILTIN(10)
|
|
108
|
-
/** The instruction expected additional account keys */
|
|
109
|
-
#define ERROR_NOT_ENOUGH_ACCOUNT_KEYS TO_BUILTIN(11)
|
|
110
|
-
/** Note: Not applicable to program written in C */
|
|
111
|
-
#define ERROR_ACCOUNT_BORROW_FAILED TO_BUILTIN(12)
|
|
112
|
-
/** The length of the seed is too long for address generation */
|
|
113
|
-
#define MAX_SEED_LENGTH_EXCEEDED TO_BUILTIN(13)
|
|
114
|
-
/** Provided seeds do not result in a valid address */
|
|
115
|
-
#define INVALID_SEEDS TO_BUILTIN(14)
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Boolean type
|
|
119
|
-
*/
|
|
120
|
-
#ifndef __cplusplus
|
|
121
|
-
#include <stdbool.h>
|
|
122
|
-
#endif
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Prints a string to stdout
|
|
126
|
-
*/
|
|
127
|
-
void sol_log_(const char *, uint64_t);
|
|
128
|
-
#define sol_log(message) sol_log_(message, sol_strlen(message))
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Prints a 64 bit values represented in hexadecimal to stdout
|
|
132
|
-
*/
|
|
133
|
-
void sol_log_64_(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
|
134
|
-
#define sol_log_64 sol_log_64_
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Prints the current compute unit consumption to stdout
|
|
138
|
-
*/
|
|
139
|
-
void sol_log_compute_units_();
|
|
140
|
-
#define sol_log_compute_units() sol_log_compute_units_()
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Size of Public key in bytes
|
|
144
|
-
*/
|
|
145
|
-
#define SIZE_PUBKEY 32
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Public key
|
|
149
|
-
*/
|
|
150
|
-
typedef struct {
|
|
151
|
-
uint8_t x[SIZE_PUBKEY];
|
|
152
|
-
} SolPubkey;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Compares two public keys
|
|
156
|
-
*
|
|
157
|
-
* @param one First public key
|
|
158
|
-
* @param two Second public key
|
|
159
|
-
* @return true if the same
|
|
160
|
-
*/
|
|
161
|
-
static bool SolPubkey_same(const SolPubkey *one, const SolPubkey *two) {
|
|
162
|
-
for (int i = 0; i < sizeof(*one); i++) {
|
|
163
|
-
if (one->x[i] != two->x[i]) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Keyed Account
|
|
172
|
-
*/
|
|
173
|
-
typedef struct {
|
|
174
|
-
SolPubkey *key; /** Public key of the account */
|
|
175
|
-
uint64_t *lamports; /** Number of lamports owned by this account */
|
|
176
|
-
uint64_t data_len; /** Length of data in bytes */
|
|
177
|
-
uint8_t *data; /** On-chain data within this account */
|
|
178
|
-
SolPubkey *owner; /** Program that owns this account */
|
|
179
|
-
uint64_t rent_epoch; /** The epoch at which this account will next owe rent */
|
|
180
|
-
bool is_signer; /** Transaction was signed by this account's key? */
|
|
181
|
-
bool is_writable; /** Is the account writable? */
|
|
182
|
-
bool executable; /** This account's data contains a loaded program (and is now read-only) */
|
|
183
|
-
} SolAccountInfo;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Copies memory
|
|
187
|
-
*/
|
|
188
|
-
static void sol_memcpy(void *dst, const void *src, int len) {
|
|
189
|
-
for (int i = 0; i < len; i++) {
|
|
190
|
-
*((uint8_t *)dst + i) = *((const uint8_t *)src + i);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Compares memory
|
|
196
|
-
*/
|
|
197
|
-
static int sol_memcmp(const void *s1, const void *s2, int n) {
|
|
198
|
-
for (int i = 0; i < n; i++) {
|
|
199
|
-
uint8_t diff = *((uint8_t *)s1 + i) - *((const uint8_t *)s2 + i);
|
|
200
|
-
if (diff) {
|
|
201
|
-
return diff;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return 0;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Fill a byte string with a byte value
|
|
209
|
-
*/
|
|
210
|
-
static void *sol_memset(void *b, int c, size_t len) {
|
|
211
|
-
uint8_t *a = (uint8_t *) b;
|
|
212
|
-
while (len > 0) {
|
|
213
|
-
*a = c;
|
|
214
|
-
a++;
|
|
215
|
-
len--;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Find length of string
|
|
221
|
-
*/
|
|
222
|
-
static size_t sol_strlen(const char *s) {
|
|
223
|
-
size_t len = 0;
|
|
224
|
-
while (*s) {
|
|
225
|
-
len++;
|
|
226
|
-
s++;
|
|
227
|
-
}
|
|
228
|
-
return len;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Computes the number of elements in an array
|
|
233
|
-
*/
|
|
234
|
-
#define SOL_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Internal memory alloc/free function
|
|
239
|
-
*/
|
|
240
|
-
void *sol_alloc_free_(uint64_t size, void *ptr);
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Alloc zero-initialized memory
|
|
244
|
-
*/
|
|
245
|
-
static void *sol_calloc(size_t nitems, size_t size) {
|
|
246
|
-
return sol_alloc_free_(nitems * size, 0);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Deallocates the memory previously allocated by sol_calloc
|
|
251
|
-
*/
|
|
252
|
-
static void sol_free(void *ptr) {
|
|
253
|
-
(void) sol_alloc_free_(0, ptr);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* The Solana runtime provides a memory region that is available to programs at
|
|
258
|
-
* a fixed virtual address and length. The builtin functions `sol_calloc` and
|
|
259
|
-
* `sol_free` call into the Solana runtime to allocate from this memory region
|
|
260
|
-
* for heap operations. Because the memory region is directly available to
|
|
261
|
-
* programs another option is a program can implement their own heap directly on
|
|
262
|
-
* top of that region. If a program chooses to implement their own heap they
|
|
263
|
-
* should not call the builtin heap functions because they will conflict.
|
|
264
|
-
* `HEAP_START_ADDRESS` and `HEAP_LENGTH` specify the memory region's start
|
|
265
|
-
* virtual address and length.
|
|
266
|
-
*/
|
|
267
|
-
#define HEAP_START_ADDRESS (uint64_t)0x300000000
|
|
268
|
-
#define HEAP_LENGTH (uint64_t)(32 * 1024)
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Panics
|
|
272
|
-
*
|
|
273
|
-
* Prints the line number where the panic occurred and then causes
|
|
274
|
-
* the BPF VM to immediately halt execution. No accounts' data are updated
|
|
275
|
-
*/
|
|
276
|
-
void sol_panic_(const char *, uint64_t, uint64_t, uint64_t);
|
|
277
|
-
#define sol_panic() sol_panic_(__FILE__, sizeof(__FILE__), __LINE__, 0)
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Asserts
|
|
281
|
-
*/
|
|
282
|
-
#define sol_assert(expr) \
|
|
283
|
-
if (!(expr)) { \
|
|
284
|
-
sol_panic(); \
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Structure that the program's entrypoint input data is deserialized into.
|
|
289
|
-
*/
|
|
290
|
-
typedef struct {
|
|
291
|
-
SolAccountInfo* ka; /** Pointer to an array of SolAccountInfo, must already
|
|
292
|
-
point to an array of SolAccountInfos */
|
|
293
|
-
uint64_t ka_num; /** Number of SolAccountInfo entries in `ka` */
|
|
294
|
-
const uint8_t *data; /** pointer to the instruction data */
|
|
295
|
-
uint64_t data_len; /** Length in bytes of the instruction data */
|
|
296
|
-
const SolPubkey *program_id; /** program_id of the currently executing program */
|
|
297
|
-
} SolParameters;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Maximum number of bytes a program may add to an account during a single realloc
|
|
301
|
-
*/
|
|
302
|
-
#define MAX_PERMITTED_DATA_INCREASE (1024 * 10)
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* De-serializes the input parameters into usable types
|
|
306
|
-
*
|
|
307
|
-
* Use this function to deserialize the buffer passed to the program entrypoint
|
|
308
|
-
* into usable types. This function does not perform copy deserialization,
|
|
309
|
-
* instead it populates the pointers and lengths in SolAccountInfo and data so
|
|
310
|
-
* that any modification to lamports or account data take place on the original
|
|
311
|
-
* buffer. Doing so also eliminates the need to serialize back into the buffer
|
|
312
|
-
* at the end of the program.
|
|
313
|
-
*
|
|
314
|
-
* @param input Source buffer containing serialized input parameters
|
|
315
|
-
* @param params Pointer to a SolParameters structure
|
|
316
|
-
* @return Boolean true if successful.
|
|
317
|
-
*/
|
|
318
|
-
static bool sol_deserialize(
|
|
319
|
-
const uint8_t *input,
|
|
320
|
-
SolParameters *params,
|
|
321
|
-
uint64_t ka_num
|
|
322
|
-
) {
|
|
323
|
-
if (NULL == input || NULL == params) {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
params->ka_num = *(uint64_t *) input;
|
|
327
|
-
input += sizeof(uint64_t);
|
|
328
|
-
|
|
329
|
-
for (int i = 0; i < params->ka_num; i++) {
|
|
330
|
-
uint8_t dup_info = input[0];
|
|
331
|
-
input += sizeof(uint8_t);
|
|
332
|
-
|
|
333
|
-
if (i >= ka_num) {
|
|
334
|
-
if (dup_info == UINT8_MAX) {
|
|
335
|
-
input += sizeof(uint8_t);
|
|
336
|
-
input += sizeof(uint8_t);
|
|
337
|
-
input += sizeof(uint8_t);
|
|
338
|
-
input += 4; // padding
|
|
339
|
-
input += sizeof(SolPubkey);
|
|
340
|
-
input += sizeof(SolPubkey);
|
|
341
|
-
input += sizeof(uint64_t);
|
|
342
|
-
uint64_t data_len = *(uint64_t *) input;
|
|
343
|
-
input += sizeof(uint64_t);
|
|
344
|
-
input += data_len;
|
|
345
|
-
input += MAX_PERMITTED_DATA_INCREASE;
|
|
346
|
-
input = (uint8_t*)(((uint64_t)input + 8 - 1) & ~(8 - 1)); // padding
|
|
347
|
-
input += sizeof(uint64_t);
|
|
348
|
-
}
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
if (dup_info == UINT8_MAX) {
|
|
352
|
-
// is signer?
|
|
353
|
-
params->ka[i].is_signer = *(uint8_t *) input != 0;
|
|
354
|
-
input += sizeof(uint8_t);
|
|
355
|
-
|
|
356
|
-
// is writable?
|
|
357
|
-
params->ka[i].is_writable = *(uint8_t *) input != 0;
|
|
358
|
-
input += sizeof(uint8_t);
|
|
359
|
-
|
|
360
|
-
// executable?
|
|
361
|
-
params->ka[i].executable = *(uint8_t *) input;
|
|
362
|
-
input += sizeof(uint8_t);
|
|
363
|
-
|
|
364
|
-
input += 4; // padding
|
|
365
|
-
|
|
366
|
-
// key
|
|
367
|
-
params->ka[i].key = (SolPubkey *) input;
|
|
368
|
-
input += sizeof(SolPubkey);
|
|
369
|
-
|
|
370
|
-
// owner
|
|
371
|
-
params->ka[i].owner = (SolPubkey *) input;
|
|
372
|
-
input += sizeof(SolPubkey);
|
|
373
|
-
|
|
374
|
-
// lamports
|
|
375
|
-
params->ka[i].lamports = (uint64_t *) input;
|
|
376
|
-
input += sizeof(uint64_t);
|
|
377
|
-
|
|
378
|
-
// account data
|
|
379
|
-
params->ka[i].data_len = *(uint64_t *) input;
|
|
380
|
-
input += sizeof(uint64_t);
|
|
381
|
-
params->ka[i].data = (uint8_t *) input;
|
|
382
|
-
input += params->ka[i].data_len;
|
|
383
|
-
input += MAX_PERMITTED_DATA_INCREASE;
|
|
384
|
-
input = (uint8_t*)(((uint64_t)input + 8 - 1) & ~(8 - 1)); // padding
|
|
385
|
-
|
|
386
|
-
// rent epoch
|
|
387
|
-
params->ka[i].rent_epoch = *(uint64_t *) input;
|
|
388
|
-
input += sizeof(uint64_t);
|
|
389
|
-
} else {
|
|
390
|
-
params->ka[i].is_signer = params->ka[dup_info].is_signer;
|
|
391
|
-
params->ka[i].is_writable = params->ka[dup_info].is_writable;
|
|
392
|
-
params->ka[i].executable = params->ka[dup_info].executable;
|
|
393
|
-
params->ka[i].key = params->ka[dup_info].key;
|
|
394
|
-
params->ka[i].owner = params->ka[dup_info].owner;
|
|
395
|
-
params->ka[i].lamports = params->ka[dup_info].lamports;
|
|
396
|
-
params->ka[i].data_len = params->ka[dup_info].data_len;
|
|
397
|
-
params->ka[i].data = params->ka[dup_info].data;
|
|
398
|
-
params->ka[i].rent_epoch = params->ka[dup_info].rent_epoch;
|
|
399
|
-
input += 7; // padding
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
params->data_len = *(uint64_t *) input;
|
|
404
|
-
input += sizeof(uint64_t);
|
|
405
|
-
params->data = input;
|
|
406
|
-
input += params->data_len;
|
|
407
|
-
|
|
408
|
-
params->program_id = (SolPubkey *) input;
|
|
409
|
-
input += sizeof(SolPubkey);
|
|
410
|
-
|
|
411
|
-
return true;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Byte array pointer and string
|
|
416
|
-
*/
|
|
417
|
-
typedef struct {
|
|
418
|
-
const uint8_t *addr; /** bytes */
|
|
419
|
-
uint64_t len; /** number of bytes*/
|
|
420
|
-
} SolBytes;
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Length of a sha256 hash result
|
|
424
|
-
*/
|
|
425
|
-
#define SHA256_RESULT_LENGTH 32
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Sha256
|
|
429
|
-
*
|
|
430
|
-
* @param bytes Array of byte arrays
|
|
431
|
-
* @param bytes_len Number of byte arrays
|
|
432
|
-
* @param result 32 byte array to hold the result
|
|
433
|
-
*/
|
|
434
|
-
static uint64_t sol_sha256(
|
|
435
|
-
const SolBytes *bytes,
|
|
436
|
-
int bytes_len,
|
|
437
|
-
const uint8_t *result
|
|
438
|
-
);
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Account Meta
|
|
442
|
-
*/
|
|
443
|
-
typedef struct {
|
|
444
|
-
SolPubkey *pubkey; /** An account's public key */
|
|
445
|
-
bool is_writable; /** True if the `pubkey` can be loaded as a read-write account */
|
|
446
|
-
bool is_signer; /** True if an Instruction requires a Transaction signature matching `pubkey` */
|
|
447
|
-
} SolAccountMeta;
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Instruction
|
|
451
|
-
*/
|
|
452
|
-
typedef struct {
|
|
453
|
-
SolPubkey *program_id; /** Pubkey of the instruction processor that executes this instruction */
|
|
454
|
-
SolAccountMeta *accounts; /** Metadata for what accounts should be passed to the instruction processor */
|
|
455
|
-
uint64_t account_len; /** Number of SolAccountMetas */
|
|
456
|
-
uint8_t *data; /** Opaque data passed to the instruction processor */
|
|
457
|
-
uint64_t data_len; /** Length of the data in bytes */
|
|
458
|
-
} SolInstruction;
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Seed used to create a program address or passed to sol_invoke_signed
|
|
462
|
-
*/
|
|
463
|
-
typedef struct {
|
|
464
|
-
const uint8_t *addr; /** Seed bytes */
|
|
465
|
-
uint64_t len; /** Length of the seed bytes */
|
|
466
|
-
} SolSignerSeed;
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Seeds used by a signer to create a program address or passed to
|
|
470
|
-
* sol_invoke_signed
|
|
471
|
-
*/
|
|
472
|
-
typedef struct {
|
|
473
|
-
const SolSignerSeed *addr; /** An arry of a signer's seeds */
|
|
474
|
-
uint64_t len; /** Number of seeds */
|
|
475
|
-
} SolSignerSeeds;
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Create a program address
|
|
479
|
-
*
|
|
480
|
-
* @param seeds Seed bytes used to sign program accounts
|
|
481
|
-
* @param seeds_len Length of the seeds array
|
|
482
|
-
* @param program_id Program id of the signer
|
|
483
|
-
* @param program_address Program address created, filled on return
|
|
484
|
-
*/
|
|
485
|
-
static uint64_t sol_create_program_address(
|
|
486
|
-
const SolSignerSeed *seeds,
|
|
487
|
-
int seeds_len,
|
|
488
|
-
const SolPubkey *program_id,
|
|
489
|
-
const SolPubkey *program_address
|
|
490
|
-
);
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Try to find a program address and return corresponding bump seed
|
|
494
|
-
*
|
|
495
|
-
* @param seeds Seed bytes used to sign program accounts
|
|
496
|
-
* @param seeds_len Length of the seeds array
|
|
497
|
-
* @param program_id Program id of the signer
|
|
498
|
-
* @param program_address Program address created, filled on return
|
|
499
|
-
* @param bump_seed Bump seed required to create a valid program address
|
|
500
|
-
*/
|
|
501
|
-
static uint64_t sol_try_find_program_address(
|
|
502
|
-
const SolSignerSeed *seeds,
|
|
503
|
-
int seeds_len,
|
|
504
|
-
const SolPubkey *program_id,
|
|
505
|
-
const SolPubkey *program_address,
|
|
506
|
-
const uint8_t *bump_seed
|
|
507
|
-
);
|
|
508
|
-
|
|
509
|
-
/**
|
|
510
|
-
* Cross-program invocation
|
|
511
|
-
* * @{
|
|
512
|
-
*/
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Invoke another program and sign for some of the keys
|
|
516
|
-
*
|
|
517
|
-
* @param instruction Instruction to process
|
|
518
|
-
* @param account_infos Accounts used by instruction
|
|
519
|
-
* @param account_infos_len Length of account_infos array
|
|
520
|
-
* @param seeds Seed bytes used to sign program accounts
|
|
521
|
-
* @param seeds_len Length of the seeds array
|
|
522
|
-
*/
|
|
523
|
-
static uint64_t sol_invoke_signed(
|
|
524
|
-
const SolInstruction *instruction,
|
|
525
|
-
const SolAccountInfo *account_infos,
|
|
526
|
-
int account_infos_len,
|
|
527
|
-
const SolSignerSeeds *signers_seeds,
|
|
528
|
-
int signers_seeds_len
|
|
529
|
-
) {
|
|
530
|
-
uint64_t sol_invoke_signed_c(
|
|
531
|
-
const SolInstruction *instruction,
|
|
532
|
-
const SolAccountInfo *account_infos,
|
|
533
|
-
int account_infos_len,
|
|
534
|
-
const SolSignerSeeds *signers_seeds,
|
|
535
|
-
int signers_seeds_len
|
|
536
|
-
);
|
|
537
|
-
|
|
538
|
-
return sol_invoke_signed_c(
|
|
539
|
-
instruction,
|
|
540
|
-
account_infos,
|
|
541
|
-
account_infos_len,
|
|
542
|
-
signers_seeds,
|
|
543
|
-
signers_seeds_len
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Invoke another program
|
|
548
|
-
*
|
|
549
|
-
* @param instruction Instruction to process
|
|
550
|
-
* @param account_infos Accounts used by instruction
|
|
551
|
-
* @param account_infos_len Length of account_infos array
|
|
552
|
-
*/
|
|
553
|
-
static uint64_t sol_invoke(
|
|
554
|
-
const SolInstruction *instruction,
|
|
555
|
-
const SolAccountInfo *account_infos,
|
|
556
|
-
int account_infos_len
|
|
557
|
-
) {
|
|
558
|
-
const SolSignerSeeds signers_seeds[] = {{}};
|
|
559
|
-
return sol_invoke_signed(
|
|
560
|
-
instruction,
|
|
561
|
-
account_infos,
|
|
562
|
-
account_infos_len,
|
|
563
|
-
signers_seeds,
|
|
564
|
-
0
|
|
565
|
-
);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/**@}*/
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Debugging utilities
|
|
572
|
-
* @{
|
|
573
|
-
*/
|
|
574
|
-
|
|
575
|
-
/**
|
|
576
|
-
* Prints the hexadecimal representation of a public key
|
|
577
|
-
*
|
|
578
|
-
* @param key The public key to print
|
|
579
|
-
*/
|
|
580
|
-
void sol_log_pubkey(
|
|
581
|
-
const SolPubkey *pubkey
|
|
582
|
-
);
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Prints the hexadecimal representation of an array
|
|
586
|
-
*
|
|
587
|
-
* @param array The array to print
|
|
588
|
-
*/
|
|
589
|
-
static void sol_log_array(const uint8_t *array, int len) {
|
|
590
|
-
for (int j = 0; j < len; j++) {
|
|
591
|
-
sol_log_64(0, 0, 0, j, array[j]);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* Prints the program's input parameters
|
|
597
|
-
*
|
|
598
|
-
* @param params Pointer to a SolParameters structure
|
|
599
|
-
*/
|
|
600
|
-
static void sol_log_params(const SolParameters *params) {
|
|
601
|
-
sol_log("- Program identifier:");
|
|
602
|
-
sol_log_pubkey(params->program_id);
|
|
603
|
-
|
|
604
|
-
sol_log("- Number of KeyedAccounts");
|
|
605
|
-
sol_log_64(0, 0, 0, 0, params->ka_num);
|
|
606
|
-
for (int i = 0; i < params->ka_num; i++) {
|
|
607
|
-
sol_log(" - Is signer");
|
|
608
|
-
sol_log_64(0, 0, 0, 0, params->ka[i].is_signer);
|
|
609
|
-
sol_log(" - Is writable");
|
|
610
|
-
sol_log_64(0, 0, 0, 0, params->ka[i].is_writable);
|
|
611
|
-
sol_log(" - Key");
|
|
612
|
-
sol_log_pubkey(params->ka[i].key);
|
|
613
|
-
sol_log(" - Lamports");
|
|
614
|
-
sol_log_64(0, 0, 0, 0, *params->ka[i].lamports);
|
|
615
|
-
sol_log(" - data");
|
|
616
|
-
sol_log_array(params->ka[i].data, params->ka[i].data_len);
|
|
617
|
-
sol_log(" - Owner");
|
|
618
|
-
sol_log_pubkey(params->ka[i].owner);
|
|
619
|
-
sol_log(" - Executable");
|
|
620
|
-
sol_log_64(0, 0, 0, 0, params->ka[i].executable);
|
|
621
|
-
sol_log(" - Rent Epoch");
|
|
622
|
-
sol_log_64(0, 0, 0, 0, params->ka[i].rent_epoch);
|
|
623
|
-
}
|
|
624
|
-
sol_log("- Instruction data\0");
|
|
625
|
-
sol_log_array(params->data, params->data_len);
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
/**@}*/
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* Program instruction entrypoint
|
|
632
|
-
*
|
|
633
|
-
* @param input Buffer of serialized input parameters. Use sol_deserialize() to decode
|
|
634
|
-
* @return 0 if the instruction executed successfully
|
|
635
|
-
*/
|
|
636
|
-
uint64_t entrypoint(const uint8_t *input);
|
|
637
|
-
|
|
638
|
-
#ifdef SOL_TEST
|
|
639
|
-
/**
|
|
640
|
-
* Stub functions when building tests
|
|
641
|
-
*/
|
|
642
|
-
#include <stdio.h>
|
|
643
|
-
void sol_log_(const char *s, uint64_t len) {
|
|
644
|
-
printf("Program log: %s\n", s);
|
|
645
|
-
}
|
|
646
|
-
void sol_log_64(uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) {
|
|
647
|
-
printf("Program log: %llu, %llu, %llu, %llu, %llu\n", arg1, arg2, arg3, arg4, arg5);
|
|
648
|
-
}
|
|
649
|
-
void sol_log_pubkey(const SolPubkey *pubkey) {
|
|
650
|
-
printf("Program log: ");
|
|
651
|
-
for (int i = 0; i < SIZE_PUBKEY; i++) {
|
|
652
|
-
printf("%02 ", pubkey->x[i]);
|
|
653
|
-
}
|
|
654
|
-
printf("\n");
|
|
655
|
-
}
|
|
656
|
-
void sol_log_compute_units_() {
|
|
657
|
-
printf("Program consumption: __ units remaining\n");
|
|
658
|
-
}
|
|
659
|
-
void sol_panic_(const char *file, uint64_t len, uint64_t line, uint64_t column) {
|
|
660
|
-
printf("Panic in %s at %d:%d\n", file, line, column);
|
|
661
|
-
abort();
|
|
662
|
-
}
|
|
663
|
-
#endif
|
|
664
|
-
|
|
665
|
-
#ifdef __cplusplus
|
|
666
|
-
}
|
|
667
|
-
#endif
|
|
668
|
-
|
|
669
|
-
/**@}*/
|
package/bpf-sdk/c/inc/stdio.h
DELETED
package/bpf-sdk/c/inc/stdlib.h
DELETED
package/bpf-sdk/c/inc/string.h
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#pragma once
|
package/bpf-sdk/c/inc/wchar.h
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#pragma once
|