Ejemplo n.º 1
0
 def test_get_received_amount_withdrawal(self):
     self.assertEqual(
         get_received_amount('1', 'withdrawal'),
         Decimal('0.994'),
     )
     self.assertEqual(
         get_received_amount('1.1', 'withdrawal'),
         Decimal('1.0935'),
     )
     self.assertEqual(
         get_received_amount('0', 'withdrawal'),
         Decimal('0'),
     )
     self.assertEqual(
         get_received_amount('1.123456789', 'withdrawal'),
         Decimal('1.11683949'),
     )
     self.assertEqual(
         get_received_amount('1.123456784', 'withdrawal'),
         Decimal('1.11683949'),
     )
Ejemplo n.º 2
0
 def test_get_received_amount_deposit(self):
     self.assertEqual(
         get_received_amount('1', 'deposit'),
         Decimal('0.995'),
     )
     self.assertEqual(
         get_received_amount('1.1', 'deposit'),
         Decimal('1.0945'),
     )
     self.assertEqual(
         get_received_amount('0', 'deposit'),
         Decimal('0'),
     )
     self.assertEqual(
         get_received_amount('1.123456789', 'deposit'),
         Decimal('1.11783949'),
     )
     self.assertEqual(
         get_received_amount('1.123456784', 'deposit'),
         Decimal('1.11783949'),
     )
Ejemplo n.º 3
0
 def test_sends_dash_and_marks_transaction_as_processed(
     self,
     patched_send_to_address,
 ):
     patched_send_to_address.return_value = 'hash'
     tasks.send_dash_transaction.apply((self.transaction.id,))
     patched_send_to_address.assert_called_with(
         self.transaction.dash_address,
         utils.get_received_amount(
             self.transaction.dash_to_transfer,
             'withdrawal',
         ),
     )
     self.transaction.refresh_from_db()
     self.assertEqual(self.transaction.state, self.transaction.PROCESSED)
     self.assertEqual(
         self.transaction.outgoing_dash_transaction_hash,
         patched_send_to_address.return_value,
     )
Ejemplo n.º 4
0
def send_dash_transaction(transaction_id):
    logger.info(
        'Withdrawal {}. Sending Dash transaction'.format(transaction_id), )

    transaction = models.WithdrawalTransaction.objects.get(id=transaction_id)

    dash_wallet = wallet.DashWallet()
    dash_transaction_hash = dash_wallet.send_to_address(
        transaction.dash_address,
        utils.get_received_amount(transaction.dash_to_transfer, 'withdrawal'),
    )

    logger.info(
        'Withdrawal {}. Processed. Dash transaction {}'.format(
            transaction_id,
            dash_transaction_hash,
        ), )
    transaction.outgoing_dash_transaction_hash = dash_transaction_hash
    transaction.state = transaction.PROCESSED
    transaction.save()
Ejemplo n.º 5
0
def send_ripple_transaction(transaction_id):
    logger.info(
        'Deposit {}. Sending Ripple transaction'.format(transaction_id), )

    dash_transaction = models.DepositTransaction.objects.get(id=transaction_id)

    ripple_credentials = models.RippleWalletCredentials.get_solo()

    minimal_trust_limit = (dash_transaction.dash_to_transfer +
                           get_ripple_balance(
                               dash_transaction.ripple_address,
                               ripple_credentials.address,
                               'DSH',
                           ))
    if not is_trust_set(
            trusts=dash_transaction.ripple_address,
            peer=ripple_credentials.address,
            currency='DSH',
            limit=minimal_trust_limit,
    ):
        logger.info(
            'Deposit {}. Ripple account does not trust '
            '(should trust {})'.format(transaction_id, minimal_trust_limit), )
        dash_transaction.state = dash_transaction.NO_RIPPLE_TRUST
        dash_transaction.save()
        raise send_ripple_transaction.retry(
            (transaction_id, ),
            countdown=5 * 60,
            max_retries=100,
        )

    new_ripple_transaction = RippleTransaction.objects.create(
        account=ripple_credentials.address,
        destination=dash_transaction.ripple_address,
        currency='DSH',
        value='{0:f}'.format(
            utils.get_received_amount(
                dash_transaction.get_normalized_dash_to_transfer(),
                'deposit',
            ), ),
    )

    sign_task(new_ripple_transaction.pk, ripple_credentials.secret)
    new_ripple_transaction.refresh_from_db()
    if new_ripple_transaction.status != new_ripple_transaction.PENDING:
        logger.error(
            'Deposit {}. Signing Ripple transaction #{} failed'.format(
                transaction_id,
                new_ripple_transaction.id,
            ), )
        dash_transaction.state = dash_transaction.FAILED
        dash_transaction.save()
        return

    submit_task(new_ripple_transaction.pk)
    new_ripple_transaction.refresh_from_db()
    if new_ripple_transaction.status != new_ripple_transaction.SUBMITTED:
        logger.error(
            'Deposit {}. Submitting Ripple transaction #{} failed'.format(
                transaction_id,
                new_ripple_transaction.id,
            ), )
        dash_transaction.state = dash_transaction.FAILED
        dash_transaction.save()
        return

    logger.info(
        'Deposit {}. Processed. Ripple transaction {}'.format(
            transaction_id,
            new_ripple_transaction.hash,
        ), )
    dash_transaction.state = dash_transaction.PROCESSED
    dash_transaction.outgoing_ripple_transaction_hash = (
        new_ripple_transaction.hash)
    dash_transaction.save()