Move errors to their own file.
Change-Id: If76fc6096f2788e13dad15ea088202159793fb0b
This commit is contained in:
parent
35bdef1f8b
commit
18a6f429cb
|
@ -16,6 +16,12 @@ use crate::{
|
|||
GuardianSet,
|
||||
GuardianSetDerivationData,
|
||||
},
|
||||
error::Error::{
|
||||
InvalidFeeRecipient,
|
||||
InvalidGovernanceKey,
|
||||
InvalidGovernanceWithdrawal,
|
||||
InvalidGuardianSetUpgrade,
|
||||
},
|
||||
types::{
|
||||
GovernancePayloadGuardianSetChange,
|
||||
GovernancePayloadSetMessageFee,
|
||||
|
@ -26,12 +32,6 @@ use crate::{
|
|||
ClaimableVAA,
|
||||
DeserializePayload,
|
||||
},
|
||||
Error::{
|
||||
InvalidFeeRecipient,
|
||||
InvalidGovernanceKey,
|
||||
InvalidGovernanceWithdrawal,
|
||||
InvalidGuardianSetUpgrade,
|
||||
},
|
||||
CHAIN_ID_SOLANA,
|
||||
};
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::{
|
|||
GuardianSet,
|
||||
GuardianSetDerivationData,
|
||||
},
|
||||
error::Error::TooManyGuardians,
|
||||
types::*,
|
||||
Error::TooManyGuardians,
|
||||
MAX_LEN_GUARDIAN_KEYS,
|
||||
};
|
||||
use solana_program::sysvar::clock::Clock;
|
||||
|
|
|
@ -7,14 +7,13 @@ use crate::{
|
|||
Sequence,
|
||||
SequenceDerivationData,
|
||||
},
|
||||
Error::{
|
||||
error::Error::{
|
||||
InsufficientFees,
|
||||
MathOverflow,
|
||||
},
|
||||
CHAIN_ID_SOLANA,
|
||||
};
|
||||
use solana_program::{
|
||||
msg,
|
||||
pubkey::Pubkey,
|
||||
sysvar::clock::Clock,
|
||||
};
|
||||
|
|
|
@ -19,8 +19,11 @@ use crate::{
|
|||
SignatureSet,
|
||||
SignatureSetDerivationData,
|
||||
},
|
||||
Error,
|
||||
Error::GuardianSetMismatch,
|
||||
error::Error::{
|
||||
GuardianSetMismatch,
|
||||
PostVAAConsensusFailed,
|
||||
PostVAAGuardianSetExpired,
|
||||
},
|
||||
CHAIN_ID_SOLANA,
|
||||
};
|
||||
use byteorder::{
|
||||
|
@ -29,7 +32,6 @@ use byteorder::{
|
|||
};
|
||||
use sha3::Digest;
|
||||
use solana_program::{
|
||||
msg,
|
||||
program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
@ -155,7 +157,7 @@ pub fn post_vaa(ctx: &ExecutionContext, accs: &mut PostVAA, vaa: PostVAAData) ->
|
|||
};
|
||||
|
||||
if signature_count < required_consensus_count {
|
||||
return Err(Error::PostVAAConsensusFailed.into());
|
||||
return Err(PostVAAConsensusFailed.into());
|
||||
}
|
||||
|
||||
// If the VAA originates from another chain we need to create the account and populate all fields
|
||||
|
@ -186,7 +188,7 @@ fn check_active<'r>(
|
|||
if guardian_set.expiration_time != 0
|
||||
&& (guardian_set.expiration_time as i64) < clock.unix_timestamp
|
||||
{
|
||||
return Err(Error::PostVAAGuardianSetExpired.into());
|
||||
return Err(PostVAAGuardianSetExpired.into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
SignatureSet,
|
||||
SignatureSetDerivationData,
|
||||
},
|
||||
Error::{
|
||||
error::Error::{
|
||||
GuardianSetMismatch,
|
||||
InstructionAtWrongIndex,
|
||||
InvalidHash,
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
//! Define application level errors that can be returned by the various instruction handlers that
|
||||
//! make up the wormhole bridge.
|
||||
|
||||
use crate::trace;
|
||||
use solitaire::SolitaireError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
GuardianSetMismatch,
|
||||
InstructionAtWrongIndex,
|
||||
InsufficientFees,
|
||||
InvalidFeeRecipient,
|
||||
InvalidGovernanceAction,
|
||||
InvalidGovernanceChain,
|
||||
InvalidGovernanceKey,
|
||||
InvalidGovernanceModule,
|
||||
InvalidGovernanceWithdrawal,
|
||||
InvalidGuardianSetUpgrade,
|
||||
InvalidHash,
|
||||
InvalidSecpInstruction,
|
||||
MathOverflow,
|
||||
PostVAAConsensusFailed,
|
||||
PostVAAGuardianSetExpired,
|
||||
TooManyGuardians,
|
||||
VAAAlreadyExecuted,
|
||||
}
|
||||
|
||||
/// Errors thrown by the program will bubble up to the solitaire wrapper, which needs a way to
|
||||
/// translate these errors into something Solitaire can log and handle.
|
||||
impl From<Error> for SolitaireError {
|
||||
fn from(e: Error) -> SolitaireError {
|
||||
trace!("ProgramError: {:?}", e);
|
||||
SolitaireError::Custom(e as u64)
|
||||
}
|
||||
}
|
|
@ -2,10 +2,9 @@
|
|||
#![allow(non_upper_case_globals)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use solana_program::msg;
|
||||
|
||||
pub mod accounts;
|
||||
pub mod api;
|
||||
pub mod error;
|
||||
pub mod types;
|
||||
pub mod vaa;
|
||||
|
||||
|
@ -50,39 +49,8 @@ pub use vaa::{
|
|||
};
|
||||
|
||||
const MAX_LEN_GUARDIAN_KEYS: usize = 19;
|
||||
|
||||
const CHAIN_ID_SOLANA: u16 = 1;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
GuardianSetMismatch,
|
||||
InstructionAtWrongIndex,
|
||||
InsufficientFees,
|
||||
InvalidFeeRecipient,
|
||||
InvalidGovernanceAction,
|
||||
InvalidGovernanceChain,
|
||||
InvalidGovernanceKey,
|
||||
InvalidGovernanceModule,
|
||||
InvalidGovernanceWithdrawal,
|
||||
InvalidGuardianSetUpgrade,
|
||||
InvalidHash,
|
||||
InvalidSecpInstruction,
|
||||
MathOverflow,
|
||||
PostVAAConsensusFailed,
|
||||
PostVAAGuardianSetExpired,
|
||||
TooManyGuardians,
|
||||
VAAAlreadyExecuted,
|
||||
}
|
||||
|
||||
/// Translate from program specific errors to Solitaire framework errors. Log the error on the way
|
||||
/// out of the program for debugging.
|
||||
impl From<Error> for SolitaireError {
|
||||
fn from(e: Error) -> SolitaireError {
|
||||
msg!("ProgramError: {:?}", e);
|
||||
SolitaireError::Custom(e as u64)
|
||||
}
|
||||
}
|
||||
|
||||
solitaire! {
|
||||
Initialize(InitializeData) => initialize,
|
||||
PostMessage(PostMessageData) => post_message,
|
||||
|
|
|
@ -21,7 +21,6 @@ use solitaire::{
|
|||
AccountOwner,
|
||||
Owned,
|
||||
},
|
||||
trace,
|
||||
SolitaireError,
|
||||
};
|
||||
use std::{
|
||||
|
@ -309,7 +308,6 @@ pub struct GovernancePayloadSetMessageFee {
|
|||
|
||||
impl SerializePayload for GovernancePayloadSetMessageFee {
|
||||
fn serialize<W: Write>(&self, v: &mut W) -> std::result::Result<(), SolitaireError> {
|
||||
use byteorder::WriteBytesExt;
|
||||
let mut fee_data = [0u8; 32];
|
||||
self.fee.to_big_endian(&mut fee_data);
|
||||
v.write(&fee_data[..])?;
|
||||
|
@ -359,11 +357,10 @@ pub struct GovernancePayloadTransferFees {
|
|||
|
||||
impl SerializePayload for GovernancePayloadTransferFees {
|
||||
fn serialize<W: Write>(&self, v: &mut W) -> std::result::Result<(), SolitaireError> {
|
||||
use byteorder::WriteBytesExt;
|
||||
let mut amount_data = [0u8; 32];
|
||||
self.amount.to_big_endian(&mut amount_data);
|
||||
v.write(&amount_data)?;
|
||||
v.write(&self.to);
|
||||
v.write(&self.to)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ use crate::{
|
|||
Claim,
|
||||
ClaimDerivationData,
|
||||
},
|
||||
types::PostedMessage,
|
||||
Error::{
|
||||
error::Error::{
|
||||
InvalidGovernanceAction,
|
||||
InvalidGovernanceChain,
|
||||
InvalidGovernanceModule,
|
||||
VAAAlreadyExecuted,
|
||||
},
|
||||
types::PostedMessage,
|
||||
Result,
|
||||
CHAIN_ID_SOLANA,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue