Skip to content

Commit

Permalink
use the new xnm cache column for getBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
nibty committed Sep 20, 2024
1 parent 11399d4 commit ee6e6fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ python-dotenv
gevent
gunicorn
eth_utils
ethereum
24 changes: 5 additions & 19 deletions rpc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,13 @@ def get_xblk_account_count(account):

def get_balance_from_db(account):
try:
conn = sqlite3.connect("blocks.db")
cursor = conn.cursor()

conn_cache = sqlite3.connect("cache.db")
cursor_cache = conn_cache.cursor()

query = "SELECT super_block_count FROM super_blocks WHERE LOWER(account) = LOWER(?)"
#print(f"Executing SQL query: {query} with account: {account}") # Print the query and account to standard output
#cursor.execute("SELECT super_block_count FROM super_blocks WHERE LOWER(account) = LOWER(?)", (account,))
print ("Account: ", account)
cursor_cache.execute("SELECT total_blocks FROM cache_table WHERE LOWER(account) = ?", (account.lower(),))
row = cursor_cache.fetchone()
print ("Balance for ", account, row[0] * 10 if row else 0) # Modified this line to handle None
return row[0] * 10 if row else 0
with sqlite3.connect("cache.db") as conn_cache:
cursor_cache = conn_cache.cursor()
cursor_cache.execute("SELECT xnm FROM cache_table WHERE LOWER(account) = LOWER(?)", (account,))
return cursor_cache.fetchone()[0]
except Exception as e:
print("Database error:", e)
return 0
finally:
if conn:
conn.close()
conn_cache.close()

def rlp_encode(input_string):
if len(input_string) == 1 and ord(input_string) < 0x80:
Expand Down Expand Up @@ -369,7 +355,7 @@ def index():
elif data['method'] == 'eth_getBalance':
account = data['params'][0] # Convert account to lower case to ensure it matches
balance_decimal = get_balance_from_db(account) # Fetch balance from the database
result = hex(int(balance_decimal * 10**18)) # Convert to Wei
result = hex(int(balance_decimal)) # Convert to Wei

elif data['method'] == 'eth_estimateGas':
# Simulate gas estimation here. This is a simplified example and
Expand Down

0 comments on commit ee6e6fc

Please sign in to comment.