Skip to content

Commit 48a5902

Browse files
authored
Boolinator (#288)
* Start anchor program * pythnet folder * Renames * Implement processor * Comments * More comments * Bump anchor * Use new version of the wormhole package * Get Solana chain id from wormhole core * Pythnet bridge address * Remove comment * Fix borsh headers * Format * Fix precommit * Fix precommit * Precommit * Add to CI * Fix CI * Use boolinator * Enable boolinator * Remove duplicate macro
1 parent e7b9c88 commit 48a5902

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

pythnet/remote-executor/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pythnet/remote-executor/programs/remote-executor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ overflow-checks = true
2222
anchor-lang = {version = "0.25.0", features = ["init-if-needed"]}
2323
wormhole-solana = { git = "https://github.com/guibescos/wormhole", branch = "gbescos/sdk-solana"}
2424
wormhole-core = { git = "https://github.com/guibescos/wormhole", branch = "gbescos/sdk-solana"}
25+
boolinator = "2.4.0"

pythnet/remote-executor/programs/remote-executor/src/lib.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod remote_executor {
2121
instruction::Instruction,
2222
program::invoke_signed,
2323
};
24+
use boolinator::Boolinator;
2425
use wormhole::Chain::{
2526
self,
2627
Solana,
@@ -36,14 +37,11 @@ pub mod remote_executor {
3637
pub fn execute_posted_vaa(ctx: Context<ExecutePostedVaa>) -> Result<()> {
3738
let posted_vaa = &ctx.accounts.posted_vaa;
3839
let claim_record = &mut ctx.accounts.claim_record;
39-
assert_or_err(
40-
Chain::from(posted_vaa.emitter_chain) == Solana,
41-
err!(ExecutorError::EmitterChainNotSolana),
42-
)?;
43-
assert_or_err(
44-
posted_vaa.sequence > claim_record.sequence,
45-
err!(ExecutorError::NonIncreasingSequence),
46-
)?;
40+
41+
(Chain::from(posted_vaa.emitter_chain) == Solana)
42+
.ok_or(error!(ExecutorError::EmitterChainNotSolana))?;
43+
(posted_vaa.sequence > claim_record.sequence)
44+
.ok_or(error!(ExecutorError::NonIncreasingSequence))?;
4745
claim_record.sequence = posted_vaa.sequence;
4846

4947
let payload = ExecutorPayload::try_from_slice(&posted_vaa.payload)?;
@@ -80,11 +78,3 @@ pub struct ExecutePostedVaa<'info> {
8078
pub claim_record: Account<'info, ClaimRecord>,
8179
pub system_program: Program<'info, System>,
8280
}
83-
84-
pub fn assert_or_err(condition: bool, error: Result<()>) -> Result<()> {
85-
if !condition {
86-
error
87-
} else {
88-
Result::Ok(())
89-
}
90-
}

pythnet/remote-executor/programs/remote-executor/src/state/governance_payload.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ use anchor_lang::{
88
prelude::*,
99
solana_program::instruction::Instruction,
1010
};
11+
use boolinator::Boolinator;
1112
use wormhole::Chain;
1213

13-
use crate::{
14-
assert_or_err,
15-
error::ExecutorError,
16-
};
14+
use crate::error::ExecutorError;
1715

1816
pub const MAGIC_NUMBER: u32 = 0x4d475450; // Reverse order of the solidity contract because borsh uses little endian numbers (the solidity contract uses 0x5054474d)
1917

@@ -126,21 +124,13 @@ impl ExecutorPayload {
126124
const ACTION: Action = Action::ExecutePostedVaa;
127125

128126
pub fn check_header(&self) -> Result<()> {
129-
assert_or_err(
130-
self.header.magic_number == MAGIC_NUMBER,
131-
err!(ExecutorError::GovernanceHeaderInvalidMagicNumber),
132-
)?;
133-
assert_or_err(
134-
self.header.module == ExecutorPayload::MODULE,
135-
err!(ExecutorError::GovernanceHeaderInvalidMagicNumber),
136-
)?;
137-
assert_or_err(
138-
self.header.action == ExecutorPayload::ACTION,
139-
err!(ExecutorError::GovernanceHeaderInvalidMagicNumber),
140-
)?;
141-
assert_or_err(
142-
Chain::from(self.header.chain.value) == Chain::Pythnet,
143-
err!(ExecutorError::GovernanceHeaderInvalidMagicNumber),
144-
)
127+
(self.header.magic_number == MAGIC_NUMBER)
128+
.ok_or(error!(ExecutorError::GovernanceHeaderInvalidMagicNumber))?;
129+
(self.header.module == ExecutorPayload::MODULE)
130+
.ok_or(error!(ExecutorError::GovernanceHeaderInvalidMagicNumber))?;
131+
(self.header.action == ExecutorPayload::ACTION)
132+
.ok_or(error!(ExecutorError::GovernanceHeaderInvalidMagicNumber))?;
133+
(Chain::from(self.header.chain.value) == Chain::Pythnet)
134+
.ok_or(error!(ExecutorError::GovernanceHeaderInvalidMagicNumber))
145135
}
146136
}

0 commit comments

Comments
 (0)