Apply some const

This commit is contained in:
Michael Vines 2018-10-29 19:56:24 -07:00
parent 4aba05d749
commit 71d6eaacef
5 changed files with 23 additions and 23 deletions

View File

@ -75,7 +75,7 @@ typedef struct {
* @param two Second public key * @param two Second public key
* @return True if the same * @return True if the same
*/ */
SOL_FN_PREFIX bool SolPubkey_same(SolPubkey *one, SolPubkey *two) { SOL_FN_PREFIX bool SolPubkey_same(const SolPubkey *one, const SolPubkey *two) {
for (int i = 0; i < SIZE_PUBKEY; i++) { for (int i = 0; i < SIZE_PUBKEY; i++) {
if (one->x[i] != two->x[i]) { if (one->x[i] != two->x[i]) {
return false; return false;
@ -98,9 +98,9 @@ typedef struct {
/** /**
* Copies memory * Copies memory
*/ */
SOL_FN_PREFIX void sol_memcpy(void *dst, void *src, int len) { SOL_FN_PREFIX void sol_memcpy(void *dst, const void *src, int len) {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
*((uint8_t *)dst + i) = *((uint8_t *)src + i); *((uint8_t *)dst + i) = *((const uint8_t *)src + i);
} }
} }
@ -142,7 +142,7 @@ SOL_FN_PREFIX void _sol_panic(uint64_t line) {
* @param data_len On return, the length in bytes of the instruction data * @param data_len On return, the length in bytes of the instruction data
* @return Boolan True if successful * @return Boolan True if successful
*/ */
SOL_FN_PREFIX bool sol_deserialize(uint8_t *input, uint64_t num_ka, SOL_FN_PREFIX bool sol_deserialize(const uint8_t *input, uint64_t num_ka,
SolKeyedAccounts *ka, uint8_t **data, SolKeyedAccounts *ka, uint8_t **data,
uint64_t *data_len) { uint64_t *data_len) {
if (num_ka != *(uint64_t *)input) { if (num_ka != *(uint64_t *)input) {
@ -187,7 +187,7 @@ SOL_FN_PREFIX bool sol_deserialize(uint8_t *input, uint64_t num_ka,
* *
* @param key The public key to print * @param key The public key to print
*/ */
SOL_FN_PREFIX void sol_print_key(SolPubkey *key) { SOL_FN_PREFIX void sol_print_key(const SolPubkey *key) {
for (int j = 0; j < SIZE_PUBKEY; j++) { for (int j = 0; j < SIZE_PUBKEY; j++) {
sol_print(0, 0, 0, j, key->x[j]); sol_print(0, 0, 0, j, key->x[j]);
} }
@ -198,7 +198,7 @@ SOL_FN_PREFIX void sol_print_key(SolPubkey *key) {
* *
* @param array The array to print * @param array The array to print
*/ */
SOL_FN_PREFIX void sol_print_array(uint8_t *array, int len) { SOL_FN_PREFIX void sol_print_array(const uint8_t *array, int len) {
for (int j = 0; j < len; j++) { for (int j = 0; j < len; j++) {
sol_print(0, 0, 0, j, array[j]); sol_print(0, 0, 0, j, array[j]);
} }
@ -212,8 +212,8 @@ SOL_FN_PREFIX void sol_print_array(uint8_t *array, int len) {
* @param data A pointer to the instruction data to print * @param data A pointer to the instruction data to print
* @param data_len The length in bytes of the instruction data * @param data_len The length in bytes of the instruction data
*/ */
SOL_FN_PREFIX void sol_print_params(uint64_t num_ka, SolKeyedAccounts *ka, SOL_FN_PREFIX void sol_print_params(uint64_t num_ka, const SolKeyedAccounts *ka,
uint8_t *data, uint64_t data_len) { const uint8_t *data, uint64_t data_len) {
sol_print(0, 0, 0, 0, num_ka); sol_print(0, 0, 0, 0, num_ka);
for (int i = 0; i < num_ka; i++) { for (int i = 0; i < num_ka; i++) {
sol_print_key(ka[i].key); sol_print_key(ka[i].key);
@ -235,12 +235,12 @@ SOL_FN_PREFIX void sol_print_params(uint64_t num_ka, SolKeyedAccounts *ka,
* *
* #define NUM_KA 1 * #define NUM_KA 1
* *
* bool entrypoint(uint8_t *input) { * bool entrypoint(const uint8_t *input) {
* SolKeyedAccounts ka[NUM_KA]; * SolKeyedAccounts ka[NUM_KA];
* uint8_t *data; * uint8_t *data;
* uint64_t data_len; * uint64_t data_len;
* *
* if (1 != sol_deserialize((uint8_t *)buf, NUM_KA, ka, &data, &data_len)) { * if (1 != sol_deserialize(buf, NUM_KA, ka, &data, &data_len)) {
* return false; * return false;
* } * }
* print_params(1, ka, data, data_len); * print_params(1, ka, data, data_len);
@ -254,7 +254,7 @@ SOL_FN_PREFIX void sol_print_params(uint64_t num_ka, SolKeyedAccounts *ka,
* @param input An array containing serialized input parameters * @param input An array containing serialized input parameters
* @return True if successful * @return True if successful
*/ */
extern bool entrypoint(uint8_t *input); extern bool entrypoint(const uint8_t *input);
/**@}*/ /**@}*/

View File

@ -6,17 +6,17 @@
#include <sol_bpf_c.h> #include <sol_bpf_c.h>
/** /**
* Numer of SolKeyedAccounts expected. The program should bail if an * Number of SolKeyedAccounts expected. The program should bail if an
* unexpected number of accounts are passed to the program's entrypoint * unexpected number of accounts are passed to the program's entrypoint
*/ */
#define NUM_KA 3 #define NUM_KA 3
extern bool entrypoint(uint8_t *input) { extern bool entrypoint(const uint8_t *input) {
SolKeyedAccounts ka[NUM_KA]; SolKeyedAccounts ka[NUM_KA];
uint8_t *data; uint8_t *data;
uint64_t data_len; uint64_t data_len;
if (!sol_deserialize((uint8_t *)input, NUM_KA, ka, &data, &data_len)) { if (!sol_deserialize(input, NUM_KA, ka, &data, &data_len)) {
return false; return false;
} }

View File

@ -6,17 +6,17 @@
#include <sol_bpf_c.h> #include <sol_bpf_c.h>
/** /**
* Numer of SolKeyedAccounts expected. The program should bail if an * Number of SolKeyedAccounts expected. The program should bail if an
* unexpected number of accounts are passed to the program's entrypoint * unexpected number of accounts are passed to the program's entrypoint
*/ */
#define NUM_KA 1 #define NUM_KA 1
extern bool entrypoint(uint8_t *input) { extern bool entrypoint(const uint8_t *input) {
SolKeyedAccounts ka[NUM_KA]; SolKeyedAccounts ka[NUM_KA];
uint8_t *data; uint8_t *data;
uint64_t data_len; uint64_t data_len;
if (!sol_deserialize((uint8_t *)input, NUM_KA, ka, &data, &data_len)) { if (!sol_deserialize(input, NUM_KA, ka, &data, &data_len)) {
return false; return false;
} }
sol_print_params(1, ka, data, data_len); sol_print_params(1, ka, data, data_len);

View File

@ -173,7 +173,7 @@ SOL_FN_PREFIX Result game_keep_alive(Game *self, SolPubkey *player,
} }
/** /**
* Numer of SolKeyedAccounts expected. The program should bail if an * Number of SolKeyedAccounts expected. The program should bail if an
* unexpected number of accounts are passed to the program's entrypoint * unexpected number of accounts are passed to the program's entrypoint
* *
* accounts[0] On Init must be player X, after that doesn't matter, * accounts[0] On Init must be player X, after that doesn't matter,
@ -183,13 +183,13 @@ SOL_FN_PREFIX Result game_keep_alive(Game *self, SolPubkey *player,
*/ */
#define NUM_KA 3 #define NUM_KA 3
extern bool entrypoint(uint8_t *input) { extern bool entrypoint(const uint8_t *input) {
SolKeyedAccounts ka[NUM_KA]; SolKeyedAccounts ka[NUM_KA];
uint8_t *data; uint8_t *data;
uint64_t data_len; uint64_t data_len;
int err = 0; int err = 0;
if (!sol_deserialize((uint8_t *)input, NUM_KA, ka, &data, &data_len)) { if (!sol_deserialize(input, NUM_KA, ka, &data, &data_len)) {
return false; return false;
} }

View File

@ -54,7 +54,7 @@ SOL_FN_PREFIX bool update(Dashboard *self, Game *game, SolPubkey *game_pubkey) {
} }
/** /**
* Numer of SolKeyedAccounts expected. The program should bail if an * Number of SolKeyedAccounts expected. The program should bail if an
* unexpected number of accounts are passed to the program's entrypoint * unexpected number of accounts are passed to the program's entrypoint
* *
* accounts[0] doesn't matter, anybody can cause a dashboard update * accounts[0] doesn't matter, anybody can cause a dashboard update
@ -63,13 +63,13 @@ SOL_FN_PREFIX bool update(Dashboard *self, Game *game, SolPubkey *game_pubkey) {
*/ */
#define NUM_KA 3 #define NUM_KA 3
extern bool entrypoint(uint8_t *input) { extern bool entrypoint(const uint8_t *input) {
SolKeyedAccounts ka[NUM_KA]; SolKeyedAccounts ka[NUM_KA];
uint8_t *data; uint8_t *data;
uint64_t data_len; uint64_t data_len;
int err = 0; int err = 0;
if (!sol_deserialize((uint8_t *)input, NUM_KA, ka, &data, &data_len)) { if (!sol_deserialize(input, NUM_KA, ka, &data, &data_len)) {
return false; return false;
} }