Beispiel #1
0
 def estimate_gas(self, transaction):
     data = {
         "data": transaction["data"],
         "value": (encode_number(transaction.get("value", 0))).decode("utf-8"),
         "caller": transaction.get("from", None),
     }
     result = self.accounts(transaction.get("to", None)).make_request(post, data=data)
     if result is None:
         return 0
     return int(result["gasUsed"] * 1.2) + intrinsic_gas(transaction)
Beispiel #2
0
 async def estimate_gas(self, transaction):
     data = {
         "data": transaction["data"],
         "value": (encode_number(transaction.get("value",
                                                 0))).decode("utf-8"),
         "caller": transaction.get("from", None),
     }
     result = await self.accounts(transaction.get("to", None)
                                  ).make_request(post, data=data)
     if result is None or result["reverted"]:
         raise ValueError("Gas estimation failed.")
     return int(result["gasUsed"] * 1.2) + intrinsic_gas(transaction)
Beispiel #3
0
 def estimate_gas(self, transaction):
     if "to" not in transaction:
         to_addr = None
     else:
         to_addr = transaction["to"]
     data = {
         "data": transaction["data"],
         "value": (encode_number(transaction.get("value", 0))).decode("utf-8"),
         "caller": transaction["from"],
     }
     result = self.account(to_addr)(post, data=data)
     if result is None:
         return encode_number(0)
     return encode_number(int(result["gasUsed"] * 1.2) + intrinsic_gas(transaction))
Beispiel #4
0
 async def estimate_gas(self, transaction):
     data = {
         "data": transaction.get("data", '0x'),
         "value": encode_number(transaction.get("value", 0)),
         "caller": transaction.get("from", None),
     }
     toAddr = transaction.get("to", "0x")
     toAddr = "0x" if toAddr == None else toAddr
     result = await self.accounts(toAddr).make_request(post, data=data)
     if result is None:
         print("[WARN] empty response, estimate gas with data: ", data)
         raise JsonRpcError(2, 'no response from server', '')
     if result["reverted"]:
         print("[WARN] reverted, estimate gas with data: ", data)
         data = result.get('data', '0x')
         err = result.get('vmError', '')
         if data.startswith(ERROR_SELECTOR):
             decoded = decode_abi(['string'], bytes.fromhex(data[10:]))
             err += ': ' + decoded[0]
         if data.startswith(PANIC_SELECTOR):
             decoded = decode_abi(['uint256'], bytes.fromhex(data[10:]))
             err += ': ' + str(decoded[0])
         raise JsonRpcError(3, err, data)
     return int(result["gasUsed"] * 1.2) + intrinsic_gas(transaction)