Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
implement new style transaction fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
peerchemist committed Apr 12, 2019
1 parent c3bb098 commit 8927b4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pypeerassets/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ def get_next_tx(self, mutable=False):
def calculate_tx_fee(tx_size: int) -> Decimal:
'''return tx fee from tx size in bytes'''

min_fee = Decimal(0.01) # minimum
per_kb_cost = 0.01
min_fee = Decimal(0.001)

return Decimal(ceil(tx_size / 1000) * min_fee)
fee = Decimal((tx_size / 1000) * per_kb_cost)

if fee <= min_fee:
return min_fee
else:
return fee


def nulldata_script(data: bytes) -> NulldataScript:
Expand Down
7 changes: 6 additions & 1 deletion test/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ def test_peercoin_tx_unhexilify():
@pytest.mark.parametrize("tx_size", [181, 311])
def test_calculate_transaction_fee(tx_size):

assert round(calculate_tx_fee(tx_size), 2) == round(Decimal(0.01), 2)
if tx_size == 181:
assert calculate_tx_fee(tx_size) == Decimal(0.00181)
if tx_size == 311:
assert calculate_tx_fee(tx_size) == Decimal(0.00311)
if tx_size == 3903:
assert calculate_tx_fee(tx_size) == Decimal(0.03903)


@pytest.mark.parametrize("network", ['peercoin'])
Expand Down

0 comments on commit 8927b4a

Please sign in to comment.