| |
- address_to_key_hash(s)
- Given a Bitcoin address decodes the version and
RIPEMD-160 hash of the public key.
Args:
s (bytes): The Bitcoin address to decode
Returns:
(version, h160) (tuple): A tuple containing the version and
RIPEMD-160 hash of the public key.
- bits_to_difficulty(bits)
- Determines the difficulty corresponding to bits.
See: https://en.bitcoin.it/wiki/Difficulty
Args:
bits (int): Compact target (32 bits)
Returns:
diff (float): Measure of how hard it is to find a solution
below the target represented by bits.
- bits_to_target(bits)
- Decodes the full target from a compact representation.
See: https://bitcoin.org/en/developer-reference#target-nbits
Args:
bits (int): Compact target (32 bits)
Returns:
target (Bignum): Full 256-bit target
- bytes_to_str(b)
- Converts bytes into a hex-encoded string.
Args:
b (bytes): bytes to encode
Returns:
h (str): hex-encoded string corresponding to b.
- compute_reward(height)
- Computes the block reward for a block at the supplied height.
See: https://en.bitcoin.it/wiki/Controlled_supply for the reward
schedule.
Args:
height (int): Block height
Returns:
reward (int): Number of satoshis rewarded for solving a block at the
given height.
- difficulty_to_bits(difficulty)
- Converts a difficulty to a compact target.
Args:
difficulty (float): The difficulty to create a target for
Returns:
ct (int): Compact target
- difficulty_to_target(difficulty)
- Converts a difficulty to a long-form target.
Args:
difficulty (float): The difficulty to return the appropriate target for
Returns:
target (int): The corresponding target
- hash160(b)
- Computes the HASH160 of b.
Args:
b (bytes): A byte string to compute the HASH160 of.
Returns:
The RIPEMD-160 digest of the SHA256 hash of b.
- hex_str_to_bytes(h)
- Converts a hex-encoded string to bytes.
Args:
h (str): hex-encoded string to convert.
Returns:
b (bytes): bytes corresponding to h.
- key_hash_to_address(hash160, version=0)
- Convert RIPEMD-160 hash to bitcoin address.
Args:
hash160 (bytes/str): bitcoin hash160 to decode
version (int): The version prefix
Returns:
(bitcoin address): base58 encoded bitcoin address
- pack_compact_int(i)
- See
https://bitcoin.org/en/developer-reference#compactsize-unsigned-integers
Args:
i (int): Integer to be serialized.
Returns:
b (bytes): Serialized bytes corresponding to i.
- pack_u32(i)
- Serializes a 32-bit integer into little-endian form.
Args:
i (int): integer to be serialized.
Returns:
b (bytes): 4 bytes containing the little-endian serialization of i.
- pack_u64(i)
- Serializes a 64-bit integer into little-endian form.
Args:
i (int): integer to be serialized.
Returns:
b (bytes): 8 bytes containing the little-endian serialization of i.
- pack_var_str(s)
- Serializes a variable length byte stream.
Args:
s (bytes): byte stream to serialize
Return:
b (bytes): Serialized bytes, prepended with the length of the
byte stream.
- rand_bytes(n, secure=True)
- Returns n random bytes.
Args:
n (int): number of bytes to return.
secure (bool): If True, uses os.urandom to generate
cryptographically secure random bytes. Otherwise, uses
random.randint() which generates pseudo-random numbers.
Returns:
b (bytes): n random bytes.
- render_int(n)
- Renders an int in the shortest possible form.
When packing the height into the coinbase script, the integer
representing the height must be encoded in the shortest possible
manner. See: https://bitcoin.org/en/developer-reference#coinbase.
Args:
n (int): number to be encoded.
Returns:
b (bytes): bytes representing n in the shortest possible form.
- target_to_bits(target)
- Creates a compact target representation for a given target.
Args:
target (Bignum): The long-form target to make compact.
Returns:
ct (int): Compact target
- unpack_compact_int(bytestr)
- See
https://bitcoin.org/en/developer-reference#compactsize-unsigned-integers
Args:
bytestr (bytes): bytes containing an unsigned integer to be
deserialized.
Returns:
n (int): deserialized integer.
- unpack_u32(b)
- Deserializes a 32-bit integer from bytes.
Args:
b (bytes): At least 4 bytes containing the serialized integer.
Returns:
(i, b) (tuple): A tuple containing the deserialized integer and the
remainder of the byte stream.
- unpack_u64(b)
- Deserializes a 64-bit integer from bytes.
Args:
b (bytes): At least 8 bytes containing the serialized integer.
Returns:
(i, b) (tuple): A tuple containing the deserialized integer and the
remainder of the byte stream.
- unpack_var_str(b)
- Deserializes a variable length byte stream.
Args:
b (bytes): variable length byte stream to deserialize
Returns:
(s, b) (tuple): A tuple containing the variable length byte stream
and the remainder of the input byte stream.
|