Crates.io | aleph-solana-contract |
lib.rs | aleph-solana-contract |
version | 0.1.1 |
source | src |
created_at | 2023-04-12 13:14:18.555963 |
updated_at | 2023-06-23 14:01:34.207765 |
description | Aleph Solana program for handling messages |
homepage | |
repository | https://github.com/ricardocr987/aleph-solana-contract |
max_upload_size | |
id | 836908 |
size | 5,204 |
The program instructions can be called in two ways:
1- via CPI (in this case another program calls to the to do_message instruction). This one is the more efficient. For this you need:
aleph-solana-contract = { version="0.1.0", features = [ "no-entrypoint" ] }
https://crates.io/crates/aleph-solana-contract
/// CHECK: contraint added to force using actual aleph message program
#[account(address = aleph_solana_contract::ID, executable)]
pub messages_program: UncheckedAccount<'info>
solana_program::program::invoke(
&Instruction {
program_id: ctx.accounts.messages_program.key(),
accounts: vec![
AccountMeta::new(ctx.accounts.signer.key(), true),
AccountMeta::new_readonly(ctx.accounts.messages_program.key(), false)
],
data: aleph_solana_contract::instruction::DoMessage {
msgtype: "aggregate".to_string(),
msgcontent: "content".to_string(),
}
.data(),
},
&[
ctx.accounts.signer.to_account_info().clone(),
ctx.accounts.messages_program.to_account_info().clone(),
],
)?;
you need to import in the instruction: anchor_lang::InstructionData (to be able to use the data trait when building the instruction)
in local you should add this to your Anchor.toml:
[test.validator]
url = "https://api.devnet.solana.com"
[[test.validator.clone]]
address = "ALepH1n9jxScbz45aZhBYVa35zxBNbKSvL6rWQpb4snc"
2- including the aleph message instruction inside the transaction in the client, so its creating an specific instruction inside an transaction.
current related discussion in the anchor repo to improve this: add emit_cpi to allow programs to store logs in CPI data:
https://github.com/coral-xyz/anchor/pull/2438
https://github.com/coral-xyz/anchor/issues/2408
https://github.com/coral-xyz/anchor/pull/2438#discussion_r1155121788
Anchor (Solana framework) events are emitted through logs. There are two options:
Benchmark of these options: https://github.com/coral-xyz/anchor/issues/863#issuecomment-1101779506