def parseSamples(path, limit): print " " print "......................... START .........................." num = 0 for dirpath, subdirs, files in os.walk(path): for filename in files: if filename[0] != '.': num += 1 name = os.path.join(dirpath, filename) f = io.open(name, 'rU', encoding='utf-8', errors='ignore') text = f.read() if num < limit: k = contract.Contract(dirpath, filename, text) k.output_filename_header(num) k.output_basic_stats() k.extract_parties() k.output_parties() # k.output_parties_rule_data() print " \n " # output set of tokens which includes 5 tokens before # and after the first occurrence of the token "agreement" # print k.get_token_in_context(k.find_token('agreement'), 8) # k.test() print ".......................... END ..........................." print " "
def dict2Contract(d): conID = d['Id'] name = d['Name'] underlying = d['Name'].split()[0] if underlying == 'Dow': K = contract.findDowStrike(name) else: K = float(d['Name'].split('$')[1].split('/')[0]) expiry = time.strptime(d['EventDate'], "%Y-%m-%dT%H:%M:%S") return contract.Contract(conID, name, underlying, K, expiry)
def conjunction(contracts): """Takes the conjunction of a list of contracts Args: contracts: a list of contract objects Returns: A contract object that is the conjunction of whole list """ if len(contracts) == 1: return contracts[0] else: conj = contract.Contract() conj.add_name(contracts[0].name + "_conj_" + contracts[1].name) conj.add_variables(_merge(contracts[0].variables, contracts[1].variables)) conj.add_assumption(_or(contracts[0].get_assumptions(), contracts[1].get_assumptions())) conj.add_guarantee(_and(contracts[0].get_guarantees(), contracts[1].get_guarantees())) contracts.pop(0) #remove first element in list contracts[0] = conj #replace "new" first element with conj return conjunction(contracts)
def Debugger(self, input): """ A debug function that checks and handles input """ if (input[0] == "sh"): self.show(input[1]) if (input[0] == "ac"): # Add a contract if input[1] == "a": newC = contract.Contract(self, input[3:]) msg = message.Message("ac", newC, self.agents[int(input[2])]) self.agents[int(input[2])].Notify(self, msg) self.agents[int(input[2])].Run() else: newC = Contract(self, input) self.Contracts.append(newC) if input[0] == "fc": # Cheat-finish a contract if input[1] == "a": self.agents[int(input[2])].FinishCtr() del self.Contracts[int(input[3])]
def composition(contracts): """Perform a composition operation on a list of contracts Args: contracts: a list of contract objects Returns: A contract object that is the composition of whole list """ if len(contracts) == 1: return contracts[0] else: comp = contract.Contract() comp.add_name(contracts[0].name + '_comp_' + contracts[1].name) comp.add_variables(_merge(contracts[0].variables, contracts[1].variables)) comp.add_assumption(_or(_and(contracts[0].get_assumptions(), contracts[1].get_assumptions()), _inv(_and(contracts[0].get_guarantees(), contracts[1].get_guarantees())))) comp.add_guarantee(_and(contracts[0].get_guarantees(), contracts[1].get_guarantees())) contracts.pop(0) #remove first element in list contracts[0] = comp #replace "new" first element with conj return composition(contracts)
def finalize_on_contract(contr, finalize_sig, finalization_filter): v, r, s = utils.signature_from_hex_to_solidity(finalize_sig) contr.functions.finalize(v, r, s).transact() while True: event = finalization_filter.get_new_entries() if event: print("finalized on contract") break web3 = Web3(HTTPProvider('http://localhost:8545')) accounts = web3.eth.accounts web3.eth.defaultAccount = accounts[0] plasma_contract = contract.Contract(web3) contr = plasma_contract.deploy_contract() block_init = web3.eth.getBlock("latest") deposit_filter = contr.events.Deposit.createFilter(fromBlock='latest') finalization_filter = contr.events.Finalization.createFilter( fromBlock='latest') start_exit_filter = contr.events.ExitStart.createFilter(fromBlock='latest') exits_finalized_filter = contr.events.ExitsFinalized.createFilter( fromBlock='latest') with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) print("Requesting Enclave initialization") s.sendall( to_bytes(text=create_enclave_initialization( block_init, plasma_contract.get_abi(), plasma_contract.get_address())))