async def pocket(args, websockets_path): if args.pocket is None and args.delete: print("Need a pocket specified when deleting a pocket.", file=sys.stderr) return -1 if args.pocket is None: async with api.WebSocket(websockets_path) as ws: ec, pockets = await api.Pocket.list(ws) if ec: print("Error: unable to fetch pockets.", ec, file=sys.stderr) return for pocket in pockets: print(pocket) elif args.delete: message = json.dumps({ "command": "dw_delete_pocket", "id": create_random_id(), "params": [args.pocket] }) else: async with api.WebSocket(websockets_path) as ws: ec = await api.Pocket.create(ws, args.pocket) if ec: print("Error: unable to create pocket.", ec, file=sys.stderr) return print("Pocket created.") return 0
async def start(screen): curses.noecho() curses.cbreak() screen.keypad(True) curses.start_color() curses.use_default_colors() curses.curs_set(0) if curses.can_change_color(): curses.init_color(COLOR_DARKBLACK, 0, 0, 0) curses.init_color(COLOR_SUPERWHITE, 1000, 1000, 1000) curses.init_pair(PAIR_ACTIVE_TAB, COLOR_SUPERWHITE, COLOR_DARKBLACK) curses.init_pair(PAIR_TABBAR_BG, COLOR_DARKBLACK, COLOR_SUPERWHITE) else: curses.init_pair(PAIR_ACTIVE_TAB, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(PAIR_TABBAR_BG, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(PAIR_INACTIVE_TAB, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(PAIR_ACTIVE_ACCOUNT_SEL, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(PAIR_INACTIVE_ACCOUNT_SEL, curses.COLOR_WHITE, -1) curses.init_pair(PAIR_POSITIVE_VALUE, curses.COLOR_GREEN, -1) curses.init_pair(PAIR_NEGATIVE_VALUE, curses.COLOR_RED, -1) websockets_path = "ws://localhost:8888" async with api.WebSocket(websockets_path) as ws: app = Application(screen, ws) await app.start()
async def history(args, websockets_path): async with api.WebSocket(websockets_path) as ws: ec, history = await api.Wallet.history(ws, args.pocket) if ec: print("Error: fetching history.", ec, file=sys.stderr) return print(json.dumps(history, indent=2)) return 0
async def balance(args, websockets_path): async with api.WebSocket(websockets_path) as ws: ec, balance = await api.Wallet.balance(ws, args.pocket) if ec: print("Error: fetching balance.", ec, file=sys.stderr) return print(balance) return 0
async def stealth(args, websockets_path): async with api.WebSocket(websockets_path) as ws: ec, stealth_addr = await api.Wallet.stealth(ws, args.pocket) if ec: print("Error: fetching receive addresses.", ec, file=sys.stderr) return print(stealth_addr) return 0
async def recv(args, websockets_path): async with api.WebSocket(websockets_path) as ws: ec, addrs = await api.Wallet.receive(ws, args.pocket) if ec: print("Error: fetching receive addresses.", ec, file=sys.stderr) return for addr in addrs: print(addr) return 0
async def seed(args, websockets_path): async with api.WebSocket(websockets_path) as ws: ec, seed = await api.Account.seed(ws) if ec: print("Error: failed to get seed.", ec, file=sys.stderr) return -1 print(" ".join(seed)) return 0
async def account(args, websockets_path): async with api.WebSocket(websockets_path) as ws: active_account, account_names = await api.Account.list(ws) for name in account_names: if name == active_account: print("*", name) else: print(" ", name) return 0
async def dw_set(args, websockets_path): assert args.account account_name = args.account[0] #password = getpass.getpass() password = "******" async with api.WebSocket(websockets_path) as ws: ec = await api.Account.set(ws, account_name, password) return 0
async def pending(args, websockets_path): async with api.WebSocket(websockets_path) as ws: ec, pending_payments = \ await api.Wallet.pending_payments(ws, args.pocket) if ec: print("Error: fetching pending_payments.", ec, file=sys.stderr) return for payment in pending_payments: for address, value in payment["destinations"]: print(address, value) print(payment["tx_hash"], payment["created_date"]) print() return 0
async def send(args, websockets_path): assert args.address assert args.amount address = args.address[0] amount = args.amount[0] dests = [(address, amount)] async with api.WebSocket(websockets_path) as ws: ec, tx_hash = await api.Wallet.send(ws, dests, args.pocket, args.fee) if ec: print("Error: sending funds.", ec, file=sys.stderr) return print(tx_hash) return 0
async def init(args, websockets_path): assert args.account account_name = args.account[0] #password = enter_confirmed_password() password = "******" if password is None: print("Error: passwords don't match.", file=sys.stderr) return -1 is_testnet = args.testnet async with api.WebSocket(websockets_path) as ws: ec = await api.Account.create(ws, account_name, password, is_testnet) if ec: print("Error: failed to create account.", ec, file=sys.stderr) return -1 print("Account created.") return 0
async def stop(args, websockets_path): async with api.WebSocket(websockets_path) as ws: await api.Daemon.stop(ws)