from hashlib import blake2b
def method_number(name):
name = '1|' + name
hash = blake2b(name.encode('ascii'), digest_size=64)
digest = hash.digest()
while digest:
chunk = digest[:4]
num = int.from_bytes(chunk, byteorder='big')
if num >= 1<<24:
return num
digest = digest[4:]
raise Exception("Method ID could not be determined, please change it")
methods = ['Name', 'Symbol', 'TotalSupply', 'BalanceOf', 'Allowance', 'IncreaseAllowance',
'DecreaseAllowance', 'RevokeAllowance', 'Burn', 'TransferFrom', 'Transfer', 'Mint']
for method in methods:
num = method_number(method)
print(f'assert_eq!(method_hash!("{method}"), 0x{num:08x});')