@@ -67,21 +67,10 @@ contract OrderContract is ReentrancyGuard{
6767 address private immutable pyUSD; // Address of the pyUSD token contract
6868 address private immutable a3aToken; // Address of the A3A token contract
6969
70- // will make mappings to struct!!! thus too messy.
71- //////////////////////////////////////////////
72- // FIX THIS!!!!
73- ///////////////////////////////////
74- // mapping(address => mapping(uint64 offerId => bytes32 promptHash)) private addressToOfferIdToPromptHash;
75- // mapping(uint64 offerId => uint256 timestamp) private offerIdToTimestamp;
76- // mapping(uint64 offerId => mapping(address user => uint256 amountPaid)) private offerIdToUserToAmountPaid;
77- // mapping(uint64 offerId => OrderStatus status) private offerIdToStatus;
78- // mapping(uint64 offerId => bytes32 answerHash) private offerIdToAnswerHash;
79- // mapping(uint64 => address) private offerIdToUser;
8070
8171 mapping (uint64 => Offer) public offers;
8272
83- // User order tracking mappings
84- mapping (address => mapping (uint64 => bool )) private userOrders;
73+
8574 mapping (address => uint64 []) private userOrderIds;
8675
8776 // merchants address->orderIds mapping to fetch all orders for a merchant
@@ -125,11 +114,9 @@ contract OrderContract is ReentrancyGuard{
125114 offers[offerID].promptHash = promptHash;
126115
127116 // Update user order mappings
128- userOrders[userWalletAddress][offerID] = true ;
117+
129118 userOrderIds[userWalletAddress].push (offerID);
130-
131- // addressToOfferIdToPromptHash[msg.sender][offerID] = promptHash;
132- // offerIdToUser[offerID] = msg.sender;
119+
133120
134121 emit OrderProposed (offers[offerID].buyer, offerID, offers[offerID].promptHash);
135122 // Burn 10 A3A tokens from uses. This acts as Fee for using the platform.
@@ -155,12 +142,10 @@ contract OrderContract is ReentrancyGuard{
155142 }
156143 // update amount paid for the offer by the user
157144 uint256 amountToPay = offers[offerId].price + AGENT_FEE;
158- // offerIdToUserToAmountPaid[offerId][msg.sender] += amountToPay;
159- // offerIdToStatus[offerId] = OrderStatus.Confirmed;
145+
160146 offers[offerId].paid = amountToPay;
161147 offers[offerId].status = OrderStatus.Confirmed;
162- // Record the current timestamp for the offer
163- // offerIdToTimestamp[offerId] = block.timestamp;
148+
164149 offers[offerId].timestamp = block .timestamp ;
165150 bool success= ERC20 (pyUSD).transferFrom (msg .sender , address (this ), amountToPay);
166151
@@ -277,6 +262,10 @@ contract OrderContract is ReentrancyGuard{
277262 return offers[orderId];
278263 }
279264
265+ function getA3ATokenAddress () external view returns (address ) {
266+ return a3aToken;
267+ }
268+
280269 // User order query functions for backend integration
281270
282271 /**
@@ -294,8 +283,12 @@ contract OrderContract is ReentrancyGuard{
294283 * @param orderId The order ID to check
295284 * @return bool indicating if the user has this order
296285 */
297- function hasUserOrder (address user , uint64 orderId ) external view returns (bool ) {
298- return userOrders[user][orderId];
286+ function hasUserOrder (address user , uint64 orderId ) public view returns (bool ) {
287+ if (offers[orderId].buyer == user) {
288+ return true ;
289+ } else {
290+ return false ;
291+ }
299292 }
300293
301294 /**
@@ -311,23 +304,8 @@ contract OrderContract is ReentrancyGuard{
311304 // require(userOrders[user][orderId], "Order does not belong to user");
312305 return offers[orderId].status;
313306 }
307+
314308
315- /**
316- * @notice Get all orders with their statuses for a specific user
317- * @param user The user address to query
318- * @return orderIds Array of order IDs
319- * @return statuses Array of corresponding order statuses
320- */
321- function getUserOrdersWithStatus (address user ) external view returns (uint64 [] memory orderIds , OrderStatus[] memory statuses ) {
322- uint64 [] memory userIds = userOrderIds[user];
323- OrderStatus[] memory orderStatuses = new OrderStatus [](userIds.length );
324-
325- for (uint256 i = 0 ; i < userIds.length ; i++ ) {
326- orderStatuses[i] = offers[userIds[i]].status;
327- }
328-
329- return (userIds, orderStatuses);
330- }
331309
332310 /**
333311 * @notice Get complete order details for a user's specific order
@@ -336,36 +314,14 @@ contract OrderContract is ReentrancyGuard{
336314 * @return Complete Offer struct for the specified order
337315 */
338316 function getUserOrderDetails (address user , uint64 orderId ) external view returns (Offer memory ) {
339- require (userOrders[user][orderId], "Order does not belong to user " );
317+ if (hasUserOrder (user, orderId) == false ) {
318+ revert OrderContract__userHasNoAccessToOffer ();
319+ }
340320 return offers[orderId];
341321 }
342322
343- /**
344- * @notice Get orders filtered by status for a user
345- * @param user The user address
346- * @param status The status to filter by
347- * @return Array of order IDs matching the specified status
348- */
349- function getUserOrdersByStatus (address user , OrderStatus status ) external view returns (uint64 [] memory ) {
350- uint64 [] memory userIds = userOrderIds[user];
351- uint64 [] memory filteredIds = new uint64 [](userIds.length );
352- uint256 count = 0 ;
353-
354- for (uint256 i = 0 ; i < userIds.length ; i++ ) {
355- if (offers[userIds[i]].status == status) {
356- filteredIds[count] = userIds[i];
357- count++ ;
358- }
359- }
360-
361- // Create a properly sized array
362- uint64 [] memory result = new uint64 [](count);
363- for (uint256 i = 0 ; i < count; i++ ) {
364- result[i] = filteredIds[i];
365- }
366-
367- return result;
368- }
323+
324+
369325
370326
371327}
0 commit comments