import re import json import time import requests from harvest import Harvest harvester = Harvest() # ERC20 Transfer Only abiUrl1 = "https://raw.githubusercontent.com/tpmccallum/test_endpoint2/master/erc20_transfer_function_only_abi.txt" abiData1 = requests.get(abiUrl1).content abiData1JSON = json.loads(abiData1) theDeterministicHash1 = harvester.shaAnAbi(abiData1JSON) cleanedAndOrderedAbiText1 = harvester.cleanAndConvertAbiToText(abiData1JSON) data1 = {} data1['indexInProgress'] = "false" data1['epochOfLastUpdate'] = int(time.time()) data1['abi'] = cleanedAndOrderedAbiText1 harvester.es.index(index=harvester.abiIndex, id=theDeterministicHash1, body=data1) #v1 abiUrl1 = "https://raw.githubusercontent.com/CyberMiles/smart_contracts/master/FairPlay/v1/dapp/FairPlay.abi" abiData1 = requests.get(abiUrl1).content abiData1JSON = json.loads(abiData1) theDeterministicHash1 = harvester.shaAnAbi(abiData1JSON) cleanedAndOrderedAbiText1 = harvester.cleanAndConvertAbiToText(abiData1JSON)
import json import requests from harvest import Harvest harvester = Harvest() #BAT abiUrl = "http://api.etherscan.io/api?module=contract&action=getabi&address=0x0d8775f648430679a709e98d2b0cb6250d2887ef&format=raw" abiData = requests.get(abiUrl).content officialAbiJSON = json.loads(abiData) theDeterministicHash = harvester.shaAnAbi(officialAbiJSON) cleanedAndOrderedAbiText = harvester.cleanAndConvertAbiToText(officialAbiJSON) erc20Hashes = harvester.createUniqueAbiComparisons(json.loads(cleanedAndOrderedAbiText)) # print("\nThe original ABI is as follows:") # print(officialAbiJSON) # print("\nThe cleaned and ordered ABI is as follows:") # print(cleanedAndOrderedAbiText) # print("\nThe Sha3 of this ABI is as follows:") print(theDeterministicHash) # print("\nThe unique function hashes for this official ERC20 ABI are as follows:") # print(erc20Hashes) txReceipt = harvester.web3.eth.getTransactionReceipt("0xcceb1fd34dcc4b18defa4ff29d51a225b20af8ed179db37da72ec5d5a4e8d385") tx = harvester.web3.eth.getTransaction("0xcceb1fd34dcc4b18defa4ff29d51a225b20af8ed179db37da72ec5d5a4e8d385") #print("Transaction is as follows:") #print(tx) print(officialAbiJSON)
}, "uniqueAbiAndAddressHash": "0x54040994221542e1ce9fdfc9c7396d02de07a2b7df065865b8a404a5498c6fef" } ] }, "requiresUpdating": "yes", "quality": "50", "indexInProgress": "false" }''' sourceJSON = json.loads(source) #transferABI = '''[{"constant":true,"inputs":[],"name":"proxyType","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_masterCopy","type":"address"},{"name":"initializer","type":"bytes"},{"name":"funder","type":"address"},{"name":"paymentToken","type":"address"},{"name":"payment","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"}]''' transferABI = '''[{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]''' transferABIJSON = json.loads(transferABI) theDeterministicHash = harvester.shaAnAbi(transferABIJSON) cleanedAndOrderedAbiText = harvester.cleanAndConvertAbiToText(transferABIJSON) erc20Hashes = harvester.createUniqueAbiComparisons( json.loads(cleanedAndOrderedAbiText)) print("\nThe original ABI is as follows:") print(transferABIJSON) print("\nThe cleaned and ordered ABI is as follows:") print(cleanedAndOrderedAbiText) print("\nThe Sha3 of this ABI is as follows:") print(theDeterministicHash) print( "\nThe unique function hashes for this official ERC20 ABI are as follows:") print(erc20Hashes) harvester.abiCompatabilityUpdate(transferABIJSON, sourceJSON)
randomAbis = [] abiUrl = "https://raw.githubusercontent.com/tpmccallum/mixed_ordered_erc20_abis_for_testing/master/vanilla.txt" singleAbiString = requests.get(abiUrl).content singleAbiJSON = json.loads(singleAbiString) for i in range(20): string = randomizeAndConvertAbiToText(singleAbiJSON) randomAbis.append(string) outputHashes = [] print("Hashes of random ABIs") for rItem in randomAbis: hashToPrint = harvester.createHashFromString(rItem) print(hashToPrint) jsonAbi = json.loads(rItem) singleHash = harvester.shaAnAbi(jsonAbi) outputHashes.append(singleHash) print("Output hashes are as follows, these should all be exactly the same") print("Hashes of sorted ABIs ...") for singleHash in outputHashes: print(singleHash) # Output will look something like this # Hashes of random ABIs # 0x43064f4849beb02ce7998480bf90ee4dd4123782c6f409da4e800f8021d9cef6 # 0x8375c0a54cc9f59f1b8b4d3dc217100b26ff4be1f487d7fa0220638c47df77af # 0x58873a40bffb7101ec49f989e2c5dbf34a52a9e923aa09ca9aacf35880f42a91 # 0x8b7aa83fcfad46b2372161d6fbe40fda6fc45438d250b59db493f162bcd6b0b9 # 0xabe80b8b85acff2eb974259801bd046387cfd099fe7994c6965615eb83b60d3f # 0xffebfc7c425a8a83d2b3001244b25f50d653c27e2bb4fee67ff949a20b9d1755
import re import json import requests from harvest import Harvest harvester = Harvest() # RAW text of ABIs for sorting and hashing abiUrls = [] abiUrls.append( "https://raw.githubusercontent.com/tpmccallum/mixed_ordered_cmt_abis_for_testing/master/vanilla.txt" ) abiUrls.append( "https://raw.githubusercontent.com/tpmccallum/mixed_ordered_cmt_abis_for_testing/master/increaseApproval_inputs_reversed.txt" ) abiUrls.append( "https://raw.githubusercontent.com/tpmccallum/mixed_ordered_cmt_abis_for_testing/master/random.txt" ) outputHashes = [] for singleAbiUrl in abiUrls: print("Processing: " + singleAbiUrl) singleAbiString = requests.get(singleAbiUrl).content singleAbiJSON = json.loads(singleAbiString) singleHash = harvester.shaAnAbi(singleAbiJSON) outputHashes.append(singleHash) print("Output hashes are as follows, these should all be exactly the same") for singleHash in outputHashes: print(singleHash)
"indexed": false, "name": "value", "type": "uint256" } ], "name": "Transfer", "type": "event" } ] ''' officialBATAbi = '''[{"constant":true,"inputs":[],"name":"batFundDeposit","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"batFund","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"tokenExchangeRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"finalize","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"refund","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"tokenCreationCap","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"isFinalized","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"fundingEndBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"ethFundDeposit","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"createTokens","outputs":[],"payable":true,"type":"function"},{"constant":true,"inputs":[],"name":"tokenCreationMin","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"fundingStartBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"_ethFundDeposit","type":"address"},{"name":"_batFundDeposit","type":"address"},{"name":"_fundingStartBlock","type":"uint256"},{"name":"_fundingEndBlock","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"LogRefund","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"CreateBAT","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"}]''' #ERC20 officialAbiJSON = json.loads(officialERC20Abi) theDeterministicHash = harvester.shaAnAbi(officialAbiJSON) cleanedAndOrderedAbiText = harvester.cleanAndConvertAbiToText(officialAbiJSON) erc20Hashes = harvester.createUniqueAbiComparisons(json.loads(cleanedAndOrderedAbiText)) print("\nThe original ABI is as follows:") print(officialAbiJSON) print("\nThe cleaned and ordered ABI is as follows:") print(cleanedAndOrderedAbiText) print("\nThe Sha3 of this ABI is as follows:") print(theDeterministicHash) print("\nThe unique function hashes for this official ERC20 ABI are as follows:") print(erc20Hashes) #BAT officialBATAbiJSON = json.loads(officialBATAbi) theDeterministicBATHash = harvester.shaAnAbi(officialBATAbiJSON) cleanedAndOrderedBATAbiText = harvester.cleanAndConvertAbiToText(officialBATAbiJSON)