区块链本质上是一个去中心化的数据库。
The blockchain system verifies all data generated during the period every 10 minutes(such as transaction records and records of when the block was edited or created),并将这些数据储存在一个新的区块上,这个区块会与前一个区块连接,从而形成一根链条。每个区块都必须包含前一区块的相关信息才能生效。
from web3.auto.infura.kovan import w3
from contract import CalSelector
#bytes4(keccak256('isApprovedForAll(address,address)'))==0xe985e9c5
func='isApprovedForAll(address,address)'
#0x70a08231^0x6352211e^0x095ea7b3^0x081812fc^
#0xa22cb465^0xe985e9c^0x23b872dd^0x42842e0e^0xb88d4fde==0x80ac58cd
selectors=[
0x70a08231,
0x6352211e,
0x095ea7b3,
0x081812fc,
0xa22cb465,
0xe985e9c5,
0x23b872dd,
0x42842e0e,
0xb88d4fde
]
def calSelectorByPython(_func):
result=w3.keccak(text=_func)
selector=(w3.toHex(result))[:10]
return selector
def calSelectorBySolidity(_func):
selector=CalSelector.functions.getSelector(_func).call()
return w3.toHex(selector)
def calSupportedInterfaceByPython(_selectors):
result=int('0x00000000',16)
for selector in _selectors:
result=result^selector
return w3.toHex(result)
def calSupportedInterfaceBySolidity(_selectors):
_param=[w3.toBytes(selector)for selector in _selectors]
supported_interface=CalSelector.functions.getSupportedInterface(_param).call()
return w3.toHex(supported_interface)
if name=="main":
print(calSelectorByPython(func))
print(calSelectorBySolidity(func))
print('-------------------------')
print(calSupportedInterfaceByPython(selectors))
print(calSupportedInterfaceBySolidity(selectors))