Ejemplo n.º 1
0
def thor_receipt_convert_to_eth_receipt(receipt):
    return {
        "status":
        encode_number(0 if receipt["reverted"] else 1),
        "transactionHash":
        receipt["meta"]["txID"],
        "transactionIndex":
        encode_number(0),
        "blockNumber":
        encode_number(receipt["meta"]["blockNumber"]),
        "blockHash":
        receipt["meta"]["blockID"],
        "cumulativeGasUsed":
        encode_number(receipt["gasUsed"]),
        "gasUsed":
        encode_number(receipt["gasUsed"]),
        "contractAddress":
        None
        if receipt["reverted"] else receipt["outputs"][0]["contractAddress"],
        "logs":
        None if receipt["reverted"] else [
            thor_receipt_log_convert_to_eth_log(receipt, index, log)
            for index, log in enumerate(receipt["outputs"][0]["events"])
        ],
    }
Ejemplo n.º 2
0
def thor_receipt_log_convert_to_eth_log(receipt, index, log):
    return {
        "type": "mined",
        "logIndex": encode_number(index),
        "transactionIndex": encode_number(0),
        "transactionHash": receipt["meta"]["txID"],
        "blockHash": receipt["meta"]["blockID"],
        "blockNumber": encode_number(receipt["meta"]["blockNumber"]),
        "address": log["address"],
        "data": log["data"],
        "topics": log["topics"],
    }
Ejemplo n.º 3
0
def thor_log_convert_to_eth_log(address, logs):
    if logs:
        return [{
            "logIndex": encode_number(index),
            "blockNumber": encode_number(log["meta"]["blockNumber"]),
            "blockHash": log["meta"]["blockID"],
            "transactionHash": log["meta"]["txID"],
            "transactionIndex": encode_number(0),
            "address": address,
            "data": log["data"],
            "topics": log["topics"],
        } for index, log in enumerate(logs)]
    return []
Ejemplo n.º 4
0
def thor_tx_convert_to_eth_tx(tx):
    return {
        "hash": tx["id"],
        "nonce": tx["nonce"],
        "blockHash": tx["meta"]["blockID"],
        "blockNumber": encode_number(tx["meta"]["blockNumber"]),
        "transactionIndex": encode_number(0),
        "from": tx["origin"],
        "to": tx["clauses"][0]["to"],
        "value": tx["clauses"][0]["value"],
        "gas": encode_number(tx["gas"]),
        "gasPrice": encode_number(1),
        "input": tx["clauses"][0]["data"]
    }
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 async 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 = await self.accounts(transaction.get("to", None)
                                  ).make_request(post,
                                                 data=data,
                                                 params=params)
     return _attribute(result, "data")
Ejemplo n.º 7
0
async def eth_estimateGas(transaction):
    formatted_transaction = input_transaction_formatter(transaction)
    return encode_number(await thor.estimate_gas(formatted_transaction))
Ejemplo n.º 8
0
async def eth_blockNumber():
    return encode_number(await thor.get_block_number())
Ejemplo n.º 9
0
async def eth_getTransactionCount(address, block_identifier="best"):
    '''
    ethereum 用来处理 nonce, Thor 不需要
    '''
    return encode_number(0)
Ejemplo n.º 10
0
async def evm_snapshot():
    return encode_number(0)