Add a store map fate value.
A store map is a (contract local) unique id pointing to a map saved in the contract store, plus a cache of updates.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
-type fate_list() :: ?FATE_LIST_T.
|
||||
-type fate_unit() :: ?FATE_UNIT_T.
|
||||
-type fate_map() :: ?FATE_MAP_T.
|
||||
-type fate_store_map() :: ?FATE_STORE_MAP_T.
|
||||
-type fate_string() :: ?FATE_STRING_T.
|
||||
-type fate_address() :: ?FATE_ADDRESS_T.
|
||||
-type fate_hash() :: ?FATE_BYTES_T(32).
|
||||
@@ -71,6 +72,7 @@
|
||||
, fate_channel/0
|
||||
, fate_variant/0
|
||||
, fate_map/0
|
||||
, fate_store_map/0
|
||||
, fate_bits/0
|
||||
, fate_type_type/0
|
||||
]).
|
||||
@@ -82,6 +84,8 @@
|
||||
, make_tuple/1
|
||||
, make_string/1
|
||||
, make_map/1
|
||||
, make_store_map/1
|
||||
, make_store_map/2
|
||||
, make_address/1
|
||||
, make_bytes/1
|
||||
, make_hash/1
|
||||
@@ -108,6 +112,8 @@ make_list(L) -> ?MAKE_FATE_LIST(L).
|
||||
make_unit() -> ?FATE_UNIT.
|
||||
make_tuple(T) -> ?FATE_TUPLE(T).
|
||||
make_map(M) -> ?MAKE_FATE_MAP(M).
|
||||
make_store_map(Id) -> make_store_map(#{}, Id).
|
||||
make_store_map(Cache, Id) -> ?FATE_STORE_MAP(Cache, Id).
|
||||
make_address(X) -> ?FATE_ADDRESS(X).
|
||||
make_bytes(X) -> ?FATE_BYTES(X).
|
||||
make_hash(X) -> make_bytes(X).
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
%% %% 1000 1111 - FREE (Possibly for bytecode in the future.)
|
||||
-define(OBJECT , 2#10011111). %% 1001 1111 | ObjectType | RLP encoded Array
|
||||
-define(VARIANT , 2#10101111). %% 1010 1111 | [encoded arities] | encoded tag | [encoded values]
|
||||
-define(MAP_ID , 2#10111111). %% 1011 1111 | RLP encoded integer (store map id)
|
||||
-define(NEG_BITS , 2#11001111). %% 1100 1111 | RLP encoded integer (infinite 1:s bitfield)
|
||||
-define(EMPTY_MAP , 2#11011111). %% 1101 1111
|
||||
-define(NEG_BIG_INT , 2#11101111). %% 1110 1111 | RLP encoded (integer - 64)
|
||||
@@ -193,6 +194,9 @@ serialize(Map) when ?IS_FATE_MAP(Map) ->
|
||||
<<?MAP,
|
||||
(rlp_encode_int(Size))/binary,
|
||||
(Elements)/binary>>;
|
||||
serialize(?FATE_STORE_MAP(Cache, Id)) when Cache =:= #{} ->
|
||||
%% We should never get to serialization without having flushed the caches.
|
||||
<<?MAP_ID, (rlp_encode_int(Id))/binary>>;
|
||||
serialize(?FATE_VARIANT(Arities, Tag, Values)) ->
|
||||
Arities = [A || A <- Arities, is_integer(A), A < 256],
|
||||
Size = length(Arities),
|
||||
@@ -426,6 +430,9 @@ deserialize2(<<?MAP, Rest/binary>>) ->
|
||||
false ->
|
||||
error({unknown_map_serialization_format, KVList})
|
||||
end;
|
||||
deserialize2(<<?MAP_ID, Rest/binary>>) ->
|
||||
{Id, Rest1} = rlp_decode_int(Rest),
|
||||
{?FATE_STORE_MAP(#{}, Id), Rest1};
|
||||
deserialize2(<<?VARIANT, Rest/binary>>) ->
|
||||
{AritiesBin, <<Tag:8, Rest2/binary>>} = aeser_rlp:decode_one(Rest),
|
||||
Arities = binary_to_list(AritiesBin),
|
||||
|
||||
Reference in New Issue
Block a user