This package implements Wormhole's Core Bridge specification on Solana with some modifications (due to the nature of how Solana works). The program itself is written using the [Anchor] framework.
```rust use anchorlang::prelude::*; use wormholecorebridgesolana::sdk as corebridgesdk;
declare_id!("CoreBridgeHe11oWor1d11111111111111111111111");
pub struct PublishHelloWorld<'info> { #[account(mut)] payer: Signer<'info>,
/// CHECK: We need this emitter to invoke the Core Bridge program to send Wormhole messages as
/// its program ID.
#[account(
seeds = [core_bridge_sdk::PROGRAM_EMITTER_SEED_PREFIX],
bump,
)]
core_program_emitter: AccountInfo<'info>,
/// CHECK: This account is needed for the Core Bridge program.
#[account(mut)]
core_bridge_config: UncheckedAccount<'info>,
/// CHECK: This account will be created by the Core Bridge program using a generated keypair.
#[account(mut)]
core_message: AccountInfo<'info>,
/// CHECK: This account is needed for the Core Bridge program.
#[account(mut)]
core_emitter_sequence: UncheckedAccount<'info>,
/// CHECK: This account is needed for the Core Bridge program.
#[account(mut)]
core_fee_collector: Option<UncheckedAccount<'info>>,
system_program: Program<'info, System>,
core_bridge_program: Program<'info, core_bridge_sdk::cpi::CoreBridge>,
}
impl<'info> corebridgesdk::cpi::InvokeCoreBridge<'info> for PublishHelloWorld<'info> { fn corebridgeprogram(&self) -> AccountInfo<'info> { self.corebridgeprogram.toaccountinfo() } }
impl<'info> corebridgesdk::cpi::CreateAccount<'info> for PublishHelloWorld<'info> { fn payer(&self) -> AccountInfo<'info> { self.payer.toaccountinfo() }
fn system_program(&self) -> AccountInfo<'info> {
self.system_program.to_account_info()
}
}
impl<'info> corebridgesdk::cpi::PublishMessage<'info> for PublishHelloWorld<'info> { fn corebridgeconfig(&self) -> AccountInfo<'info> { self.corebridgeconfig.toaccountinfo() }
fn core_emitter(&self) -> Option<AccountInfo<'info>> {
None
}
fn core_emitter_authority(&self) -> Option<AccountInfo<'info>> {
Some(self.core_program_emitter.to_account_info())
}
fn core_emitter_sequence(&self) -> AccountInfo<'info> {
self.core_emitter_sequence.to_account_info()
}
fn core_fee_collector(&self) -> Option<AccountInfo<'info>> {
self.core_fee_collector
.as_ref()
.map(|acc| acc.to_account_info())
}
fn core_message(&self) -> AccountInfo<'info> {
self.core_message.to_account_info()
}
}
pub mod corebridgehello_world { use super::*;
pub fn publish_hello_world(ctx: Context<PublishHelloWorld>) -> Result<()> {
let nonce = 420;
let payload = b"Hello, world!".to_vec();
core_bridge_sdk::cpi::publish_message(
ctx.accounts,
core_bridge_sdk::cpi::PublishMessageDirective::ProgramMessage {
program_id: crate::ID,
nonce,
payload,
commitment: core_bridge_sdk::types::Commitment::Finalized,
},
&[
core_bridge_sdk::PROGRAM_EMITTER_SEED_PREFIX,
&[ctx.bumps["core_program_emitter"]],
],
None,
)
}
} ```