Skip to content

Commit

Permalink
Revert bns stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bbedward committed Jan 31, 2025
1 parent 37d7c3d commit 2d9a332
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 69 deletions.
5 changes: 2 additions & 3 deletions cogs/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def cog_before_invoke(self, ctx: Context):
ctx.error = True
return
try:
ctx.destination = RegexUtil.find_address_match(msg.content, config.Config.instance().get_bns_enabled())
ctx.destination = RegexUtil.find_address_match(msg.content)
except AddressMissingException:
await Messages.send_usage_dm(msg.author, SEND_INFO)
ctx.error = True
Expand All @@ -109,8 +109,7 @@ async def cog_before_invoke(self, ctx: Context):
await Messages.send_error_dm(msg.author, "You can only specify 1 destination address")
ctx.error = True
return
#Disallow invalid Banano addresses but allow BNS domains
if not Validators.is_valid_address(ctx.destination) and not "." in ctx.destination:
if not Validators.is_valid_address(ctx.destination):
await Messages.send_error_dm(msg.author, "The destination address you specified is invalid")
ctx.error = True
return
Expand Down
10 changes: 1 addition & 9 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,4 @@ def get_no_stats_channels(self) -> List[int]:
return default
elif 'restrictions' in self.yaml and 'no_stats_channels' in self.yaml['restrictions']:
return self.yaml['restrictions']['no_stats_channels']
return default

def get_bns_enabled(self) -> bool:
default = False
if not self.has_yaml():
return default
elif 'bns' in self.yaml:
return self.yaml['bns']
return default
return default
4 changes: 1 addition & 3 deletions config.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,4 @@ server:
# Used for callbacks and APIs
# Callback is at $host:$port/callback (e.g. 127.0.0.1:11337/callback)
host: 127.0.0.1
port: 11337

bns: true
port: 11337
2 changes: 0 additions & 2 deletions kubernetes/bananobot/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,3 @@ data:
# Callback is at $host:$port/callback (e.g. 127.0.0.1:11337/callback)
host: 0.0.0.0
port: 11337
bns: true
18 changes: 3 additions & 15 deletions rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
from config import Config
from typing import List, Tuple
from util.util import Utils, BNSResolvingException

class RPCClient(object):
_instance = None
Expand All @@ -32,7 +31,7 @@ async def close(cls):
cls._instance = None

async def make_request(self, req_json: dict):
async with self.session.post(self.node_url, json=req_json, timeout=300) as resp:
async with self.session.post(self.node_url ,json=req_json, timeout=300) as resp:
respJson = await resp.json()
if resp.status != 200:
self.logger.error(f"RPC request failed with status {resp.status}")
Expand Down Expand Up @@ -62,18 +61,7 @@ async def account_balance(self, account: str, include_only_confirmed: bool) -> d
return None

async def send(self, id: str, source: str, destination: str, amount: str) -> str:
"""Make transaction, return hash if successful, resolve BNS domain if relevant"""
if '.' in destination:
#if . is in destination, this is a BNS domain not a Banano address
#resolve it into a Banano address if possible
bnsrespjson = await Utils.resolve_bns(destination)
resolved = False
if 'domain' in bnsrespjson:
if 'resolved_address' in bnsrespjson['domain']:
destination = bnsrespjson['domain']['resolved_address']
resolved = True
if not resolved:
raise BNSResolvingException("Could not resolve BNS Domain to address")
"""Make transaction, return hash if successful"""
send_action = {
'action': 'send',
'wallet': Config.instance().wallet,
Expand Down Expand Up @@ -149,4 +137,4 @@ async def block_count(self) -> Tuple[int, int]:
respjson = await self.make_request(count_action)
if 'count' in respjson and 'unchecked' in respjson:
return int(respjson['count']), int(respjson['unchecked'])
return None, None
return None, None
12 changes: 0 additions & 12 deletions tasks/transaction_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from discord.ext.commands import Bot
from db.models.transaction import Transaction
from util.env import Env
from util.util import BNSResolvingException

class TransactionQueue(object):
_instance = None
Expand Down Expand Up @@ -50,14 +49,6 @@ async def notify_user(self, tx: Transaction, hash: str):
else:
await user.send(f"Withdraw processed: https://blocklattice.io/block/{hash}")

async def notify_user_bns_fail(self, tx: Transaction):
bot: Bot = self.bot
user = bot.get_user(tx.sending_user.id)
if user is None:
self.logger.warn(f"User with ID {tx.sending_user.id} was not found, so I couldn't notify them that we could not resolve the withdrawal BNS domain to an address")
return
await user.send("Failed to resolve that BNS name")

async def retry(self, tx: Transaction):
delay = tx.retries + 1 * 5
tx.retries += 1
Expand All @@ -77,9 +68,6 @@ async def queue_consumer(self):
elif tx.receiving_user is None:
# Notify user their withdraw was processed
asyncio.ensure_future(self.notify_user(tx=tx, hash=res))
except BNSResolvingException:
asyncio.ensure_future(self.notify_user_bns_fail(tx=tx))
break #not needed?
except KeyboardInterrupt:
break
except Exception:
Expand Down
5 changes: 1 addition & 4 deletions util/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ def find_send_amounts(input_text: str) -> float:
raise AmountMissingException("amount_not_found")

@staticmethod
def find_address_match(input_text: str, bns_enabled: bool = False) -> str:
def find_address_match(input_text: str) -> str:
"""Find nano/banano address in a string"""
if Env.banano():
address_regex = '(?:ban)(?:_)(?:1|3)(?:[13456789abcdefghijkmnopqrstuwxyz]{59})'
else:
address_regex = '(?:nano|xrb)(?:_)(?:1|3)(?:[13456789abcdefghijkmnopqrstuwxyz]{59})'
matches = re.findall(address_regex, input_text)
#if bns not enabled, don't match bns domains so they can't be passed down to later functions
if bns_enabled:
matches += re.findall('[0-9a-z]+\.[0-9a-z]+', input_text)
if len(matches) == 1:
return matches[0]
elif len(matches) > 1:
Expand Down
22 changes: 1 addition & 21 deletions util/util.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from pathlib import Path
from typing import List

import aiohttp
import asyncio
import emoji
import rapidjson as json
import re
import secrets

class BNSResolvingException(Exception):
pass

class Utils(object):
"""Generic utilities"""
@staticmethod
Expand All @@ -33,19 +28,4 @@ async def run_task_list(task_list: List[asyncio.Future]):

@staticmethod
def random_float() -> float:
return secrets.randbelow(100) / 100

@staticmethod
async def resolve_bns(domain_and_tld: str) -> dict:
parts = domain_and_tld.split('.')
async with aiohttp.ClientSession(json_serialize=json.dumps) as session:
async with session.post("https://api.creeper.banano.cc/banano/v1/account/bns", json={
'domain_name': parts[0],
'tld': parts[1],
}, timeout=300) as resp:
respJson = await resp.json()
if resp.status != 200:
self.logger.error(f"BNS resolve request failed with status {resp.status}")
self.logger.error(f"Request: {req_json}")
self.logger.error(f"Response: {respJson}")
return respJson
return secrets.randbelow(100) / 100

0 comments on commit 2d9a332

Please sign in to comment.