Ejemplo n.º 1
0
def inputPostFormatter(post):
    """
    Formats the input of a whisper post and converts all values to HEX
    """

    post["ttl"] = from_decimal(post["ttl"])
    post["workToProve"] = from_decimal(post.get("workToProve", 0))
    post["priority"] = from_decimal(post["priority"])

    if not is_array(post.get("topics")):
        post["topics"] = [post["topics"]] if post.get("topics") else []

    post["topics"] = [topic if is_0x_prefixed(topic) else encode_hex(topic)
                      for topic in post["topics"]]

    return post
Ejemplo n.º 2
0
def outputTransactionReceiptFormatter(receipt):
    """
    Formats the output of a transaction receipt to its proper values
    """
    if receipt is None:
        return None

    if receipt.get("blockNumber"):
        receipt["blockNumber"] = to_decimal(receipt["blockNumber"])
    if receipt.get("transactionIndex"):
        receipt["transactionIndex"] = to_decimal(receipt["transactionIndex"])
    receipt["cumulativeGasUsed"] = to_decimal(receipt["cumulativeGasUsed"])
    receipt["gasUsed"] = to_decimal(receipt["gasUsed"])

    if is_array(receipt.get("logs")):
        receipt["logs"] = [outputLogFormatter(log) for log in receipt["logs"]]

    return receipt
Ejemplo n.º 3
0
def inputPostFormatter(post):
    """
    Formats the input of a whisper post and converts all values to HEX
    """

    post["ttl"] = from_decimal(post["ttl"])
    post["workToProve"] = from_decimal(post.get("workToProve", 0))
    post["priority"] = from_decimal(post["priority"])

    if not is_array(post.get("topics")):
        post["topics"] = [post["topics"]] if post.get("topics") else []

    post["topics"] = [
        topic if is_0x_prefixed(topic) else encode_hex(topic)
        for topic in post["topics"]
    ]

    return post
Ejemplo n.º 4
0
def outputBlockFormatter(block):
    """
    Formats the output of a block to its proper values
    """

    # Transform to number
    block["gasLimit"] = to_decimal(block["gasLimit"])
    block["gasUsed"] = to_decimal(block["gasUsed"])
    block["size"] = to_decimal(block["size"])
    block["timestamp"] = to_decimal(block["timestamp"])

    if block.get("number"):
        block["number"] = to_decimal(block["number"])

    block["difficulty"] = to_decimal(block["difficulty"])
    block["totalDifficulty"] = to_decimal(block["totalDifficulty"])

    if is_array(block.get("transactions")):
        for item in block["transactions"]:
            if not is_string(item):
                item = outputTransactionFormatter(item)

    return block
Ejemplo n.º 5
0
def test_isArray(value, expected):
    assert is_array(value) == expected
Ejemplo n.º 6
0
def test_isArray(value, expected):
    assert is_array(value) == expected