zpywallet.transactions package
Submodules
zpywallet.transactions.decode module
- exception InvalidTransactionError[source]
Bases:
ExceptionException raised for invalid Bitcoin transactions.
- message
Explanation of the error.
- Type:
str
- insert_address_in_outputs(fine_rawtx, network=<class 'zpywallet.network.BitcoinSegwitMainNet'>)[source]
- parse_transaction(raw_transaction_hex, segwit=False)[source]
Parse a raw Bitcoin-like transaction in hexadecimal format.
- Parameters:
raw_transaction_hex (str) – The raw transaction data in hexadecimal format.
segwit (bool, optional) – Whether the transaction follows SegWit rules. Defaults to False.
- Returns:
A tuple containing the parsed transaction dictionary and the witness size.
- Return type:
tuple
- Raises:
InvalidTransactionError – If the transaction data is invalid or incomplete.
- parse_transaction_simple(raw_transaction_hex)[source]
Convenience wrapper around parse_transaction that auto-detects the transaction type.
- transaction_size(raw_transaction_hex, segwit=False)[source]
Calculate the size of a Bitcoin-like transaction.
- Parameters:
raw_transaction_hex (str) – The raw transaction data in hexadecimal format.
segwit (bool, optional) – Whether the transaction follows SegWit rules. Defaults to False.
- Returns:
The size of the transaction in virtual bytes (vbytes) if SegWit, otherwise bytes.
- Return type:
int
- Raises:
InvalidTransactionError – If the transaction data is invalid or incomplete.
zpywallet.transactions.encode module
- create_transaction(inputs: ~typing.List[~zpywallet.utxo.UTXO], outputs: ~typing.List[~zpywallet.destination.Destination], rbf=True, network=<class 'zpywallet.network.BitcoinSegwitMainNet'>, full_nodes=None, **kwargs)[source]
Creates a signed Bitcoin transaction.
Usually you do not want to use this function, because it does not automatically calculate change or fees. Instead, use Wallet.create_transaction().
- Parameters:
inputs (List[UTXO]) – A list of Unspent Transaction Output objects.
outputs (List[Destination]) – A list of Destination objects representing the transaction outputs.
rbf (bool, optional) – Whether to enable Replace-By-Fee. Defaults to True. Only for Bitcoin-like blockchains. <Deprecated>
network (CryptoNetwork, optional) – The network to use. Defaults to BitcoinSegwitMainNet.
full_nodes (list, optional) – List of Web3 nodes to connect for signing. Only for EVM blockchains.
gas (int, optional) – Specifies the gas in Gwei. Only for EVM blockchains.
- Returns:
The signed transaction data in bytes.
- Return type:
bytes
- Raises:
ValueError – If there’s an issue with the transaction or network configuration.
zpywallet.transactions.script module
- class Script(script, network=<class 'zpywallet.network.BitcoinSegwitMainNet'>)[source]
Bases:
object- Represents a script in Bitcoin. Can also represent most scripts in other altcoins
like Litecoin, Dogecoin, and Bitcoin Cash.
A Script contains just a list of OP_CODES and also knows how to serialize into bytes.
- script
The list with all the script OP_CODES and data.
- Type:
list
- Raises:
ValueError – If string data is too large or integer is negative.
- static from_raw(scriptraw, has_segwit=False, network=<class 'zpywallet.network.BitcoinSegwitMainNet'>)[source]
Imports a Script commands list from raw hexadecimal data
- Parameters:
txinputraw – string (hex) The hexadecimal raw string representing the Script commands
has_segwit – boolean Is the Tx Input segwit or not
- to_bytes()[source]
Returns a serialized byte version of the script
If an OP code the appropriate byte is included according to: https://en.bitcoin.it/wiki/Script If not consider it data (signature, public key, public key hash, etc.) and and include with appropriate OP_PUSHDATA OP code plus length