Skip to content

Comments

Suggested fix to issue 192 (market - execution timestamp) + docs fixes#229

Open
AkstonCap wants to merge 2 commits intoNexusoft:merging-6.0from
AkstonCap:merging-6.0
Open

Suggested fix to issue 192 (market - execution timestamp) + docs fixes#229
AkstonCap wants to merge 2 commits intoNexusoft:merging-6.0from
AkstonCap:merging-6.0

Conversation

@AkstonCap
Copy link
Contributor

Suggestion for fix to issue 192: #192 (market/list/executed/timestamp seem to be inherited from order creation time, not execution time).

See commits for detailed explanation where transaction hash is added. Please validate if this inclusion fits the "bigger picture", this fix was only done with this specific issue in mind.

Feel free to edit or decline.

AkstonCap added 2 commits January 16, 2026 18:43
correct executed order timestamps

Previously, executed orders in market/list/executed and market/user/executed
APIs would display the original order creation timestamp instead of the
actual execution timestamp. This made it impossible to accurately determine
when trades occurred, breaking functionality for last price fetching and
price charting.

Root Cause:
-----------
The ContractDB only stored the hashCaller (genesis hash of who executed the
order) when an order was fulfilled. There was no link to the execution
transaction, so when displaying executed orders, the API had no way to
retrieve the execution timestamp and fell back to the order's creation time.

Solution:
---------
1. Database Schema (LLD/types/contract.h):
   - Added ContractData struct to store both hashCaller and hashExecution
   - Updated ContractTransaction::mapContracts to use ContractData
   - Extended WriteContract() to accept execution tx hash parameter
   - Extended ReadContract() to return execution tx hash via output param

2. Validation Layer (TAO/Operation/validate.cpp):
   - Modified Validate::Commit() to accept and store execution tx hash
   - Passes contract.Hash() (executing transaction's hash) to WriteContract

3. Execution Layer (TAO/Operation/execute.cpp):
   - OP::VALIDATE case now passes contract.Hash() to Validate::Commit()

4. Market API (TAO/API/commands/market/):
   - OrderToJSON() now accepts optional nExecutionTimestamp parameter
   - When provided (> 0), uses execution time instead of creation time
   - list.cpp and user.cpp fetch execution tx via ReadContract()
   - Retrieve timestamp from execution transaction for executed orders

Backward Compatibility:
-----------------------
Orders executed before this fix have hashExecution = 0 in the database.
ReadTx(0) fails gracefully, leaving nExecutionTimestamp = 0, which causes
OrderToJSON to fall back to the original creation timestamp. New orders
will correctly display execution timestamps.

Files Changed:
- src/LLD/types/contract.h - ContractData struct, updated interfaces
- src/LLD/contract.cpp - Store/retrieve ContractData with execution hash
- src/TAO/Operation/include/validate.h - Updated Commit() signature
- src/TAO/Operation/validate.cpp - Pass execution hash to WriteContract
- src/TAO/Operation/execute.cpp - Pass contract.Hash() to Commit()
- src/LLP/lookup.cpp - Updated WriteContract call
- src/TAO/API/types/commands/market.h - Added timestamp param to OrderToJSON
- src/TAO/API/commands/market/json.cpp - Use execution timestamp if provided
- src/TAO/API/commands/market/list.cpp - Fetch execution timestamp
- src/TAO/API/commands/market/user.cpp - Fetch execution timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant