【发布时间】:2019-12-26 00:17:35
【问题描述】:
我正在尝试检测函数调用是否被还原,我总是得到事务哈希并且永远不会失败。
这个错误是针对 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");
如果不成功,它应该恢复并引发错误,但我总是收到没有错误的事务哈希
【问题讨论】:
标签: python-3.x blockchain solidity web3