def __init__(self): # active_chain is initialized with a chain index and a list with genesis block in it self.active_chain: BlockChain = BlockChain( idx=Params.ACTIVE_CHAIN_IDX, chain=[Block.genesis_block()]) self.side_branches: Iterable[BlockChain] = [] self.orphan_blocks: Iterable[Block] = [] self.utxo_set: UTXO_Set = UTXO_Set() self.mempool: MemPool = MemPool() self.wallet: Wallet = Wallet.init_wallet(Params.WALLET_FILE) # PeerManager use Peer.init_peer() to read peer from PEERS_FILE or peer list in Params.py self.peerManager: PeerManager = PeerManager( Peer.init_peers(Params.PEERS_FILE)) self.mine_interrupt: threading.Event = threading.Event() self.ibd_done: threading.Event = threading.Event() self.chain_lock: threading.RLock = threading.RLock() self.peers_lock: threading.RLock = threading.RLock() self.gs = dict() ( self.gs["Block"], self.gs["Transaction"], self.gs["UnspentTxOut"], self.gs["Message"], self.gs["TxIn"], self.gs["TxOut"], self.gs["Peer"], self.gs["OutPoint"], ) = ( globals()["Block"], globals()["Transaction"], globals()["UnspentTxOut"], globals()["Message"], globals()["TxIn"], globals()["TxOut"], globals()["Peer"], globals()["OutPoint"], )
def __init__(self): self.active_chain: BlockChain = BlockChain( idx=Params.ACTIVE_CHAIN_IDX, chain=[Block.genesis_block()]) self.side_branches: Iterable[BlockChain] = [] self.orphan_blocks: Iterable[Block] = [] self.utxo_set: UTXO_Set = UTXO_Set() self.mempool: MemPool = MemPool() self.wallet: Wallet = Wallet.init_wallet(Params.WALLET_FILE) #self.peers: Iterable[Peer] = Peer.init_peers(Params.PEERS_FILE) self.peerManager: PeerManager = PeerManager( Peer.init_peers(Params.PEERS_FILE)) self.mine_interrupt: threading.Event = threading.Event() self.ibd_done: threading.Event = threading.Event() self.chain_lock: _thread.RLock = threading.RLock() self.peers_lock: _thread.RLock = threading.RLock() self.gs = dict() self.gs['Block'], self.gs['Transaction'], self.gs['UnspentTxOut'], self.gs['Message'], self.gs['TxIn'], self.gs['TxOut'], self.gs['Peer'], self.gs['OutPoint']= \ globals()['Block'], globals()['Transaction'], globals()['UnspentTxOut'], globals()['Message'], \ globals()['TxIn'], globals()['TxOut'], globals()['Peer'], globals()['OutPoint']
from ds.Block import Block from consensus.Consensus import PoW import threading import time time_start = time.time() genesis_block = Block.genesis_block() genesis_block = genesis_block._replace(bits=24) genesis_block = genesis_block._replace(timestamp=1554460209) genesis_block = PoW.mine(genesis_block, threading.Event()) print(genesis_block.bits, genesis_block.nonce, genesis_block.id)