Example #1
0
def get_transaction_result(tr_hash, timeout, servers, attempts=5, wait=2):
    """
    Get created offer hash and look for offer result after it's processing.

    takes:
        tr_hash  - str  - ripple transaction hash
        timeout  - int  - transaction timeout
        servers  - list - ripple servers
        attempts - int  - number of attempts to check if trade happened
        wait     - int  - seconds to wait until next check
    returns:
        transaction result if it's happened or None

    """
    transaction = {}

    # wait for ripple path find
    if not strtobool(os.environ.get("TESTING", "no")):
        time.sleep(wait)

    for i in xrange(attempts):
        transaction = tx(tr_hash, timeout=timeout, servers=servers)
        # check if offer happened
        if 'AffectedNodes' in transaction:
            break
        # wait for ripple path find a little more
        if not strtobool(os.environ.get("TESTING", "no")):
            time.sleep(wait)
    return transaction
Example #2
0
def submit_task(transaction_pk):
    if not transaction_pk:
        return
    transaction = Transaction.objects.filter(pk=transaction_pk)
    logger = logging.getLogger('ripple')
    if not transaction.exists():
        logger.error("sign_task: transaction %s not found in DB!" %
                     transaction_pk)
        return
    transaction = transaction[0]
    try:
        response = submit(transaction.tx_blob)
        if response['engine_result'] == "telINSUF_FEE_P":
            # ripple server too busy to forward or process your transaction
            while True:
                time.sleep(2)
                tx_response = tx(transaction.hash)
                status = tx_response.get('meta', {}).get('TransactionResult')
                # check if tx status is available
                if status:
                    response['engine_result'] = status
                    break

    except RippleApiError, e:
        logger.error(e)
        transaction.status = Transaction.FAILURE
        transaction.save()
        return
Example #3
0
def submit_task(transaction_pk):
    if not transaction_pk:
        return
    transaction = Transaction.objects.filter(pk=transaction_pk)
    logger = logging.getLogger('ripple')
    if not transaction.exists():
        logger.error("sign_task: transaction %s not found in DB!" % transaction_pk)
        return
    transaction = transaction[0]
    try:
        response = submit(transaction.tx_blob)
        if response['engine_result'] == "telINSUF_FEE_P":
            # ripple server too busy to forward or process your transaction
            while True:
                time.sleep(2)
                tx_response = tx(transaction.hash)
                status = tx_response.get('meta', {}).get('TransactionResult')
                # check if tx status is available
                if status:
                    response['engine_result'] = status
                    break

    except RippleApiError, e:
        logger.error(e)
        transaction.status = Transaction.FAILURE
        transaction.save()
        return
Example #4
0
def get_transaction_result(tr_hash, timeout, servers, attempts=5, wait=2):
    """
    Get created offer hash and look for offer result after it's processing.

    takes:
        tr_hash  - str  - ripple transaction hash
        timeout  - int  - transaction timeout
        servers  - list - ripple servers
        attempts - int  - number of attempts to check if trade happened
        wait     - int  - seconds to wait until next check
    returns:
        transaction result if it's happened or None

    """
    transaction = {}

    # wait for ripple path find
    if not strtobool(os.environ.get("TESTING", "no")):
        time.sleep(wait)

    for i in xrange(attempts):
        transaction = tx(tr_hash, timeout=timeout, servers=servers)
        # check if offer happened
        if "AffectedNodes" in transaction:
            break
        # wait for ripple path find a little more
        if not strtobool(os.environ.get("TESTING", "no")):
            time.sleep(wait)
    return transaction
Example #5
0
def submit_task(transaction):
    if transaction:
        logger = logging.getLogger('ripple')
        try:
            response = submit(transaction.tx_blob)
            if response['engine_result'] == "telINSUF_FEE_P":
                # ripple server too busy to forward or process your transaction
                while True:
                    time.sleep(2)
                    tx_response = tx(transaction.hash)
                    status = tx_response.get('meta', {}).get('TransactionResult')
                    # check if tx status is available
                    if status:
                        response['engine_result'] = status
                        break

        except RippleApiError, e:
            logger.error(e)
            transaction.status = Transaction.FAILURE
            transaction.save()
            return
        except ConnectionError, e:
            logger.error('Connection error: %s' % e)
            return