Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 18d96ff

Browse files
machacekchmvines
authored andcommitted
Fix cross-program-invocation C example
Correctly check if deriving the PDA with the given seed was successful. Don't pass the system program pubkey to the allocate instruction: the first account passed must be the one to be allocated.
1 parent f0b1cec commit 18d96ff

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

examples/c/src/cross-program-invocation/cross-program-invocation.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern uint64_t do_invoke(SolParameters *params) {
2222
const SolSignerSeeds signers_seeds[] = {{seeds, SOL_ARRAY_SIZE(seeds)}};
2323

2424
SolPubkey expected_allocated_key;
25-
if (SUCCESS == sol_create_program_address(seeds, SOL_ARRAY_SIZE(seeds),
25+
if (SUCCESS != sol_create_program_address(seeds, SOL_ARRAY_SIZE(seeds),
2626
params->program_id,
2727
&expected_allocated_key)) {
2828
return ERROR_INVALID_INSTRUCTION_DATA;
@@ -31,8 +31,7 @@ extern uint64_t do_invoke(SolParameters *params) {
3131
return ERROR_INVALID_ARGUMENT;
3232
}
3333

34-
SolAccountMeta arguments[] = {{system_program_info->key, false, false},
35-
{allocated_info->key, true, true}};
34+
SolAccountMeta arguments[] = {{allocated_info->key, true, true}};
3635
uint8_t data[4 + 8]; // Enough room for the Allocate instruction
3736
*(uint16_t *)data = 8; // Allocate instruction enum value
3837
*(uint64_t *)(data + 4) = SIZE; // Size to allocate

0 commit comments

Comments
 (0)