adds fees to rate limited wallet transactions
This commit is contained in:
parent
4710409529
commit
4d2f3e2597
|
@ -548,6 +548,7 @@ class RLWallet:
|
|||
rl_parent.amount,
|
||||
self.rl_info.interval,
|
||||
self.rl_info.limit,
|
||||
fee
|
||||
)
|
||||
|
||||
spends.append((puzzle, CoinSolution(coin, solution)))
|
||||
|
|
|
@ -42,7 +42,7 @@ def rl_puzzle_for_pk(
|
|||
TEMPLATE_SINGLETON_RL = f'((c (i (i (= {TEMPLATE_MY_PARENT_ID} (f 1)) (q 1) (= (f 1) (q 0x{origin_id}))) (q ()) (q (x (q "Parent doesnt satisfy RL conditions")))) 1))' # noqa: E501
|
||||
TEMPLATE_BLOCK_AGE = f'((c (i (i (= (* (f (r (r (r (r (r 1)))))) (q {rate_amount})) (* (f (r (r (r (r 1))))) (q {interval_time}))) (q 1) (q (> (* (f (r (r (r (r (r 1)))))) (q {rate_amount})) (* (f (r (r (r (r 1)))))) (q {interval_time})))) (q (c (q 0x{opcode_coin_block_age}) (c (f (r (r (r (r (r 1)))))) (q ())))) (q (x (q "wrong min block time")))) 1 ))' # noqa: E501
|
||||
TEMPLATE_MY_ID = f"(c (q 0x{opcode_myid}) (c (sha256 (f 1) (f (r 1)) (f (r (r 1)))) (q ())))" # noqa: E501
|
||||
CREATE_CHANGE = f"(c (q 0x{opcode_create}) (c (f (r 1)) (c (- (f (r (r 1))) (f (r (r (r (r 1)))))) (q ()))))" # noqa: E501
|
||||
CREATE_CHANGE = f"(c (q 0x{opcode_create}) (c (f (r 1)) (c (- (f (r (r 1))) (+ (f (r (r (r (r 1))))) (f (r (r (r (r (r (r (r (r 1))))))))))) (q ()))))" # noqa: E501
|
||||
CREATE_NEW_COIN = f"(c (q 0x{opcode_create}) (c (f (r (r (r 1)))) (c (f (r (r (r (r 1))))) (q ()))))" # noqa: E501
|
||||
RATE_LIMIT_PUZZLE = f"(c {TEMPLATE_SINGLETON_RL} (c {TEMPLATE_BLOCK_AGE} (c {CREATE_CHANGE} (c {TEMPLATE_MY_ID} (c {CREATE_NEW_COIN} (q ()))))))" # noqa: E501
|
||||
|
||||
|
@ -109,6 +109,7 @@ def solution_for_rl(
|
|||
parent_amount: uint64,
|
||||
interval,
|
||||
limit,
|
||||
fee,
|
||||
):
|
||||
"""
|
||||
Solution is (1 my_parent_id, my_puzzlehash, my_amount, outgoing_puzzle_hash, outgoing_amount,
|
||||
|
@ -119,7 +120,7 @@ def solution_for_rl(
|
|||
min_block_count = math.ceil((out_amount * interval) / limit)
|
||||
solution = (
|
||||
f"(1 0x{my_parent_id.hex()} 0x{my_puzzlehash.hex()} {my_amount} 0x{out_puzzlehash.hex()} {out_amount}"
|
||||
f" {min_block_count} 0x{my_parent_parent_id.hex()} {parent_amount})"
|
||||
f" {min_block_count} 0x{my_parent_parent_id.hex()} {parent_amount} {fee})"
|
||||
)
|
||||
return Program(binutils.assemble(solution))
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ class TestRLWallet:
|
|||
address = encode_puzzle_hash(await receiving_wallet.get_new_puzzlehash())
|
||||
assert await receiving_wallet.get_spendable_balance() == 0
|
||||
val = await api_user.send_transaction(
|
||||
{"wallet_id": user_wallet_id, "amount": 3, "fee": 0, "address": address}
|
||||
{"wallet_id": user_wallet_id, "amount": 3, "fee": 2, "address": address}
|
||||
)
|
||||
assert "transaction_id" in val
|
||||
|
||||
|
@ -144,7 +144,7 @@ class TestRLWallet:
|
|||
|
||||
for i in range(0, num_blocks):
|
||||
await full_node.farm_new_block(FarmNewBlockProtocol(32 * b"\0"))
|
||||
await time_out_assert(15, check_balance, 97, api_user, user_wallet_id)
|
||||
await time_out_assert(15, check_balance, 95, api_user, user_wallet_id)
|
||||
await time_out_assert(15, receiving_wallet.get_spendable_balance, 3)
|
||||
val = await api_admin.add_rate_limited_funds(
|
||||
{"wallet_id": admin_wallet_id, "amount": 100}
|
||||
|
@ -152,7 +152,7 @@ class TestRLWallet:
|
|||
assert val["status"] == "SUCCESS"
|
||||
for i in range(0, 50):
|
||||
await full_node.farm_new_block(FarmNewBlockProtocol(32 * b"\0"))
|
||||
await time_out_assert(15, check_balance, 197, api_user, user_wallet_id)
|
||||
await time_out_assert(15, check_balance, 195, api_user, user_wallet_id)
|
||||
|
||||
# test spending
|
||||
puzzle_hash = encode_puzzle_hash(await receiving_wallet.get_new_puzzlehash())
|
||||
|
@ -169,7 +169,7 @@ class TestRLWallet:
|
|||
)
|
||||
for i in range(0, num_blocks):
|
||||
await full_node.farm_new_block(FarmNewBlockProtocol(32 * b"\0"))
|
||||
await time_out_assert(15, check_balance, 92, api_user, user_wallet_id)
|
||||
await time_out_assert(15, check_balance, 90, api_user, user_wallet_id)
|
||||
await time_out_assert(15, receiving_wallet.get_spendable_balance, 108)
|
||||
|
||||
val = await api_admin.send_clawback_transaction({"wallet_id": admin_wallet_id})
|
||||
|
@ -181,4 +181,4 @@ class TestRLWallet:
|
|||
await time_out_assert(15, check_balance, 0, api_user, user_wallet_id)
|
||||
await time_out_assert(15, check_balance, 0, api_admin, user_wallet_id)
|
||||
final_balance = await wallet.get_confirmed_balance()
|
||||
assert final_balance == fund_owners_initial_balance - 109
|
||||
assert final_balance == fund_owners_initial_balance - 111
|
Loading…
Reference in New Issue