From 52df1a9c3009c59e2623d03a3252599fd7d3b9a9 Mon Sep 17 00:00:00 2001
From: Martin Mihaylov <3739458+martomi@users.noreply.github.com>
Date: Sun, 25 Apr 2021 19:10:52 +0200
Subject: [PATCH] Remove wallet events and added coins parser / handlers
This log has been removed from chia in the most recent versions so it
serves no purpose to have the logic here. I've submitted a PR to re-add
the log back, if that happens we can revert this change.
https://github.com/Chia-Network/chia-blockchain/pull/2720
---
README.md | 3 +-
config-example.yaml | 8 ---
src/chia_log/handlers/daily_stats/__init__.py | 7 ---
.../wallet_added_coin_stats.py | 21 --------
.../handlers/daily_stats/stats_manager.py | 13 +----
.../handlers/wallet_added_coin_handler.py | 42 ----------------
src/chia_log/log_handler.py | 3 +-
.../parsers/wallet_added_coin_parser.py | 49 -------------------
src/notifier/__init__.py | 5 +-
.../test_wallet_added_coin_handler.py | 28 -----------
.../parsers/test_wallet_added_coin_parser.py | 27 ----------
tests/notifier/test_discord_notifier.py | 1 -
tests/notifier/test_pushover_notifier.py | 1 -
tests/notifier/test_script_notifier.py | 2 +-
tests/notifier/test_slack_notifier.py | 1 -
tests/notifier/test_smtp_notifier.py | 1 -
tests/notifier/test_telegram_notifier.py | 1 -
17 files changed, 5 insertions(+), 208 deletions(-)
delete mode 100644 src/chia_log/handlers/daily_stats/stat_accumulators/wallet_added_coin_stats.py
delete mode 100644 src/chia_log/handlers/wallet_added_coin_handler.py
delete mode 100644 src/chia_log/parsers/wallet_added_coin_parser.py
delete mode 100644 tests/chia_log/handlers/test_wallet_added_coin_handler.py
delete mode 100644 tests/chia_log/parsers/test_wallet_added_coin_parser.py
diff --git a/README.md b/README.md
index 7e8afc6c..dbaeba48 100644
--- a/README.md
+++ b/README.md
@@ -21,8 +21,7 @@ helps with automated monitoring and sends you a mobile notification in case some
| Harvester | Experiencing networking issues? Harvester did not participate in any challenge for 120 seconds. It's now working again. | NORMAL |
| Harvester | Seeking plots took too long: 40 seconds! | NORMAL |
| Full Node | Experiencing networking issues? Skipped 42 signage points! | NORMAL |
-| Wallet | Cha-ching! Just received 2.0 XCH βοΈ | LOW |
-| Daily Stats | Hello farmer! π Here's what happened in the last 24 hours:
Received βοΈ: **2.00** XCHοΈ
Proofs π§Ύ: **2** found
Search π: **0.46**s average, **15.31**s max
Plots π±: **42**, new: **2**
Eligible plots π₯: **0.08** average
Skipped SPs β οΈ: 7 (0.01%)
| LOW |
+| Daily Stats | Hello farmer! π Here's what happened in the last 24 hours:
Proofs π§Ύ: **2** found
Search π: **0.46**s average, **15.31**s max
Plots π±: **42**, new: **2**
Eligible plots π₯: **0.08** average
Skipped SPs β οΈ: 7 (0.01%)
| LOW |
## How it works?
diff --git a/config-example.yaml b/config-example.yaml
index e6de0343..212f15af 100644
--- a/config-example.yaml
+++ b/config-example.yaml
@@ -34,27 +34,22 @@ daily_stats:
# information. You can delete the sections which you aren't using.
# You can also enable more than one notifier and send different
# notifications to each of them. E.g. enable daily_stats only to E-mail.
-# If you enable wallet_events you'll get notifications anytime your
-# wallet receives some XCH (e.g. farming reward).
notifier:
pushover:
enable: false
daily_stats: true
- wallet_events: true
credentials:
api_token: 'dummy_token'
user_key: 'dummy_key'
telegram:
enable: false
daily_stats: true
- wallet_events: true
credentials:
bot_token: 'dummy_bot_token'
chat_id: 'dummy_chat_id'
smtp:
enable: false
daily_stats: true
- wallet_events: true
credentials:
sender: 'chia@example.com'
sender_name: 'chiadog'
@@ -66,17 +61,14 @@ notifier:
script:
enable: false
daily_stats: true
- wallet_events: true
script_path: 'tests/test_script.sh'
discord:
enable: false
daily_stats: true
- wallet_events: true
credentials:
webhook_url: 'https://discord.com/api/webhooks/...'
slack:
enable: false
daily_stats: true
- wallet_events: true
credentials:
webhook_url: 'https://hooks.slack.com/services/...'
diff --git a/src/chia_log/handlers/daily_stats/__init__.py b/src/chia_log/handlers/daily_stats/__init__.py
index 3fe344c8..0ec6efcf 100644
--- a/src/chia_log/handlers/daily_stats/__init__.py
+++ b/src/chia_log/handlers/daily_stats/__init__.py
@@ -4,7 +4,6 @@
# project
from ...parsers.finished_signage_point_parser import FinishedSignagePointMessage
from ...parsers.harvester_activity_parser import HarvesterActivityMessage
-from ...parsers.wallet_added_coin_parser import WalletAddedCoinMessage
class FinishedSignageConsumer(ABC):
@@ -19,12 +18,6 @@ def consume(self, obj: HarvesterActivityMessage):
pass
-class WalletAddedCoinConsumer(ABC):
- @abstractmethod
- def consume(self, obj: WalletAddedCoinMessage):
- pass
-
-
class StatAccumulator(ABC):
@abstractmethod
def get_summary(self) -> str:
diff --git a/src/chia_log/handlers/daily_stats/stat_accumulators/wallet_added_coin_stats.py b/src/chia_log/handlers/daily_stats/stat_accumulators/wallet_added_coin_stats.py
deleted file mode 100644
index efede38c..00000000
--- a/src/chia_log/handlers/daily_stats/stat_accumulators/wallet_added_coin_stats.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# std
-from datetime import datetime
-
-# project
-from .. import WalletAddedCoinMessage, WalletAddedCoinConsumer, StatAccumulator
-
-
-class WalletAddedCoinStats(WalletAddedCoinConsumer, StatAccumulator):
- def __init__(self):
- self._last_reset_time = datetime.now()
- self._total_added_mojos = 0
-
- def reset(self):
- self._last_reset_time = datetime.now()
- self._total_added_mojos = 0
-
- def consume(self, obj: WalletAddedCoinMessage):
- self._total_added_mojos += obj.amount_mojos
-
- def get_summary(self) -> str:
- return f"Received βοΈ: {(self._total_added_mojos / 1e12):0.2f} XCH"
diff --git a/src/chia_log/handlers/daily_stats/stats_manager.py b/src/chia_log/handlers/daily_stats/stats_manager.py
index 6408846f..762b03ed 100644
--- a/src/chia_log/handlers/daily_stats/stats_manager.py
+++ b/src/chia_log/handlers/daily_stats/stats_manager.py
@@ -6,14 +6,12 @@
from time import sleep
# project
-from . import HarvesterActivityConsumer, WalletAddedCoinConsumer, FinishedSignageConsumer
+from . import HarvesterActivityConsumer, FinishedSignageConsumer
from .stat_accumulators.eligible_plots_stats import EligiblePlotsStats
-from .stat_accumulators.wallet_added_coin_stats import WalletAddedCoinStats
from .stat_accumulators.search_time_stats import SearchTimeStats
from .stat_accumulators.signage_point_stats import SignagePointStats
from .stat_accumulators.found_proof_stats import FoundProofStats
from .stat_accumulators.number_plots_stats import NumberPlotsStats
-from src.chia_log.parsers.wallet_added_coin_parser import WalletAddedCoinMessage
from src.chia_log.parsers.harvester_activity_parser import HarvesterActivityMessage
from src.chia_log.parsers.finished_signage_point_parser import FinishedSignagePointMessage
from src.notifier.notify_manager import NotifyManager
@@ -40,7 +38,6 @@ def __init__(self, config: dict, notify_manager: NotifyManager):
logging.info("Enabled stats for daily notifications")
self._notify_manager = notify_manager
self._stat_accumulators = [
- WalletAddedCoinStats(),
FoundProofStats(),
SearchTimeStats(),
NumberPlotsStats(),
@@ -58,14 +55,6 @@ def __init__(self, config: dict, notify_manager: NotifyManager):
self._thread = Thread(target=self._run_loop)
self._thread.start()
- def consume_wallet_messages(self, objects: List[WalletAddedCoinMessage]):
- if not self._enable:
- return
- for stat_acc in self._stat_accumulators:
- if isinstance(stat_acc, WalletAddedCoinConsumer):
- for obj in objects:
- stat_acc.consume(obj)
-
def consume_harvester_messages(self, objects: List[HarvesterActivityMessage]):
if not self._enable:
return
diff --git a/src/chia_log/handlers/wallet_added_coin_handler.py b/src/chia_log/handlers/wallet_added_coin_handler.py
deleted file mode 100644
index a83d52fa..00000000
--- a/src/chia_log/handlers/wallet_added_coin_handler.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# std
-import logging
-from typing import List, Optional
-
-# project
-from . import LogHandler
-from ..parsers.wallet_added_coin_parser import WalletAddedCoinParser
-from .daily_stats.stats_manager import StatsManager
-from src.notifier import Event, EventService, EventType, EventPriority
-
-
-class WalletAddedCoinHandler(LogHandler):
- """This handler parses all logs that report wallet
- receiving XCH and creates user notifications.
- """
-
- def __init__(self):
- self._parser = WalletAddedCoinParser()
-
- def handle(self, logs: str, stats_manager: Optional[StatsManager] = None) -> List[Event]:
- events = []
- added_coin_messages = self._parser.parse(logs)
- if stats_manager:
- stats_manager.consume_wallet_messages(added_coin_messages)
-
- total_mojos = 0
- for coin_msg in added_coin_messages:
- logging.info(f"Cha-ching! Just received {coin_msg.amount_mojos} mojos.")
- total_mojos += coin_msg.amount_mojos
-
- if total_mojos > 0:
- chia_coins = total_mojos / 1e12
- events.append(
- Event(
- type=EventType.USER,
- priority=EventPriority.LOW,
- service=EventService.WALLET,
- message=f"Cha-ching! Just received {chia_coins} XCH βοΈ",
- )
- )
-
- return events
diff --git a/src/chia_log/log_handler.py b/src/chia_log/log_handler.py
index aa125120..cce46efc 100644
--- a/src/chia_log/log_handler.py
+++ b/src/chia_log/log_handler.py
@@ -5,7 +5,6 @@
from src.chia_log.handlers.daily_stats.stats_manager import StatsManager
from src.chia_log.handlers.harvester_activity_handler import HarvesterActivityHandler
from src.chia_log.handlers.finished_signage_point_handler import FinishedSignagePointHandler
-from src.chia_log.handlers.wallet_added_coin_handler import WalletAddedCoinHandler
from src.chia_log.log_consumer import LogConsumerSubscriber, LogConsumer
from src.notifier.notify_manager import NotifyManager
@@ -29,7 +28,7 @@ def __init__(
):
self._notify_manager = notify_manager
self._stats_manager = stats_manager
- self._handlers = [HarvesterActivityHandler(), FinishedSignagePointHandler(), WalletAddedCoinHandler()]
+ self._handlers = [HarvesterActivityHandler(), FinishedSignagePointHandler()]
log_consumer.subscribe(self)
def consume_logs(self, logs: str):
diff --git a/src/chia_log/parsers/wallet_added_coin_parser.py b/src/chia_log/parsers/wallet_added_coin_parser.py
deleted file mode 100644
index 3b7913d7..00000000
--- a/src/chia_log/parsers/wallet_added_coin_parser.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# std
-import re
-import logging
-from dataclasses import dataclass
-from datetime import datetime
-from typing import List
-
-# lib
-from dateutil import parser as dateutil_parser
-
-
-@dataclass
-class WalletAddedCoinMessage:
- timestamp: datetime
- amount_mojos: int
-
-
-class WalletAddedCoinParser:
- """This class can parse info log messages from the chia wallet
-
- You need to have enabled "log_level: INFO" in your chia config.yaml
- The chia config.yaml is usually under ~/.chia/mainnet/config/config.yaml
- """
-
- def __init__(self):
- logging.info("Enabled parser for wallet activity - added coins.")
- self._regex = re.compile(
- r"([0-9:.]*) wallet (?:src|chia).wallet.wallet_state_manager(?:\s?): "
- r"INFO\s*Adding coin: {'amount': '([0-9]*)'"
- )
-
- def parse(self, logs: str) -> List[WalletAddedCoinMessage]:
- """Parses all harvester activity messages from a bunch of logs
-
- :param logs: String of logs - can be multi-line
- :returns: A list of parsed messages - can be empty
- """
-
- parsed_messages = []
- matches = self._regex.findall(logs)
- for match in matches:
- parsed_messages.append(
- WalletAddedCoinMessage(
- timestamp=dateutil_parser.parse(match[0]),
- amount_mojos=int(match[1]),
- )
- )
-
- return parsed_messages
diff --git a/src/notifier/__init__.py b/src/notifier/__init__.py
index ac21c6c8..075cbe81 100644
--- a/src/notifier/__init__.py
+++ b/src/notifier/__init__.py
@@ -40,8 +40,7 @@ class EventService(Enum):
HARVESTER = 0
FARMER = 1
FULL_NODE = 2
- WALLET = 3
- DAILY = 4
+ DAILY = 3
@dataclass
@@ -70,8 +69,6 @@ def __init__(self, title_prefix: str, config: dict):
if config["daily_stats"]:
self._notification_types.append(EventType.DAILY_STATS)
self._notification_services.append(EventService.DAILY)
- if config["wallet_events"]:
- self._notification_services.append(EventService.WALLET)
except KeyError as key:
logging.error(f"Invalid config.yaml. Missing key: {key}")
diff --git a/tests/chia_log/handlers/test_wallet_added_coin_handler.py b/tests/chia_log/handlers/test_wallet_added_coin_handler.py
deleted file mode 100644
index 83dcb844..00000000
--- a/tests/chia_log/handlers/test_wallet_added_coin_handler.py
+++ /dev/null
@@ -1,28 +0,0 @@
-# std
-import unittest
-from pathlib import Path
-
-# project
-from src.chia_log.handlers.wallet_added_coin_handler import WalletAddedCoinHandler
-from src.notifier import EventType, EventService, EventPriority
-
-
-class TestWalledAddedCoinHandler(unittest.TestCase):
- def setUp(self) -> None:
- self.handler = WalletAddedCoinHandler()
- self.example_logs_path = Path(__file__).resolve().parents[1] / "logs/wallet_added_coin"
-
- def testNominal(self):
- with open(self.example_logs_path / "nominal.txt") as f:
- logs = f.readlines()
-
- events = self.handler.handle("".join(logs))
- self.assertEqual(1, len(events))
- self.assertEqual(events[0].type, EventType.USER, "Unexpected event type")
- self.assertEqual(events[0].priority, EventPriority.LOW, "Unexpected priority")
- self.assertEqual(events[0].service, EventService.WALLET, "Unexpected service")
- self.assertEqual(events[0].message, "Cha-ching! Just received 2.0 XCH βοΈ")
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/tests/chia_log/parsers/test_wallet_added_coin_parser.py b/tests/chia_log/parsers/test_wallet_added_coin_parser.py
deleted file mode 100644
index 19466d80..00000000
--- a/tests/chia_log/parsers/test_wallet_added_coin_parser.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# std
-import unittest
-from pathlib import Path
-
-# project
-from src.chia_log.parsers.wallet_added_coin_parser import WalletAddedCoinParser
-
-
-class TestWalletAddedCoinParser(unittest.TestCase):
- def setUp(self) -> None:
- self.parser = WalletAddedCoinParser()
- self.example_logs_path = Path(__file__).resolve().parents[1] / "logs/wallet_added_coin"
- with open(self.example_logs_path / "nominal.txt") as f:
- self.nominal_logs = f.read()
-
- def testBasicParsing(self):
- added_coins = self.parser.parse(self.nominal_logs)
- total_mojos = 0
- for coin in added_coins:
- total_mojos += coin.amount_mojos
-
- chia = total_mojos / 1e12
- self.assertEqual(2, chia)
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/tests/notifier/test_discord_notifier.py b/tests/notifier/test_discord_notifier.py
index 65375de2..b68007d8 100644
--- a/tests/notifier/test_discord_notifier.py
+++ b/tests/notifier/test_discord_notifier.py
@@ -16,7 +16,6 @@ def setUp(self) -> None:
config={
"enable": True,
"daily_stats": True,
- "wallet_events": True,
"credentials": {"webhook_url": webhook_url},
},
)
diff --git a/tests/notifier/test_pushover_notifier.py b/tests/notifier/test_pushover_notifier.py
index a70d0b8b..cdd273a7 100644
--- a/tests/notifier/test_pushover_notifier.py
+++ b/tests/notifier/test_pushover_notifier.py
@@ -19,7 +19,6 @@ def setUp(self) -> None:
config={
"enable": True,
"daily_stats": True,
- "wallet_events": True,
"credentials": {"api_token": self.api_token, "user_key": self.user_key},
},
)
diff --git a/tests/notifier/test_script_notifier.py b/tests/notifier/test_script_notifier.py
index e900fe81..3b92a1b4 100644
--- a/tests/notifier/test_script_notifier.py
+++ b/tests/notifier/test_script_notifier.py
@@ -10,7 +10,7 @@ class TestScriptNotifier(unittest.TestCase):
def setUp(self) -> None:
self.notifier = ScriptNotifier(
title_prefix="Test",
- config={"enable": True, "daily_stats": True, "wallet_events": True, "script_path": "tests/test_script.sh"},
+ config={"enable": True, "daily_stats": True, "script_path": "tests/test_script.sh"},
)
def testLowPriorityNotifications(self):
diff --git a/tests/notifier/test_slack_notifier.py b/tests/notifier/test_slack_notifier.py
index 59321081..e50072cb 100644
--- a/tests/notifier/test_slack_notifier.py
+++ b/tests/notifier/test_slack_notifier.py
@@ -16,7 +16,6 @@ def setUp(self) -> None:
config={
"enable": True,
"daily_stats": True,
- "wallet_events": True,
"credentials": {"webhook_url": webhook_url},
},
)
diff --git a/tests/notifier/test_smtp_notifier.py b/tests/notifier/test_smtp_notifier.py
index de5558f4..67fade3d 100644
--- a/tests/notifier/test_smtp_notifier.py
+++ b/tests/notifier/test_smtp_notifier.py
@@ -29,7 +29,6 @@ def setUp(self) -> None:
config={
"enable": True,
"daily_stats": True,
- "wallet_events": True,
"credentials": {
"sender": sender,
"sender_name": sender_name,
diff --git a/tests/notifier/test_telegram_notifier.py b/tests/notifier/test_telegram_notifier.py
index f352bd24..97b0a4c2 100644
--- a/tests/notifier/test_telegram_notifier.py
+++ b/tests/notifier/test_telegram_notifier.py
@@ -18,7 +18,6 @@ def setUp(self) -> None:
config={
"enable": True,
"daily_stats": True,
- "wallet_events": True,
"credentials": {"bot_token": bot_token, "chat_id": chat_id},
},
)