# Inventory A system for tracking and managing order states through their lifecycle, with WebSocket event handling for order updates. ## Quick Reference ```rust // Initialize inventory let mut inventory = Inventory::new(); // Track new order inventory.add_pending_order(pending_order); // View orders inventory.view_successful_orders(); ``` ## Core Data Structures ```rust pub struct Inventory { pending_orders: HashMap, successful_orders: Vec } // Order States struct OrderPending { mm_order_id: String, order: Order, tx_hash: FixedBytes<32> } struct SuccessfulOrder { mm_order_id: String, order: Order, kuru_order_id: U256 } ``` ## Methods ### Order Management ```rust // Create new inventory pub fn new() -> Self // Add new pending order pub fn add_pending_order(&mut self, pending_order: OrderPending) // Add successful order pub fn add_successful_order(&mut self, successful_order: SuccessfulOrder) // Display successful orders pub fn view_successful_orders(&self) ``` ### Event Handlers ```rust // Handle order creation events pub fn handle_order_created(&mut self, payload: Payload) // Handle trade execution events pub fn handle_trade(&mut self, payload: Payload) // Handle order cancellation events pub fn handle_orders_cancelled(&mut self, payload: Payload) ``` ## Event Payload Processing ### Order Created Event ```json { "transactionHash": "0x...", "orderId": "123" } ``` ### Trade Event ```json { "transactionHash": "0x...", "orderId": "123" } ``` ### Cancel Event ```json { "transactionHash": "0x..." } ``` ## Flow Diagram ``` Pending Order → Order Created Event → Successful Order ↓ → Trade Event → Successful Order ↓ → Cancel Event → Removed ``` ## Notes - Orders are tracked by transaction hash - Maintains separate collections for pending and successful orders - Event handlers match incoming events with pending orders - Supports real-time order status updates - Uses hex-encoded transaction hashes with '0x' prefix - Thread-safe for concurrent access to order collections