async def broadcast_unfreeze(
    freeze: SignFreezeSchema,
    background_tasks: BackgroundTasks,
    req_wallet: WalletConfig = Depends(get_wallet),
    current_user: UserSettings = Depends(get_current_user),
    sync: bool = True,
):
    """Sign and broadcast an unfreeze message to the exchange

    """
    if not req_wallet.has_permission(WalletPermission.TRADE):
        raise HTTPException(status_code=403,
                            detail=f"No permission {WalletPermission.FREEZE}")

    # check user has permission for this wallet
    if not user_has_wallet_permission(current_user, freeze.wallet_name,
                                      WalletPermission.FREEZE):
        raise HTTPException(
            status_code=403,
            detail=
            f"User has no permission {WalletPermission.FREEZE} on wallet {freeze.wallet_name}"
        )

    # create the message
    msg = UnFreezeMsg(wallet=req_wallet.wallet, **freeze.msg.dict())

    background_tasks.add_task(increment_wallet_sequence, req_wallet)
    return await req_wallet.broadcast_msg(msg.to_hex_data(), sync=sync)
Esempio n. 2
0
async def broadcast_cancel_order(
        cancel_order: SignCancelOrderSchema,
        background_tasks: BackgroundTasks,
        req_wallet: WalletConfig = Depends(get_wallet),
        current_user: UserSettings = Depends(get_current_user),
        sync=True):
    """Sign and broadcast a cancel order message to the exchange

    """
    if not req_wallet.has_permission(WalletPermission.TRADE):
        raise HTTPException(status_code=403,
                            detail=f"No permission {WalletPermission.TRADE}")

    # check user has permission for this wallet
    if not user_has_wallet_permission(current_user, cancel_order.wallet_name,
                                      WalletPermission.TRADE):
        raise HTTPException(
            status_code=403,
            detail=
            f"User has no permission {WalletPermission.TRADE} on wallet {cancel_order.wallet_name}"
        )

    # create the message
    msg = CancelOrderMsg(wallet=req_wallet.wallet, **cancel_order.msg.dict())

    background_tasks.add_task(increment_wallet_sequence)
    return await req_wallet.broadcast_msg(msg.to_hex_data(), sync=sync)
async def sign_transfer(
    transfer: SignTransferSchema,
    req_wallet: WalletConfig = Depends(get_wallet),
    current_user: UserSettings = Depends(get_current_user)):
    """Sign a transfer message, returning the hex data

    """
    if not req_wallet.has_permission(WalletPermission.TRADE):
        raise HTTPException(
            status_code=403,
            detail=f"No permission {WalletPermission.TRANSFER}")

    # check user has permission for this wallet
    if not user_has_wallet_permission(current_user, transfer.wallet_name,
                                      WalletPermission.TRANSFER):
        raise HTTPException(
            status_code=403,
            detail=
            f"User has no permission {WalletPermission.TRANSFER} on wallet {transfer.wallet_name}"
        )

    # create the message
    msg = TransferMsg(wallet=req_wallet.wallet, **transfer.msg.dict())

    return {'signed_msg': msg.to_hex_data()}
Esempio n. 4
0
async def wallet_resync(
    wallet_req: WalletSchema,
    req_wallet: WalletConfig = Depends(get_wallet),
    current_user: UserSettings = Depends(get_current_user)):
    """Resynchronise the wallet to the chain

    Needed if the sequence gets out of sync

    """
    if not req_wallet.has_permission(WalletPermission.TRADE):
        raise HTTPException(status_code=403,
                            detail=f"No permission {WalletPermission.RESYNC}")

    # check user has permission for this wallet
    if not user_has_wallet_permission(current_user, wallet_req.wallet_name,
                                      WalletPermission.RESYNC):
        raise HTTPException(
            status_code=403,
            detail=
            f"User has no permission {WalletPermission.RESYNC} on wallet {wallet_req.wallet_name}"
        )

    req_wallet.wallet.reload_account_sequence()

    return {}
Esempio n. 5
0
async def sign_freeze(freeze: SignFreezeSchema,
                      req_wallet: WalletConfig = Depends(get_wallet),
                      current_user: UserSettings = Depends(get_current_user)):
    """Sign a freeze message, returning the hex data

    """
    if not req_wallet.has_permission(WalletPermission.FREEZE):
        raise HTTPException(status_code=403,
                            detail=f"No permission {WalletPermission.FREEZE}")

    # check user has permission for this wallet
    if not user_has_wallet_permission(current_user, freeze.wallet_name,
                                      WalletPermission.FREEZE):
        raise HTTPException(
            status_code=403,
            detail=
            f"User has no permission {WalletPermission.FREEZE} on wallet {freeze.wallet_name}"
        )

    # create the message
    msg = FreezeMsg(wallet=req_wallet.wallet, **freeze.msg.dict())

    return {'signed_msg': msg.to_hex_data()}