Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
coinsspor authored May 10, 2024
1 parent b586b70 commit df9bdab
Show file tree
Hide file tree
Showing 11 changed files with 880 additions and 0 deletions.
Binary file added crossfi.ico
Binary file not shown.
86 changes: 86 additions & 0 deletions delegate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import httpx
from cosmospy_protobuf.cosmos.base.v1beta1.coin_pb2 import Coin
from cosmospy_protobuf.cosmos.staking.v1beta1.tx_pb2 import MsgDelegate
from mospy import Transaction, Account
from tkinter import messagebox

def delegate_to_validator(validator_address, amount, gas, fee, delegator_address, private_key):
API_URL = "https://crossfi-testnet-api.coinsspor.com"
CHAIN_ID = "crossfi-evm-testnet-1"
delegator_address = delegator_address.lower()
validator_address = validator_address.lower()

print(f"Delegator Address: {delegator_address}")
print(f"Private Key: {private_key}")
print(f"Validator Address: {validator_address}")
print(f"Amount: {amount}")
print(f"Gas: {gas}")
print(f"Fee: {fee}")

if private_key.startswith('0x'):
private_key = private_key[2:]
print("Removed '0x' prefix from private key.")

with httpx.Client(verify=False) as client:
response = client.get(f"{API_URL}/cosmos/auth/v1beta1/accounts/{delegator_address}")
print(f"Fetched account details for {delegator_address} with status code {response.status_code}")

if response.status_code != 200:
print("Failed to fetch account details:", response.text)
return "Failed to fetch account details.", False

account_data = response.json().get('account', {})
account_number = account_data.get('base_account', {}).get('account_number')
sequence = account_data.get('base_account', {}).get('sequence')

if account_number is None or sequence is None:
print("Account details are incomplete.")
return "Account details are incomplete.", False

account = Account(
private_key=private_key,
account_number=int(account_number),
next_sequence=int(sequence),
eth=True
)

print("Account created successfully.")

tx = Transaction(
account=account,
chain_id=CHAIN_ID,
gas=int(gas)
)

dmsg = MsgDelegate(
delegator_address=delegator_address,
validator_address=validator_address,
amount=Coin(amount=str(amount), denom="mpx")
)

tx.set_fee(
amount=str(fee),
denom="mpx"
)

tx.add_raw_msg(dmsg, type_url="/cosmos.staking.v1beta1.MsgDelegate")
print("Delegate message added to the transaction.")

tx_bytes = tx.get_tx_bytes_as_string()
pushable_tx = {
"tx_bytes": tx_bytes,
"mode": "BROADCAST_MODE_SYNC"
}

response = client.post(f"{API_URL}/cosmos/tx/v1beta1/txs", json=pushable_tx)
print(response.json())

response_data = response.json() # JSON verisi çekildi


if response_data['tx_response']['code'] == 0:
messagebox.showinfo("Transaction successful", "Transaction successful.")
return True
else:
messagebox.showerror("The operation was not successful", f"The operation was not successful: {response_data['tx_response']}")
return False
44 changes: 44 additions & 0 deletions evmtransfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from web3 import Web3, exceptions

def evm_transfer(private_key, to_address, amount_xfi):
crossfi_rpc_url = 'https://rpc.testnet.ms/'
web3 = Web3(Web3.HTTPProvider(crossfi_rpc_url))

if not web3.is_connected():
return "Connection failed. Check the URL."

account = web3.eth.account.from_key(private_key)
nonce = web3.eth.get_transaction_count(account.address)

# Yeterli bakiye kontrolü
balance = web3.eth.get_balance(account.address)
amount = web3.to_wei(amount_xfi, 'ether')
if balance < amount:
return "Insufficient balance to perform the transaction."

try:
# Gaz fiyatını ve gaz limitini otomatik ayarla
gas_price = web3.eth.gas_price
estimated_gas = web3.eth.estimate_gas({
'from': account.address,
'to': to_address,
'value': amount
})

tx = {
'chainId': 4157,
'nonce': nonce,
'to': to_address,
'value': amount,
'gas': estimated_gas,
'gasPrice': gas_price
}

# İşlemi imzala ve gönder
signed_tx = account.sign_transaction(tx)
tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
return f"Transaction successful: {web3.to_hex(tx_hash)}"
except exceptions.TransactionNotFound as e:
return f"Transaction failed: {str(e)}"
except Exception as e:
return f"An error occurred: {str(e)}"
102 changes: 102 additions & 0 deletions login_prvtkey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import tkinter as tk
from tkinter import PhotoImage, messagebox
import mainscreen
from eth_keys import keys
from eth_utils import keccak
import bech32
import walletaction

def clear_content(root):
for widget in root.winfo_children():
widget.destroy()

def paste_text(entry_widget, root):
try:
# Clipboard'tan metni al ve Entry widget'ına yapıştır
text = root.clipboard_get()
entry_widget.insert(tk.END, text)
except tk.TclError:
pass # Clipboard boşsa, hata mesajı gösterme

def create_context_menu(root, entry_widget):
# Sağ tık menüsü oluştur
menu = tk.Menu(root, tearoff=0)
menu.add_command(label="Paste", command=lambda: paste_text(entry_widget, root))
# Menüyü yapılandır
def show_menu(event):
menu.post(event.x_root, event.y_root)
entry_widget.bind("<Button-3>", show_menu) # Sağ tık ile menüyü göster

def login_screen(root):
clear_content(root)

# Logo ve metin ekleyin
logo_image = PhotoImage(file="logo.png")
logo_label = tk.Label(root, image=logo_image)
logo_label.image = logo_image # referansı korumak için
logo_label.pack(pady=(20, 0))

title_label = tk.Label(root, text="Please enter your private key", font=("Arial", 14))
title_label.pack(pady=(10, 20))

# Özel anahtar için metin kutusu
prvt_key_entry = tk.Entry(root, font=("Arial", 14), width=50)
prvt_key_entry.pack(pady=(0, 20))
prvt_key_entry.bind("<Control-v>", lambda event: paste_text(prvt_key_entry, root)) # Ctrl+V ile yapıştırma işlevini ekle
create_context_menu(root, prvt_key_entry) # Sağ tık menüsünü ekleyin

# Yapıştırma butonu
paste_button = tk.Button(root, text="Paste", font=("Arial", 10), bg='lightblue', command=lambda: paste_text(prvt_key_entry, root))
paste_button.pack(pady=(5, 20))

# Butonlar
next_button = tk.Button(root, text="Next", font=("Arial", 12), bg='#1E90FF', fg='white', command=lambda: process_private_key(prvt_key_entry.get(), root))
next_button.pack(fill='x', expand=True, pady=(10, 2))

back_button = tk.Button(root, text="Back", font=("Arial", 12), bg='#1E90FF', fg='white', command=lambda: mainscreen.show_main_screen(root))
back_button.pack(fill='x', expand=True, pady=(2, 10))

def process_private_key(private_key_hex, root):
try:
# "0x" ifadesini kaldırma
if private_key_hex.startswith("0x"):
private_key_hex = private_key_hex[2:]

# Ethereum ve MX adreslerini hesaplama
eth_address, mx_address = get_wallet_addresses_from_private_key(private_key_hex)
if eth_address and mx_address:
# walletaction.py'daki wallet_actions fonksiyonunu çağırarak adres bilgilerini göster
walletaction.wallet_actions(root, eth_address, mx_address, private_key_hex)
else:
messagebox.showerror("Error", "Invalid private key. Please check and try again.")
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {str(e)}")

def get_wallet_addresses_from_private_key(private_key_hex):
# Hex formatındaki özel anahtarı bytes'a çevirme
priv_key_bytes = bytes.fromhex(private_key_hex)

# Özel anahtarın geçerli olup olmadığını kontrol etme
if len(priv_key_bytes) != 32:
messagebox.showerror("Error", "Invalid private key length.")
return None, None

# Ethereum anahtarlarını hesaplama
priv_key = keys.PrivateKey(priv_key_bytes)
pub_key = priv_key.public_key
eth_address = pub_key.to_checksum_address()

# Ethereum adresini MX adresine dönüştürme
mx_address = eth_to_mx_address(eth_address)

return eth_address, mx_address

def eth_to_mx_address(eth_address):
addr_hex = eth_address.lower().replace('0x', '')
addr_bytes = bytes.fromhex(addr_hex)
data = bech32.convertbits(addr_bytes, 8, 5)
if data is None:
messagebox.showerror("Error", "Error in converting bits.")
return None
mx_address = bech32.bech32_encode('mx', data)
return mx_address
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import tkinter as tk
import mainscreen # Ana ekran fonksiyonlarını içeren modül

def main():
root = tk.Tk()
root.title("Crossfi Desktop Wallet")
root.geometry("600x850")
root.configure(background='black')
mainscreen.show_main_screen(root) # Ana ekranı göster
root.mainloop()

if __name__ == "__main__":
main()
29 changes: 29 additions & 0 deletions mainscreen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import tkinter as tk
import newwallet
from login_prvtkey import login_screen # login_prvtkey.py dosyasından fonksiyonu import ediyoruz

def clear_content(root):
for widget in root.winfo_children():
widget.destroy()

def show_main_screen(root):
clear_content(root)
app_info_label = tk.Label(root, text="Crossfi Desktop Wallet v1.0", font=('Arial', 20), bg='black', fg='white')
app_info_label.pack()

logo = tk.PhotoImage(file="logo.png")
logo_label = tk.Label(root, image=logo, bg='black')
logo_label.image = logo # referansı korumak için
logo_label.pack(pady=(20, 10))

developer_info_label = tk.Label(root, text="This application is developed by Coinsspor", font=('Arial', 10), bg='black', fg='white')
developer_info_label.pack()

frame = tk.Frame(root, bg='black')
frame.pack(fill='both', expand=True)

create_wallet_button = tk.Button(frame, text="Create a New Wallet", bg='#1E90FF', fg='white', font=('Arial', 14, 'bold'), command=lambda: newwallet.create_new_wallet(root))
create_wallet_button.pack(fill='x', expand=True, padx=20, pady=(50, 10))

login_private_key_button = tk.Button(frame, text="Login in With a private key", bg='#1E90FF', fg='white', font=('Arial', 14, 'bold'), command=lambda: login_screen(root))
login_private_key_button.pack(fill='x', expand=True, padx=20, pady=(10, 50))
80 changes: 80 additions & 0 deletions newwallet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import tkinter as tk
from tkinter import messagebox
import os
from eth_keys import keys
from eth_utils import keccak
import bech32
import mainscreen
import walletaction

def generate_ethereum_keys():
priv_key_bytes = keccak(os.urandom(32))
priv_key = keys.PrivateKey(priv_key_bytes)
pub_key = priv_key.public_key
eth_address = pub_key.to_checksum_address()
return priv_key, eth_address

def eth_to_mx_address(eth_address):
addr_hex = eth_address.lower().replace('0x', '')
addr_bytes = bytes.fromhex(addr_hex)
data = bech32.convertbits(addr_bytes, 8, 5)
if data is None:
raise ValueError("Error in converting bits.")
mx_address = bech32.bech32_encode('mx', data)
return mx_address

def create_new_wallet(root):
mainscreen.clear_content(root)
frame = tk.Frame(root, bg='black')
frame.pack(fill='both', expand=True)

logo = tk.PhotoImage(file="logo.png")
logo_label = tk.Label(frame, image=logo, bg='black')
logo_label.image = logo
logo_label.pack(pady=(20, 0))

developer_info_label = tk.Label(frame, text="This application is developed by Coinsspor", font=('Arial', 10), bg='black', fg='white')
developer_info_label.pack(pady=(0, 20))

priv_key, eth_address = generate_ethereum_keys()
mx_address = eth_to_mx_address(eth_address)

# Global değişkenlere cüzdan bilgilerini ve private key'i aktar
walletaction.mx_address = mx_address
walletaction.evm_address = eth_address
walletaction.private_key = priv_key.to_hex()

# Label styles
label_style = {'font': ('Arial', 12), 'bg': 'black', 'fg': 'white', 'anchor': 'center'}
title_style = {**label_style, 'font': ('Arial', 12, 'bold', 'underline')}

# Private Key
tk.Label(frame, text="Private Key:", **{**title_style, 'fg': 'blue'}).pack(fill='x')
tk.Label(frame, text=priv_key.to_hex(), **label_style).pack(fill='x')

# EVM Address
tk.Label(frame, text="EVM Address:", **{**title_style, 'fg': 'green'}).pack(fill='x')
tk.Label(frame, text=eth_address, **label_style).pack(fill='x')

# MX Address
tk.Label(frame, text="MX Address:", **{**title_style, 'fg': 'orange'}).pack(fill='x')
tk.Label(frame, text=mx_address, **label_style).pack(fill='x')

# Buttons
copy_button = tk.Button(frame, text="Copy Information", bg='#1E90FF', fg='white', font=('Arial', 14, 'bold'), command=lambda: copy_info(root, priv_key, eth_address, mx_address))
copy_button.pack(fill='x', pady=10)

back_button = tk.Button(frame, text="Back", bg='#1E90FF', fg='white', font=('Arial', 14, 'bold'), command=lambda: mainscreen.show_main_screen(root))
back_button.pack(side='left', fill='x', expand=True, padx=20, pady=20)


next_button = tk.Button(frame, text="Next", bg='#1E90FF', fg='white', font=('Arial', 14, 'bold'), command=lambda: walletaction.wallet_actions(root, eth_address, mx_address, priv_key.to_hex()))

#next_button = tk.Button(frame, text="Next", bg='#1E90FF', fg='white', font=('Arial', 14, 'bold'), command=lambda: walletaction.wallet_actions(root))
next_button.pack(side='right', fill='x', expand=True, padx=20, pady=20)

def copy_info(root, priv_key, eth_address, mx_address):
info_text = f"Private Key: {priv_key.to_hex()}\nEVM Address: {eth_address}\nMX Address: {mx_address}"
root.clipboard_clear()
root.clipboard_append(info_text)
messagebox.showinfo("Copied", "Wallet information copied to clipboard!")
Loading

0 comments on commit df9bdab

Please sign in to comment.