Exemple #1
0
def mine(node='http://127.0.0.1:5000'):
    from config import config
    import util
    config['nodes'].add(node)
    while True:
        util.sync_blocks()
        util.sync_transaction_pool()
        coinbase_tx = util.get_coinbase_transaction(node)
        block = blockchain.Block.generate_next_block_from_remote_coinbas(
            coinbase_tx)
        print("generate block %s" % block.hash)
Exemple #2
0
def add_peer():
    params = request.get_json(silent=True)
    if params:
        url = params.get('url')
        if not url_validator(url):
            return json_res(err=1016, message="invalid url")
        config["nodes"].add(url)
        sync_blocks()
        logging.error("sync_blocks finish")
        return json_res()
    return json_res(err=1013, message="miss params")
    def setup_network(self, split=False):
        self.nodes = self.setup_nodes()

        # Connect the nodes as a "chain".  This allows us
        # to split the network between nodes 1 and 2 to get
        # two halves that can work on competing chains.

        # If we joined network halves, connect the nodes from the joint
        # on outward.  This ensures that chains are properly reorganised.
        if not split:
            connect_nodes_bi(self.nodes, 1, 2)
            sync_blocks(self.nodes[1:3])
            sync_mempools(self.nodes[1:3])

        connect_nodes_bi(self.nodes, 0, 1)
        connect_nodes_bi(self.nodes, 2, 3)
        self.is_network_split = split
        self.sync_all()
Exemple #4
0
    def setup_network(self, split = False):
        self.nodes = self.setup_nodes()

        # Connect the nodes as a "chain".  This allows us
        # to split the network between nodes 1 and 2 to get
        # two halves that can work on competing chains.

        # If we joined network halves, connect the nodes from the joint
        # on outward.  This ensures that chains are properly reorganised.
        if not split:
            connect_nodes_bi(self.nodes, 1, 2)
            sync_blocks(self.nodes[1:3])
            sync_mempools(self.nodes[1:3])

        connect_nodes_bi(self.nodes, 0, 1)
        connect_nodes_bi(self.nodes, 2, 3)
        self.is_network_split = split
        self.sync_all()
 def sync_all(self):
     if self.is_network_split:
         sync_blocks(self.nodes[:2])
         sync_blocks(self.nodes[2:])
         sync_mempools(self.nodes[:2])
         sync_mempools(self.nodes[2:])
     else:
         sync_blocks(self.nodes)
         sync_mempools(self.nodes)
Exemple #6
0
 def sync_all(self, wait=1, stop_after=-1):
     if self.is_network_split:
         sync_blocks(self.nodes[:2])
         sync_blocks(self.nodes[2:])
         sync_mempools(self.nodes[:2])
         sync_mempools(self.nodes[2:])
     else:
         sync_blocks(self.nodes, wait, stop_after)
         sync_mempools(self.nodes, wait, stop_after)
Exemple #7
0
 def sync_all(self):
     if self.is_network_split:
         sync_blocks(self.nodes[:2])
         sync_blocks(self.nodes[2:])
         sync_mempools(self.nodes[:2])
         sync_mempools(self.nodes[2:])
     else:
         sync_blocks(self.nodes)
         sync_mempools(self.nodes)