def listen_for_input(self): waiting_for_input = True while waiting_for_input: print('Please choose') print('1: Add a new transaction value') print('2: Mine a new block') print('3: Output the blockchain blocks') print('4: Check transaction validity') # print('h: Manipulate the chain') print('q: Quit') user_choice = self.get_user_choice() if user_choice == '1': tx_data = self.get_transaction_value() recipient, amount = tx_data if self.blockchain.add_transaction(recipient, self.id, amount=amount): print('Added transaction!') else: print('Transaction failed!') print(self.blockchain.open_transactions) elif user_choice == '2': self.blockchain.mine_block() elif user_choice == '3': self.print_blockchain_elements() elif user_choice == '4': v = Verification() if v.verify_transactions(self.blockchain.open_transactions, self.blockchain.get_balance): print('All transactions are valid') else: print('There are invalid transactions') # elif user_choice == 'h': # if len(blockchain) >= 1: # blockchain[0] = { # 'previous_hash': '', # 'index': 0, # 'transactions': [{ # 'sender': 'Chris', # 'recipient': 'Will', # 'amount': 100.0 # }] # } elif user_choice == 'q': waiting_for_input = False else: print('Input was invalid, please pick a value from the list!') v = Verification() if not v.verify_chain(self.blockchain.chain): self.print_blockchain_elements() print('Invalid blockchain!') break print('Balance of {}: {:6.2f}'.format( self.id, self.blockchain.get_balance())) else: print('User left!') print('Done!')
def listen_for_input(self): awaiting_input = True while awaiting_input: print("Please choose:") print("1: Add a new transaction value") print("2: Mine a new block") print("3: Output the blockchain blocks") print("4: Check transaction validity") print("q: Quit") user_choice = self.get_user_choice() if user_choice == "1": tx_data = self.get_transaction_value() # one possibility is to unpack the tuple by following where the first element of the tuple will be assigned to the first variable (recipient): recipient, amount = tx_data # second possibility is to call the respective elements directly as argument as following: # add_transaction(owner, tx_data[0], tx_data[1]) # skip the optional sender argument my having a named argument of amount #I can check it like that with if since add_transaction returns either True or False if self.blockchain.add_transaction(recipient, self.id, amount=amount): print("Successfully added a transaction!") else: print("Transaction failed!") print(self.blockchain.open_transactions) elif user_choice == "2": #reset the block when successful mined since the transactions are then already processed and shouldn't be processed again self.blockchain.mine_block() elif user_choice == "3": self.print_blockchain_output() elif user_choice == "4": verifier = Verification() if verifier.verify_transactions( self.blockchain.open_transactions, self.blockchain.get_balance): print('All transactions are valid') else: print('There are invalid transactions') elif user_choice == "q": awaiting_input = False else: print( "Input was invalid, please pick one of the values 1 or 2.") """ Check if results of verify_chain (from the returned is_valid) is not True --> because "if verify_chain()" would check if True, which we would need if we want to continue, but here we want to have the case that in case it's false we want to exit the loop """ verifier = Verification() if not verifier.verify_chain(self.blockchain.chain): self.print_blockchain_output() print("Invalid blockchain!") break print('Balance of {}:{:6.2f}'.format( self.id, self.blockchain.get_balance())) print("done!")
def listen_for_input(self): waiting_for_input = True # A while loop for the user input interface # It's a loop that exits once waiting_for_input becomes False or when break is called while waiting_for_input: print('Please choose') print('1: Add a new transaction value') print('2: Mine a new block') print('3: Output the blockchain blocks') print('4: Check transaction validity') print('q: Quit') user_choice = self.get_user_choice() if user_choice == '1': tx_data = self.get_transaction_value() recipient, amount = tx_data # Add the transaction amount to the blockchain if self.blockchain.add_transaction(recipient, self.id, amount=amount): print('Added transaction!') else: print('Transaction failed!') print(self.blockchain.open_transactions) elif user_choice == '2': self.blockchain.mine_block() elif user_choice == '3': self.print_blockchain_elements() elif user_choice == '4': verifier = Verification() if verifier.verify_transactions( self.blockchain.open_transactions, self.blockchain.get_balance): print('All transactions are valid') else: print('There are invalid transactions') elif user_choice == 'q': # This will lead to the loop to exist because it's running condition becomes False waiting_for_input = False else: print('Input was invalid, please pick a value from the list!') verifier = Verification() if not verifier.verify_chain(self.blockchain.chain): self.print_blockchain_elements() print('Invalid blockchain!') # Break out of the loop break print('Balance of {}: {:6.2f}'.format( self.id, self.blockchain.get_balance())) else: print('User left!') print('Done!')
def start(self): self.bareSignalsLock = threading.Lock() self.signalsLock = threading.Lock() self.bareSignals = [] self.signals = [] turnThread = TurnListener(self.bareSignals, self.bareSignalsLock) #touchThread = TouchListener(self.bareSignals, self.bareSignalsLock) verificationThread = Verification(self.bareSignals, self.bareSignalsLock, self.signals, self.signalsLock) executionerThread = Executioner(self.signals, self.signalsLock) turnThread.start() #touchThread.start() verificationThread.start() executionerThread.start() #self.test1() #self.test2() turnThread.join() #touchThread.join() verificationThread.join() executionerThread.join() print('Controller wird beendet')
def add_transaction(self, sender, recipient, signature, amount=1, is_receiving=False): transaction = Transaction(sender, recipient, signature, amount) if Verification().checking_transaction(transaction=transaction, get_balance=self.get_balance): self.__open_transactions.append(transaction) self.save_data() if not is_receiving: for node in self.__peer_nodes: url = 'http://{}/broadcast-transaction'.format(node) try: response = requests.post(url, json={ 'sender': sender, 'recipient': recipient, 'signature': signature, 'amount': amount }) if response.status_code == 400 or response.status_code == 500: print('Transaction declined, needs resolving') return False except requests.ConnectionError: continue return True return False
def proof_of_work(self): last_block = self.chain[-1] last_hash = hash_block(last_block) proof = 0 v = Verification() while not v.valid_proof(self.open_transactions, last_hash, proof): proof += 1 return proof
def proof_of_work(): last_block = blockchain[-1] last_hash = hash_block(last_block) proof = 0 verifier = Verification() while not verifier.valid_proof(open_transactions, last_hash, proof): proof += 1 return proof
def listen_for_input(self): waiting_for_input = True while waiting_for_input: print('Please choose') print('1: Add a new transaction value') print('2: Mine a new block') print('3: Output the blockchain blocks') print('4: Check transactions validity') print('q: Quit') user_choice = self.get_user_choice() if user_choice == '1': tx_data = self.get_transaction_value() recipient, amount = tx_data if self.blockchain.add_transaction(recipient, self.id, amount=amount): print('Added transaction!') else: print('Transaction failed!') print(self.blockchain.open_transactions) elif user_choice == '2': self.blockchain.mine_block() elif user_choice == '3': self.print_blockchain_elements() elif user_choice == '4': verifier = Verification() if verifier.verify_transactions( self.blockchain.open_transactions, self.blockchain.get_balance): print('All transactions are valid') else: print('There are invalid transactions') elif user_choice == 'q': waiting_for_input = False else: print('Input was invalid, please pick a value from the list!') verifier = Verification() if not verifier.verify_chain(self.blockchain.chain): self.print_blockchain_elements() print('Invalid blockchain!') break print('Balance of {}: {:6.2f}'.format( self.id, self.blockchain.get_balance())) else: print('User left!') print('Done!')
def add_transaction(self, recipient, sender, amount=1.0): transaction = Transaction(sender, recipient, amount) verifier = Verification() if verifier.verify_transaction(transaction, self.get_balance): self.open_transactions.append(transaction) self.save_data() return True return False
def proof_of_work(self): """Increment the proof number""" last_block = self.chain[-1] last_hash = hash_block(last_block) proof = 0 verifier = Verification() while not verifier.valid_proof(self.open_transactions, last_hash, proof): proof += 1 return proof
def main(argv=None): verification = Verification() testCases = TestCases(verification) testCases.execute() verification.closeFile() verification.createExecutable() verification.executeFile() verification.debugFile() if not verification.isOk(): sys.exit(1)
def add_transaction(recipient, sender=owner, amount=1.0): transaction = Transaction(sender, recipient, amount) verifier = Verification() if verifier.verify_transaction(transaction, get_balance): open_transactions.append(transaction) participants.add(sender) participants.add(recipient) save_data() return True return False
def proof_of_work(self): """Generate a proof of work for the open transactions, the hash of the previous block and a random number (which is guessed until it fits).""" last_block = self.chain[-1] last_hash = hash_block(last_block) proof = 0 # Try different PoW numbers and return the first valid one verifier = Verification() while not verifier.valid_proof(self.open_transactions, last_hash, proof): proof += 1 return proof
def add_transaction(recipient, sender=owner, amount=1.0): """ Append a new value as well as the last blockchain value """ # transaction = { # 'sender': sender, # 'recipient': recipient, # 'amount': amount # } transaction = Transaction(sender, recipient, amount) verifier = Verification() if verifier.verify_transaction(transaction, get_balance): open_transactions.append(transaction) save_data() return True return False
def add_transaction(self, recipient, sender, amount=1.0): """ append a new value and last BC value to BC Arguments: :sender: the sender of the coins. :recipient: the recipient of the coins. :amount: the amount of coins sent with the transaction (default=1.0) """ transaction = Transaction(sender, recipient, amount) verifier = Verification() if verifier.verify_transaction(transaction, self.get_balance): self.open_transactions.append(transaction) #Benefit of sets is here that if we add another Sophia which is already in the set it will ignore that #Hence sets make sure that we have only unique values in the set self.save_data() return True return False
def add_transaction(self, recipient, sender, amount=1.0): """ Append a new value as well as the last blockchain value to the blockchain. Arguments: :sender: The sender of the coins. :recipient: The recipient of the coins. :amount: The amount of coins sent with the transaction (default = 1.0) """ # transaction = { # 'sender': sender, # 'recipient': recipient, # 'amount': amount # } transaction = Transaction(sender, recipient, amount) verifier = Verification() if verifier.verify_transaction(transaction, self.get_balance): self.open_transactions.append(transaction) self.save_data() return True return False
def execute_detection_news_stance(news): detect_news = Verification() search_object = Search() related_object = search_object.search_input(keyword=news) # print(related_object) fa, re = 0, 0 fa_count, re_count, probs = 0, 0, 0 for i in range(len(related_object)): # print(related_object[i]['snippet']) label, prob = detect_news.detect_fake_news_stance( [news], [related_object[i]['snippet']]) fa = fa + prob[0] re = re + prob[1] if prob[0] > prob[1]: fa_count += 1 elif prob[0] < prob[1]: re_count += 1 if fa_count > re_count: label = 'Fake' elif fa_count < re_count: label = 'Real' if fa > re: prob_label = 'Fake' elif fa < re: prob_label = 'Real' print(fa_count, fa, re_count, re, '\n\n') return label, prob_label
def main(): parameters = sys.argv[1:] #print(parameters) if parameters[0] == '-h' and len(parameters) == 1: print("四则运算生成程序文档:\n") print("参数:-r,指定数值范围\n") print(" -n,指定生成题目的数量,默认为10\n") print(" -h,查看帮助\n") print(" -e,指定读取题目文件\n") print(" -a,指定读取答案文件\n") else: if '-e' in parameters and '-a' in parameters: vis = Verification() exercisesfile, answersfile = parameters[ parameters.index('-e') + 1], parameters[parameters.index('-a') + 1] vis.verification(exercisesfile, answersfile) wr = Write2file() wr.writeGrade(vis.wrongsum, vis.correstsum, vis.wronglist, vis.correstlist) else: if '-r' not in parameters: print("请输入-r,指定数值范围!运行python xxx.py -h查看帮助") else: try: if '-n' in parameters: n = int(parameters[parameters.index('-n') + 1]) else: n = 10 r = int(parameters[parameters.index('-r') + 1]) generations = New_Arithmetic(r, n) generations.New_arithmetic() except Exception as e: print(e)
monitor = args.Monitor verification = args.Verification report = args.Report if not (monitor and verification and report): cprint('Please provide ' + monitor_name + ', ' + verification_name + ' and ' + report_name, COLOR_INFO) exit() if not is_asset_exists(monitor, True, monitor_name): exit() if not is_outside_monitor(monitor, verification, verification_name): exit() if not is_outside_monitor(monitor, report, report_name): exit() if args.i and args.v: cprint('Initialization and Verification can not perform together', COLOR_ERROR) elif args.i: file_check(verification, verification_name, True) file_check(report, report_name, True) if not is_hash_supported(args.hash): exit() exec_initialization(monitor=monitor, verification=verification, report=report) cprint('Initialization mode completed', COLOR_SUCCESS) elif args.v: file_check(verification, verification_name, False) ver = Verification(monitor=monitor, verification=verification, report=report) ver.execute() cprint('Verification mode completed', COLOR_SUCCESS)
if add_transaction(recipient, amount=amount): print('Added Transactoin.') else: print('Transaction failed.') print(open_transactions) elif user_choice == '2': if mine_block(): open_transactions = [] save_data() elif user_choice == '3': print_blockchain_elements() elif user_choice == '4': verifier = Verification() if verifier.verify_transactions(open_transactions, get_balance): print('All transactions are valid.') else: print('There are invalid transactions.') elif user_choice == 'q': waiting_for_input = False else: print('Input was invalid, please pick a value from the list!') verifier = Verification() if not verifier.verify_chain(blockchain): print_blockchain_elements() print('Blockchain no longer valid') break
def __init__(self): self.userVer=UserviewVer() self.imagess = Verification()
from flask import Flask, request, jsonify, json from algorithm import Algorithm from remedies import Remedies from verification import Verification import numpy as np x = [] c = Verification() x.append('spinning_movements') x.append('loss_of_balance') x.append('unsteadiness') x.append('nausea') #x.append('continuous_sneezing') print(c.predict(x)) print(np.random.uniform(0.8, 0.99))
def verify_booking(self, booking_data): booking = FareHarborService().post_verify_booking(booking_data) return Verification(booking)