Example #1
0
def push(data):
    print("Pushing...")
    txhash = embed_data(to_embed=data,
             api_key=key,
             data_is_hex=True,
             coin_symbol='btc-testnet')['hash']

    return txhash
 def add_to_blockchain(self, data_value):
     try:
         response = embed_data(to_embed=data_value, api_key=blockcypher_token, data_is_hex=True,
                               coin_symbol=config.get_coin_network())
         transaction_hash = response['hash']
         return transaction_hash
     except requests.ConnectionError as e:
         self.logger.exception("Failed to update account nonce %s" % e.message)
         return None
Example #3
0
 def register_block(self, new_block_id: int, txs_hashes: list):
     # saving root_hash in blockchain
     if len(txs_hashes) == 0:
         return None
     tree = MerkleTree([hash[1] for hash in txs_hashes])
     root_hash = tree.calc_root_hash()
     blockchain_tx_hash = None
     try:
         blockchain_tx_hash = embed_data(to_embed=root_hash, api_key=self.key)['hash']
         db.save_block(new_block_id, root_hash, blockchain_tx_hash, txs_hashes)
     except Exception as e:
         print(e)
     finally:
         return blockchain_tx_hash
Example #4
0
 def journal(self, merkle_root):
     try:
         data = embed_data(to_embed=merkle_root,
                           api_key=settings.BLOCKCYPHER_API_TOKEN,
                           coin_symbol=settings.CHAIN)
         if isinstance(data, dict):
             self.logger.info('[PoE data]:{}'.format(data))
             return data.get("hash", "")
         else:
             self.logger.error("Type of data:".format(type(data)))
             return None
     except Exception as e:
         self.logger.error(
             "[PoE ERROR] Error returning hash from embed data, Error :{}, type({})"
             .format(e, type(e)))