-
Notifications
You must be signed in to change notification settings - Fork 6
Add DeclareEntrypoint #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
joncinque
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! I like the concept, we just need to figure out what to do for the error type
src/error.zig
Outdated
| pub const ProgramError = error{ | ||
| AlreadyInUse, | ||
| InvalidAccountType, | ||
| Uninitialized, | ||
| IncorrectSize, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to add these and have them work similarly to the program error in the Rust SDK, may as well just copy all the variants at https://github.com/anza-xyz/solana-sdk/blob/2d88eb491e52705ec73ee8204dc41d510c298909/program-error/src/lib.rs#L57, but that will require also setting the values individually, ie:
const ProgramError = enum(u64) {
InvalidArgument = 1 << 32,
InvalidInstructionData = 2 << 32,
};
And so on. That'll be a bit more conformant than this error type.
On the other hand, it's not a proper zig error, which makes me think we might want to omit this entirely, and allow processInstruction to return any error. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fix
- Change callconv(.C) to callconv(.c) in entrypoint.zig - Add direct exports in root.zig for convenience (entrypoint, PublicKey, etc.) - Fix print format in pubkey example - Add .surfpool to gitignore
- Replace Zig error type with enum(u64) matching Solana SDK values - Add all 26 builtin errors with correct bit-shifted values (n << 32) - Support custom errors in lower 32 bits - Add ProgramResult union type for cleaner error handling - Add helper methods: toU64(), custom(), getCustomCode(), toString() - Update entrypoint to use new ProcessInstruction function pointer type - Add unit tests verifying compatibility with Rust SDK
Add pub fn declareEntrypoint(comptime process_instruction: processInstruction) void ; so we can just only write processInstruction