Encoding

Riemann provides support for encoding addresses for all supported chains, including native SegWit and cashaddrs. Typically, we recommend using the high level addresses module, but the encoders themselves are also available.

We recommend generally using the addresses module. Addresses may be encoded by type (e.g. make_p2wsh_address) or you may allow Riemann to select for you (e.g. make_sh_address). Riemann prefers cashaddr where available, and legacy elsewhere. Developers wanting Segwit addresses should be careful to use Segwit specific methods.

Note: Compatibility Segwit addresses (witness-over-p2sh) are not first-class address types in Riemann. You’ll have to make script-sigs yourself.

Encoder Info:

Addresses

riemann.encoding.addresses.from_output_script(output_script: bytes, cashaddr: bool = True) → str

Convert an output script (the on-chain format) to an address

Parameters
  • output_script – The output script to encode as an address

  • cashaddr – Pass False to prefer legacy to cashaddr. Default True.

riemann.encoding.addresses.make_legacy_p2pkh_address(pubkey: bytes) → str

Turns a pubkey into a legacy p2pkh address

Parameters

pubkey – The 33 or 65 byte public key

Returns

The encoded address

riemann.encoding.addresses.make_legacy_p2sh_address(script_string: str) → str

Turns a human-readable script into a non-cashaddr p2sh address

Parameters

script_string – The human-readable script

Returns

The encoded address

riemann.encoding.addresses.make_p2pkh_address(pubkey: bytes) → str

Turns a pubkey into a p2pkh address, cashaddr if available

Parameters

pubkey – The 33 or 65 byte public key

Returns

The encoded address

riemann.encoding.addresses.make_p2sh_address(script_string: str) → str

Turns a human-readable script into a p2sh address, cashaddr if possible

Parameters

script_string – The human-readable script

Returns

The encoded address

riemann.encoding.addresses.make_p2wpkh_address(pubkey: bytes) → str

Turns a pubkey into a p2wpkh address

Parameters

pubkey – The 33 or 65 byte public key

Returns

The encoded address

riemann.encoding.addresses.make_p2wsh_address(script_string: str) → str

Turns a human-readable script into a p2wsh address

Parameters

script_string – The human-readable script

Returns

The encoded address

riemann.encoding.addresses.make_pkh_address(pubkey: bytes, witness: bool = False, cashaddr: bool = True) → str

Turns a pubkey into an address. Prefers Cashaddrs to legacy addresses whenever supported.

Parameters
  • pubkey – The 33 or 65 byte public key

  • witness – Pass True to generate a witness address if supported. Default False.

  • cashaddr – Pass False to prefer legacy to cashaddr. Default True

Returns

The encoded address

riemann.encoding.addresses.make_sh_address(script_string: str, witness: bool = False, cashaddr: bool = True) → str

Turns a human-readable script into an address. Prefers Cashaddrs to legacy addresses whenever supported.

Parameters
  • script_string – The human-readable script

  • witness – Pass True to generate a witness address if supported. Default False.

  • cashaddr – Pass False to prefer legacy to cashaddr. Default True

Returns

The encoded address

riemann.encoding.addresses.parse(address: str) → bytes

Decode an address to the underlying raw bytes

Parameters

address – The address to parse

Returns

The raw bytestring encoded by the address

riemann.encoding.addresses.parse_hash(address: str) → bytes

Extract the pubkey or script hash encoded in an address

Parameters

address – The address to parse

Returns

The 20 or 32 byte hash represented by the address

riemann.encoding.addresses.to_output_script(address: str) → bytes

Convert an address into its associated output script.

Parameters

address – The address to parse

Returns

The output script that corresponds to the address, suitable for inclusion in a TxOut