// Adds a transaction to the rejected list or not, it it has been mined already // Make sure to call it with locked TxMutex. // Returns the OneTxRejected or nil if it has not been added. func RejectTx(id *btc.Uint256, size int, why byte) *OneTxRejected { rec := new(OneTxRejected) rec.Id = id rec.Time = time.Now() rec.Size = uint32(size) rec.Reason = why TransactionsRejected[id.BIdx()] = rec return rec }
func txChecker(h *btc.Uint256) bool { TxMutex.Lock() rec, ok := TransactionsToSend[h.BIdx()] TxMutex.Unlock() if ok && rec.Own != 0 { return false // Assume own txs as non-trusted } if ok { common.CountSafe("TxScrBoosted") } else { common.CountSafe("TxScrMissed") } return ok }
// Return false if we do not want to receive a data fotr this tx func NeedThisTx(id *btc.Uint256, cb func()) (res bool) { TxMutex.Lock() if _, present := TransactionsToSend[id.Hash]; present { //res = false } else if _, present := TransactionsRejected[id.BIdx()]; present { //res = false } else if _, present := TransactionsPending[id.Hash]; present { //res = false } else { res = true if cb != nil { cb() } } TxMutex.Unlock() return }
// Return false if we do not want to receive a data for this tx func NeedThisTx(id *btc.Uint256, cb func()) (res bool) { TxMutex.Lock() if _, present := TransactionsToSend[id.Hash]; present { //res = false } else if _, present := TransactionsRejected[id.BIdx()]; present { //res = false } else if _, present := TransactionsPending[id.Hash]; present { //res = false } else if txo, _ := common.BlockChain.Unspent.UnspentGet(&btc.TxPrevOut{Hash: id.Hash}); txo != nil { // This assumes that tx's out #0 has not been spent yet, which may not always be the case, but well... common.CountSafe("TxMinedRejected") } else { res = true if cb != nil { cb() } } TxMutex.Unlock() return }
// Return false if we do not want to receive a data for this tx func NeedThisTx(id *btc.Uint256, cb func()) (res bool) { TxMutex.Lock() if _, present := TransactionsToSend[id.Hash]; present { //res = false } else if _, present := TransactionsRejected[id.BIdx()]; present { //res = false } else if _, present := TransactionsPending[id.Hash]; present { //res = false } else if txo, _ := common.BlockChain.Unspent.UnspentGet(&btc.TxPrevOut{Hash: id.Hash}); txo != nil { //res = falseuint32() common.CountSafe("TxMinedRejected") } else { res = true if cb != nil { cb() } } TxMutex.Unlock() return }
func TxMined(h *btc.Uint256) { TxMutex.Lock() if rec, ok := TransactionsToSend[h.Hash]; ok { common.CountSafe("TxMinedToSend") for i := range rec.Spent { delete(SpentOutputs, rec.Spent[i]) } delete(TransactionsToSend, h.Hash) } if _, ok := TransactionsRejected[h.BIdx()]; ok { common.CountSafe("TxMinedRejected") deleteRejected(h.BIdx()) } if _, ok := TransactionsPending[h.Hash]; ok { common.CountSafe("TxMinedPending") delete(TransactionsPending, h.Hash) } wtg := WaitingForInputs[h.BIdx()] TxMutex.Unlock() // Try to redo waiting txs if wtg != nil { common.CountSafe("TxMinedGotInput") RetryWaitingForInput(wtg) } }