I have a Tic Tac Toe game contract which looks like this:
#[program]
pub mod tic_tac_toe {
use super::*;
pub fn start_game(ctx: Context<StartGame>) -> Result<()> {
start::start_game(ctx)
}
// two other instructions here
}
If I run cargo expand
I se that instruction numbers are expanded to this:
match sighash {
[249, 47, 252, 172, 184, 162, 245, 14] => {
__private::__global::start_game(program_id, accounts, ix_data)
}
// two other instructions here
_ => Err(anchor_lang::error::ErrorCode::InstructionFallbackNotFound.into()),
}
Questions:
- I have only three instructions. Why does Anchor generates 8 bytes per instruction? Why not one byte which would be enough to encode my three instruction numbers?
- How can I derive this byte array without having to run
cargo expand
? I want to use this instruction id in Java and I cannot use the Anchors JavaScript APIs. - Can I give instructions predefined numbers? Let's say I want my instructions to be 1, 2 and 3.