def getinfo(name): info = get(name) fullname = getfullname(name) if info and new_enough(fullname, info): return info else: code = IMPORTP.sub(import_repl, open(fullname).read()) evm = '0x' + serpent.compile(code).encode('hex') sig = serpent.mk_signature(code) fullsig = serpent.mk_full_signature(code) address = RPC.eth_sendTransaction(sender=COINBASE, data=evm, gas=GAS) print Style.BRIGHT + "Waiting for " + name + " to get on chain..." check = RPC.eth_getCode(address)['result'] tries = 1 while check == '0x' and tries < TRIES: time.sleep(12) check = RPC.eth_getCode(address)['result'] tries += 1 if tries == TRIES and check == '0x': print ERROR, 'couldn\'t load contract to chain:', name print 'ABORTING' sys.exit(1) newinfo = {'addr':address, 'sig':sig, 'fullsig':fullsig, 'mtime':os.path.getmtime(fullname)} put(name, newinfo) return newinfo
def getinfo(name): info = get(name) fullname = getfullname(name) if info and new_enough(fullname, info): return info else: code = IMPORTP.sub(import_repl, open(fullname).read()) evm = '0x' + serpent.compile(code).encode('hex') sig = serpent.mk_signature(code) fullsig = serpent.mk_full_signature(code) address = RPC.eth_sendTransaction(sender=COINBASE, data=evm, gas=GAS) print Style.BRIGHT + "Waiting for " + name + " to get on chain..." check = RPC.eth_getCode(address)['result'] tries = 1 while check == '0x' and tries < TRIES: time.sleep(12) check = RPC.eth_getCode(address)['result'] tries += 1 if tries == TRIES and check == '0x': print ERROR, 'couldn\'t load contract to chain:', name print 'ABORTING' sys.exit(1) newinfo = { 'addr': address, 'sig': sig, 'fullsig': fullsig, 'mtime': os.path.getmtime(fullname) } put(name, newinfo) return newinfo
def compile(fullname): old_dir = os.getcwd() os.chdir(os.path.dirname(fullname)) global DB if IMPORTS: code = process_imports(fullname) else: code = process_externs(fullname) with open(fullname, 'w') as f: f.write(code) # old version of serpent # fullsig = json.loads(serpent.mk_full_signature(code)) fullsig = serpent.mk_full_signature(code) shortname = get_shortname(fullname) if 'WHITELIST' in code: print "SHITS GETTING WHITELISTED BITCH" whitelist_line = code.find('\n', code.find('WHITELIST')) prefixes = get_prefixes(fullname, fullsig) whitelist_code = WHITELIST_CODE.format(prefixes=prefixes) code = code[:whitelist_line + 1] + whitelist_code + code[whitelist_line + 1:] try: evm = '0x' + serpent.compile(code).encode('hex') except: traceback.print_exc() # print 'Code that broke everything:' # print code # print 'DB dump:' # print json.dumps(DB, indent=4, sort_keys=True) sys.exit(1) address = broadcast_code(evm, code, fullname) sig = serpent.mk_signature(code) # serpent makes the contract name in the sig "main" # if the code it compiles is in a string instead of a file. sig = sig.replace('main', shortname, 1) # Also, there is a serpent bug which can't handle multiple # return types in a function signature, which causes compilation # to fail. This is a workaround... sig = sig.replace(':,', ':_,').replace(':]', ':_]') DB[shortname] = { 'address': address, 'sig': sig, 'fullsig': fullsig, 'code': code.split('\n') } os.chdir(old_dir)
def compile(fullname): if USE_EXTERNS: new_code = translate_code_with_externs(fullname) else: new_code = translate_code_with_imports(fullname) print new_code evm = "0x" + serpent.compile(new_code).encode("hex") new_address = broadcast_code(evm) short_name = os.path.split(fullname)[-1][:-3] new_sig = serpent.mk_signature(new_code).replace("main", short_name, 1).replace(":,", ":_,").replace(":]", ":_]") fullsig = serpent.mk_full_signature(new_code) new_info = {"address": new_address, "sig": new_sig, "fullsig": fullsig} set_info(short_name, new_info)
def compile(fullname): old_dir = os.getcwd() os.chdir(os.path.dirname(fullname)) global DB if IMPORTS: code = process_imports(fullname) else: code = process_externs(fullname) with open(fullname, 'w') as f: f.write(code) # old version of serpent # fullsig = json.loads(serpent.mk_full_signature(code)) fullsig = serpent.mk_full_signature(code) shortname = get_shortname(fullname) if 'WHITELIST' in code: print "SHITS GETTING WHITELISTED BITCH" whitelist_line = code.find('\n', code.find('WHITELIST')) prefixes = get_prefixes(fullname, fullsig) whitelist_code = WHITELIST_CODE.format(prefixes=prefixes) code = code[:whitelist_line+1] + whitelist_code + code[whitelist_line+1:] try: evm = '0x' + serpent.compile(code).encode('hex') except: traceback.print_exc() # print 'Code that broke everything:' # print code # print 'DB dump:' # print json.dumps(DB, indent=4, sort_keys=True) sys.exit(1) address = broadcast_code(evm, code, fullname) sig = serpent.mk_signature(code) # serpent makes the contract name in the sig "main" # if the code it compiles is in a string instead of a file. sig = sig.replace('main', shortname, 1) # Also, there is a serpent bug which can't handle multiple # return types in a function signature, which causes compilation # to fail. This is a workaround... sig = sig.replace(':,', ':_,').replace(':]', ':_]') DB[shortname] = {'address':address, 'sig':sig, 'fullsig':fullsig, 'code':code.split('\n')} os.chdir(old_dir)
def compile(fullname): old_dir = os.getcwd() os.chdir(os.path.dirname(fullname)) global DB if IMPORTS: code = process_imports(fullname) else: code = process_externs(fullname) with open(fullname, "w") as f: f.write(code) fullsig = json.loads(serpent.mk_full_signature(code)) shortname = get_shortname(fullname) if "WHITELIST" in code: whitelist_line = code.find("\n", code.find("WHITELIST")) prefixes = get_prefixes(fullname, fullsig) whitelist_code = WHITELIST_CODE.format(prefixes=prefixes) code = code[: whitelist_line + 1] + whitelist_code + code[whitelist_line + 1 :] try: evm = "0x" + serpent.compile(code).encode("hex") except: traceback.print_exc() print "Code that broke everything:" print code print "DB dump:" print json.dumps(DB, indent=4, sort_keys=True) sys.exit(1) address = broadcast_code(evm, code, fullname) sig = serpent.mk_signature(code) # serpent makes the contract name in the sig "main" # if the code it compiles is in a string instead of a file. sig = sig.replace("main", shortname, 1) # Also, there is a serpent bug which can't handle multiple # return types in a function signature, which causes compilation # to fail. This is a workaround... sig = sig.replace(":,", ":_,").replace(":]", ":_]") DB[shortname] = {"address": address, "sig": sig, "fullsig": fullsig, "code": code.split("\n")} os.chdir(old_dir)
def parse_dependencies(self): """Separates code and import statements.""" for name in self.namespace: contract_info = self.namespace[name] path = contract_info['path'] source = open(path) stripped_code = [] dependencies = [] for line in source: if line.startswith('import'): parts = line.split(' ') dep_name = parts[1] code_alias = parts[3] dependency_address = self[dep_name]['address'] dependencies.append((code_alias, dependency_address)) else: stripped_code.append(line) stripped_code = '\n'.join(stripped_code) self.namespace[] yield stripped_code, dependencies, serpent.mk_signature(stripped_code)