Exemple #1
0
 def mine(self):
     api = "http://%s:%d/api/blockchain/mine" % (settings.host,
                                                 settings.port)
     code, body = fetch_html(api)
     if code != 200:
         logging.info("code %s , cannot sync data" % str(code))
     return body
Exemple #2
0
 def sync_data(self):
     api = "http://%s:%d/api/blockchain/sync_data" % (settings.host,
                                                      settings.port)
     code, body = fetch_html(api)
     if code != 200:
         logging.info("code %s , cannot sync data" % str(code))
     write_file(settings.block_save_file, body)
Exemple #3
0
 def consensus(self):
     api = "http://%s:%d/api/blockchain/nodes/resolve" % (settings.host,
                                                          settings.port)
     code, body = fetch_html(api)
     if code != 200:
         print "code %s , cannot solve consensus" % str(code)
         logging.info("code %s , cannot solve consensus" % str(code))
         return None
     return body
Exemple #4
0
 def full_chain(self):
     api = "http://%s:%d/api/blockchain/chain" % (settings.host,
                                                  settings.port)
     code, body = fetch_html(api)
     if code != 200:
         print "code %s , cannot register_nodes" % str(code)
         logging.info("code %s , cannot get full_chain" % str(code))
         return None
     return body
Exemple #5
0
 def register_nodes(self, nodes=None):
     api = "http://%s:%d/api/blockchain/nodes/register" % (settings.host,
                                                           settings.port)
     code, body = fetch_html(api, data=json.dumps(dict(nodes=nodes)))
     if code != 200:
         print "code %s , cannot register_nodes" % str(code)
         logging.info("code %s , cannot register_nodes" % str(code))
         return None
     return body
Exemple #6
0
 def new_transaction(self):
     api = "http://%s:%d/api/blockchain/new/transaction" % (settings.host,
                                                            settings.port)
     data = json.dumps(
         dict(sender_address=self.sender_addr,
              recipient_address=self.receive_addr,
              value=self.money,
              signature=self.get_trade_sign()))
     code, body = fetch_html(url=api, data=data)
     if code != 200:
         print "code %s , cannot solve consensus" % str(code)
         logging.info("code %s , cannot solve consensus" % str(code))
         return None
     return body