Skip to content

Commit

Permalink
runtime: Move From<AddressLookupError> from sdk (#141)
Browse files Browse the repository at this point in the history
sdk: Move `From<AddressLookupError>` into runtime
  • Loading branch information
joncinque authored Mar 8, 2024
1 parent c0239c8 commit 377e1f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
28 changes: 21 additions & 7 deletions runtime/src/bank/address_lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ use {
},
};

fn into_address_loader_error(err: AddressLookupError) -> AddressLoaderError {
match err {
AddressLookupError::LookupTableAccountNotFound => {
AddressLoaderError::LookupTableAccountNotFound
}
AddressLookupError::InvalidAccountOwner => AddressLoaderError::InvalidAccountOwner,
AddressLookupError::InvalidAccountData => AddressLoaderError::InvalidAccountData,
AddressLookupError::InvalidLookupIndex => AddressLoaderError::InvalidLookupIndex,
}
}

impl AddressLoader for &Bank {
fn load_addresses(
self,
Expand All @@ -23,15 +34,18 @@ impl AddressLoader for &Bank {
.get_slot_hashes()
.map_err(|_| AddressLoaderError::SlotHashesSysvarNotFound)?;

Ok(address_table_lookups
address_table_lookups
.iter()
.map(|address_table_lookup| {
self.rc.accounts.load_lookup_table_addresses(
&self.ancestors,
address_table_lookup,
&slot_hashes,
)
self.rc
.accounts
.load_lookup_table_addresses(
&self.ancestors,
address_table_lookup,
&slot_hashes,
)
.map_err(into_address_loader_error)
})
.collect::<Result<_, AddressLookupError>>()?)
.collect::<Result<_, _>>()
}
}
14 changes: 0 additions & 14 deletions sdk/program/src/address_lookup_table/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(not(target_os = "solana"))]
use solana_program::message::AddressLoaderError;
use thiserror::Error;

#[derive(Debug, Error, PartialEq, Eq, Clone)]
Expand All @@ -20,15 +18,3 @@ pub enum AddressLookupError {
#[error("Address lookup contains an invalid index")]
InvalidLookupIndex,
}

#[cfg(not(target_os = "solana"))]
impl From<AddressLookupError> for AddressLoaderError {
fn from(err: AddressLookupError) -> Self {
match err {
AddressLookupError::LookupTableAccountNotFound => Self::LookupTableAccountNotFound,
AddressLookupError::InvalidAccountOwner => Self::InvalidAccountOwner,
AddressLookupError::InvalidAccountData => Self::InvalidAccountData,
AddressLookupError::InvalidLookupIndex => Self::InvalidLookupIndex,
}
}
}

0 comments on commit 377e1f9

Please sign in to comment.