API¶
aiobitcoin.mnemonic module¶
-
class
aiobitcoin.mnemonic.
Mnemonic
(language='english')[source]¶ Bases:
object
-
static
checksum
(data)[source]¶ Calculates checksum for given data key
Parameters: data (bytes, hexstring) – key string Return str: Checksum of key in bits
-
generate
(strength=128, add_checksum=True, encoding=True)[source]¶ Generate a random Mnemonic key
Uses cryptographically secure os.urandom() function to generate data. Then creates a Mnemonic sentence with the ‘to_mnemonic’ method. :param strength: Key strength in number of bits, default is 128 bits. It advised to specify 128 bits or more, i.e.: 128, 256, 512 or 1024 :type strength: int :param add_checksum: Included a checksum? Default is True :type add_checksum: bool :param encoding :type encoding: bool
Return str: Mnemonic passphrase consisting of a space seperated list of words
-
to_mnemonic
(data, add_checksum=True, check_on_curve=True)[source]¶ Convert key data entropy to Mnemonic sentence
Parameters: - data (bytes, hexstring) – Key data entropy
- add_checksum (bool) – Included a checksum? Default is True
- check_on_curve – Check if data integer value is on secp256k1 curve. Should be enabled when not
testing and working with crypto :type check_on_curve: bool
Return str: Mnemonic passphrase consisting of a space seperated list of words
-
static
aiobitcoin.grambitcoin module¶
-
class
aiobitcoin.grambitcoin.
GramBitcoin
(url=None, read_timeout=20, session_required=False)[source]¶ Bases:
object
This class is needed to create a session and then transfer the class instance with already active session to other classes , in order to avoid creating multiple sessions. RPC-API https://bitcoincore.org/en/doc/0.17.0/
Parameters: - url (optional) (str) – Node URI in format http://alice:bob@127.0.0.1:18332
- read_timeout (20) (int) – Request operations timeout
- session_required (optional) (object) – Will create session or not
Important note: if you create an instance of this class, then you need to pass the session_required parameter with the value True. It is not necessary to pass the url parameter, if you do not pass it, then do not forget to pass the url to other classes to which you intend to pass an object of this class.
aiobitcoin.blockchain module¶
-
class
aiobitcoin.blockchain.
Blockchain
(url=None, gram=None, read_timeout=20)[source]¶ Bases:
aiobitcoin.grambitcoincommon.GramBitcoinCommon
Methods from Blockchain section https://bitcoincore.org/en/doc/0.17.0/.
Parameters: - url (optional) (str) – Node URI in format http://alice:bob@127.0.0.1:18332
- gram (optional) (object) – GramBitcoin object
- read_timeout (20) (int) – Request operations timeout
Note: You must pass at least one parameter or url or gram (with active session).
-
get_blockchain_info
() → dict[source]¶ Provides information about the current state of the block chain. :return: full blockchain information.
aiobitcoin.network module¶
-
class
aiobitcoin.network.
Network
(url=None, gram=None, read_timeout=20)[source]¶ Bases:
aiobitcoin.grambitcoincommon.GramBitcoinCommon
Methods from Network section https://bitcoincore.org/en/doc/0.17.0/.
Parameters: - url (optional) (str) – Node URI in format http://alice:bob@127.0.0.1:18332
- gram (optional) (object) – GramBitcoin object
- read_timeout (20) (int) – Request operations timeout
Note: You must pass at least one parameter or url or gram (with active session).
-
get_network_info
() → dict[source]¶ Returns: Returns an object containing various state info regarding P2P networking.
-
get_peer_info
(to_list: bool = True) → list[source]¶ Parameters: to_list – will return list or genexpr Returns: Returns data about each connected network node as a json array of objects.
-
list_banned
(to_list: bool = True) → list[source]¶ Parameters: to_list – Returns: List all banned IPs/Subnets.
-
ping
() → None[source]¶ Requests that a ping be sent to all other nodes, to measure ping time. Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds. Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping. :return: None
-
set_ban
(subnet: str, command: str = 'add', bantime: int = 0, absolute: bool = False) → aiobitcoin.bitcoinerrors.InvalidIpOrSubnet[source]¶ Attempts to add or remove an IP/Subnet from the banned list. :param subnet: The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP) :param command: ‘add’ to add an IP/Subnet to the list, ‘remove’ to remove an IP/Subnet from the list :param bantime: Time in seconds how long (or until when if [absolute] is set) the IP is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument) :param absolute: If set, the bantime must be an absolute timestamp in seconds since epoch (Jan 1 1970 GMT) :return: None
aiobitcoin.util module¶
-
class
aiobitcoin.util.
Util
(url=None, gram=None, read_timeout=20)[source]¶ Bases:
aiobitcoin.grambitcoincommon.GramBitcoinCommon
Methods from Util section https://bitcoincore.org/en/doc/0.17.0/.
Parameters: - url (optional) (str) – Node URI in format http://alice:bob@127.0.0.1:18332
- gram (optional) (object) – GramBitcoin object
- read_timeout (20) (int) – Request operations timeout
Note: You must pass at least one parameter or url or gram (with active session).
aiobitcoin.wallet module¶
-
class
aiobitcoin.wallet.
Wallet
(url=None, gram=None, read_timeout=20)[source]¶ Bases:
aiobitcoin.grambitcoincommon.GramBitcoinCommon
Methods from Wallet section https://bitcoincore.org/en/doc/0.17.0/.
Parameters: - url (optional) (str) – Node URI in format http://alice:bob@127.0.0.1:18332
- gram (optional) (object) – GramBitcoin object
- read_timeout (20) (int) – Request operations timeout
Note: You must pass at least one parameter or url or gram (with active session).
-
import_address
(addr: str, rescan: bool = False) → aiobitcoin.bitcoinerrors.PrivateKeyForThisAddressAlreadyInWallet[source]¶ Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. :param addr: bitcoin address :param rescan: activate rescanning blockchain after importing :return: boolean value
-
import_priv_key
(wif: str) → aiobitcoin.bitcoinerrors.InvalidPrivateKeyEncoding[source]¶ Adds a private key (as returned by dumpprivkey) to your wallet. :param wif: bitcoin private key :return: boolean value
-
list_transactions
(count: int = 100, include_watchonly: bool = True, to_list: bool = True) → list[source]¶ Returns up to ‘count’ most recent transactions. :param count: The number of transactions to return :param include_watchonly: Include transactions to watch-only addresses :param to_list: will return list or genexpr :return: list of transactions
aiobitcoin.bitcoinerrors module¶
-
exception
aiobitcoin.bitcoinerrors.
IncorrectCreds
(uri)[source]¶ Bases:
aiobitcoin.bitcoinerrors._BitcoinErrors
Login or password in URI is incorrect.
-
exception
aiobitcoin.bitcoinerrors.
InvalidAddress
(error_msg='')[source]¶ Bases:
aiobitcoin.bitcoinerrors._BitcoinErrors
Invalid address.
-
exception
aiobitcoin.bitcoinerrors.
InvalidIpOrSubnet
(error_msg='')[source]¶ Bases:
aiobitcoin.bitcoinerrors._BitcoinErrors
Invalid ip or subnet.
-
exception
aiobitcoin.bitcoinerrors.
InvalidPrivateKeyEncoding
(error_msg='')[source]¶ Bases:
aiobitcoin.bitcoinerrors._BitcoinErrors
Invalid private key encoding.