Skip to content

Commit

Permalink
Fix C header to include state structures (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored Jul 21, 2020
1 parent 11ca35d commit 7fa8706
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 21 deletions.
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;

0 comments on commit 7fa8706

Please sign in to comment.