Created
July 1, 2022 17:55
-
-
Save bji/03ea25979c16a31565356adfa477a9e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```c | |
typedef struct __attribute__((packed)) | |
{ | |
uint32_t instruction_code; // 2 for Transfer | |
uint64_t amount; | |
} util_SystemTransferData; | |
static uint64_t util_transfer_lamports_signed(SolPubkey *source_account, SolPubkey *destination_account, | |
uint64_t lamports, SolSignerSeeds *seeds, int seeds_len, | |
SolAccountInfo *transaction_accounts, int transaction_accounts_len) | |
{ | |
SolAccountMeta account_metas[] = | |
/// 0. `[writable, signer]` The source account. | |
{ { source_account, true, true }, | |
/// 1. `[writable]` The destination account. | |
{ destination_account, true, false } }; | |
sol_log("util_transfer_lamports_signed"); | |
sol_log("source_account (writable, signer):"); | |
sol_log_pubkey(account_metas[0].pubkey); | |
sol_log("destination_account (writable):"); | |
sol_log_pubkey(account_metas[1].pubkey); | |
sol_log("transaction_accounts"); | |
for (uint32_t i = 0; i < transaction_accounts_len; i++) { | |
SolAccountInfo *ta = &(transaction_accounts[i]); | |
sol_log_pubkey(ta->key); | |
if (ta->is_writable) { | |
if (ta->is_signer) { | |
sol_log("(writable, signer)"); | |
} | |
else { | |
sol_log("(writable)"); | |
} | |
} | |
else if (ta->is_signer) { | |
sol_log("(signer)"); | |
} | |
} | |
util_SystemTransferData data = { 2, lamports }; | |
SolInstruction instruction; | |
instruction.program_id = &(Constants.system_program_id); | |
instruction.accounts = account_metas; | |
instruction.account_len = sizeof(account_metas) / sizeof(account_metas[0]); | |
instruction.data = (uint8_t *) &data; | |
instruction.data_len = sizeof(data); | |
return sol_invoke_signed(&instruction, transaction_accounts, transaction_accounts_len, seeds, seeds_len); | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment