Ejemplo n.º 1
0
def open_xrb(index, account, wallet_seed):
    ws = create_connection('ws://yapraiwallet.space:8000')
    representative = 'xrb_1kd4h9nqaxengni43xy9775gcag8ptw8ddjifnm77qes1efuoqikoqy5sjq3'
    # Get pending blocks

    rx_data = get_pending(str(account))
    for block in rx_data:
        #print(block)
        block_hash = block
        #print(rx_data[block])
        balance = int(rx_data[block]['amount'])
        source = rx_data[block]['source']

    hex_balance = hex(balance)
    #print(hex_balance)
    hex_final_balance = hex_balance[2:].upper().rjust(32, '0')
    #print(hex_final_balance)

    priv_key, pub_key = seed_account(wallet_seed, int(index))
    public_key = ed25519.SigningKey(priv_key).get_verifying_key().to_ascii(
        encoding="hex")

    # print("Starting PoW Generation")
    work = get_pow(str(public_key, 'ascii'))
    # print("Completed PoW Generation")

    # Calculate signature
    bh = blake2b(digest_size=32)
    bh.update(
        BitArray(
            hex=
            '0x0000000000000000000000000000000000000000000000000000000000000006'
        ).bytes)
    bh.update(BitArray(hex=xrb_account(account)).bytes)
    bh.update(
        BitArray(
            hex=
            '0x0000000000000000000000000000000000000000000000000000000000000000'
        ).bytes)
    bh.update(BitArray(hex=xrb_account(account)).bytes)
    bh.update(BitArray(hex=hex_final_balance).bytes)
    bh.update(BitArray(hex=block_hash).bytes)

    sig = ed25519.SigningKey(priv_key + pub_key).sign(bh.digest())
    signature = str(binascii.hexlify(sig), 'ascii')

    finished_block = '{ "type" : "state", "previous" : "0000000000000000000000000000000000000000000000000000000000000000", "representative" : "%s" , "account" : "%s", "balance" : "%s", "link" : "%s", \
            "work" : "%s", "signature" : "%s" }' % (
        account, account, balance, block_hash, work, signature)

    #print(finished_block)

    data = json.dumps({'action': 'process', 'block': finished_block})
    # print(data)
    ws.send(data)

    block_reply = ws.recv()

    #print(block_reply)
    ws.close()
Ejemplo n.º 2
0
def receive_xrb(index, account, wallet_seed):
    ws = create_connection('ws://yapraiwallet.space:8000')

    # Get pending blocks

    rx_data = get_pending(str(account))
    if len(rx_data) == 0:
        return

    for block in rx_data:
        #print(block)
        block_hash = block
        #print(rx_data[block])
        balance = int(rx_data[block]['amount'])
        source = rx_data[block]['source']

    previous = get_previous(str(account))

    current_balance = get_balance(previous)
    #print(current_balance)
    new_balance = int(current_balance) + int(balance)
    hex_balance = hex(new_balance)
    #print(hex_balance)
    hex_final_balance = hex_balance[2:].upper().rjust(32, '0')
    #print(hex_final_balance)

    priv_key, pub_key = seed_account(wallet_seed, int(index))
    public_key = ed25519.SigningKey(priv_key).get_verifying_key().to_ascii(encoding="hex")

    # print("Starting PoW Generation")
    work = get_pow(previous)
    # print("Completed PoW Generation")

    # Calculate signature
    bh = blake2b(digest_size=32)
    bh.update(BitArray(hex='0x0000000000000000000000000000000000000000000000000000000000000006').bytes)
    bh.update(BitArray(hex=xrb_account(account)).bytes)
    bh.update(BitArray(hex=previous).bytes)
    bh.update(BitArray(hex=xrb_account(account)).bytes)
    bh.update(BitArray(hex=hex_final_balance).bytes)
    bh.update(BitArray(hex=block_hash).bytes)

    sig = ed25519.SigningKey(priv_key +pub_key).sign(bh.digest())
    signature = str(binascii.hexlify(sig), 'ascii')

    finished_block = '{ "type" : "state", "previous" : "%s", "representative" : "%s" , "account" : "%s", "balance" : "%s", "link" : "%s", \
            "work" : "%s", "signature" : "%s" }' % \
    (previous, account, account, new_balance, block_hash, work, signature)

    #print(finished_block)

    data = json.dumps({'action': 'process', 'block': finished_block})
    # print(data)
    ws.send(data)

    block_reply = ws.recv()

    #print(block_reply)
    ws.close()
    return str(balance)
Ejemplo n.º 3
0
def send_xrb(dest_account, amount, account, index):
    ws = create_connection('ws://yapraiwallet.space:8000')

    representative = 'xrb_1kd4h9nqaxengni43xy9775gcag8ptw8ddjifnm77qes1efuoqikoqy5sjq3'

    previous = get_previous(str(account))

    current_balance = get_balance(previous)
    print(current_balance)
    new_balance = int(current_balance) - int(amount)
    hex_balance = hex(new_balance)

    print(hex_balance)
    hex_final_balance = hex_balance[2:].upper().rjust(32, '0')
    print(hex_final_balance)

    priv_key, pub_key = seed_account(settings.seed, int(index))
    public_key = ed25519.SigningKey(priv_key).get_verifying_key().to_ascii(
        encoding="hex")

    # print("Starting PoW Generation")
    work = get_pow(previous)
    # print("Completed PoW Generation")

    # Calculate signature
    bh = blake2b(digest_size=32)
    bh.update(
        BitArray(
            hex=
            '0x0000000000000000000000000000000000000000000000000000000000000006'
        ).bytes)
    bh.update(BitArray(hex=xrb_account(account)).bytes)
    bh.update(BitArray(hex=previous).bytes)
    bh.update(BitArray(hex=xrb_account(account)).bytes)
    bh.update(BitArray(hex=hex_final_balance).bytes)
    bh.update(BitArray(hex=xrb_account(dest_account)).bytes)

    sig = ed25519.SigningKey(priv_key + pub_key).sign(bh.digest())
    signature = str(binascii.hexlify(sig), 'ascii')

    finished_block = '{ "type" : "state", "previous" : "%s", "representative" : "%s" , "account" : "%s", "balance" : "%s", "link" : "%s", \
            "work" : "%s", "signature" : "%s" }' % (
        previous, account, account, new_balance, dest_account, work, signature)

    print(finished_block)

    data = json.dumps({'action': 'process', 'block': finished_block})
    # print(data)
    ws.send(data)

    block_reply = ws.recv()

    print(block_reply)
    ws.close()
Ejemplo n.º 4
0
def private_public(private):
    return ed25519.SigningKey(private).get_verifying_key().to_bytes()