jsonrpc.py (2080B)
1 # proposed custom errors 2 # source: https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal 3 4 #1 Unauthorized Should be used when some action is not authorized, e.g. sending from a locked account. 5 #2 Action not allowed Should be used when some action is not allowed, e.g. preventing an action, while another depending action is processing on, like sending again when a confirmation popup is shown to the user (?). 6 #3 Execution error Will contain a subset of custom errors in the data field. See below. 7 8 #100 X doesn’t exist Should be used when something which should be there is not found. (Doesn’t apply to eth_getTransactionBy_ and eth_getBlock_. They return a success with value null) 9 #101 Requires ether Should be used for actions which require somethin else, e.g. gas or a value. 10 #102 Gas too low Should be used when a to low value of gas was given. 11 #103 Gas limit exceeded Should be used when a limit is exceeded, e.g. for the gas limit in a block. 12 #104 Rejected Should be used when an action was rejected, e.g. because of its content (too long contract code, containing wrong characters ?, should differ from -32602 - Invalid params). 13 #105 Ether too low Should be used when a to low value of Ether was given. 14 15 #106 Timeout Should be used when an action timedout. 16 #107 Conflict Should be used when an action conflicts with another (ongoing?) action. 17 18 # external imports 19 from hexathon import add_0x 20 21 def to_blockheight_param(height): 22 """Translate blockheight specifier to Ethereum json-rpc blockheight argument. 23 24 :param height: Height argument 25 :type height: any 26 :rtype: str 27 :returns: Argument value 28 """ 29 if height == None: 30 height = 'latest' 31 elif isinstance(height, str): 32 try: 33 height = int(height) 34 except ValueError: 35 pass 36 if isinstance(height, int): 37 if height == 0: 38 height = 'latest' 39 elif height < 0: 40 height = 'pending' 41 else: 42 height = add_0x(int(height).to_bytes(8, 'big').hex()) 43 return height