Skip to content

resp undefined if the last_valid_block_height is already expired #553

@dim-4

Description

@dim-4

In the confirm_transaction() if you pass an old blockheight (that's older than the current blockheight), the while loop does not enter so resp never gets assigned.
The else statement should in this case raise TransactionExpiredBlockheightExceededError but instead raises UnboundLocalError: cannot access local variable 'resp' where it is not associated with a value.

if isinstance(resp, RPCError.__args__): # type: ignore

if last_valid_block_height:  # pylint: disable=no-else-return
    current_blockheight = (self.get_block_height(commitment)).value
    # FIX
    if current_blockheight > last_valid_block_height:
        raise TransactionExpiredBlockheightExceededError(f"{tx_sig} has expired: block height exceeded")
    # /FIX
    while current_blockheight <= last_valid_block_height:
        resp = self.get_signature_statuses([tx_sig])                         # <-- never gets here
        if isinstance(resp, RPCError.__args__):  # type: ignore
            raise RPCException(resp)
        resp_value = resp.value[0]
        if resp_value is not None:
            confirmation_status = resp_value.confirmation_status
            if confirmation_status is not None:
                confirmation_rank = int(confirmation_status)
                if confirmation_rank >= commitment_rank:
                    break
        current_blockheight = (self.get_block_height(commitment)).value
        sleep(sleep_seconds)
    else:
        if isinstance(resp, RPCError.__args__):
            raise RPCException(resp)
        raise TransactionExpiredBlockheightExceededError(f"{tx_sig} has expired: block height exceeded")
    return resp

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions