示例#1
0
async def get_wallets(request: Request):
    config = load_config()
    wallets = []
    for w in config:
        if isinstance(config[w], WalletConfig):
            wallets.append(w)

    return {"error": None, "result": wallets}
示例#2
0
async def get_wallets(request: BaseRequest):
    config = load_config()
    wallets = []
    for w in config:
        if config[w].get("type", None) == "wallet":
            wallets.append(w)

    return {"error": None, "result": wallets}
示例#3
0
async def get_wallet(request: Request):
    config = load_config()
    outs = load_outs_file()
    wallet_id = request.match_info.get('wallet', None)
    res = {
        "BTC": {"pub": config[wallet_id].btc_xpub, "outs": outs.get(wallet_id, {}).get("BTC", {}).get("outs", None)},
        "ETH": {"pub": config[wallet_id].eth_xpub, "outs": outs.get(wallet_id, {}).get("ETH", {}).get("outs", None)}
    }
    return {"error": None, "result": res}
示例#4
0
async def send_transactions(request: Request):
    wallet_id = request.match_info.get('wallet', None)
    currency = request.match_info.get('currency', None)
    password = request.all_data.get("password", None)
    start = request.all_data.get("start", None)
    end = request.all_data.get("end", None)
    n_array = request.all_data.get("n_array", None)

    if n_array is None:
        if start is None:
            return {"error": "No n_array and no start fields", "result": None}
        if end is None:
            return {"error": "No n_array and no end fields", "result": None}
        n_array = range(start, end)

    config = load_config()

    masterwallet = config.get("Master", None)
    if masterwallet is None or not masterwallet.has_encrypted_seed():
        return {"error": "No master wallet", "result": None}

    wallet = config.get(wallet_id, None)
    if wallet is None or not wallet.has_encrypted_seed():
        return {"error": f"No wallet [{wallet_id}]", "result": None}
    walletseed = decrypt_seed(wallet.encrypted_seed, password)
    if walletseed is None:
        return {"error": f"Problems with [{wallet_id}] wallet", "result": None}

    network_type = load_network_type()
    outs = load_outs_file()
    if wallet_id not in outs:
        return {"error": f"No outs for wallet [{wallet_id}]", "result": None}
    wallet_outs = outs[wallet_id]
    if currency not in wallet_outs:
        return {"error": f"No outs for wallet [{wallet_id}] and currency [{currency}]", "result": None}
    currency_outs: dict = wallet_outs[currency]["outs"]
    factory = CurrencyModelFactory()

    currency_model = factory.get_currency_model(currency, network_type)

    # TODO сheck signature
    # btc_model = BitcoinClass()
    # signature = currency_outs[currency]["signature"]
    # verify_result = btc_model.verify_data(json.dumps(outs), signature, masterwallet.btc_xpub)
    # if not verify_result:
    #     return {"error": f"Wrong outs signature", "result": None}
    # print(f"send_transaction, verify_result: {verify_result}")

    print(f"currency_outs: {currency_outs}")
    currency_outs: dict = wallet_outs[currency]["outs"]
    currency_model.send_transactions(walletseed, currency_outs, n_array)

    return {"error": None, "result": True}
示例#5
0
async def get_address(request: BaseRequest):
    wallet_id = request.match_info.get('wallet', None)
    currency = request.match_info.get('currency', None)
    number = request.match_info.get('number', None)
    config = load_config()
    if currency == "BTC":
        pubkey = config.get(wallet_id, {}).get("BTC", None)
        if pubkey is None:
            return {"error": "Cannot get address"}
        addr = BitcoinClass().get_addr_from_pub(pubkey, number)
    if currency == "ETH":
        pubkey = config.get(wallet_id, {}).get("ETH", None)
        if pubkey is None:
            return {"error": "Cannot get address"}
        addr = EthereumClass().get_addr_from_pub(pubkey, number)

    return {"error": None, "result": addr}
示例#6
0
async def get_balance(request: Request):
    wallet_id = request.match_info.get('wallet', None)
    currency = request.match_info.get('currency', None)
    number = request.match_info.get('number', None)
    config = load_config()
    if wallet_id not in config:
        return {"error": f"Not found wallet [{wallet_id}]"}
    network_type = load_network_type()
    wallet_config = config[wallet_id]
    factory = CurrencyModelFactory()
    currency_model = factory.get_currency_model(currency, network_type)
    xpubkey = currency_model.get_xpub(wallet_config)
    if xpubkey is None:
        return {"error": "Cannot get address"}
    addr = currency_model.get_addr_from_pub(xpubkey, number)
    balance = currency_model.get_balance(addr)
    return {"error": None, "result": balance}
示例#7
0
async def add_wallet(request: BaseRequest):
    wallet_id = request.match_info.get('wallet', None)
    config = load_config()
    if wallet_id in config and "encrypted_seed" in config["wallet_id"]:
        return {"error": "Seed phrase is already set"}
    encrypted_seed, btc_pub, eth_pub = generate_encrypted_seed(
        request.all_data["mnemonic"], request.all_data["keypassword"])
    cfg = {
        wallet_id: {
            "type": "wallet",
            "wallettype": request.all_data["wallettype"],
            "encrypted_seed": str(encrypted_seed),
            "BTC": btc_pub,
            "ETH": eth_pub
        }
    }
    save_config(cfg)
    return {"error": None, "result": True}
示例#8
0
async def set_outs(request: BaseRequest):
    wallet_id = request.match_info.get('wallet', None)
    currency = request.match_info.get('currency', None)
    password = request.all_data.get("password")
    outs = request.all_data.get("outs")
    config = load_config()
    masterwallet = config.get("Master", None)
    if masterwallet is None or "encrypted_seed" not in masterwallet:
        return {"error": "No master wallet", "result": None}
    masterseed = decrypt_seed(masterwallet["encrypted_seed"], password)
    if masterseed is None:
        return {"error": "Problems with master wallet", "result": None}
    btc = BitcoinClass()
    _priv, _pub, _addr = btc.get_priv_pub_addr(masterseed, 0)
    signature = btc.sign_data(json.dumps(outs), _priv)
    verify_result = btc.verify_data(json.dumps(outs), signature, _pub)
    if verify_result:
        save_outs_to_file(wallet_id, currency, outs, signature)
    return {"error": None, "result": verify_result}
示例#9
0
async def add_wallet(request: Request):
    wallet_id = request.match_info.get('wallet', None)
    config = load_config()
    if wallet_id in config and not config[wallet_id].has_encrypted_seed():
        return {"error": "Seed phrase is already set"}
    network_type = request.all_data["network_type"]
    encrypted_seed, btc_xpub, eth_xpub = generate_encrypted_seed(request.all_data["mnemonic"],
                                                                 request.all_data["keypassword"],
                                                                 network_type)
    cfg = WalletConfig(
        wallet_id=wallet_id,
        wallet_type=request.all_data["wallettype"],
        network_type=network_type,
        encrypted_seed=str(encrypted_seed),
        btc_xpub=btc_xpub,
        eth_xpub=eth_xpub
    )
    save_config(cfg.to_dict())
    return {"error": None, "result": True}