Skip to content
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

Fix C header to include state structures #138

Merged
merged 1 commit into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion token/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ fn main() {
pragma_once: true,
export: cbindgen::ExportConfig {
prefix: Some("Token_".to_string()),
include: vec!["TokenInstruction".to_string(), "State".to_string()],
include: vec![
"TokenInstruction".to_string(),
"TokenInstruction".to_string(),
"Mint".to_string(),
"Account".to_string(),
"Multisig".to_string(),
],
..cbindgen::ExportConfig::default()
},
parse: cbindgen::ParseConfig {
Expand Down
15 changes: 0 additions & 15 deletions token/cbindgen.toml

This file was deleted.

109 changes: 104 additions & 5 deletions token/inc/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
*/
#define Token_MIN_SIGNERS 1

/**
* Program state handler.
*/
typedef struct Token_State Token_State;

/**
* Instructions supported by the token program.
*/
Expand Down Expand Up @@ -258,3 +253,107 @@ typedef struct Token_TokenInstruction {
Token_Burn_Body burn;
};
} Token_TokenInstruction;

typedef uint8_t Token_Pubkey[32];

/**
* A C representation of Rust's `std::option::Option`
*/
typedef enum Token_COption_Pubkey_Tag {
/**
* No value
*/
None_Pubkey,
/**
* Some value `T`
*/
Some_Pubkey,
} Token_COption_Pubkey_Tag;

typedef struct Token_Some_Body_Pubkey {
Token_Pubkey _0;
} Token_Some_Body_Pubkey;

typedef struct Token_COption_Pubkey {
Token_COption_Pubkey_Tag tag;
union {
Token_Some_Body_Pubkey some;
};
} Token_COption_Pubkey;

/**
* Mint data.
*/
typedef struct Token_Mint {
/**
* Optional owner, used to mint new tokens. The owner may only
* be provided during mint creation. If no owner is present then the mint
* has a fixed supply and no further tokens may be minted.
*/
Token_COption_Pubkey owner;
/**
* Number of base 10 digits to the right of the decimal place.
*/
uint8_t decimals;
/**
* Is `true` if this structure has been initialized
*/
bool is_initialized;
} Token_Mint;

/**
* Account data.
*/
typedef struct Token_Account {
/**
* The mint associated with this account
*/
Token_Pubkey mint;
/**
* The owner of this account.
*/
Token_Pubkey owner;
/**
* The amount of tokens this account holds.
*/
uint64_t amount;
/**
* If `delegate` is `Some` then `delegated_amount` represents
* the amount authorized by the delegate
*/
Token_COption_Pubkey delegate;
/**
* Is `true` if this structure has been initialized
*/
bool is_initialized;
/**
* Is this a native token
*/
bool is_native;
/**
* The amount delegated
*/
uint64_t delegated_amount;
} Token_Account;

/**
* Multisignature data.
*/
typedef struct Token_Multisig {
/**
* Number of signers required
*/
uint8_t m;
/**
* Number of valid signers
*/
uint8_t n;
/**
* Is `true` if this structure has been initialized
*/
bool is_initialized;
/**
* Signer public keys
*/
Token_Pubkey signers[Token_MAX_SIGNERS];
} Token_Multisig;