pub struct Tree {
pub program: Pubkey,
pub creator: Pubkey,
pub tree_id: u32,
}Expand description
A handle to one tree: (program, creator, tree_id). All PDA/seed logic lives here.
Fields§
§program: Pubkey§creator: Pubkey§tree_id: u32Implementations§
Source§impl Tree
impl Tree
pub fn new(program: Pubkey, creator: Pubkey, tree_id: u32) -> Self
pub fn header_pda(&self) -> (Pubkey, u8)
pub fn alloc_pda(&self) -> (Pubkey, u8)
pub fn node_pda(&self, idx: u64) -> (Pubkey, u8)
pub fn header(&self, r: &dyn AccountReader) -> Option<Header>
Sourcepub fn path(&self, r: &dyn AccountReader, key: &[u8; 32]) -> Option<Vec<u64>>
pub fn path(&self, r: &dyn AccountReader, key: &[u8; 32]) -> Option<Vec<u64>>
Descent path root..leaf (node_idx list) for key. Empty if the tree is empty.
Mirrors the engine’s descent: lower_bound, then “key == separator -> go right”.
Sourcepub fn insert_fast_ix(
&self,
r: &dyn AccountReader,
authority: Pubkey,
key: &[u8; 32],
value: &[u8],
) -> Option<Instruction>
pub fn insert_fast_ix( &self, r: &dyn AccountReader, authority: Pubkey, key: &[u8; 32], value: &[u8], ) -> Option<Instruction>
InsertFast: place a new key/value into an existing leaf (fails if the leaf is
full -> caller falls back to insert for the cold split path).
Sourcepub fn update_fast_ix(
&self,
r: &dyn AccountReader,
authority: Pubkey,
key: &[u8; 32],
value: &[u8],
) -> Option<Instruction>
pub fn update_fast_ix( &self, r: &dyn AccountReader, authority: Pubkey, key: &[u8; 32], value: &[u8], ) -> Option<Instruction>
UpdateFast: overwrite the value of an existing key in place.
Sourcepub fn delete_fast_ix(
&self,
r: &dyn AccountReader,
authority: Pubkey,
key: &[u8; 32],
) -> Option<Instruction>
pub fn delete_fast_ix( &self, r: &dyn AccountReader, authority: Pubkey, key: &[u8; 32], ) -> Option<Instruction>
DeleteFast: remove a key without rebalancing (a leaf may drop below MIN).
Sourcepub fn find_ix(
&self,
r: &dyn AccountReader,
key: &[u8; 32],
) -> Option<Instruction>
pub fn find_ix( &self, r: &dyn AccountReader, key: &[u8; 32], ) -> Option<Instruction>
Find: returns the instruction; the caller reads return_data [found u8, value..].
Sourcepub fn insert_ix(
&self,
r: &dyn AccountReader,
payer: Pubkey,
key: &[u8; 32],
value: &[u8],
rent_node: u64,
) -> Option<Instruction>
pub fn insert_ix( &self, r: &dyn AccountReader, payer: Pubkey, key: &[u8; 32], value: &[u8], rent_node: u64, ) -> Option<Instruction>
Insert (cold path): handles the empty-tree first insert and splits. Resolves the
spare node PDAs (height+2 of them) the engine may need. rent_node = rent-exempt
lamports for one node account (caller computes from its client).
Sourcepub fn delete_ix(
&self,
r: &dyn AccountReader,
payer: Pubkey,
key: &[u8; 32],
) -> Option<Instruction>
pub fn delete_ix( &self, r: &dyn AccountReader, payer: Pubkey, key: &[u8; 32], ) -> Option<Instruction>
Delete (cold path): removes a key and rebalances (borrow/merge), reclaiming
rent to payer. Resolves, for each non-root level, which sibling the engine
needs (right if our child is not the last, else left) by reading each parent.
payer must be the tree authority (Delete is primary-only).
Sourcepub fn cold_plan(
&self,
r: &dyn AccountReader,
key: &[u8; 32],
) -> Option<(Vec<u64>, Vec<(Pubkey, u8)>)>
pub fn cold_plan( &self, r: &dyn AccountReader, key: &[u8; 32], ) -> Option<(Vec<u64>, Vec<(Pubkey, u8)>)>
Resolve the cold-path Insert plan for key: the descent path and the spare node
PDAs (height+2 of them, with bumps) the engine may consume on a split. Used to
build a cold place when InsertFast hits a full leaf (ERR_NEED_SPLIT_SLOT).
Sourcepub fn init_tree_ix(
&self,
payer: Pubkey,
value_size: u16,
fanout: u16,
rent_hdr: u64,
rent_alloc: u64,
) -> Instruction
pub fn init_tree_ix( &self, payer: Pubkey, value_size: u16, fanout: u16, rent_hdr: u64, rent_alloc: u64, ) -> Instruction
InitTree. rent_hdr/rent_alloc from the caller’s client.
Sourcepub fn scan(
&self,
r: &dyn AccountReader,
max: usize,
) -> Vec<([u8; 32], Vec<u8>)>
pub fn scan( &self, r: &dyn AccountReader, max: usize, ) -> Vec<([u8; 32], Vec<u8>)>
In-order scan from the smallest key, up to max entries: (key, value) pairs.
Walks the forward leaf chain via the AccountReader. For an orderbook this is
the book in price-time order (best price first); take(1) = top of book.
Sourcepub fn best(&self, r: &dyn AccountReader) -> Option<([u8; 32], Vec<u8>)>
pub fn best(&self, r: &dyn AccountReader) -> Option<([u8; 32], Vec<u8>)>
The smallest entry (top of book), or None if empty.
Sourcepub fn get(&self, r: &dyn AccountReader, key: &[u8; 32]) -> Option<Vec<u8>>
pub fn get(&self, r: &dyn AccountReader, key: &[u8; 32]) -> Option<Vec<u8>>
The value stored at key, or None if absent.
Sourcepub fn scan_accounts(
&self,
r: &dyn AccountReader,
max_entries: usize,
) -> Vec<Pubkey>
pub fn scan_accounts( &self, r: &dyn AccountReader, max_entries: usize, ) -> Vec<Pubkey>
The header + the leaf account pubkeys a forward scan of up to max_entries
would traverse. A K-order match tx references these, so they go in an Address
Lookup Table (build the v0 message + ALT with solana-sdk’s address_lookup_table;
the ALT program calls are standard Solana, not Torna-specific).