async def broadcast_transfer(
    transfer: SignTransferSchema,
    background_tasks: BackgroundTasks,
    req_wallet: WalletConfig = Depends(get_wallet),
    current_user: UserSettings = Depends(get_current_user),
    sync: bool = True,
):
    """Sign and broadcast a transfer message to the exchange

    """
    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())

    background_tasks.add_task(increment_wallet_sequence, req_wallet)
    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()}
示例#3
0
    def test_transfer_message_hex(self, wallet):

        wallet._account_number = 23452
        wallet._sequence = 2

        symbol = 'BNB'
        from_address = 'tbnb18fhdlzyqj360nympg5ejl7c5g4frlzheuealvg'
        to_address = 'tbnb10a6kkxlf823w9lwr6l9hzw4uyphcw7qzrud5rr'
        amount = 1

        msg = TransferMsg(
            wallet=wallet,
            symbol=symbol,
            from_address=from_address,
            to_address=to_address,
            amount=amount
        )

        expected = (b'c601f0625dee0a4c2a2c87fa0a220a143a6edf88809474f9936145332ffb1445523f8af9120a0a03424e421080c2'
                    b'd72f12220a147f756b1be93aa2e2fdc3d7cb713abc206f877802120a0a03424e421080c2d72f12700a26eb5ae987'
                    b'2102cce2ee4e37dc8c65d6445c966faf31ebfe578a90695138947ee7cab8ae9a2c0812403189d8cda9a93298cc27'
                    b'24c27d2dd4536f6ba8f3b0aa9338c43ae9f1616c36b312984ee1b3cda93b25f8b7680702c5505f1697cec7249fed'
                    b'b7bf092b221457e3189cb70120022001')

        print(msg.to_hex_data())

        assert msg.to_hex_data() == expected
示例#4
0
async def broadcast_transfer(
    background_tasks: BackgroundTasks,
    transfer: SignTransferSchema = Body(
        ...,
        example={
            "msg": {
                "symbol": "BNB",
                "amount": 1,
                "to_address": "<to address>"
            },
            "wallet_name": "wallet_1"
        }),
    req_wallet: WalletConfig = Depends(get_wallet),
    current_user: UserSettings = Depends(get_current_user),
    sync: bool = True,
):
    """Sign and broadcast a transfer message to the exchange

    """
    assert_wallet_has_permission(req_wallet, WalletPermission.TRANSFER)
    assert_user_has_wallet_permission(current_user, transfer.wallet_name,
                                      WalletPermission.TRANSFER)

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

    log_broadcast_transaction(current_user, req_wallet, msg)

    background_tasks.add_task(increment_wallet_sequence, req_wallet)
    return await req_wallet.broadcast_msg(msg.to_hex_data(), sync=sync)
示例#5
0
async def sign_transfer(
        transfer: SignTransferSchema = Body(
            ...,
            example={
                "msg": {
                    "symbol": "BNB",
                    "amount": 1,
                    "to_address": "<to address>"
                },
                "wallet_name": "wallet_1",
                "memo": "Thanks for the beer"
            }),
        req_wallet: WalletConfig = Depends(get_wallet),
        current_user: UserSettings = Depends(get_current_user)):
    """Sign a transfer message, returning the hex data

    """
    assert_wallet_has_permission(req_wallet, WalletPermission.TRANSFER)
    assert_user_has_wallet_permission(current_user, transfer.wallet_name,
                                      WalletPermission.TRANSFER)

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

    log_sign_transaction(current_user, req_wallet, msg)

    return {'signed_msg': msg.to_hex_data()}
示例#6
0
    async def transfer(self, asset: Asset, amount, recipient, memo=''):
        """transfer balances

        :param asset: asset object containing : chain , symbol , ticker(optional)
        :type asset: Asset
        :param amount: amount of asset to transfer (don't multiply by 10**8)
        :type amount: int, float, decimal
        :param recipient: destination address
        :type recipient: str
        :param memo: optional memo for transaction
        :type memo: str
        :returns: the transaction hash
        :raises: raises if asset or amount or destination address not provided
        """
        wallet = Wallet(self.get_private_key(), env=self.env)

        if not asset:
            raise Exception('Asset must be provided')
        if not amount:
            raise Exception('Amount must be provided')
        if not recipient:
            raise Exception('Destination address must be provided')

        try:
            transfer_msg = TransferMsg(wallet=wallet,
                                       symbol=asset.symbol,
                                       amount=amount,
                                       to_address=recipient,
                                       memo=memo)
            transfer_result = await self.client.broadcast_msg(transfer_msg)
            return transfer_result[0]['hash']

        except Exception as err:
            return err
示例#7
0
def prepare_transfer_tx(wallet, target_addr, memo_bytes):
    tx = TransferMsg(
        wallet=wallet,
        symbol='BNB',
        amount=0.0001,
        to_address=target_addr,  # send to target
        memo=memo_bytes)
    return tx
示例#8
0
 def thor_swap(self, i_symbol, amount, to_address, memo):
     self.wallet.reload_account_sequence()
     transfer_msg = TransferMsg(wallet=self.wallet,
                                symbol=i_symbol,
                                amount=amount,
                                to_address=to_address,
                                memo=memo)
     res = self.client.broadcast_msg(transfer_msg, sync=True)
     tx_hash = res[0]['hash']
     arb_logger.debug(f'broadcasting {tx_hash}')
     return tx_hash
示例#9
0
 def send_transaction(self,
                      address,
                      symbol,
                      value,
                      memo="Send from swingby integration-tester"):
     transfer_msg = TransferMsg(wallet=wallet,
                                symbol=symbol,
                                amount=value,
                                to_address=address,
                                memo=memo)
     client.broadcast_msg(transfer_msg, sync=True)
    def test_transfer_message_hex(self, wallet):

        wallet._account_number = 23452
        wallet._sequence = 2

        symbol = 'BNB'
        to_address = 'tbnb10a6kkxlf823w9lwr6l9hzw4uyphcw7qzrud5rr'
        amount = 1

        msg = TransferMsg(wallet=wallet,
                          symbol=symbol,
                          to_address=to_address,
                          amount=amount)

        expected = (
            b'c401f0625dee0a4c2a2c87fa0a220a147f756b1be93aa2e2fdc3d7cb713abc206f877802120a0a03424e421080c2d7'
            b'2f12220a147f756b1be93aa2e2fdc3d7cb713abc206f877802120a0a03424e421080c2d72f12700a26eb5ae9872102'
            b'cce2ee4e37dc8c65d6445c966faf31ebfe578a90695138947ee7cab8ae9a2c081240d3dab13ba287b21467e735f2db'
            b'5385479ada835d22cb59721682e53e696d807c6401ae48c51a898582baec46a1906d9448b5150f7c0322181101257d'
            b'cc917fd2189cb7012002')

        assert msg.to_hex_data() == expected
示例#11
0
 def thor_swap(self, chain, i_symbol, o_symbol, amount, to_address, dest_address=None, limit=None):
     if limit:
         memo = 'SWAP:' + chain + '.' + o_symbol + '::' + str(int(limit * 10**8))
     else:
         memo = 'SWAP:' + chain + '.' + o_symbol
     transfer_msg = TransferMsg(
         wallet=self.wallet,
         symbol=i_symbol,
         amount=amount,
         to_address=to_address,
         memo=memo
     )
     res = self.client.broadcast_msg(transfer_msg, sync=True)
     binance_logger.info(f'swap response: {res}')
     hash = res[0]['hash']
     return hash
示例#12
0
def freeze_bnb_wish(amount):
    freeze_env = BinanceEnvironment.get_production_env()
    if NETWORK_SIGN_TRANSACTION_BWISH == 'testnet':
        freeze_env = BinanceEnvironment.get_testnet_env()

    client = HttpApiClient(env=freeze_env)
    bep_wallet = Wallet(BINANCE_PAYMENT_PASSWORD,
                        env=freeze_env)  # from settings
    value = float(amount / 10**18)
    freeze_msg = TransferMsg(wallet=bep_wallet,
                             symbol=COLD_TOKEN_SYMBOL_BNB,
                             amount=value,
                             to_address=COLD_BNB_ADDRESS,
                             memo='freeze bnb wish')
    res = client.broadcast_msg(freeze_msg, sync=True)
    print('result', res, flush=True)
    if not res[0]['ok']:
        raise Exception('cannot make bnb wish freeze tx')
示例#13
0
 def thor_withdraw(self, chain, symbol, percent, to_address):
     if chain == 'BNB':
         payload = 0.00000001
         payload_token = 'BNB'
     else:
         payload = 0
     percent_str = str(int(percent * 10**2))
     memo = "WITHDRAW:" + chain + '.' + symbol + ':' + percent_str
     transfer_msg = TransferMsg(
         wallet=self.wallet,
         symbol=payload_token,
         amount=payload,
         to_address=to_address,
         memo=memo
     )
     res = self.client.broadcast_msg(transfer_msg, sync=True)
     binance_logger.info(f'withdraw response: {res}')
     hash = res[0]['hash']
     return hash
示例#14
0
    async def transfer(self, asset: Asset, amount, recipient, memo=''):
        """transfer balances

        :param asset: asset object containing : chain , symbol , ticker(optional)
        :type asset: Asset
        :param amount: amount of asset to transfer (don't multiply by 10**8)
        :type amount: int, float, decimal
        :param recipient: destination address
        :type recipient: str
        :param memo: optional memo for transaction
        :type memo: str
        :returns: the transaction hash
        :raises: raises if asset or amount or destination address not provided
        """
        wallet = Wallet(self.get_private_key(), env=self.env)

        if not asset:
            raise Exception('Asset must be provided')
        if not amount:
            raise Exception('Amount must be provided')
        if not recipient:
            raise Exception('Destination address must be provided')

        before_balance = await self.get_balance()
        before_balance_amount = before_balance[0].amount
        fee = await self.get_transfer_fee()
        fee = fee['fixed_fee_params']['fee'] * 10**-8
        if (amount + fee) > float(before_balance_amount):
            raise Exception(
                'input asset amout is higher than current (asset balance - transfer fee)'
            )

        try:
            transfer_msg = TransferMsg(wallet=wallet,
                                       symbol=asset.symbol,
                                       amount=amount,
                                       to_address=recipient,
                                       memo=memo)
            transfer_result = await self.client.broadcast_msg(transfer_msg)
            return transfer_result[0]['hash']

        except Exception as err:
            raise Exception(str(err))