示例#1
0
def test_vector79000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "d60987f22773e4c7-7efb079e9900554e-b6efb568de81ec74-f7396efab7f5605d")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_8dp9y_8Et~j7wMJ7EGB0mkYUZZmFVF7JuftXsMHV.n1upfKfwunh"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#2
0
def test_vector25000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "2882cc9feb9e0861-ccb999c8400cf515-49b73fab4cc6c7a8-0cffef201fc2e777")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_82z2R9_IExyyRbDqQ40c.hm9KR~Ijcs7H0R_ZQ0wNLuV9ieWk_p4"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#3
0
def test_vector0():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "74d84ed425f51e6f-aa9bae140e952601-29d16a73241231dc-6962619b5fbc6e27")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_87jpjKgC.hXMHGLL50Ym9x4GSnGR918PV6CzpqKwM6WEgqRzfABZ"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#4
0
def test_vector19000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "c253802154f4aa04-906275b8f922ed86-81cf11d2cac11a92-8dcdf3bee1c5af32")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_8c9jx25k.aF4B69TLfBzZpr1RP7iQJ4rBFVd-ZZyPr-QQWm3Ivcv"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector0():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "848db2de31cbe4c4-28dbb9e6bdda3aba-98581356ab0e6e02-37b37fd370ac3c7b")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__88idJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZXtxdHx7u"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#6
0
def test_vector8000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "83a2c34eef86da60-e0d26b82a305367b-cf4ed6893ed5d807-0f2fae99a97d77bd")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_88ezNSZMyKGxWd9IxHc5dEMfjKr9fKop1N-MIGDGwov.tBBqPRDY"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#7
0
def test_vector13000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "e58d51a913e209db-8645d6d78f061309-d2af2ef1ed651788-4ea8d4bc4f678401")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_8endkrBjWxEsyBonTW-64NEiIQZPZnkoz4YFTbPfqWg1jt28sUiM"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector8000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "1a7d496278a9ffc7-febfed9f3e8d83ab-eb4a227d020fbbaa-ab1544f0cef8f53f")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__81G.in9WHw_7_I_KERYdxYMIiz9.0x~ZHHJmhf3e~fk_3tn4IuEs"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector19000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "4c66c2c9ef2f6d7a-ec0057d224dcf8eb-f21ce9f1f938fd7c-b3ab6c77ffd805cc")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__84PDNJEMbUTYZ01oSzjt~eMQ7eEP~jA.wbeIs7w_U0ocYX2G.tGZ"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector13000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "39558c7380ba4817-1a748b48fac7bed0-b2d5cbff5d38bf45-8b1f41aacef67881")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__83CmA7e0LBxo6EibifI7MK2QTtM_ojz_hpJwgrIe.Ez1H8dsIm5."
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#11
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)
示例#12
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)
def test_vector25000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "701a37089b596a18-b719922a543fff1b-54879e7ca1d4fd5c-64eabd2c85d55231")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__870rdNzsnnFpKPDiaCg__PKkyXX-Fuj.o6jHMiQ5Tm8PkBAY.aa9"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector79000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "af4fdb9a637d7e83-a0b9d222e3cd1326-8c07c20ad66cf08e-b506f79d2865e2ad")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__8a.fUXGAwoY3FbEi8Lfd4Qrc1-8aTDRNAIk6.XSFqvaKuiPwfgjC"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#15
0
def normalize_address(
        address: str,
        asHex: bool = False) -> Union[Tuple[str, str], Tuple[str, bytes]]:
    """Takes an address as raw byte or id__ and provides both formats back"""
    try:
        # convert recipient to raw if provided as id__
        if address.startswith("id__"):
            address_raw = NyzoStringEncoder.decode(address).get_bytes().hex()
            if VERBOSE:
                print(f"Raw address is {address_raw}")
        else:
            raise RuntimeWarning("Not an id__")
    except:
        if VERBOSE:
            print(f"address was not a proper id_ nyzostring")
        address_raw = re.sub(r"[^0-9a-f]", "", address.lower())
        # print(address_raw)
        if len(address_raw) != 64:
            raise ValueError(
                "Wrong address format. 64 bytes as hex or id_ nyzostring required"
            )
        if VERBOSE:
            print(f"Trying with {address_raw}")
        address = NyzoStringEncoder.encode(
            NyzoStringPublicIdentifier.from_hex(address_raw))
    # Here we should have both recipient and recipient_raw in all cases.
    if asHex:
        return address, address_raw
    else:
        return address, bytes.fromhex(address_raw)
示例#16
0
def test_vector1():
    nyzo_string = NyzoStringSignature.from_hex(
        "1da1460c6b796f7e44734fd2a7b01c63846e42df4ba422a717c1e1389b5a0e539f2337c41345d86b12a9b48728eb72483f85a2d8fde0b612bdcd85453b05b702"
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    # lucyLuky17
    assert encoded == "sig_g1UyhxPIvn.~h7dfSHvN76e4sBbwiYgzGPw1WjzsnxXjEQcVP1d5U6JiHsi7aeKQi3~5FKA.WbpiMtU5hjJ5KN8xEaQt"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#17
0
def test_vector0():
    nyzo_string = NyzoStringSignature.from_hex(
        "2529c59201fc91f34fcd4329563997fa89ebe16b15751ab6b93a09988c6d637b9a28d2a77fa02a319466fad2f5cc2b6a03c3c06794c64eb19b243423832cfe01"
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    # oops10
    assert encoded == "sig_g2kGPq81_97Rj-T3ampXC_H9Y~5I5okrKIBY2qzcsndZDzAiGV~xaA6kqMIi.tNIrxf3N6vkPBYPDQgS8WcJ_x6Ya_pG"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector44000():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "b0c5aef7f03d6c95-e6643f98e12196cb-41fff5e71d4903f4-55419cf80e28781e",
        "")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "pre_8s35IMwNfnQmXDg_De4yCJK1__oE7kB3.5m1Efxea7xv0c64GT24"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#19
0
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 test_vector0():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "1a74dff9c1bb47f7-01eabcfd217f2d6e-ab58a6889efaa44b-5bbe06d396596560",
        "82fb2a31c2fdedd9",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pre_ahGSV_E1LSwV0vH-_i5_bnYInar8EMHBiTL~1Kennnmx28bZaA72_vVqroRgFqRe")
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector0new():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "848db2de31cbe4c4-28dbb9e6bdda3aba-98581356ab0e6e02-37b37fd370ac3c7b",
        # id__88idJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZXtxdHx7u
        "",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded == "pre_8pidJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZ0fp93qvz")
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.amount == nyzo_string.amount
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector75000():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "7182d875367fbb32-eef8831d47079a78-fd5daf7aabaa145e-1bdb4914676ae579",
        "8044e813bd9acf83149a31d819e22c820edc76f3cd00cd87e67958495e562cd3",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pre_go62U7kUwZJQZMz37kt7DEA.or.YHYFkoyMsihhErLmX8814Y1e.DJ~359FPU1Ezb88eV7sRRg3dy~qXn4CvmzRjFuo.qVfn"
    )
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector17000():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "53daaf0f7243222a-89324a82a2f2da6d-e9a3c025c3156b9d-fbd1bdab6af1409c",
        "536142cd5127b085fd48d3512cc3300abdd7bbca774d691e76437f7db0",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pre_fCfrIN.QgQ8Hzj9axHbQUDVGF-0CNPmIEwMhMrKH-k2t7mdygJTh9Z25_kAjkiR3c0H.TZMauSTG7Eq3wVUNIh0cVwG-"
    )
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#24
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)
示例#25
0
def test_vector_vote():
    nyzo_string = NyzoStringTransaction.from_hex_vote(
        "9bdecd1085b8f5e1",
        "3ce4eaf311934276-673752ccb5cf4cac-61eed231d8fcb649-6310887ecf99f6e5",
        "6a675732bd20a2c203a925fc62f1d5249b98c128b555472c980f84d9d37fb3452c7211ea448eeed51b7af17785490593a429e97a4f373788a1a768e40d64657c",
        1,
        "1da1460c6b796f7e44734fd2a7b01c63846e42df4ba422a717c1e1389b5a0e539f2337c41345d86b12a9b48728eb72483f85a2d8fde0b612bdcd85453b05b702"  # fake sig
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "tx__HxisVJSgysATWjRBYMchBS9UqRuiRbofjaPyZK8PUfQUincgz7ZfDwsC0hUyhxPIvn.~h7dfSHvN76e4sBbwiYgzGPw1WjzsnxXjEQcVP1d5U6JiHsi7aeKQi3~5FKA.WbpiMtU5hjJ5KN9HqTtQMi2zNxeG9wPz-ukBDXA1abmmhQQp3WjqSV~RhiPQ4vG4ALZm6VIPuWm91qeBavCYjRtVza6Eregdq6m-hccQ7-vf"
    )
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#26
0
 async def deposit(self, ctx, block_id: int = -1):
     """Used to deposit Nyzo on you account"""
     if block_id != -1:
         count = 0
         successed = 0
         result = await async_get("{}/block/{}".format(
             CONFIG["api_url"], block_id),
                                  is_json=True)
         for block in result:
             for transaction in block["value"]["transactions"]:
                 if transaction["value"]["receiver_identifier"] == MAIN_ADDRESS and \
                         transaction["value"]["sender_data"]:
                     count += 1
                     if self.deposit_transaction(
                             transaction["value"]["amount"] -
                             ceil(transaction["value"]["amount"] * 0.0025),
                             bytes.fromhex(transaction["value"]
                                           ["sender_data"]).decode("utf-8"),
                             transaction["value"]["signature"],
                             transaction["value"]["sender_identifier"]):
                         successed += 1
         await ctx.send(
             "{} deposit transactions found in block {}\nSuccessfuly processed {}"
             .format(count, block_id, successed))
     else:
         nyzostring = NyzoStringEncoder.encode(
             NyzoStringPrefilledData.from_hex(
                 MAIN_ADDRESS,
                 str(ctx.author.id).encode().hex()))
         await ctx.send(
             "To deposit nyzo on your account, send a transaction to `{}` with `{}` in the data field\n"
             "Or use this nyzostring: `{}`\nYou will get a message once the deposit is validated."
             .format(MAIN_ID, ctx.author.id, nyzostring))
def test_vector75000_noise1():
    # Add content at end
    encoded = (
        "pre_go62U7kUwZJQZMz37kt7DEA.or.YHYFkoyMsihhErLmX8814Y1e.DJ~359FPU1Ezb88eV7sRRg3dy~qXn4CvmzRjFuo.qVfn"
        + "q")
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded is None
def test_vector0new2():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "848db2de31cbe4c4-28dbb9e6bdda3aba-98581356ab0e6e02-37b37fd370ac3c7b",
        # id__88idJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZXtxdHx7u
        "",
        10 *
        1000000  # Amount to be provided as int, micronyzos. no amount = 0.
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pre_apidJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZx0000000D9r0fJmDjEFZ")
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.amount == nyzo_string.amount
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#29
0
def test_vector0():
    nyzo_string = NyzoStringMicropay.from_hex(
        "f786ad285a251faa-6b59b353b83b0cc7-5a5a9e53a99d148c-a7f1439909da15a6",
        "1e0621f818c44de5700ccb243fb9e8d0a65acdc70943",
        "fbe53e25acb1caf0",
        "d8e13cd700325825",
        "6da37b293519ca78",
        "a045e3c666ffec05-e7e392c0c09c8a99-3a883c8f2a40f915-a9e50659e0e16f08",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pay_s_v6Iiyr9h~HrTDRkZxZ3curnGXjHqSkAawPgXB9UynD5yW68wxpP4VCt0Rb93~XYd2DnJV72kfZXjWCIb7a-dAyfdt0cCxCsrdZajkqQEzxhvf6qM_J1vwABJ30E8HqeFx-AQG0~hnGXgqqWe5M2avMAHTp"
    )
    decoded = NyzoStringEncoder.decode(encoded)
    # todo: More detailed tests (but comparing core bytes storage should be enough)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
示例#30
0
 def send(self, recipient: str, amount: float = 0, data: str = "", key_: str = "", frozen: dict=None):
     """
     Send Nyzo with data string to a RECIPIENT.
     """
     if key_ == "":
         raise ValueError("Need a key_")
     seed = NyzoStringEncoder.decode(key_).get_bytes()
     # convert key to address
     address = KeyUtil.private_to_public(seed.hex())
     recipient, recipient_raw = self.normalize_address(recipient, as_hex=True)
     if frozen is None:
         frozen = self.get_frozen()
     # print (f"Sending {amount} to {recipient} since balance of {address} is > {above}.")
     # print(f"Frozen edge is at {frozen['height']}")
     # Create a tx
     timestamp = int(time() * 10) * 100 + 10000  # Fixed 10 sec delay for inclusion
     # print(timestamp, hex(timestamp))
     data_bytes = data[:32].encode("utf-8")
     transaction = Transaction(buffer=None, type=Transaction.type_standard, timestamp=timestamp,
                               sender_identifier=bytes.fromhex(address), amount=int(amount * 1e6),
                               receiver_identifier=bytes.fromhex(recipient_raw),
                               previous_block_hash=bytes.fromhex(frozen["hash"]),
                               previous_hash_height=frozen['height'],
                               signature=b'', sender_data=data_bytes)
     # print(transaction.to_json())
     key, _ = KeyUtil.get_from_private_seed(seed.hex())
     to_sign = transaction.get_bytes(for_signing=True)
     sign = KeyUtil.sign_bytes(to_sign, key)
     tx = NyzoStringTransaction(Transaction.type_standard, timestamp, int(amount * 1e6),
                                bytes.fromhex(recipient_raw),
                                frozen['height'],
                                bytes.fromhex(frozen["hash"]),
                                bytes.fromhex(address), data_bytes,
                                sign)
     tx__ = NyzoStringEncoder.encode(tx)
     # Send the tx
     url = "{}/forwardTransaction?transaction={}&action=run".format(self.client, tx__)
     res = get(url)
     # print(res.text)
     temp = self.fake_table_to_list(res.text)
     # print(temp)
     temp = temp[0]
     # Add tx to data
     temp["tx__"] = tx__
     return temp