Пример #1
0
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"
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)