来自solc的compile_source无法在Windows10上编译

问题描述

这是我要运行的代码

def投票(request,question_id): bashCommand =“复制unique_sig_empty unique_sig” + str(question_id) 进程= subprocess.Popen(bashCommand.split(),shell = True,stdout = subprocess.PIPE) 输出错误= process.communicate() 列印(question_id) 问题= get_object_or_404(问题,pk = question_id) _commit_end = question.pub_date #打印(类型(日期)) #print(int(_commit_end))

commit_end = int((_commit_end.replace(tzinfo=None) - datetime.datetime(1970,1,1).replace(tzinfo=None)).total_seconds())

# print(commit_end)
# start of contract work

r=requests.get("http://127.0.0.1:8000/polls/"+str(question_id))
print(r.content)
resp=str(r.content).split('\\n')
print("before strip")
print(resp)
resp=[x.strip() for x in resp]

print("before after")
print(resp)
choices=[]
for i in resp:
    if('label' in i):
        temp=""
        fl=0
        for j in range(1,len(i)):
            if(i[j]=='>'):
                fl=1
                continue
            if(i[j]=='<'):
                fl=0
            if(fl==1):
                temp+=i[j]
        choices.append(temp)


http_provider = HTTPProvider('http://localhost:8545')
eth_provider = Web3(http_provider).eth

default_account = eth_provider.accounts[0]
transaction_details = {
    'from': default_account,}
def get_contract_source(file_name):
    with open(file_name) as f:
        return f.read()

contract_source_code = get_contract_source("polls/poll.sol")
compiled_code = compile_source(contract_source_code)


            

# store contract_name so we keep our code DRY
contract_name = 'pollBooth'

contract_bytecode = compiled_code[f'<stdin>:{contract_name}']['bin']
contract_abi = compiled_code[f'<stdin>:{contract_name}']['abi']

contract_factory = eth_provider.contract(
    abi=contract_abi,bytecode=contract_bytecode,)

facultylist = pickle.load(open('conf/faculty.pub','rb'))

contract_constructor = contract_factory.constructor(len(choices),len(facultylist),40,70)

transaction_hash = contract_constructor.transact(transaction_details)

transaction_receipt = eth_provider.getTransactionReceipt(transaction_hash)
contract_address = transaction_receipt['contractAddress']

contract_instance = eth_provider.contract(
    abi=contract_abi,address=contract_address,ContractFactoryClass=ConciseContract,)

with open ("conf/"+ str(question_id) + "contract_abi",'wb') as handle:
    pickle.dump(contract_abi,handle,protocol=3)

with open ("conf/"+ str(question_id) + "contract_address",'wb') as handle:
    pickle.dump(contract_address,protocol=3)

with open ("conf/"+ str(question_id) + "ConciseContract",'wb') as handle:
    pickle.dump(ConciseContract,protocol=3)

try:
    selected_choice = question.choice_set.get(pk=request.POST['choice'])
except (KeyError,Choice.DoesNotExist):
    # Redisplay the question voting form.
    return render(request,'polls/detail.html',{
        'question': question,'error_message': "Contract created.",})
else:
    selected_choice.Votes += 1
    selected_choice.save()
    # Always return an HttpResponseRedirect after successfully dealing
    # with POST data. This prevents data from being posted twice if a
    # user hits the Back button.
    return HttpResponseRedirect(reverse('polls:results',args=(question.id,)))

**在**上出现错误

def get_contract_source(file_name):
    with open(file_name) as f:
        return f.read()
contract_source_code = get_contract_source("polls/poll.sol")
compiled_code = compile_source(contract_source_code) 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)