CryptoFly.us | CRYPTOCURRENCY BITCOIN SHIRTS CLOTHING APPAREL HATS

CRYPTO NEWS

How a single-strategy crypto algorithm turned $100 into $36,205 in 10 months

Warren Buffett said that “What we learn from history, is that people don’t learn from history.” Crypto traders can change that.

Efficient way to save and retrieve hash in blockchain

I am learning Ethereum using Geth. I have a private blockchain and I am saving hashes through a REST API (python web service). I have readed I can save hash values using maps (mapping data type) and using logs. I am using the logs option and it works fine, but I want to know if::Listen

I am learning Ethereum using Geth. I have a private blockchain and I am saving hashes through a REST API (python web service). I have readed I can save hash values using maps (mapping data type) and using logs. I am using the logs option and it works fine, but I want to know if it is the most efficient way, or if I should use a map or other kind of variable (like a string or byte array). I need to save millions of hashes (about 1 per second) so I am worried about the long-term scalability, mainly related to the search. By now I have a service saveHash(string hexHashValue) returning the transaction hash, and a service verifyHash(string hexHashValue, string transactionHash).

In python using web3.py I have this functions, I don’t now if this can be improved, if using a map I can save millions of values in a better way or if I can find a specific string value in the contract using other methods. So my question is if the best way is logs, maps, strings or if the difference is trivial.

The contract:

pragma solidity ^0.5.0;  contract HashSave {                       event log_current_hash(bytes hashArg);     constructor() public {                           }     function set_hash(bytes memory objectHash) public {        emit log_current_hash(objectHash);    } } 

My current test methods using logs (event log_current_hash):

def save_new_hash(hash_bytes):     tx_hash = contract_instance.functions.set_hash(hash_bytes).transact()        log_test_file=open("hash_logs_simplified.txt","a")     log_test_file.write("Hash: 0x%s Tx: %srn" % (hash_bytes.hex(), tx_hash.hex()))     log_test_file.close()         return tx_hash.hex()   def check_transaction_exists(tx_hex_hash, obj_hash_bytes):     try:         tx_data = w3.eth.getTransaction(tx_hex_hash)         if tx_data is not None:             print("Transaction is in the blockchain")             if find_obj_hash_in_transaction(tx_data.blockNumber, obj_hash_bytes) is True:                 return "Data validated ok"             else:                 return "Data is not valid"     except Exception:         return "Transaction does't exists"   def find_obj_hash_in_transaction(block_num, obj_hash_bytes):     hash_filter = contract_instance.events.log_current_hash.createFilter(fromBlock=block_num, toBlock=block_num,                                                                        argument_filters={'hashArg': obj_hash_bytes})     if hash_filter is None:         return False     hash_events = hash_filter.get_all_entries()     if len(hash_events) > 0:         return True     else:         return False 

How a single-strategy crypto algorithm turned $100 into $36,205 in 10 months

Shopping cart
There are no products in the cart!
Continue shopping
0