我正在尝试检测函数调用是否已还原,我一直在获取事务哈希并且从未失败。
此错误是针对Web3.py的,该Web3.py不提供带事务处理的回调函数,在web3.js中启用了此将来。
def addParticipants(request):
web3 = Web3(HTTPProvider(settings.Blockchain_IP_address, request_kwargs={'timeout': 60}))
project_address = '0x93aeD90401a182247EE28848229531bC78053cd6'
project = web3.eth.contract(address=project_address,
abi=Project_sol.abi,
bytecode=Project_sol.bytecode)
func_to_call = 'addParticipant'
addParticipant = project.functions[func_to_call]
result = addParticipant(settings.ADMIN_ACCOUNT,0).transact( {'from': settings.ADMIN_ACCOUNT, 'gasLimit': '6000000', 'gasPrice': '0', 'gas': 600000})
web3.eth.waitForTransactionReceipt(result)
print(result)
合同功能
function addParticipant(address _Participant, uint _weight)public isOwner returns (bool) {
require(_weight!=0,"weight cannot be null");
require(status,"this Donation is closed");
Participants[_Participant].weight = _weight;
Participants[_Participant].status = true;
ParticipantsIndex[ParticipantsIndexSize] = _Participant;
ParticipantsIndexSize++;
emit ParticipantAction(_Participant, 'added');
return true;
}
我必须测试,
require(_weight!=0,"weight cannot be null");
require(status,"this Donation is closed");
如果没有成功,它应该还原并引发错误,但是我总是收到没有错误的事务哈希
您应检查交易收据。
result = addParticipant(settings.ADMIN_ACCOUNT,0).transact( {'from': settings.ADMIN_ACCOUNT, 'gasLimit': '6000000', 'gasPrice': '0', 'gas': 600000})
receipt = web3.eth.waitForTransactionReceipt(result)
print(receipt['status'])
如果status
字段为0
,则表示事务已还原。