Revert "Mark Various Functions, And Enums Public For On-Chain Price Calculations (#106)"

This reverts commit 905aed67b5.
This commit is contained in:
armaniferrante 2021-04-22 11:16:39 -07:00
parent 905aed67b5
commit 419a780fd4
No known key found for this signature in database
GPG Key ID: 58BEF301E91F7828
3 changed files with 30 additions and 29 deletions

View File

@ -28,12 +28,12 @@ enum NodeTag {
#[derive(Copy, Clone)]
#[repr(packed)]
#[allow(dead_code)]
pub struct InnerNode {
pub tag: u32,
pub prefix_len: u32,
pub key: u128,
pub children: [u32; 2],
pub _padding: [u64; 5],
struct InnerNode {
tag: u32,
prefix_len: u32,
key: u128,
children: [u32; 2],
_padding: [u64; 5],
}
unsafe impl Zeroable for InnerNode {}
unsafe impl Pod for InnerNode {}
@ -139,6 +139,7 @@ const fn _const_max(a: usize, b: usize) -> usize {
let gt = (a > b) as usize;
gt * a + (1 - gt) * b
}
const _INNER_NODE_SIZE: usize = size_of::<InnerNode>();
const _LEAF_NODE_SIZE: usize = size_of::<LeafNode>();
const _FREE_NODE_SIZE: usize = size_of::<FreeNode>();
@ -167,12 +168,12 @@ pub struct AnyNode {
unsafe impl Zeroable for AnyNode {}
unsafe impl Pod for AnyNode {}
pub enum NodeRef<'a> {
enum NodeRef<'a> {
Inner(&'a InnerNode),
Leaf(&'a LeafNode),
}
pub enum NodeRefMut<'a> {
enum NodeRefMut<'a> {
Inner(&'a mut InnerNode),
Leaf(&'a mut LeafNode),
}
@ -200,7 +201,7 @@ impl AnyNode {
}
}
pub fn case(&self) -> Option<NodeRef> {
fn case(&self) -> Option<NodeRef> {
match NodeTag::try_from(self.tag) {
Ok(NodeTag::InnerNode) => Some(NodeRef::Inner(cast_ref(self))),
Ok(NodeTag::LeafNode) => Some(NodeRef::Leaf(cast_ref(self))),
@ -251,13 +252,13 @@ const_assert_eq!(_NODE_ALIGN, align_of::<AnyNode>());
#[derive(Copy, Clone)]
#[repr(packed)]
pub struct SlabHeader {
pub bump_index: u64,
pub free_list_len: u64,
pub free_list_head: u32,
struct SlabHeader {
bump_index: u64,
free_list_len: u64,
free_list_head: u32,
pub root_node: u32,
pub leaf_count: u64,
root_node: u32,
leaf_count: u64,
}
unsafe impl Zeroable for SlabHeader {}
unsafe impl Pod for SlabHeader {}
@ -346,19 +347,19 @@ impl Slab {
(header, nodes)
}
pub fn header(&self) -> &SlabHeader {
fn header(&self) -> &SlabHeader {
self.parts().0
}
pub fn header_mut(&mut self) -> &mut SlabHeader {
fn header_mut(&mut self) -> &mut SlabHeader {
self.parts_mut().0
}
pub fn nodes(&self) -> &[AnyNode] {
fn nodes(&self) -> &[AnyNode] {
self.parts().1
}
pub fn nodes_mut(&mut self) -> &mut [AnyNode] {
fn nodes_mut(&mut self) -> &mut [AnyNode] {
self.parts_mut().1
}
}
@ -491,7 +492,7 @@ pub enum SlabTreeError {
}
impl Slab {
pub fn root(&self) -> Option<NodeHandle> {
fn root(&self) -> Option<NodeHandle> {
if self.header().leaf_count == 0 {
return None;
}

View File

@ -45,7 +45,7 @@ pub enum OrderType {
PostOnly = 2,
}
pub fn extract_price_from_order_id(order_id: u128) -> u64 {
fn extract_price_from_order_id(order_id: u128) -> u64 {
(order_id >> 64) as u64
}
@ -57,14 +57,14 @@ pub struct OrderBookState<'a> {
}
impl<'ob> OrderBookState<'ob> {
pub fn orders_mut(&mut self, side: Side) -> &mut Slab {
fn orders_mut(&mut self, side: Side) -> &mut Slab {
match side {
Side::Bid => self.bids,
Side::Ask => self.asks,
}
}
pub fn find_bbo(&self, side: Side) -> Option<NodeHandle> {
fn find_bbo(&self, side: Side) -> Option<NodeHandle> {
match side {
Side::Bid => self.bids.find_max(),
Side::Ask => self.asks.find_min(),
@ -143,7 +143,7 @@ impl<'ob> OrderBookState<'ob> {
}
}
pub struct RequestProceeds {
pub(crate) struct RequestProceeds {
pub coin_unlocked: u64,
pub native_pc_unlocked: u64,
@ -182,7 +182,7 @@ impl RequestProceeds {
impl_incr_method!(debit_native_pc, native_pc_debit);
}
pub struct NewOrderParams {
pub(crate) struct NewOrderParams {
side: Side,
order_type: OrderType,
order_id: u128,
@ -195,13 +195,13 @@ pub struct NewOrderParams {
self_trade_behavior: SelfTradeBehavior,
}
pub struct OrderRemaining {
struct OrderRemaining {
coin_qty_remaining: NonZeroU64,
native_pc_qty_remaining: Option<NonZeroU64>,
}
impl<'ob> OrderBookState<'ob> {
pub fn new_order(
fn new_order(
&mut self,
params: NewOrderParams,

View File

@ -258,7 +258,7 @@ impl MarketState {
Ok(open_orders)
}
pub fn load_bids_mut<'a>(&self, bids: &'a AccountInfo) -> DexResult<RefMut<'a, Slab>> {
fn load_bids_mut<'a>(&self, bids: &'a AccountInfo) -> DexResult<RefMut<'a, Slab>> {
check_assert_eq!(&bids.key.to_aligned_bytes(), &identity(self.bids))
.map_err(|_| DexErrorCode::WrongBidsAccount)?;
let (header, buf) = strip_header::<OrderBookStateHeader, u8>(bids, false)?;
@ -267,7 +267,7 @@ impl MarketState {
Ok(RefMut::map(buf, Slab::new))
}
pub fn load_asks_mut<'a>(&self, asks: &'a AccountInfo) -> DexResult<RefMut<'a, Slab>> {
fn load_asks_mut<'a>(&self, asks: &'a AccountInfo) -> DexResult<RefMut<'a, Slab>> {
check_assert_eq!(&asks.key.to_aligned_bytes(), &identity(self.asks))
.map_err(|_| DexErrorCode::WrongAsksAccount)?;
let (header, buf) = strip_header::<OrderBookStateHeader, u8>(asks, false)?;