async def utxo_get_address(self, tx_hash, index): '''Returns the address sent to in a UTXO, or null if the UTXO cannot be found. tx_hash: the transaction hash of the UTXO index: the index of the UTXO in the transaction''' # Used only for electrum client command-line requests. We no # longer index by address, so need to request the raw # transaction. So it works for any TXO not just UTXOs. self.assert_tx_hash(tx_hash) index = self.non_negative_integer(index) raw_tx = await self.daemon_request('getrawtransaction', tx_hash) if not raw_tx: return None raw_tx = util.hex_to_bytes(raw_tx) tx, tx_hash = self.coin.DESERIALIZER(raw_tx).read_tx() if index >= len(tx.outputs): return None return self.coin.address_from_script(tx.outputs[index].pk_script)
async def raw_blocks(self, hex_hashes): '''Return the raw binary blocks with the given hex hashes.''' params_iterable = ((h, False) for h in hex_hashes) blocks = await self._send_vector('getblock', params_iterable) # Convert hex string to bytes return [hex_to_bytes(block) for block in blocks]
def test_hex_transforms(): h = "AABBCCDDEEFF" assert util.hex_to_bytes(h) == b'\xaa\xbb\xcc\xdd\xee\xff'
def hex_str_to_hash(x): '''Convert a displayed hex string to a binary hash.''' return bytes(reversed(hex_to_bytes(x)))
def from_string(cls, string): '''Create from a hex string.''' return cls.from_bytes(hex_to_bytes(string))