Classes and their methods¶
Here we want to give an overview of libchain’s classes and the methods avaiable.
Note
In the methods documentation 1bitcoinaddress, txhash and blockhash
are used instead of real addresses, transaction hashes and blocks hashes. If
you want to try the examples listed below, you have to use real values.
user¶
-
class
libchain.user(_addres=0, _value=0)¶ Defines an address, its balance, its num of tx, and the amount wich has sent or received in a tx
-
balance()¶ Give the balance of the address of the user
Parameters: none –
Returns: the amount of BTC owned by the user
Return type: float
Raises: AddressError– if the address is wrongBech32AddressError– if the address a bech32, this kind of address is not yet supported by blockchain.info
Examples:
>>>> u = lc.user('1bitcoinaddresshash') >>>> u.balance() 1.0284
-
parse(_json={}, *args)¶ When a json is given, it is loaded in the user
Parameters: response (json) – a requests’ json encoded response from blockchain.info. An example can be found here address sample Returns: none Examples:
>>>> import requests as rq >>>> data = rq.get('https://blockchain.info/rawaddr/1bitcoinaddress') >>>> data = data.json() >>>> u = lc.user() >>>> u.parse(data)
Warning
This method shouldn’t be used, use
fromhashinstead
-
totalreceived()¶ Gives the amount of BTC wich has been received by the user
Parameters: none –
Returns: the total amount of BTC received in all history by the address of the user
Return type: float
Raises: AddressError– if the address is wrongBech32AddressError– if the address a bech32, this kind of address is not yet supported by blockchain.info
Examples:
>>>> u = lc.user('1bitcoinaddresshash') >>>> u.totalreceived() 12.084
-
totaltx()¶ Gives the number of transactions in wich the user is involved
See also
It’s the same as
len(u.transactions())Parameters: none –
Returns: total number of transactions in wich the address of the user is involved
Return type: int
Raises: AddressError– if the address is wrongBech32AddressError– if the address a bech32, this kind of address is not yet supported by blockchain.info
Examples:
>>>> u = lc.user('1bitcoinaddresshash') >>>> u.totaltx() 3
-
transactions()¶ Gives the list of tx in wich the user is involved
Parameters: none –
Returns: a list of all the tx hashes in wich is involved the address of the user
Return type: string list
Raises: AddressError– if the address is wrongBech32AddressError– if the address a bech32, this kind of address is not yet supported by blockchain.info
Examples:
>>>> u = lc.user('1bitcoinaddresshash') >>>> u.transactions() ['txhash1','txhash2','txhash3']
-
transaction¶
-
class
libchain.tx(_hash=0, _index=0, _senders=[], _recipients=[], *args)¶ Defines a transaction in a block of the bitcoin’s blockchain
-
fromhash(_hash)¶ When a hash is given, the corrisponding transaction is loaded
Parameters: string – the hash of a valid transaction Returns: none Raises: TxHashError– if the hash argument is invalidExamples:
>>>> t = lc.tx() >>>> t.fromhash('txhash')
-
parse(_json={}, *args)¶ When a json is given, it is loaded in the transaction.
-------------- mined -------------is assigned for newly created BTC------- op return / unknown ------is assigned for transactions with no recepient
Parameters: response (json) – a requests’ json encoded response from blockchain.info. An example can be found here: tx sample Returns: none Examples:
>>>> import requests as rq >>>> data = rq.get('https://blockchain.info/rawtx/1bitcoinaddress') >>>> data = data.json() >>>> t = lc.tx() >>>> t.parse(data)
Warning
This method shouldn’t be used, use
fromhashinstead
-
simplelinks()¶ Gives a list of tuple (from addr, to addr) from the transaction
Parameters: none – Returns: a list of tuple (from addr, to addr) from the transaction. Each sender is counted once for each recepients Return type: tuple list Examples:
>>>> t = lc.tx('txhash') >>>> t.simplelinks() [('1bitcoinaddress','3bitcoinaddress'),('1bitcoinaddress','4bitcoinaddress'), ('2bitcoinaddress','3bitcoinaddress'),('2bitcoinaddress','4bitcoinaddress')]
-
value()¶ Gives the amount of BTC moved within the transaction
Parameters: none – Returns: the amount of BTC moved within the transaction Return type: float Examples:
>>>> t = lc.tx('txhash') >>>> t.value() 1051.13479
-
block¶
-
class
libchain.block(_hash=0, _prevblock=0, _time=0, _index=0, _height=0, _tx=[], *args)¶ Defines a block of the bitcoin’s blockchain
-
fromhash(_hash)¶ When a hash is given, the corrisponding block is loaded
Parameters: string – the hash of a valid block Returns: none Raises: BlockHashError– if the hash argument is invalidExamples:
>>>> b = lc.b() >>>> b.fromhash('blockhash')
-
fromheight(_height)¶ When a height is given, the corrisponding block is loaded
Parameters: string – the hash of a valid block Returns: none Raises: BlockHashError– if the hash argument is invalidExamples:
>>>> t = lc.tx() >>>> t.fromheight('blockheight')
-
parse(_json={}, *args)¶ When a json file is given, it is loaded in the block
Parameters: response (json) – a requests’ json encoded response from blockchain.info. An example can be found here block sample Returns: none Examples:
>>>> import requests as rq >>>> data = rq.get('https://blockchain.info/rawblock/blockhash') >>>> data = data.json() >>>> b = lc.block() >>>> b.parse(data)
Warning
This method shouldn’t be used, use
fromhashinstead
-
value()¶ Give the amount of BTC moved within the block
Parameters: none – Returns: the amount of BTC moved within the block Return type: float Examples:
>>>> b = lc.b('blockhash') >>>> b.value() 101951.179
-