Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BPF version of address lookup table #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,815 changes: 5,815 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]
members = [
"programs/address-lookup-table"
]

resolver = "2"
27 changes: 27 additions & 0 deletions programs/address-lookup-table/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "solana-address-lookup-table-program"
version = "0.1.0"
edition = "2021"

[features]
no-entrypoint = []
test-sbf = []

[dependencies]
bincode = "1.3.3"
bytemuck = "1.14.0"
log = "0.4.20"
serde = { version = "1.0.193", features = ["derive"] }
solana-frozen-abi = "1.17.7"
solana-frozen-abi-macro = "1.17.7"
solana-program = "1.17.7"
spl-pod = "0.1.0"
spl-program-error = "0.3.0"

[lib]
crate-type = ["cdylib", "lib"]

[dev-dependencies]
assert_matches = "1.5.0"
solana-program-test = "1.17.7"
solana-sdk = "1.17.7"
22 changes: 22 additions & 0 deletions programs/address-lookup-table/src/entrypoint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Program entrypoint

use {
crate::{error::AddressLookupError, processor::process},
solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError,
pubkey::Pubkey,
},
};

solana_program::entrypoint!(process_instruction);
fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
if let Err(error) = process(program_id, accounts, instruction_data) {
error.print::<AddressLookupError>();
return Err(error);
}
Ok(())
}
32 changes: 32 additions & 0 deletions programs/address-lookup-table/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Program error types

use spl_program_error::*;

/// Errors that may be returned by the program.
#[spl_program_error]
pub enum AddressLookupError {
/// Attempted to lookup addresses from a table that does not exist
#[error("Attempted to lookup addresses from a table that does not exist")]
LookupTableAccountNotFound,
/// Attempted to lookup addresses from an account owned by the wrong program
#[error("Attempted to lookup addresses from an account owned by the wrong program")]
InvalidAccountOwner,
/// Attempted to lookup addresses from an invalid account
#[error("Attempted to lookup addresses from an invalid account")]
InvalidAccountData,
/// Address lookup contains an invalid index
#[error("Address lookup contains an invalid index")]
InvalidLookupIndex,
/// Address lookup is immutable
#[error("Address lookup is immutable")]
LookupTableImmutable,
/// Incorrect address lookup authority provided
#[error("Incorrect address lookup authority provided")]
IncorrectAuthority,
// Failed to serialize address lookup table
#[error("Failed to serialize address lookup table")]
FailedToSerialize,
// Failed to deserialize address lookup table
#[error("Failed to deserialize address lookup table")]
FailedToDeserialize,
}
14 changes: 14 additions & 0 deletions programs/address-lookup-table/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! The [address lookup table program][np].
//!
//! [np]: https://docs.solana.com/developing/runtime-facilities/programs#address-lookup-table-program

#[cfg(not(feature = "no-entrypoint"))]
mod entrypoint;
pub mod error;
pub mod processor;

solana_program::declare_id!("AddressLookupTab1e1111111111111111111111111");

// Export current sdk types for downstream users building with a different sdk
// version
pub use solana_program::address_lookup_table::{instruction, state};
Loading