Skip to content

Commit

Permalink
Merge pull request raiden-network#61 from palango/fee-format
Browse files Browse the repository at this point in the history
Define fee format
  • Loading branch information
LefterisJP committed Apr 30, 2018
2 parents 4767256 + 02fbd5e commit e9ebb1e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
15 changes: 10 additions & 5 deletions raiden_libs/messages/fee_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ def __init__(
channel_identifier: ChannelIdentifier,
chain_id: int = 1,
nonce: int = 0,
# Fixme: convert precentage_fee to an appropriate type
percentage_fee: str = '0.0',
percentage_fee: int = 0, # in parts per million
signature: str = None,
) -> None:
""" Creates a new FeeInfo message
Args:
percentage_fee: The fee defined in parts per million, e.g. a value of 10000
corresponds to a relative fee of one percent.
"""
super().__init__()
assert channel_identifier >= 0
assert is_address(token_network_address)
Expand All @@ -42,18 +47,18 @@ def serialize_data(self) -> Dict:
'channel_identifier': self.channel_identifier,
'chain_id': self.chain_id,
'nonce': self.nonce,
'percentage_fee': str(self.percentage_fee),
'percentage_fee': self.percentage_fee,
'signature': self.signature,
}

def serialize_bin(self):
def serialize_bin(self) -> bytes:
"""Return FeeInfo serialized to binary"""
return pack_data([
'address',
'uint256',
'uint256',
'uint256',
'string'
'uint256'
], [
self.token_network_address,
self.channel_identifier,
Expand Down
3 changes: 2 additions & 1 deletion raiden_libs/messages/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def make_properties_required(schema):
'minimum': 0
},
'percentage_fee': {
'type': 'string',
'type': 'integer',
'minimum': 0
},
'signature': {
'type': 'string'
Expand Down
4 changes: 2 additions & 2 deletions raiden_libs/utils/signing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import rlp
from typing import Union
from typing import Union, Any
from sha3 import keccak_256

from coincurve import PrivateKey, PublicKey
Expand Down Expand Up @@ -114,7 +114,7 @@ def address_from_signature(sig: bytes, msg: bytes) -> Address:
return public_key_to_address(receiver_pubkey)


def eth_verify(sig: bytes, msg: str) -> Address:
def eth_verify(sig: bytes, msg: Any) -> Address:
return address_from_signature(sig, keccak256(msg))


Expand Down
5 changes: 2 additions & 3 deletions tests/test_client_mock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from math import isclose
import pytest

from eth_utils import decode_hex, is_same_address
Expand All @@ -21,13 +20,13 @@ def test_client_fee_info(generate_raiden_clients):
channel_id = c1.open_channel(c2.address)
assert channel_id > 0

fi = c1.get_fee_info(c2.address, nonce=5, percentage_fee='0.1', chain_id=2)
fi = c1.get_fee_info(c2.address, nonce=5, percentage_fee=1000, chain_id=2)
fee_info_signer = eth_verify(decode_hex(fi.signature), fi.serialize_bin())

assert is_same_address(fee_info_signer, c1.address)

assert fi.nonce == 5
assert isclose(float(fi.percentage_fee), 0.1)
assert fi.percentage_fee == 1000
assert fi.chain_id == 2


Expand Down
4 changes: 2 additions & 2 deletions tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_fee_info():
chain_id=1,
channel_identifier=123,
nonce=1,
percentage_fee='0.1',
percentage_fee=10000,
signature='signature'
)
assert message == Message.deserialize(message).serialize_data()
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_deserialize_with_required_type():
chain_id=1,
channel_identifier=123,
nonce=1,
percentage_fee='0.1',
percentage_fee=1000,
signature='signature'
)

Expand Down

0 comments on commit e9ebb1e

Please sign in to comment.