def execute_pull_outbound_oracle(): r"""Wrapps the evalution logic for the pull outbound oracle. Note that we always retrieve the same state such that this is not a varying factor, and hence it can not influence the performance. This is without loss of generality. """ pull_outbound_oracle = PullOutboundOracle( public_address=config.PUBLIC_ADDRESS, private_address=config.PRIVATE_ADDRESS, smart_contract_address=config.ARRIVAL_SMART_CONTRACT_ADDRESS, web_socket=config.WEB_SOCKET, abi=config.ARRIVAL_ABI) start_timestamp = get_unix_timestamp() retrieved_state = pull_outbound_oracle.retrieve_state_from_transaction_hash( transaction_hash= "0xf15753a9ef3d83e6d9974a936795039605449cdf2530545c8b339deaa6a7641f") end_timestamp = get_unix_timestamp() save_to_mongo( db="pullOutboundOracle", collection="arrival", document={ "start_timestamp": start_timestamp, "end_timestamp": end_timestamp, "transaction_hash": "0xf15753a9ef3d83e6d9974a936795039605449cdf2530545c8b339deaa6a7641f", "state": retrieved_state[1] }) print(retrieved_state)
def process_new_event(self, new_event): verify_customer_received_timestamp = get_unix_timestamp() # Respond to event via transaction self.count += 1 self.state = { "is_verified": True, "order_ID": self.count, "error_code": 0 } self.encoded_abi = self.encoded_abi_order(self.state) start_timestamp = get_unix_timestamp() transaction_hash = web3.eth.to_hex(self.send_raw_transaction()) end_timestamp = get_unix_timestamp() save_to_mongo(db="pullInboundOracle", collection="order", document={ "transaction_hash": transaction_hash, "order": self.state, "order_start_timestamp": start_timestamp, "order_end_timestamp": end_timestamp, "verify_customer": new_event, "verify_customer_received_timestamp": verify_customer_received_timestamp }) print( f'(Order) Timestamp: {convert_unix_timesamp_to_datetime(get_unix_timestamp())} | Transaction hash: {transaction_hash} |' )
def execute_push_inbound_oracle(): r""" Sends a transaction to the smart contract which triggers an event, which then triggers the pull inbound oracle. """ random_verify_customer_state = RandomVerifyCustomerGenerator( ).get_random_verify_customer() push_inbound_oracle = VerifyCustomerState( verify_customer=random_verify_customer_state, public_address=config.PUBLIC_ADDRESS, private_address=config.PRIVATE_ADDRESS, smart_contract_address=config.CUSTOMER_SMART_CONTRACT_ADDRESS_TWO, abi=config.CUSTOMER_ABI, web_socket=config.WEB_SOCKET) start_timestamp = get_unix_timestamp() transaction_hash = web3.eth.to_hex( push_inbound_oracle.send_raw_transaction()) end_timestamp = get_unix_timestamp() save_to_mongo(db="pullInboundOracle", collection="verifyCustomer", document={ "transaction_hash": transaction_hash, "start_timestamp": start_timestamp, "end_timestamp": end_timestamp, "document": random_verify_customer_state }) print(f'(Verify Customer) Timestamp: {convert_unix_timesamp_to_datetime(get_unix_timestamp())} | Transaction hash: {transaction_hash} |'\ f'Verify Customer: {random_verify_customer_state}')
def execute_push_inbound_oracle(): r"""Wrapps the logic that is necessary to execute the push inbound oracle and the associated measuring logic. The measuring logic includes taking timestamps and storing the generatred random arrival states with the timestamps into MongoDB. """ random_arrival_state = RandomArrivalGenerator().get_random_arrival() push_inbound_oracle = ArrivalState( public_address=config.PUBLIC_ADDRESS, private_address=config.PRIVATE_ADDRESS, smart_contract_address=config.ARRIVAL_SMART_CONTRACT_ADDRESS, web_socket=config.WEB_SOCKET, abi=config.ARRIVAL_ABI, arrival=random_arrival_state) start_timestamp = get_unix_timestamp() transaction_hash = web3.eth.to_hex( push_inbound_oracle.send_raw_transaction()) end_timestamp = get_unix_timestamp() save_to_mongo(db="pushInboundOracle", collection="arrival", document={ "transaction_hash": transaction_hash, "start_timestamp": start_timestamp, "end_timestamp": end_timestamp, "document": push_inbound_oracle.state }) return transaction_hash, push_inbound_oracle.state
def process_new_event(self, new_event): received_timestamp = get_unix_timestamp() save_to_mongo(db="pushOutboundOracle", collection="arrival", document={ "received_timestamp": received_timestamp, "event": new_event })
def batch_processing(sc): try: utils.copy("HDFS/new/", "HDFS/master/") texts = sc.textFile("HDFS/master/*/*") if texts: word_count = get_word_count(texts) utils.save_to_mongo(word_count, database="kschool", collection="batch_view") except OSError: print "New directory is empty..."