How to use the gear.utils.types.encode_number function in gear

To help you get started, we’ve selected a few gear examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vechain / web3-gear / gear / utils / compat.py View on Github external
# block
#
ETH_BLOCK_KWARGS_MAP = {
    "id": "hash",
    "parentID": "parentHash",
    "signer": "miner",
    "totalScore": "totalDifficulty",
    "txsRoot": "transactionsRoot",
}


BLOCK_FORMATTERS = {
    "number": encode_number,
    "size": encode_number,
    "timestamp": encode_number,
    "gasLimit": encode_number,
    "gasUsed": encode_number,
    "totalScore": encode_number,
}


def thor_block_convert_to_eth_block(block):
    return {
        ETH_BLOCK_KWARGS_MAP.get(k, k): BLOCK_FORMATTERS.get(k, noop)(v)
        for k, v in block.items()
    }


#
# receipt
#
def thor_receipt_convert_to_eth_receipt(receipt):
github vechain / web3-gear / gear / utils / compat.py View on Github external
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 []
github vechain / web3-gear / gear / utils / compat.py View on Github external
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"],
    }
github vechain / web3-gear / gear / utils / compat.py View on Github external
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"],
    }
github vechain / web3-gear / gear / utils / compat.py View on Github external
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"]
    }
github vechain / web3-gear / gear / utils / compat.py View on Github external
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"])
        ],
github vechain / web3-gear / gear / utils / compat.py View on Github external
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"]
    }
github vechain / web3-gear / gear / utils / compat.py View on Github external
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"]
    }
github vechain / web3-gear / gear / utils / compat.py View on Github external
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"],
    }
github vechain / web3-gear / gear / utils / compat.py View on Github external
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"])
        ],