You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.8 KiB

WOWlet WS Client

Sample Python asyncio websocket client for communicating with wowlet running in "background mode" via websockets.

This library was made in a few hours, so it's not complete, and should serve as an example and PoC.

Example

First, start wowlet:

./wowlet --background 127.0.0.1:42069

Then run the following script, it will:

  1. Open a wallet
  2. Request a receiving address listing
  3. Run forever
import asyncio

from wowlet_ws_client.client import WowletWSClient


wowlet = WowletWSClient(
    host="127.0.0.1", port=1234, password="sekrit", debug=True)


@wowlet.event("passwordIncorrect")
async def on_password_incorrect(data):
    print(data)


@wowlet.event("passwordSuccess")
async def on_password_success(data):
    print(data)


@wowlet.event("walletList")
async def on_wallet_list(data):
    print("wallet listing received")
    print(data)


@wowlet.event("addressList")
async def on_address_list(data):
    print("address listing received")
    print(data)


@wowlet.event("transactionHistory")
async def on_transaction_history(data):
    print(data)


@wowlet.event("addressBook")
async def on_address_book(data):
    print(data)


@wowlet.event("synchronized")
async def on_synchronized(data):
    # called when the wallet is synchronized with the network
    print(data)


@wowlet.event("transactionCommitted")
async def on_transaction_commited(data):
    # when a transaction was sent
    print(data)


async def main():
    await wowlet.connect()
    await asyncio.sleep(3)
    await wowlet.authenticate()
    await asyncio.sleep(3)

    await wowlet.open_wallet("/home/user/Wownero/wallets/wstest.keys", "test")

    await asyncio.sleep(3)
    await wowlet.address_list(0, 0)

    # hack to keep the script running
    while True:
        await asyncio.sleep(1)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Creating a wallet

Default directory = wowlet's default wallet directory

@wowlet.event("walletCreated")
async def on_wallet_created(data):
    print(data)

@wowlet.event("walletCreatedError")
async def on_wallet_created_error(data):
    print("error")
    print(data)

await wowlet.create_wallet("cool_wallet", password="sekrit")

Creating a transaction

address = "WW2cyFaAu4NSpZdpEP3egWcK99QqU8afJEpfZW1HNxofB9sH86Nir5pes7ofwAE3ZWVNdgxFrWeSiSiSLumSeZ7538zCXb6gp"
await wowlet.send_transaction(
    address=address,
    amount=2,
    description="test transaction from Python")

QR

This library can also generate QR codes because why not.

import aiofiles
from wowlet_ws_client.qr import qr_png

addr = "some_address_here"
qr_image = qr_png(addr)

async with aiofiles.open('output.png', mode="wb") as f:
    await f.write(qr_image.getbuffer())

License

BSD