def test_client_send(verbose=False): client = NyzoClient() # Test vector, do not use IRL res = client.send(recipient="id__88idJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZXtxdHx7u", amount=0, data="test", key_="key_87jpjKgC.hXMHGLL50Ym9x4GSnGR918PV6CzpqKwM6WEgqRzfABZ") if verbose: print("res", res) assert "block height" in res assert "forwarded" in res assert "tx__" in res assert res["forwarded"] == "false" assert "error" in res # Test vector, do not use IRL res = client.send(recipient="id__88idJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZXtxdHx7u", amount=1, data="test", key_="key_87jpjKgC.hXMHGLL50Ym9x4GSnGR918PV6CzpqKwM6WEgqRzfABZ") if verbose: print("res", res) assert "block height" in res assert "forwarded" in res assert "tx__" in res assert "error" not in res assert res["forwarded"] == "true"
def token_ownership(ctx, token_name: str, recipient: str, key_: str = ""): # ./Nyzocli.py --verbose token ownership TEST3 3f19e603b9577b6f91d4c84531e1e94e946aa172063ea3a88efb26e3fe75bb84 if key_ == "": seed = config.PRIVATE_KEY.to_bytes() key_ = NyzoStringEncoder.encode( NyzoStringPrivateSeed.from_hex(seed.hex())) else: seed = NyzoStringEncoder.decode(key_).get_bytes() key, pub = KeyUtil.get_from_private_seed(seed.hex()) address = pub.to_ascii(encoding="hex").decode('utf-8') id__recipient, recipient = normalize_address(recipient, asHex=True) print(f"token ownership transfer {token_name} to {recipient}") data = f"TO:{token_name}" fees = 0.000001 # Test via API url = f"{ctx.obj['token']}/check_tx/{address}/{recipient}/{fees:0.6f}/{data}" if VERBOSE: print(url) res = get(url).text if VERBOSE: print(res) if "Error:" in res: print("E", res) else: # Assemble, sign and forward if ok client = NyzoClient(ctx.obj['client']) res = client.send(recipient, fees, data, key_) print(res)
def token_burn(ctx, token_name: str, amount: str, key_: str = ""): # ./Nyzocli.py --verbose token burn TEST3 1.12345 if key_ == "": seed = config.PRIVATE_KEY.to_bytes() key_ = NyzoStringEncoder.encode( NyzoStringPrivateSeed.from_hex(seed.hex())) else: seed = NyzoStringEncoder.decode(key_).get_bytes() key, pub = KeyUtil.get_from_private_seed(seed.hex()) address = pub.to_ascii(encoding="hex").decode('utf-8') if float(amount) <= 0: raise ValueError("Amount has to be > 0") if not re.match(r"[0-9A-Z_]{3,32}", token_name): raise ValueError(f"Token name '{token_name}' does not follow rules") if VERBOSE: print(f"token burn {token_name} amount {amount}") data = f"TB:{token_name}:{amount}" fees = 0.000001 # Test via API recipient = CYCLE_ADDRESS_HEX url = f"{ctx.obj['token']}/check_tx/{address}/{recipient}/{fees:0.6f}/{data}" if VERBOSE: print(url) res = get(url).text if VERBOSE: print(res) if "Error:" in res: print(res) else: # Assemble, sign and forward if ok client = NyzoClient(ctx.obj['client']) res = client.send(recipient, fees, data, key_) print(res)
def test_client_frozen(verbose=False): client = NyzoClient() res = client.get_frozen() if verbose: print("res", res) assert "height" in res assert "hash" in res assert "timestamp" in res
def safe_send(ctx, recipient, amount: float = 0, data: str = "", key_: str = ""): """ Send Nyzo to a RECIPIENT then makes sure it is embedded in the planned block. If no seed is given, use the wallet one. - ex: python3 Nyzocli.py safe_send abd7fede35a84b10-8a36e6dc361d9b32-ca84d149f6eb85b4-a4e63015278d4c9f 10 - ex: python3 Nyzocli.py safe_send abd7fede35a84b10-8a36e6dc361d9b32-ca84d149f6eb85b4-a4e63015278d4c9f 10 key_... """ if key_ == "": seed = config.PRIVATE_KEY.to_bytes() key_ = NyzoStringEncoder.encode( NyzoStringPrivateSeed.from_hex(seed.hex())) else: seed = NyzoStringEncoder.decode(key_).get_bytes() # convert key to address address = KeyUtil.private_to_public(seed.hex()) my_balance = ctx.invoke(balance, address=address) if amount == -1: if my_balance is None: my_balance = ctx.invoke(balance, address=address) print(my_balance) # my_balance = balance(ctx, address) amount = float(my_balance) if amount <= 0: if VERBOSE: app_log.warning( "Balance too low or unknown {}, dropping.".format( my_balance)) print( json.dumps({ "result": "Error", "reason": "Balance too low, {}".format(my_balance) })) return else: if VERBOSE: app_log.warning("Sending full balance {}.".format(my_balance)) recipient, recipient_raw = normalize_address(recipient, asHex=True) client = NyzoClient(ctx.obj['client']) res = client.safe_send(recipient, amount, data, key_, max_tries=5, verbose=True) print(res) return
def token_issue(ctx, token_name: str, decimals: int, supply: str, key_: str = ""): # ./Nyzocli.py --verbose token issue -- TEST3 3 -1 if key_ == "": seed = config.PRIVATE_KEY.to_bytes() key_ = NyzoStringEncoder.encode( NyzoStringPrivateSeed.from_hex(seed.hex())) else: seed = NyzoStringEncoder.decode(key_).get_bytes() key, pub = KeyUtil.get_from_private_seed(seed.hex()) address = pub.to_ascii(encoding="hex").decode('utf-8') if decimals < 0: raise ValueError("Decimals have to be >= 0") if decimals > 18: raise ValueError("Decimals have to be <= 18") dec = str(decimals) while len(dec) < 2: dec = "0" + dec if not re.match(r"[0-9A-Z_]{3,32}", token_name): raise ValueError(f"Token name '{token_name}' does not follow rules") if VERBOSE: print(f"token issue {token_name} decimals {dec} supply {supply}") data = f"TI:{token_name}:d{dec}:{supply}" # get fees url = f"{ctx.obj['token']}/fees" res = get(url) fees = res.json() issue_fees = fees[-1]["issue_fees"] # micro_nyzos amount = issue_fees / 1000000 if VERBOSE: print(f"Issue fees are {issue_fees} micro nyzos.") # Test via API recipient = CYCLE_ADDRESS_HEX url = f"{ctx.obj['token']}/check_tx/{address}/{recipient}/{amount:0.6f}/{data}" if VERBOSE: print(url) res = get(url).text if VERBOSE: print(res) if "Error:" in res: print(res) else: # Assemble, sign and forward if ok client = NyzoClient(ctx.obj['client']) res = client.send(recipient, amount, data, key_) print(res)
def test_query_tx(verbose=False): # valid format but non existing tx tx = "tx__Ex80005V9jQZj00000000000y8UQVA7bXcgFUZEDMuFYLGyp4TrI3DW2dZd_SV2Jf7J000000a94zmGmH~BUTQLE0soovtG4Q-Pqsj4.0J.TgZLDSyDId_~yN17hCtVifoSKi8UnJdoTYhCzuvhqq7rjxkr_.ecK~vaJJe.rb2ACj.3icD29_VnH6dz7u~GPS-aNu2m9ztGd_KQvAzRxbTSzXvX8f" client = NyzoClient() res = client.query_tx(tx) if verbose: print("res1", res) assert "height" not in res # real tx, but may be past retention edge tx = "tx__Dx40005V9j-ti000000m~Jmn4KhkGGkA.REIoIttwvL70hx4VRdHWeb1ExJBGAqFfA400000000001bkmarm8_tXYTYV77VIyN4p1d-RrL3zNqWb9apUr3WP00KXB4MbiWoAY-bEF~GAC_8rjDDVQ2p_VtiXQVL7yoAaidw5YELtQPEL.7xVE4xjpZX9MaHPdEhLo2SYjoVeJ0eaLH~I" res = client.query_tx(tx) if verbose: print("res2", res) assert "height" in res
from modules.database import Db from random import randint, shuffle from math import floor, ceil from nyzostrings.nyzostringprefilleddata import NyzoStringPrefilledData from nyzostrings.nyzostringencoder import NyzoStringEncoder from modules.helpers import async_get from modules.config import CONFIG from pynyzo.clienthelpers import NyzoClient import time import discord DB_PATH = 'data/wallets.db' MAIN_ADDRESS = "b34b3320b0291be2cd063f049bdef05ba57f313a60c173c3abce4b770e4e10b5" MAIN_ID = "id__8bdbcQ2NahMzRgp_19Mv-5LCwR4Ypc5RNYMeiVtejy2TGnPC3AqE" LAST_HEIGHT_FILE = "data/last_height.txt" NYZO_CLIENT = NyzoClient() with open("private/wallet_key.txt") as f: PRIVATE_KEY = f.read().strip() class Wallet(commands.Cog): """Nyzeye wallet commands""" def __init__(self): self.db = Db(DB_PATH) self.db.execute( "CREATE TABLE IF NOT EXISTS balances(user_id TEXT PRIMARY KEY, balance INT DEFAULT 0)" ) self.db.execute( "CREATE TABLE IF NOT EXISTS transactions(sender TEXT, recipient TEXT, amount INT, " "fee INT DEFAULT 0, type TEXT, offchain BOOL DEFAULT 1, id TEXT, timestamp INT)" )