示例#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
示例#2
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_list_like(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
示例#3
0
def test_conversion_rount_trip(value):
    intermediate_value = from_decimal(value)
    result_value = to_decimal(intermediate_value)
    error_msg = "Expected: {0!r}, Result: {1!r}, Intermediate: {2!r}".format(
        value,
        result_value,
        intermediate_value,
    )
    assert result_value == value, error_msg
示例#4
0
def inputTransactionFormatter(options):
    """
    Formats the input of a transaction and converts all values to HEX
    """
    options.setdefault("from", config.defaultAccount)
    options["from"] = inputAddressFormatter(options["from"])

    if options.get("to"):
        options["to"] = inputAddressFormatter(options["to"])

    for key in ("gasPrice", "gas", "value", "nonce"):
        if key in options:
            options[key] = from_decimal(options[key])

    return options
示例#5
0
def test_from_decimal(value, expected):
    assert from_decimal(value) == expected
示例#6
0
 def fromDecimal(decimal):
     return from_decimal(decimal)
示例#7
0
def test_conversion_rount_trip(value):
    intermediate_value = from_decimal(value)
    result_value = to_decimal(intermediate_value)
    assert result_value == value, "Expected: {0!r}, Result: {1!r}, Intermediate: {2!r}".format(value, result_value, intermediate_value)
示例#8
0
def test_from_decimal(value, expected):
    assert from_decimal(value) == expected
示例#9
0
def test_conversion_rount_trip(value):
    intermediate_value = from_decimal(value)
    result_value = to_decimal(intermediate_value)
    assert result_value == value