Utils

Bitcoin Utils.

shuttle.providers.bitcoin.utils.address_to_hash(address, network='testnet')

Get hash from address.

Parameters
  • address (str) – bitcoin address.

  • network (str) – bitcoin network, defaults to testnet.

Returns

P2pkhScript, P2shScript – bitcoin p2pkh or p2sh script instance.

>>> from shuttle.providers.bitcoin.utils import address_to_hash
>>> address_to_hash("mrmtGq2HMmqAogSsGDjCtXUpxrb7rHThFH", "testnet")
"7b7c4431a43b612a72f8229935c469f1f6903658"
shuttle.providers.bitcoin.utils.decode_transaction_raw(tx_raw)

Decode bitcoin transaction raw.

Parameters

tx_raw (str) – bitcoin transaction raw.

Returns

dict – decoded bitcoin transaction.

>>> from shuttle.providers.bitcoin.utils import decode_transaction_raw
>>> decode_transaction_raw(transaction_raw)
{...}
shuttle.providers.bitcoin.utils.double_sha256(data)

Double SHA256 hash.

Parameters

data (bytes) – encoded data.

Returns

bytearray – hashed double sha256.

>>> from shuttle.providers.bitcoin.utils import double_sha256
>>> double_sha256("Hello Meheret!".encode())
b"..."
shuttle.providers.bitcoin.utils.fee_calculator(transaction_input=1, transaction_output=1)

Bitcoin fee calculator.

Parameters
  • transaction_input (int) – transaction input numbers, defaults to 1.

  • transaction_output (int) – transaction output numbers, defaults to 1.

Returns

int – bitcoin fee.

>>> from shuttle.providers.bitcoin.utils import fee_calculator
>>> fee_calculator(2, 9)
1836
shuttle.providers.bitcoin.utils.is_address(address, network=None)

Check bitcoin address.

Parameters
  • address (str) – bitcoin address.

  • network (str) – bitcoin network, defaults to testnet.

Returns

bool – bitcoin valid/invalid address.

>>> from shuttle.providers.bitcoin.utils import is_address
>>> is_address(bitcoin_address, "testnet")
True
shuttle.providers.bitcoin.utils.script_from_address(address, network='testnet')

Get script from address.

Parameters
  • address (str) – bitcoin address.

  • network (str) – bitcoin network, defaults to testnet.

Returns

P2pkhScript, P2shScript – bitcoin p2pkh or p2sh script instance.

>>> from shuttle.providers.bitcoin.utils import script_from_address
>>> script_from_address("mrmtGq2HMmqAogSsGDjCtXUpxrb7rHThFH", "testnet")
P2pkhScript('7b7c4431a43b612a72f8229935c469f1f6903658')
shuttle.providers.bitcoin.utils.sha256(data)

SHA256 hash.

Parameters

data (bytes) – encoded data.

Returns

bytearray – hashed sha256.

>>> from shuttle.providers.bitcoin.utils import sha256
>>> sha256("Hello Meheret!".encode())
b"..."
shuttle.providers.bitcoin.utils.submit_transaction_raw(tx_raw)

Submit transaction raw to Bitcoin blockchain.

Parameters

tx_raw (str) – bitcoin transaction raw.

Returns

dict – bitcoin transaction id, fee, type and date.

>>> from shuttle.providers.bitcoin.utils import submit_transaction_raw
>>> submit_transaction_raw(transaction_raw)
{...}