Remove program error footgun and cleaner developer experience (#8042)
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
uint64_t x = *(uint64_t *) input;
|
||||
uint64_t *result = (uint64_t *) input + 1;
|
||||
uint64_t count = 0;
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "helper.h"
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
sol_log(__FILE__);
|
||||
helper_function();
|
||||
sol_log(__FILE__);
|
||||
|
@@ -8,12 +8,12 @@
|
||||
* Custom error for when input serialization fails
|
||||
*/
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
SolKeyedAccount ka[4];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return INVALID_ARGUMENT;
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
switch (params.data[0]) {
|
||||
@@ -48,7 +48,7 @@ extern uint32_t entrypoint(const uint8_t *input) {
|
||||
break;
|
||||
default:
|
||||
sol_log("Unrecognized command");
|
||||
return INVALID_INSTRUCTION_DATA;
|
||||
return ERROR_INVALID_INSTRUCTION_DATA;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@@ -8,30 +8,33 @@
|
||||
* Custom error for when input serialization fails
|
||||
*/
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
SolKeyedAccount ka[4];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return INVALID_ARGUMENT;
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
switch (params.data[0]) {
|
||||
case(1):
|
||||
sol_log("return success");
|
||||
return SUCCESS;
|
||||
sol_log("return success");
|
||||
return SUCCESS;
|
||||
case(2):
|
||||
sol_log("return a builtin");
|
||||
return INVALID_ACCOUNT_DATA;
|
||||
sol_log("return a builtin");
|
||||
return ERROR_INVALID_ACCOUNT_DATA;
|
||||
case(3):
|
||||
sol_log("return custom error");
|
||||
return 42;
|
||||
sol_log("return custom error 42");
|
||||
return 42;
|
||||
case(4):
|
||||
sol_log("return error that conflicts with success");
|
||||
return 0x40000000;
|
||||
sol_log("return an invalid error");
|
||||
return ERROR_INVALID_ACCOUNT_DATA + 1;
|
||||
case(5):
|
||||
sol_log("return unknown builtin");
|
||||
return TO_BUILTIN(50);
|
||||
default:
|
||||
sol_log("Unrecognized command");
|
||||
return INVALID_INSTRUCTION_DATA;
|
||||
sol_log("Unrecognized command");
|
||||
return ERROR_INVALID_INSTRUCTION_DATA;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@@ -11,17 +11,17 @@
|
||||
*/
|
||||
#define NUM_KA 3
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
SolKeyedAccount ka[NUM_KA];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return INVALID_ARGUMENT;
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (!params.ka[0].is_signer) {
|
||||
sol_log("Transaction not signed by key 0");
|
||||
return MISSING_REQUIRED_SIGNATURES;
|
||||
return ERROR_MISSING_REQUIRED_SIGNATURES;
|
||||
}
|
||||
|
||||
int64_t lamports = *(int64_t *)params.data;
|
||||
|
@@ -3,7 +3,7 @@
|
||||
static const char msg[] = "This is a message";
|
||||
static const char msg2[] = "This is a different message";
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
sol_log((char*)msg);
|
||||
sol_log((char*)msg2);
|
||||
return SUCCESS;
|
||||
|
@@ -9,14 +9,14 @@
|
||||
*/
|
||||
#define INVALID_INPUT 1
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
SolKeyedAccount ka[1];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
sol_log(__FILE__);
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return INVALID_ARGUMENT;
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
// Log the provided input parameters. In the case of the no-op
|
||||
|
@@ -4,14 +4,14 @@
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
SolKeyedAccount ka[1];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
sol_log(__FILE__);
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return INVALID_ARGUMENT;
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
// Log the provided input parameters. In the case of the no-op
|
||||
|
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
sol_panic();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ void __attribute__ ((noinline)) helper() {
|
||||
sol_log(__func__);
|
||||
}
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
sol_log(__func__);
|
||||
helper();
|
||||
return SUCCESS;
|
||||
|
@@ -3,7 +3,7 @@
|
||||
struct foo {const uint8_t *input;};
|
||||
void foo(const uint8_t *input, struct foo foo) ;
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t *input) {
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
struct foo f;
|
||||
f.input = input;
|
||||
foo(input, f);
|
||||
|
@@ -15,7 +15,7 @@ static struct test_struct __attribute__ ((noinline)) test_function(void) {
|
||||
return s;
|
||||
}
|
||||
|
||||
extern uint32_t entrypoint(const uint8_t* input) {
|
||||
extern uint64_t entrypoint(const uint8_t* input) {
|
||||
struct test_struct s = test_function();
|
||||
sol_log("foobar");
|
||||
if (s.x + s.y + s.z == 12 ) {
|
||||
|
Reference in New Issue
Block a user