Skip to content

Commit

Permalink
feat(rpc): optional configurable fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Awea committed Oct 6, 2024
1 parent 12e6636 commit aa6462c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ defmodule Tezex.Rpc do
gas_limit: non_neg_integer(),
storage_limit: non_neg_integer(),
gas_reserve: non_neg_integer(),
burn_reserve: non_neg_integer()
burn_reserve: non_neg_integer(),
fee: non_neg_integer()
) :: operation()
def fill_operation_fee(operation, preapplied_operations, opts \\ []) do
gas_limit = Keyword.get(opts, :gas_limit)
storage_limit = Keyword.get(opts, :storage_limit)
gas_reserve = Keyword.get(opts, :gas_reserve, Fee.default_gas_reserve())
burn_reserve = Keyword.get(opts, :burn_reserve, Fee.default_gas_reserve())
fee = Keyword.get(opts, :fee)

number_contents = length(preapplied_operations)

Expand Down Expand Up @@ -130,8 +132,13 @@ defmodule Tezex.Rpc do
gas_limit_new
end

extra_size = 1 + div(Fee.extra_size(), number_contents)
fee = Fee.calculate_fee(content, gas_limit_new, extra_size: extra_size)
fee =
if is_nil(fee) do
extra_size = 1 + div(Fee.extra_size(), number_contents)
Fee.calculate_fee(content, gas_limit_new, extra_size: extra_size)
else
fee
end

%{
content
Expand Down

0 comments on commit aa6462c

Please sign in to comment.