Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion routes/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ func (fes *APIServer) GetTxn(ww http.ResponseWriter, req *http.Request) {
txnStatus = TxnStatusInMempool
}
txnInMempool := fes.backendServer.GetMempool().IsTransactionInPool(txnHash)
//
if txnStatus == TxnStatusInMempool && txnInMempool {
if err := json.NewEncoder(ww).Encode(&GetTxnResponse{TxnFound: true}); err != nil {
_AddBadRequestError(ww, fmt.Sprintf("GetTxn: Problem encoding response as JSON: %v", err))
return
}
}
startTime := time.Now()
// We have to wait until txindex has reached the uncommitted tip height, not the
// committed tip height. Otherwise we'll be missing ~2 blocks in limbo.
Expand All @@ -94,6 +101,14 @@ func (fes *APIServer) GetTxn(ww http.ResponseWriter, req *http.Request) {
_AddBadRequestError(ww, fmt.Sprintf("GetTxn: Timed out waiting for txindex to sync."))
return
}
if lib.DbCheckTxnExistence(fes.TXIndex.TXIndexChain.DB(), nil, txnHash) {
// If the txn is found in txindex, we can return early.
if err := json.NewEncoder(ww).Encode(&GetTxnResponse{TxnFound: true}); err != nil {
_AddBadRequestError(ww, fmt.Sprintf("GetTxn: Problem encoding response as JSON: %v", err))
return
}
return
}
time.Sleep(10 * time.Millisecond)
}
txnInTxindex := lib.DbCheckTxnExistence(fes.TXIndex.TXIndexChain.DB(), nil, txnHash)
Expand All @@ -117,7 +132,7 @@ func (fes *APIServer) GetTxn(ww http.ResponseWriter, req *http.Request) {
}

if err := json.NewEncoder(ww).Encode(res); err != nil {
_AddBadRequestError(ww, fmt.Sprintf("GetSinglePost: Problem encoding response as JSON: %v", err))
_AddBadRequestError(ww, fmt.Sprintf("GetTxn: Problem encoding response as JSON: %v", err))
return
}
}
Expand Down