Exemplo n.º 1
0
 def make_post(self, group_id, owner_id, data, post_key, proof_of_work_args):
 
     timestamp = ut.current_time()
 
     data_hash = ut.hash_function(data)
 
     request_string = ut.serialize_request(
             ['MAKE_POST', timestamp, self.node_name, group_id, owner_id, data_hash])
 
     post_id = ut.hash_function(request_string)
 
     post_signature = None
     if post_key != None:
         post_signature = post_key.sign(post_id)
 
     proof_of_work = None
     if proof_of_work_args != None:
         proof_of_work = ut.make_proof_of_work(proof_of_work_args, post_id)
 
     resp = self.client_raw.make_post(
             timestamp, self.node_name, group_id, owner_id,
             data_hash, post_id, data,
             post_signature, proof_of_work)[0]
 
     gen = (post_id, timestamp, data_hash, post_signature, proof_of_work)
 
     return resp, gen
Exemplo n.º 2
0
 def send_message(
         self, to_user, to_user_key_hash,
         from_user, from_key,
         message, proof_of_work_args):
 
     timestamp = ut.current_time()
 
     message_hash = ut.hash_function(message)
 
     from_user_key_hash = None
     if from_key != None:
         from_user_key_hash = from_key.public_key_hash
 
     request_string = ut.serialize_request(
             ['SEND_MESSAGE', timestamp, self.node_name,
              to_user, to_user_key_hash,
              from_user, from_user_key_hash,
              message_hash])
 
     message_id = ut.hash_function(request_string)
 
     from_signature = None
     if from_key != None:
         from_signature = from_key.sign(message_id)
 
     proof_of_work = None
     if proof_of_work_args != None:
         proof_of_work = ut.make_proof_of_work(proof_of_work_args, message_id)
 
     resp = self.client_raw.send_message(
             timestamp, self.node_name,
             to_user, to_user_key_hash,
             from_user, from_user_key_hash,
             message_hash,
             message_id, message,
             from_signature, proof_of_work)[0]
 
     return resp, (message_id, timestamp, message_hash, from_signature, proof_of_work)