Client: fix fee calculation
This commit is contained in:
parent
6f07a25a3c
commit
86e355c32e
@ -384,9 +384,45 @@ let may_patch_limits
|
|||||||
| Some c, Some rest -> Some (Cons (c, rest))
|
| Some c, Some rest -> Some (Cons (c, rest))
|
||||||
end in
|
end in
|
||||||
|
|
||||||
|
let rec patch_fee :
|
||||||
|
type kind. bool -> kind contents -> kind contents = fun first -> function
|
||||||
|
| Manager_operation c as op ->
|
||||||
|
let gas_limit = c.gas_limit in
|
||||||
|
let size =
|
||||||
|
if first then
|
||||||
|
Data_encoding.Binary.fixed_length_exn
|
||||||
|
Tezos_base.Operation.shell_header_encoding +
|
||||||
|
Data_encoding.Binary.length
|
||||||
|
Operation.contents_encoding
|
||||||
|
(Contents op) +
|
||||||
|
Signature.size
|
||||||
|
else
|
||||||
|
Data_encoding.Binary.length
|
||||||
|
Operation.contents_encoding
|
||||||
|
(Contents op)
|
||||||
|
in
|
||||||
|
let minimal_fees_in_nanotez =
|
||||||
|
Z.mul (Z.of_int64 (Tez.to_mutez fee_parameter.minimal_fees)) (Z.of_int 1000) in
|
||||||
|
let minimal_fees_for_gas_in_nanotez =
|
||||||
|
Z.mul fee_parameter.minimal_nanotez_per_gas_unit gas_limit in
|
||||||
|
let minimal_fees_for_size_in_nanotez =
|
||||||
|
Z.mul fee_parameter.minimal_nanotez_per_byte (Z.of_int size) in
|
||||||
|
let fees_in_nanotez =
|
||||||
|
Z.add minimal_fees_in_nanotez @@
|
||||||
|
Z.add minimal_fees_for_gas_in_nanotez minimal_fees_for_size_in_nanotez in
|
||||||
|
begin match Tez.of_mutez (Z.to_int64 (Z.div (Z.add (Z.of_int 999) fees_in_nanotez) (Z.of_int 1000))) with
|
||||||
|
| None -> assert false
|
||||||
|
| Some fee ->
|
||||||
|
if fee <= c.fee then
|
||||||
|
op
|
||||||
|
else
|
||||||
|
patch_fee first (Manager_operation { c with fee })
|
||||||
|
end
|
||||||
|
| c -> c in
|
||||||
|
|
||||||
let patch :
|
let patch :
|
||||||
type kind. bool -> kind contents * kind contents_result -> kind contents tzresult Lwt.t = fun first -> function
|
type kind. bool -> kind contents * kind contents_result -> kind contents tzresult Lwt.t = fun first -> function
|
||||||
| Manager_operation c as op, (Manager_operation_result _ as result) ->
|
| Manager_operation c, (Manager_operation_result _ as result) ->
|
||||||
begin
|
begin
|
||||||
if c.gas_limit < Z.zero || gas_limit <= c.gas_limit then
|
if c.gas_limit < Z.zero || gas_limit <= c.gas_limit then
|
||||||
Lwt.return (estimated_gas_single result) >>=? fun gas ->
|
Lwt.return (estimated_gas_single result) >>=? fun gas ->
|
||||||
@ -417,37 +453,11 @@ let may_patch_limits
|
|||||||
end
|
end
|
||||||
else return c.storage_limit
|
else return c.storage_limit
|
||||||
end >>=? fun storage_limit ->
|
end >>=? fun storage_limit ->
|
||||||
begin
|
let c = Manager_operation { c with gas_limit ; storage_limit } in
|
||||||
if compute_fee then
|
if compute_fee then
|
||||||
let size =
|
return (patch_fee first c)
|
||||||
if first then
|
else
|
||||||
Data_encoding.Binary.fixed_length_exn
|
return c
|
||||||
Tezos_base.Operation.shell_header_encoding +
|
|
||||||
Data_encoding.Binary.length
|
|
||||||
Operation.contents_encoding
|
|
||||||
(Contents op) +
|
|
||||||
Signature.size
|
|
||||||
else
|
|
||||||
Data_encoding.Binary.length
|
|
||||||
Operation.contents_encoding
|
|
||||||
(Contents op)
|
|
||||||
in
|
|
||||||
let minimal_fees_in_nanotez =
|
|
||||||
Z.mul (Z.of_int64 (Tez.to_mutez fee_parameter.minimal_fees)) (Z.of_int 1000) in
|
|
||||||
let minimal_fees_for_gas_in_nanotez =
|
|
||||||
Z.mul fee_parameter.minimal_nanotez_per_gas_unit gas_limit in
|
|
||||||
let minimal_fees_for_size_in_nanotez =
|
|
||||||
Z.mul fee_parameter.minimal_nanotez_per_byte (Z.of_int size) in
|
|
||||||
let fees_in_nanotez =
|
|
||||||
Z.add minimal_fees_in_nanotez @@
|
|
||||||
Z.add minimal_fees_for_gas_in_nanotez minimal_fees_for_size_in_nanotez in
|
|
||||||
match Tez.of_mutez (Z.to_int64 (Z.div (Z.add (Z.of_int 999) fees_in_nanotez) (Z.of_int 1000))) with
|
|
||||||
| None -> assert false
|
|
||||||
| Some fee -> return fee
|
|
||||||
else
|
|
||||||
return c.fee
|
|
||||||
end >>=? fun fee ->
|
|
||||||
return (Manager_operation { c with gas_limit ; storage_limit ; fee })
|
|
||||||
| (c, _) -> return c in
|
| (c, _) -> return c in
|
||||||
let rec patch_list :
|
let rec patch_list :
|
||||||
type kind. bool -> kind contents_and_result_list -> kind contents_list tzresult Lwt.t =
|
type kind. bool -> kind contents_and_result_list -> kind contents_list tzresult Lwt.t =
|
||||||
|
Loading…
Reference in New Issue
Block a user