Repository: smicallef/spiderfoot
File: modules/sfp_bitcoinabuse.py (Python)

Code before:
            return None

        if res["content"] is None:
            self.sf.info(f"Failed to get results for {address}, empty content")
            return None

        try:
            info = json.loads(res["content"])
        except Exception as e:
            self.sf.error("Error processing JSON response from BitcoinAbuse.", False)
            return None

        return info

    def handleEvent(self, event):
        eventName = event.eventType
        srcModuleName = event.module
        eventData = event.data

        if self.errorState:
            return None

        self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")

        if self.opts["api_key"] == "":
            self.sf.error("You enabled sfp_template but did not set an API key!", False)
            self.errorState = True
            return None

        if eventData in self.results:
            self.sf.debug(f"Skipping {eventData}, already checked.")
            return None
        else:
            self.results[eventData] = True

        if eventName == "BITCOIN_ADDRESS":
            rec = self.query(eventData)
            if isinstance(rec, dict):
                count = rec.get("count")
                if isinstance(count, int):
                    if count != 0:
                        evt = SpiderFootEvent(
                            "MALICIOUS_BITCOIN_ADDRESS", rec["address"], self.__name__, event
                        )
                        self.notifyListeners(evt)

                        rirevt = SpiderFootEvent(
                            "RAW_RIR_DATA", json.dumps(rec), self.__name__, event
                        )
                        self.notifyListeners(rirevt)


Review comment (suggestion):
```suggestion
            self.sf.error("You enabled sfp_bitcoinabuse but did not set an API key!", False)
```

Code after:

        if res["content"] is None:
            self.sf.info(f"Failed to get results for {address}, empty content")
            return None

        try:
            info = json.loads(res["content"])
        except Exception as e:
            self.sf.error("Error processing JSON response from BitcoinAbuse.", False)
            return None

        return info

    def handleEvent(self, event):
        eventName = event.eventType
        srcModuleName = event.module
        eventData = event.data

        if self.errorState:
            return None

        self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")

        if self.opts["api_key"] == "":
            self.sf.error("You enabled sfp_bitcoinabuse but did not set an API key!", False)
            self.errorState = True
            return None

        if eventData in self.results:
            self.sf.debug(f"Skipping {eventData}, already checked.")
            return None

        self.results[eventData] = True

        if eventName == "BITCOIN_ADDRESS":
            rec = self.query(eventData)
            if isinstance(rec, dict):
                count = rec.get("count")
                if isinstance(count, int):
                    if count > 0:
                        evt = SpiderFootEvent(
                            "MALICIOUS_BITCOIN_ADDRESS", f"BitcoinAbuse[{rec['address']}]", self.__name__, event
                        )
                        self.notifyListeners(evt)

                        rirevt = SpiderFootEvent(
                            "RAW_RIR_DATA", json.dumps(rec), self.__name__, event
                        )
                        self.notifyListeners(rirevt)