Exemplo n.º 1
0
def request_tx_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[TxInput]:  # type: ignore
    assert tx_req.details is not None
    if tx_hash:
        tx_req.request_type = TXORIGINPUT
        tx_req.details.tx_hash = tx_hash
    else:
        tx_req.request_type = TXINPUT
    tx_req.details.request_index = i
    ack = yield TxAckInput, tx_req
    _clear_tx_request(tx_req)
    return sanitize_tx_input(ack.tx.input, coin)
Exemplo n.º 2
0
def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: Optional[bytes] = None) -> Awaitable[TxOutput]:  # type: ignore
    assert tx_req.details is not None
    if tx_hash:
        tx_req.request_type = TXORIGOUTPUT
        tx_req.details.tx_hash = tx_hash
    else:
        tx_req.request_type = TXOUTPUT
    tx_req.details.request_index = i
    ack = yield TxAckOutput, tx_req
    _clear_tx_request(tx_req)
    return sanitize_tx_output(ack.tx.output, coin)
Exemplo n.º 3
0
def request_tx_meta(tx_req: TxRequest, tx_hash: bytes = None):
    tx_req.request_type = TXMETA
    tx_req.details.tx_hash = tx_hash
    tx_req.details.request_index = None
    ack = yield tx_req
    tx_req.serialized = None
    return sanitize_tx_meta(ack.tx)
Exemplo n.º 4
0
def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[Any]:  # type: ignore
    tx_req.request_type = TXMETA
    tx_req.details.tx_hash = tx_hash
    ack = yield tx_req
    _clear_tx_request(tx_req)
    gc.collect()
    return sanitize_tx_meta(ack.tx, coin)
Exemplo n.º 5
0
def request_tx_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[Any]:  # type: ignore
    tx_req.request_type = TXINPUT
    tx_req.details.request_index = i
    tx_req.details.tx_hash = tx_hash
    ack = yield tx_req
    _clear_tx_request(tx_req)
    return sanitize_tx_input(ack.tx, coin)
Exemplo n.º 6
0
def request_tx_input(tx_req: TxRequest, i: int, tx_hash: bytes = None):
    tx_req.request_type = TXINPUT
    tx_req.details.request_index = i
    tx_req.details.tx_hash = tx_hash
    ack = yield tx_req
    tx_req.serialized = None
    return sanitize_tx_input(ack.tx)
Exemplo n.º 7
0
def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[PrevTx]:  # type: ignore
    assert tx_req.details is not None
    tx_req.request_type = TXMETA
    tx_req.details.tx_hash = tx_hash
    ack = yield TxAckPrevMeta, tx_req
    _clear_tx_request(tx_req)
    return sanitize_tx_meta(ack.tx, coin)
Exemplo n.º 8
0
def request_tx_output(tx_req: TxRequest, i: int,
                      coin: CoinInfo) -> Awaitable[TxOutput]:  # type: ignore
    assert tx_req.details is not None
    tx_req.request_type = TXOUTPUT
    tx_req.details.request_index = i
    ack = yield TxAckOutput, tx_req
    _clear_tx_request(tx_req)
    return sanitize_tx_output(ack.tx.output, coin)
Exemplo n.º 9
0
def request_tx_prev_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[PrevInput]:  # type: ignore
    assert tx_req.details is not None
    tx_req.request_type = TXINPUT
    tx_req.details.request_index = i
    tx_req.details.tx_hash = tx_hash
    ack = yield TxAckPrevInput, tx_req
    _clear_tx_request(tx_req)
    return sanitize_tx_prev_input(ack.tx.input, coin)
Exemplo n.º 10
0
def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes = None):
    tx_req.request_type = TXMETA
    tx_req.details.tx_hash = tx_hash
    tx_req.details.request_index = None
    ack = yield tx_req
    tx_req.serialized = None
    gc.collect()
    return sanitize_tx_meta(ack.tx, coin)
Exemplo n.º 11
0
def _clear_tx_request(tx_req: TxRequest) -> None:
    tx_req.request_type = None
    tx_req.details.request_index = None
    tx_req.details.tx_hash = None
    tx_req.details.extra_data_len = None
    tx_req.details.extra_data_offset = None
    tx_req.serialized.signature = None
    tx_req.serialized.signature_index = None
    tx_req.serialized.serialized_tx[:] = bytes()
Exemplo n.º 12
0
def request_tx_prev_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[PrevOutput]:  # type: ignore
    assert tx_req.details is not None
    tx_req.request_type = TXOUTPUT
    tx_req.details.request_index = i
    tx_req.details.tx_hash = tx_hash
    ack = yield TxAckPrevOutput, tx_req
    _clear_tx_request(tx_req)
    # return sanitize_tx_prev_output(ack.tx, coin)  # no sanitize is required
    return ack.tx.output
Exemplo n.º 13
0
def request_tx_extra_data(tx_req: TxRequest, offset: int, size: int, tx_hash: bytes=None):
    tx_req.request_type = TXEXTRADATA
    tx_req.details.extra_data_offset = offset
    tx_req.details.extra_data_len = size
    tx_req.details.tx_hash = tx_hash
    tx_req.details.request_index = None
    ack = yield tx_req
    tx_req.serialized = None
    return ack.tx.extra_data
Exemplo n.º 14
0
def request_tx_output(tx_req: TxRequest, i: int, tx_hash: bytes = None):
    tx_req.request_type = TXOUTPUT
    tx_req.details.request_index = i
    tx_req.details.tx_hash = tx_hash
    ack = yield tx_req
    tx_req.serialized = None
    if tx_hash is None:
        return sanitize_tx_output(ack.tx)
    else:
        return sanitize_tx_binoutput(ack.tx)
Exemplo n.º 15
0
def request_tx_extra_data(  # type: ignore
    tx_req: TxRequest, offset: int, size: int, tx_hash: bytes = None
) -> Awaitable[Any]:
    tx_req.request_type = TXEXTRADATA
    tx_req.details.extra_data_offset = offset
    tx_req.details.extra_data_len = size
    tx_req.details.tx_hash = tx_hash
    ack = yield tx_req
    _clear_tx_request(tx_req)
    return ack.tx.extra_data
Exemplo n.º 16
0
def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[Any]:  # type: ignore
    tx_req.request_type = TXOUTPUT
    tx_req.details.request_index = i
    tx_req.details.tx_hash = tx_hash
    ack = yield tx_req
    _clear_tx_request(tx_req)
    gc.collect()
    if tx_hash is None:
        return sanitize_tx_output(ack.tx, coin)
    else:
        return sanitize_tx_binoutput(ack.tx, coin)
Exemplo n.º 17
0
def request_tx_input(tx_req: TxRequest,
                     i: int,
                     coin: CoinInfo,
                     tx_hash: bytes = None):
    tx_req.request_type = TXINPUT
    tx_req.details.request_index = i
    tx_req.details.tx_hash = tx_hash
    ack = yield tx_req
    tx_req.serialized = None
    gc.collect()
    return sanitize_tx_input(ack.tx, coin)
Exemplo n.º 18
0
def request_tx_extra_data(  # type: ignore
    tx_req: TxRequest, offset: int, size: int, tx_hash: bytes = None
) -> Awaitable[bytearray]:
    assert tx_req.details is not None
    tx_req.request_type = TXEXTRADATA
    tx_req.details.extra_data_offset = offset
    tx_req.details.extra_data_len = size
    tx_req.details.tx_hash = tx_hash
    ack = yield TxAckPrevExtraData, tx_req
    _clear_tx_request(tx_req)
    return ack.tx.extra_data_chunk
Exemplo n.º 19
0
def _clear_tx_request(tx_req: TxRequest) -> None:
    assert tx_req.details is not None
    assert tx_req.serialized is not None
    assert tx_req.serialized.serialized_tx is not None
    tx_req.request_type = None
    tx_req.details.request_index = None
    tx_req.details.tx_hash = None
    tx_req.details.extra_data_len = None
    tx_req.details.extra_data_offset = None
    tx_req.serialized.signature = None
    tx_req.serialized.signature_index = None
    # mypy thinks serialized_tx is `bytes`, which doesn't support indexed assignment
    tx_req.serialized.serialized_tx[:] = bytes()  # type: ignore
Exemplo n.º 20
0
def request_tx_finish(tx_req: TxRequest):
    tx_req.request_type = TXFINISHED
    tx_req.details = None
    yield tx_req
    tx_req.serialized = None
Exemplo n.º 21
0
def request_tx_finish(tx_req: TxRequest) -> Awaitable[Any]:  # type: ignore
    tx_req.request_type = TXFINISHED
    yield tx_req
    _clear_tx_request(tx_req)
    gc.collect()
Exemplo n.º 22
0
def request_tx_finish(tx_req: TxRequest) -> Awaitable[None]:  # type: ignore
    tx_req.request_type = TXFINISHED
    yield None, tx_req
    _clear_tx_request(tx_req)