Wallet

The implementation of Hierarchical Deterministic (HD) wallets generator for Bitcoin blockchain.

class shuttle.providers.bitcoin.wallet.Wallet(network='testnet')

Bitcoin Wallet class.

Parameters

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

Returns

Wallet – bitcoin wallet instance.

Note

Bitcoin has only two networks, mainnet and testnet.

address(public_key=None)

Get bitcoin wallet address.

Parameters

public_key (str) – bitcoin address, default is None.

Returns

str – bitcoin address.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.address()
"mm357rHaKqVmhEhFFwUhz6mRVAHkJaDTKt"
balance(address=None, network='testnet')

Get bitcoin wallet balance.

Parameters
  • address (str) – bitcoin balance, default is None.

  • network (str) – bitcoin balance, default is testnet.

Returns

int – bitcoin balance.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.balance()
1000000
compressed(public_key=None)

Get bitcoin wallet compressed public key.

Parameters

public_key (str) – bitcoin public key, default is None.

Returns

str – bitcoin compressed public key.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.compressed()
"03afa8301b068c2c184e0a3e77183dc95ec1130371c02ed172bec8f3bfbad6b173"
from_address(address)

Initiate bitcoin wallet from address.

Parameters

address (str.) – Bitcoin wallet private key.

Returns

Wallet – bitcoin wallet instance.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_address("mqLyrNDjpENRMZAoDpspH7kR9RtgvhWzYE")
<shuttle.providers.bitcoin.wallet.Wallet object at 0x040DA268>
from_passphrase(passphrase, compressed=True)

Initiate bitcoin wallet from passphrase.

Parameters
  • passphrase (str.) – Bitcoin wallet passphrase.

  • compressed (bool) – bitcoin public key compressed, default is True.

Returns

Wallet – bitcoin wallet instance.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="mainnet")
>>> wallet.from_passphrase("meherett")
from_private_key(private_key, compressed=True)

Initiate bitcoin wallet from private key.

Parameters
  • private_key (str.) – Bitcoin wallet private key.

  • compressed (bool) – bitcoin public key compressed, default is True.

Returns

Wallet – bitcoin wallet instance.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="mainnet")
>>> wallet.from_private_key("92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b")
<shuttle.providers.bitcoin.wallet.Wallet object at 0x040DA268>
hash(public_key=None)

Get bitcoin wallet hash.

Parameters

public_key (str) – bitcoin hash, default is None.

Returns

str – bitcoin hash.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.hash()
"3c8acde1c7cf370d970725f13eff03bf74b3fc61"
p2pkh(address=None)

Get bitcoin wallet p2pkh.

Parameters

address (str) – bitcoin p2pkh, default is None.

Returns

str – bitcoin p2pkh.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.p2pkh()
"76a9143c8acde1c7cf370d970725f13eff03bf74b3fc6188ac"
p2sh(address=None)

Get bitcoin wallet p2sh.

Parameters

address (str) – bitcoin p2sh, default is None.

Returns

str – bitcoin p2sh.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.p2sh()
"a914a3c4995d9cd0303e5f89ee1433212c797d04ee5d87"
private_key()

Get bitcoin wallet private key.

Returns

str – bitcoin private key.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.private_key()
"d4f5c55a45c004660b95ec833bb24569eba1559f214e90efa6e8d0b3afa14394"
public_key(private_key=None, compressed=True)

Get bitcoin wallet public key.

Parameters
  • private_key (str) – bitcoin private key, default is None.

  • compressed (bool) – bitcoin public key compressed, default is True.

Returns

str – bitcoin public key.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett", compressed=False)
>>> wallet.public_key()
"04afa8301b068c2c184e0a3e77183dc95ec1130371c02ed172bec8f3bfbad6b17334244f64fe877d5e4839690c62b9d1f4095608f2ac29235e4b0299b6b96f6f35"
uncompressed(public_key=None)

Get bitcoin wallet uncompressed public key.

Parameters

public_key (str) – bitcoin public key, default is None.

Returns

str – bitcoin uncompressed public key.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.uncompressed()
"04afa8301b068c2c184e0a3e77183dc95ec1130371c02ed172bec8f3bfbad6b17334244f64fe877d5e4839690c62b9d1f4095608f2ac29235e4b0299b6b96f6f35"
unspent(address=None, network='testnet', limit=15)

Get bitcoin wallet unspent transaction output.

Parameters
  • address (str) – bitcoin balance, default is None.

  • network (str) – bitcoin balance, default is testnet.

  • limit (int) – bitcoin balance, default is 15.

Returns

list – bitcoin unspent transaction outputs.

>>> from shuttle.providers.bitcoin.wallet import Wallet
>>> wallet = Wallet(network="testnet")
>>> wallet.from_passphrase("meherett")
>>> wallet.unspent()
[{'index': 0, 'hash': 'be346626628199608926792d775381e54d8632c14b3ce702f90639481722392c', 'output_index': 1, 'amount': 12340, 'script': '76a9146bce65e58a50b97989930e9a4ff1ac1a77515ef188ac'}]