Blockchain¶
Classes: Blockchain: Class for storing blockchain. Connects to the sqlite3 database Main methods:
new_block - creates new block new_transaction - creates new transaction new_sc - creates new smart contract
Block: Class for storing block Transaction: Class for storing transaction. Smart_contract: Class for storing smart contract. Some abbreviations: bch - blockchain tnx - transaction sc - smart contract(DApp)
-
class
hodl.block.Blockchain.Blockchain(filename='bch.db', m='w')[source]¶ Class for blockchain
-
add_miner(miner)[source]¶ add proof-of-work miner miner = [hash, n, address, t] :param list miner: miner
-
add_sc(sc)[source]¶ Add smart contract :param sc: smart contract to add :return: index of added sc :rtype: list or tuple
-
append(block)[source]¶ Appends blockchain with a block :param block: block to add in blockchain :type block: Block
-
get_block(i, sync_get)[source]¶ Return full block (In local blockchain might be only unfilled copy of block i (UnfilledBlock), then get full block from other peer) :param i: block’s index :type i: int :param sync_get: function than gets object (block, transaction, smart contract) from network :type sync_get: function :return: Block
-
get_sc(smartcontract)[source]¶ Get smart contract by index :param smartcontract: index :type smartcontract: str :return: Smart contract :type: SmartContrct
-
has_traffic_rest(user, time_to, price, mined_hash=None)[source]¶ HODL has no commission, so, to avoid spam, user has limit of actions in proportion to his balance. Next actions must be mined by this user. (todo) :param user: author of action to confirm :type user: str :param time_to: time of action (index of last tnx at than moment) :type time_to: list[int] :param price: price of the action :type price: float :param mined_hash: mined hash for mined actions :type mined_hash: int :return: validness of the action :rtype: bool
-
index(block)[source]¶ Finds block in chain (by hash) :param block: block to index :type block: Block :return: index :rtype: int
-
money(wallet, at=None)[source]¶ Count balance of wallet :param wallet: wallet to count balance at :type wallet: str :param at: latest tnx to count :type at: list :return: balance :rtype: float
-
new_sc(text, author, author_priv, memsize=10000000, lang='js')[source]¶ Creates new smart contract and adds it to the chain :param str text: smart contract code :param str author: SC’s author :param str author_priv: author’s private key :param int memsize: SC’s memory size :param str lang: SC language :return: [index of created sc, index of transaction this SC is connected with] :rtype: [list[int], list[int]]
-
new_transaction(author, froms, outs, outns, sign='signing', privkey='', sc=())[source]¶ Creates new transaction and adds it to the chain :param str author: transaction author :param list froms: transaction froms :param list outs: transaction outs :param list outns: transaction outns :param str sign: transaction sign if it’s already signed or ‘signing’ :param str privkey: private key if tnx is not already signed :param sc: index of smart contract connected with transaction or ()/[]/None :type sc: tuple or list :return: index of created transaction :rtype: list
-
pubkey_by_nick(nick, maxn=('l', 'l'))[source]¶ Nicks can be used in transactions. Nicks can be defined in transaction with author=pubkey;nick; Nick can be transfered in transaction with autor=pubkey;nick;new pubkey; :param nick: str: pubkey, nick or nick definition :param maxn: tuple: maximum index or (‘l’, ‘l’) for entire blockchain :return: str: pubkey
-