Alpha: remove useless carbonated functor
Single carbonated data storage was useless and is buggy. It's simpler to remove than to fix it.
This commit is contained in:
parent
4c171c72a2
commit
64481a198e
@ -130,115 +130,6 @@ module Make_single_data_storage (C : Raw_context.T) (N : NAME) (V : VALUE)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Make_single_carbonated_data_storage
|
|
||||||
(C : Raw_context.T) (N : NAME) (V : CARBONATED_VALUE)
|
|
||||||
: Single_carbonated_data_storage with type t = C.t
|
|
||||||
and type value = V.t = struct
|
|
||||||
type t = C.t
|
|
||||||
type context = t
|
|
||||||
type value = V.t
|
|
||||||
let consume_mem_gas c =
|
|
||||||
Lwt.return (C.consume_gas c (Gas_limit_repr.read_bytes_cost Z.zero))
|
|
||||||
include Make_encoder(V)
|
|
||||||
let existing_size c =
|
|
||||||
match V.size with
|
|
||||||
| Fixed len ->
|
|
||||||
C.mem c N.name >>= fun exists ->
|
|
||||||
if exists then return len else return 0
|
|
||||||
| Variable ->
|
|
||||||
C.get_option c (len_name N.name) >>= function
|
|
||||||
| None -> return 0
|
|
||||||
| Some len -> decode_len_value N.name len
|
|
||||||
let consume_read_gas get c =
|
|
||||||
match V.size with
|
|
||||||
| Fixed len ->
|
|
||||||
Lwt.return (C.consume_gas c (Gas_limit_repr.read_bytes_cost (Z.of_int len)))
|
|
||||||
| Variable ->
|
|
||||||
get c (len_name N.name) >>=? fun len ->
|
|
||||||
decode_len_value N.name len >>=? fun len ->
|
|
||||||
Lwt.return (C.consume_gas c (Gas_limit_repr.read_bytes_cost (Z.of_int len)))
|
|
||||||
let consume_write_gas set c v =
|
|
||||||
match V.size with
|
|
||||||
| Fixed s ->
|
|
||||||
Lwt.return (C.consume_gas c (Gas_limit_repr.write_bytes_cost (Z.of_int s))) >>=? fun c ->
|
|
||||||
return (c, to_bytes v)
|
|
||||||
| Variable ->
|
|
||||||
let bytes = to_bytes v in
|
|
||||||
let len = MBytes.length bytes in
|
|
||||||
Lwt.return (C.consume_gas c (Gas_limit_repr.write_bytes_cost (Z.of_int len))) >>=? fun c ->
|
|
||||||
set c (len_name N.name) (encode_len_value bytes) >>=? fun c ->
|
|
||||||
return (c, bytes)
|
|
||||||
let consume_remove_gas del c =
|
|
||||||
match V.size with
|
|
||||||
| Fixed _ | Variable ->
|
|
||||||
Lwt.return (C.consume_gas c (Gas_limit_repr.write_bytes_cost Z.zero)) >>=? fun c ->
|
|
||||||
del c (len_name N.name)
|
|
||||||
let mem c =
|
|
||||||
consume_mem_gas c >>=? fun c ->
|
|
||||||
C.mem c N.name >>= fun res ->
|
|
||||||
return (C.project c, res)
|
|
||||||
let get c =
|
|
||||||
consume_read_gas C.get c >>=? fun c ->
|
|
||||||
C.get c N.name >>=? fun bytes ->
|
|
||||||
let key = C.absolute_key c N.name in
|
|
||||||
Lwt.return (of_bytes ~key bytes) >>=? fun res ->
|
|
||||||
return (C.project c, res)
|
|
||||||
let get_option c =
|
|
||||||
consume_mem_gas c >>=? fun c ->
|
|
||||||
C.mem c N.name >>= fun exists ->
|
|
||||||
if exists then
|
|
||||||
get c >>=? fun (c, r) ->
|
|
||||||
return (c, Some r)
|
|
||||||
else
|
|
||||||
return (C.project c, None)
|
|
||||||
let init c v =
|
|
||||||
consume_write_gas C.set c v >>=? fun (c, bytes) ->
|
|
||||||
C.init c N.name bytes >>=? fun c ->
|
|
||||||
let size = MBytes.length bytes in
|
|
||||||
Lwt.return (C.record_bytes_stored c (Int64.of_int size)) >>=? fun c ->
|
|
||||||
return (C.project c, size)
|
|
||||||
let set c v =
|
|
||||||
consume_write_gas C.init c v >>=? fun (c, bytes) ->
|
|
||||||
existing_size c >>=? fun prev_size ->
|
|
||||||
C.set c N.name bytes >>=? fun c ->
|
|
||||||
let size_diff = MBytes.length bytes - prev_size in
|
|
||||||
Lwt.return (C.record_bytes_stored c (Int64.of_int size_diff)) >>=? fun c ->
|
|
||||||
return (C.project c, size_diff)
|
|
||||||
let init_set c v =
|
|
||||||
let init_set c k v = C.init_set c k v >>= return in
|
|
||||||
consume_write_gas init_set c v >>=? fun (c, bytes) ->
|
|
||||||
existing_size c >>=? fun prev_size ->
|
|
||||||
init_set c N.name bytes >>=? fun c ->
|
|
||||||
let size_diff = MBytes.length bytes - prev_size in
|
|
||||||
Lwt.return (C.record_bytes_stored c (Int64.of_int size_diff)) >>=? fun c ->
|
|
||||||
return (C.project c, size_diff)
|
|
||||||
let remove c =
|
|
||||||
let remove c k = C.remove c k >>= return in
|
|
||||||
consume_remove_gas remove c >>=? fun c ->
|
|
||||||
existing_size c >>=? fun prev_size ->
|
|
||||||
remove c N.name >>=? fun c ->
|
|
||||||
Lwt.return (C.record_bytes_stored c (Int64.of_int ~-prev_size)) >>=? fun c ->
|
|
||||||
return (C.project c, prev_size)
|
|
||||||
let delete c =
|
|
||||||
consume_remove_gas C.delete c >>=? fun c ->
|
|
||||||
existing_size c >>=? fun prev_size ->
|
|
||||||
C.delete c N.name >>=? fun c ->
|
|
||||||
Lwt.return (C.record_bytes_stored c (Int64.of_int ~-prev_size)) >>=? fun c ->
|
|
||||||
return (C.project c, prev_size)
|
|
||||||
let set_option c v =
|
|
||||||
match v with
|
|
||||||
| None -> remove c
|
|
||||||
| Some v -> init_set c v
|
|
||||||
|
|
||||||
let () =
|
|
||||||
let open Storage_description in
|
|
||||||
register_value
|
|
||||||
~get:(fun c -> get_option c >>=? fun (_, v) -> return v)
|
|
||||||
(register_named_subcontext C.description N.name)
|
|
||||||
V.encoding
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
module type INDEX = sig
|
module type INDEX = sig
|
||||||
type t
|
type t
|
||||||
val path_length: int
|
val path_length: int
|
||||||
|
@ -21,11 +21,6 @@ module Make_single_data_storage
|
|||||||
|
|
||||||
module Make_carbonated_value (V : VALUE) : CARBONATED_VALUE with type t = V.t
|
module Make_carbonated_value (V : VALUE) : CARBONATED_VALUE with type t = V.t
|
||||||
|
|
||||||
module Make_single_carbonated_data_storage
|
|
||||||
(C : Raw_context.T) (N : NAME) (V : CARBONATED_VALUE)
|
|
||||||
: Single_carbonated_data_storage with type t = C.t
|
|
||||||
and type value = V.t
|
|
||||||
|
|
||||||
module type INDEX = sig
|
module type INDEX = sig
|
||||||
type t
|
type t
|
||||||
val path_length: int
|
val path_length: int
|
||||||
|
Loading…
Reference in New Issue
Block a user