Solidity:tx.origin==address1不匹配,即使两个地址相同



我正在尝试检查智能合约是否由特定地址发送交易,但下面提到的一些方法在Remix IDE上是如何工作的,但当使用python部署合约时失败了。以下是智能合约:

pragma solidity ^0.4.24;
contract ethersend {
address vin;
address awa;
address test;

function say(address address1, address address2) public {
test = tx.origin;
vin = address1;
awa = address2;
if(tx.origin != address1){
revert("Error Say");
}
else
{
revert("Hurray Say");
}
}

function speak(address address1, address address2) public {
test = tx.origin;
vin = address1;
awa = address2;
require(tx.origin == address1,"Error Speak");
revert("Hurray Speak");
}

}

////////////////////////////////////////////////////////////////////////////////////////////////下面是python代码:

def registerStation1():
print("n***********************************************************************************************************")
print("Test registerStation Method of Smart Contract")
print("***********************************************************************************************************n")
# call transactional method
#function registerStation(address stationAddress, address ownerAddress, string memory pwd, string memory stationDetails, string memory location, string memory availability,uint priceRate, uint rating, uint ratedby)
ownerAddress =  "0x9E498002E0e6f7b8208941cF17611de82b64Fec1" #MetaMask Third Account
ownerPrivateKey = ""
contract_func1 = contract.functions.speak(ownerAddress, "0xf886D7306336007136D87398B1Ceb4AE194949D2")
try:
transaction = contract_func1.buildTransaction()
nonce = w3.eth.getTransactionCount(ownerAddress)
transaction['nonce'] = nonce
#print(transaction)
signed_Transaction = w3.eth.account.signTransaction(transaction, ownerPrivateKey);
txn_hash = w3.eth.sendRawTransaction(signed_Transaction.rawTransaction);
print('txn_hash={} waiting for receipt..'.format(txn_hash.hex()))
tx_receipt = w3.eth.waitForTransactionReceipt(txn_hash, timeout=240)
greeting_Event = contract.events.errorLog()
result = greeting_Event.processReceipt(tx_receipt) # Modification
print(result[0]['args'])
print("Receipt accepted. gasUsed={gasUsed} blockNumber={blockNumber}". format(**tx_receipt))
except Exception as err:
print("Exception Occured: ",err)
#raise Exception(err)
print("n***********************************************************************************************************")
print("Test registerStation Method End")
print("***********************************************************************************************************n")

registerStation1()

错误:revert("Error Say"(revert("Error Speak"(;

尝试返回tx.Origin和address1变量以检查错误。它在我的安全帽测试环境中运行得很好。

最新更新