Skip to content

Commit 7db45cc

Browse files
committed
Fix erroneous deposit notifications
1 parent f9bb9a8 commit 7db45cc

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

cogs/favorites.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def addfavorite_cmd(self, ctx: Context):
125125
return
126126

127127
fav_count = await Favorite.filter(user=ctx.user).count()
128-
if (fav_count + len(to_add)) >= 25:
128+
if (fav_count + len(to_add)) > 25:
129129
await Messages.add_x_reaction(msg)
130130
await Messages.send_error_dm(msg.author, f"You can only have up to **25 favorites**. With this, you would have **{fav_count + len(to_add)}**.")
131131
return

cogs/rain.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ async def rain_cmd(self, ctx: Context):
132132
return
133133

134134
individual_send_amount = NumberUtil.truncate_digits(send_amount / len(active_users), max_digits=Env.precision_digits())
135+
individual_send_amount_str = f"{individual_send_amount:.2f}" if Env.banano() else f"{individual_send_amount:.6f}"
135136
if individual_send_amount < Constants.TIP_MINIMUM:
136137
await Messages.add_x_reaction(msg)
137138
await Messages.send_error_dm(msg.author, f"Amount is too small to divide across {len(active_users)} users")
@@ -160,15 +161,15 @@ async def rain_cmd(self, ctx: Context):
160161
task_list.append(
161162
Messages.send_basic_dm(
162163
member=msg.guild.get_member(u.id),
163-
message=f"You were tipped **{individual_send_amount} {Env.currency_symbol()}** by {msg.author.name.replace('`', '')}.\nUse `{config.Config.instance().command_prefix}mute {msg.author.id}` to disable notifications for this user.",
164+
message=f"You were tipped **{individual_send_amount_str} {Env.currency_symbol()}** by {msg.author.name.replace('`', '')}.\nUse `{config.Config.instance().command_prefix}mute {msg.author.id}` to disable notifications for this user.",
164165
skip_dnd=True
165166
)
166167
)
167168
else:
168169
task_list.append(
169170
Messages.send_basic_dm(
170171
member=msg.guild.get_member(u.id),
171-
message=f"You were tipped **{individual_send_amount} {Env.currency_symbol()}** anonymously!",
172+
message=f"You were tipped **{individual_send_amount_str} {Env.currency_symbol()}** anonymously!",
172173
skip_dnd=True
173174
)
174175
)
@@ -186,7 +187,7 @@ async def rain_cmd(self, ctx: Context):
186187
if msg.channel.id not in config.Config.instance().get_no_stats_channels():
187188
await stats.update_tip_stats(amount_needed)
188189
# DM creator
189-
await Messages.send_success_dm(msg.author, f"You rained **{amount_needed} {Env.currency_symbol()}** to **{len(tx_list)} users**, they received **{NumberUtil.truncate_digits(individual_send_amount, max_digits=Env.precision_digits())} {Env.currency_symbol()}** each.", header="Make it Rain")
190+
await Messages.send_success_dm(msg.author, f"You rained **{amount_needed} {Env.currency_symbol()}** to **{len(tx_list)} users**, they received **{individual_send_amount_str} {Env.currency_symbol()}** each.", header="Make it Rain")
190191
# Make the rainer auto-rain eligible
191192
await self.auto_rain_eligible(msg)
192193

db/models/transaction.py

-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import db.models.giveaway as gway
77
import db.models.user as usr
8-
from db.redis import RedisDB
98

109
from rpc.client import RPCClient
1110
from util.env import Env
@@ -113,9 +112,6 @@ async def send(self) -> str:
113112
amount=self.amount
114113
)
115114
if resp is not None:
116-
# Cache the hash in redis to indicate this is an internal transaction
117-
# We hope that this process is faster than NANO confirms blocks, because we use this to differentiate internal and external transactions from callback
118-
await RedisDB.instance().set(f"hash:{resp}", "value", expires=60) # expire after 1 minute
119115
async with in_transaction() as conn:
120116
self.block_hash = resp
121117
await self.save(using_db=conn)

server.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import datetime
1212
import logging
1313
import rapidjson as json
14+
from db.models.transaction import Transaction
1415

1516
class GrahamServer(object):
1617
"""An AIOHTTP server that listens for callbacks and provides various APIs"""
@@ -144,8 +145,8 @@ async def callback(self, request: web.Request):
144145
if account is None:
145146
return web.HTTPOk()
146147
# See if this is an internal TX
147-
internal = await RedisDB.instance().exists(f"hash:{hash}")
148-
if internal:
148+
transaction = await Transaction.filter(block_hash=hash).prefetch_related('receiving_user').first()
149+
if transaction is not None and transaction.receiving_user is not None:
149150
return web.HTTPOk()
150151
self.logger.debug(f'Deposit received: {request_json["amount"]} for {account.user.id}')
151152
amount_string = f"{Env.raw_to_amount(int(request_json['amount']))} {Env.currency_symbol()}"

0 commit comments

Comments
 (0)