add zig escrow example#542
Conversation
dev-jodee
left a comment
There was a problem hiding this comment.
Thanks for the work,
Seems like the litesvm.rs test file is completely empty, we should have tests
We should add a README.md like the other examples
| program.root_module.addImport("solana_program_library", solana_lib_mod); | ||
|
|
||
| _ = solana.buildProgram(b, program, target, optimize); | ||
| b.installArtifact(program); |
There was a problem hiding this comment.
isn't this redundant because of the following steps ?
| "build.zig", | ||
| "build.zig.zon", | ||
| "src", | ||
| // For example... |
There was a problem hiding this comment.
think this is boilerplate we can remove
| // This is a [Semantic Version](https://semver.org/). | ||
| // In a future version of Zig it will be used for package deduplication. | ||
| .version = "0.0.0", | ||
| // Together with name, this represents a globally unique package |
There was a problem hiding this comment.
do we need all the boilerplate from the zig init call? Maybe we should clean this up since it's a program example for solana?
| output_dir="solana-zig" | ||
| fi | ||
| output_dir="$(mkdir -p "$output_dir"; cd "$output_dir"; pwd)" | ||
| cd $output_dir |
There was a problem hiding this comment.
think if it's unquoted it might crash on paths with spaces
| } | ||
|
|
||
| pub fn take_offer(program_id: *PublicKey, accounts: []Account) ProgramError!void { | ||
| if (!(accounts.len == 10)) return ProgramError.InvalidAcctData; |
There was a problem hiding this comment.
seems like you're accessing accounts up to 12 below
There was a problem hiding this comment.
Also nit: if !(==) can just be !=
| }) catch return error.Unexpected; | ||
|
|
||
| sol_lib.token.transfer(.{ .from = vault.info(), .to = taker_token_account_a.info(), .amount = vault_amount_a, .authority = .{ .multiple = &[_]Account.Info{ | ||
| offer_info.info(), |
There was a problem hiding this comment.
think this should just be .single = offer_info.info() no? The ATA auth is the Offer PDA?
| pub const InstructionType = enum(u8) { make, take }; | ||
|
|
||
| pub fn processInstruction(program_id: *PublicKey, accounts: []Account, data: []const u8) ProgramError!void { | ||
| const instruction_type: *const InstructionType = @ptrCast(data); |
There was a problem hiding this comment.
should we check length here?
|
|
||
| switch (instruction_type.*) { | ||
| InstructionType.make => { | ||
| const make_data: *align(1) const MakeOffer = @ptrCast(data[1..]); |
There was a problem hiding this comment.
should we check length of data here as well
| const rent_info = accounts[9]; | ||
|
|
||
| if (!maker.isSigner()) return ProgramError.InvalidAcctData; | ||
|
|
There was a problem hiding this comment.
Think payer needs to be checked for signer too (in the other insturction as well)
| try assert_ata(taker_token_account_a.id(), taker.id(), token_mint_a.id()); | ||
|
|
||
| if (taker_token_account_a.lamports().* == 0) { | ||
| // TODO; improve error handling |
There was a problem hiding this comment.
Should this be done in the example?
No description provided.