Ejemplo n.º 1
0
def put_connection(data_type, key, item_key, item_value):
    if isinstance(item_value, dict):
        value = crypto.pickle_hash(item_value).decode(errors='ignore')
        write(item_value, item_value.pop('data_type'), value)
        item_value = value
    put('+'.join(['connection', data_type, item_key]), key, item_value)
    put('+'.join(['connection', item_key, data_type]), item_value, key)
Ejemplo n.º 2
0
 def verify():
     updated_signature = transaction_dict.pop('signature')
     transaction_dict['signature'] = None
     if not verifier(crypto.pickle_hash(transaction_dict), updated_signature):
         transaction_dict['signature'] = updated_signature
         return False
     transaction_dict['signature'] = updated_signature
     try:
         if not database.read('wallet', wallet_in) >= amount:
             return False
     except TypeError:
         return False
     tx_hash = crypto.pickle_hash(transaction_dict).decode(errors='ignore')
     if database.read('transaction', tx_hash) is not None:
         return False
     validated[0] = True
     transaction_hash[0] = tx_hash
     return True
Ejemplo n.º 3
0
 def _verify():
     if not check_hash(crypto.pickle_hash(header)):
         print("H1")
         return False
     if header['nonce'] > nonce_maximum:
         return False
     header['signature'] = None
     if not verifier(crypto.pickle_hash(header), signature):
         header['signature'] = signature
         print("H2")
         return False
     header['signature'] = signature
     for tx in transactions:
         if not isinstance(tx, dict):
             raise UserWarning
         if not transaction(**tx)[1]():
             print("H3")
             return False
     return True
Ejemplo n.º 4
0
 def store():
     if verify():
         database.write(header, 'block',
                        crypto.pickle_hash(header).decode(errors='ignore'))
         for tx in transactions:
             transaction(**tx)[2]()
         block_size = sys.getsizeof(pickle.dumps(header, protocol=4))
         old_mean = interface.add_mean_block_size(block_size)
         reward = config.reward_function(block_index, block_size, old_mean)
         database.add('wallet', wallet, reward)
         height = database.read('block_height', 'main')
         if block_index == height:  # < implies insertion | > does not exist
             database.add('block_height', 'main', 1)
         return
     return False
Ejemplo n.º 5
0
 def sign():
     header['signature'] = None
     header['signature'] = signer(crypto.pickle_hash(header))
Ejemplo n.º 6
0
 def sign():
     transaction_dict['signature'] = signer(crypto.pickle_hash(transaction_dict))
Ejemplo n.º 7
0
 def random_hash():
     header['nonce'] += 1
     sign()
     return crypto.pickle_hash(header)