-
Notifications
You must be signed in to change notification settings - Fork 2
/
instruction.h
77 lines (66 loc) · 2.56 KB
/
instruction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
#include "sol/parser.h"
#include "spl_associated_token_account_instruction.h"
#include "spl_token_instruction.h"
#include "stake_instruction.h"
#include "system_instruction.h"
#include "vote_instruction.h"
#include <stdbool.h>
enum ProgramId {
ProgramIdUnknown = 0,
ProgramIdStake,
ProgramIdSystem,
ProgramIdVote,
ProgramIdSplToken,
ProgramIdSplAssociatedTokenAccount,
ProgramIdSplMemo,
ProgramIdSerumAssertOwner,
};
typedef struct InstructionInfo {
enum ProgramId kind;
union {
SplAssociatedTokenAccountInfo spl_associated_token_account;
SplTokenInfo spl_token;
StakeInfo stake;
SystemInfo system;
VoteInfo vote;
};
} InstructionInfo;
enum ProgramId instruction_program_id(const Instruction* instruction, const MessageHeader* header);
int instruction_validate(const Instruction* instruction, const MessageHeader* header);
typedef struct InstructionBrief {
enum ProgramId program_id;
union {
int none;
SplTokenInstructionKind spl_token;
enum SystemInstructionKind system;
enum StakeInstructionKind stake;
enum VoteInstructionKind vote;
};
} InstructionBrief;
#define SPL_ASSOCIATED_TOKEN_ACCOUNT_IX_BRIEF \
{ ProgramIdSplAssociatedTokenAccount, .none = 0 }
#define SPL_TOKEN_IX_BRIEF(spl_token_ix) \
{ ProgramIdSplToken, .spl_token = (spl_token_ix) }
#define SYSTEM_IX_BRIEF(system_ix) \
{ ProgramIdSystem, .system = (system_ix) }
#define STAKE_IX_BRIEF(stake_ix) \
{ ProgramIdStake, .stake = (stake_ix) }
#define VOTE_IX_BRIEF(vote_ix) \
{ ProgramIdVote, .vote = (vote_ix) }
bool instruction_info_matches_brief(const InstructionInfo* info, const InstructionBrief* brief);
bool instruction_infos_match_briefs(InstructionInfo* const* infos,
const InstructionBrief* briefs,
size_t len);
typedef struct InstructionAccountsIterator {
const Pubkey* message_header_pubkeys;
uint8_t instruction_accounts_length;
const uint8_t* instruction_accounts;
size_t current_instruction_account;
} InstructionAccountsIterator;
void instruction_accounts_iterator_init(InstructionAccountsIterator* it,
const MessageHeader* header,
const Instruction* instruction);
int instruction_accounts_iterator_next(InstructionAccountsIterator* it,
const Pubkey** next_account);
size_t instruction_accounts_iterator_remaining(const InstructionAccountsIterator* it);