Skip to content

Commit 07d49be

Browse files
committed
minor solana program refactoring
1 parent 3bd01b4 commit 07d49be

File tree

8 files changed

+32
-33
lines changed

8 files changed

+32
-33
lines changed

solana/programs/bridge/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub const MESSENGER_SEED: &[u8] = b"messenger_state";
7474
pub const NATIVE_SOL_PUBKEY: Pubkey = pubkey!("LYDZWqhCarLgXtQsmWFr4DaqRE7c21xd49fpdVUUaBr");
7575

7676
#[constant]
77-
pub const ROOT_KEY: &[u8] = b"output_root";
77+
pub const OUTPUT_ROOT_SEED: &[u8] = b"output_root";
7878

7979
#[constant]
8080
pub const MESSAGE_SEED: &[u8] = b"message";

solana/programs/bridge/src/instructions/initializer.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
use anchor_lang::prelude::*;
22

3-
use crate::{MESSENGER_SEED, VAULT_SEED};
3+
use crate::{Vault, MESSENGER_SEED, VAULT_SEED};
44

55
use super::Messenger;
66

7-
#[derive(InitSpace)]
8-
#[account]
9-
pub struct Vault {}
10-
117
#[derive(Accounts)]
128
pub struct Initialize<'info> {
139
#[account(mut)]

solana/programs/bridge/src/instructions/messenger.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ pub struct SentMessage {
4141
#[event]
4242
// Emitted whenever a message is successfully relayed on this chain.
4343
pub struct RelayedMessage {
44-
// Hash of the message that was relayed.
45-
pub msg_hash: [u8; 32],
44+
pub msg_hash: [u8; 32], // Hash of the message that was relayed.
4645
}
4746

4847
#[event]
4948
// Emitted whenever a message fails to be relayed on this chain.
5049
pub struct FailedRelayedMessage {
51-
// Hash of the message that failed to be relayed.
52-
pub msg_hash: [u8; 32],
50+
pub msg_hash: [u8; 32], // Hash of the message that failed to be relayed.
5351
}
5452

5553
/// @notice Sends a message to some target address on Base. Note that if the call

solana/programs/bridge/src/instructions/portal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ fn minimum_gas_limit(byte_count: u64) -> u64 {
7676

7777
fn encode_packed(gas_limit: u64, is_creation: bool, data: Vec<u8>) -> Vec<u8> {
7878
let mut opaque_data = Vec::new();
79-
opaque_data.extend_from_slice(&gas_limit.to_be_bytes()); // Equivalent to _gasLimit
80-
opaque_data.push(is_creation as u8); // Equivalent to _isCreation
81-
opaque_data.extend_from_slice(&data); // Equivalent to _data
79+
opaque_data.extend_from_slice(&gas_limit.to_be_bytes());
80+
opaque_data.push(is_creation as u8);
81+
opaque_data.extend_from_slice(&data);
8282
return opaque_data;
8383
}
8484

solana/programs/bridge/src/instructions/post_root.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anchor_lang::prelude::*;
22

3-
use crate::{OutputRoot, ROOT_KEY, TRUSTED_ORACLE};
3+
use crate::{OutputRoot, OUTPUT_ROOT_SEED, TRUSTED_ORACLE};
44

55
#[derive(Accounts)]
66
#[instruction(root: [u8; 32], block_number: u64)]
@@ -9,7 +9,7 @@ pub struct PostRoot<'info> {
99
init,
1010
payer = payer,
1111
space = 8 + OutputRoot::INIT_SPACE,
12-
seeds = [ROOT_KEY, &block_number.to_le_bytes()],
12+
seeds = [OUTPUT_ROOT_SEED, &block_number.to_le_bytes()],
1313
bump
1414
)]
1515
pub root: Account<'info, OutputRoot>,

solana/programs/bridge/src/instructions/receiver.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use crate::{Ix, Message, MessengerPayload, OutputRoot, DEFAULT_SENDER, MESSAGE_S
77

88
use super::messenger;
99

10-
// TODO: Should we block vault transfers that don't go through the bridge component?
11-
1210
#[derive(Accounts)]
1311
#[instruction(transaction_hash: [u8; 32])]
1412
pub struct ProveTransaction<'info> {
@@ -44,22 +42,6 @@ pub struct FinalizeTransaction<'info> {
4442
pub vault: AccountInfo<'info>,
4543
}
4644

47-
pub fn finalize_transaction_handler<'a, 'info>(
48-
ctx: Context<'a, '_, 'info, 'info, FinalizeTransaction<'info>>,
49-
_transaction_hash: &[u8; 32],
50-
) -> Result<()> {
51-
if ctx.accounts.message.is_executed {
52-
return err!(ReceiverError::AlreadyExecuted);
53-
}
54-
55-
ctx.accounts.message.is_executed = true;
56-
handle_ixs(
57-
ctx.remaining_accounts,
58-
&mut ctx.accounts.message,
59-
&ctx.accounts.vault,
60-
)
61-
}
62-
6345
pub fn prove_transaction_handler(
6446
ctx: Context<ProveTransaction>,
6547
transaction_hash: &[u8; 32],
@@ -85,6 +67,22 @@ pub fn prove_transaction_handler(
8567
Ok(())
8668
}
8769

70+
pub fn finalize_transaction_handler<'a, 'info>(
71+
ctx: Context<'a, '_, 'info, 'info, FinalizeTransaction<'info>>,
72+
_transaction_hash: &[u8; 32],
73+
) -> Result<()> {
74+
if ctx.accounts.message.is_executed {
75+
return err!(ReceiverError::AlreadyExecuted);
76+
}
77+
78+
ctx.accounts.message.is_executed = true;
79+
handle_ixs(
80+
ctx.remaining_accounts,
81+
&mut ctx.accounts.message,
82+
&ctx.accounts.vault,
83+
)
84+
}
85+
8886
/**
8987
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
9088
* defined by `root`. For this, a `proof` must be provided, containing
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
pub mod deposit;
22
pub mod message;
33
pub mod output_root;
4+
pub mod vault;
45

56
pub use deposit::*;
67
pub use message::*;
78
pub use output_root::*;
9+
pub use vault::*;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use anchor_lang::prelude::*;
2+
3+
#[derive(InitSpace)]
4+
#[account]
5+
pub struct Vault {}

0 commit comments

Comments
 (0)