Esempio n. 1
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))
Esempio n. 2
0
 async def call(self, transaction, block_identifier):
     params = {
         "revision": block_identifier,
     }
     data = {
         "data": transaction.get("data", "0x"),
         "value": encode_number(transaction.get("value", 0)),
         "caller": transaction.get("from", None),
     }
     result = await self.accounts(transaction.get("to", None)
                                  ).make_request(post,
                                                 data=data,
                                                 params=params)
     if result["reverted"]:
         print("[WARN] reverted, eth_call 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 _attribute(result, 'data')
Esempio n. 3
0
 def call(self, transaction, block_identifier):
     params = {
         "revision": block_identifier,
     }
     data = {
         "data": transaction["data"],
         "value": (encode_number(transaction.get("value", 0))).decode("utf-8"),
     }
     result = self.account(transaction.get("to", None))(post, data=data, params=params)
     return None if result is None else result["data"]
Esempio n. 4
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)
Esempio n. 5
0
 def call(self, transaction, block_identifier):
     params = {
         "revision": block_identifier,
     }
     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, params=params)
     return _attribute(result, "data")
Esempio n. 6
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)
Esempio n. 7
0
 def call(self, transaction, block_identifier):
     if "to" not in transaction:
         to_addr = None
     else:
         to_addr = transaction["to"]
     params = {
         "revision": block_identifier,
     }
     data = {
         "data": transaction["data"],
         "value": (encode_number(transaction["value"])).decode("utf-8"),
     }
     result = self.account(to_addr)(post, data=data, params=params)
     return None if result is None else result["data"]
Esempio n. 8
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)
Esempio n. 9
0
 async def get_syncing(self):
     blk = await self.blocks("best").make_request(get)
     num = encode_number(_attribute(blk, 'number'))
     return {"startingBlock": num, "currentBlock": num, "highestBlock": num}