Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/dev_arweave.erl
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,15 @@ post_chunk(Request, Opts) ->
%% global Arweave data tree, or relative to the start of a specific pending
%% transaction.
get_chunk(_Base, Request, Opts) ->
HasExplicitLength = hb_maps:is_key(<<"length">>, Request, Opts),
{ok, Offset, Length, MaybeRelativeTXID} = extract_chunk_params(Request, Opts),
case fetch_chunk_range(Offset, Length, MaybeRelativeTXID, Opts) of
{ok, Chunks} ->
Data = hb_util:bin(Chunks),
case Length of
undefined ->
case HasExplicitLength of
false ->
{ok, Data};
Length ->
true ->
{
ok,
binary:part(Data, 0, min(hb_util:int(Length), byte_size(Data)))
Expand All @@ -402,7 +403,7 @@ get_chunk(_Base, Request, Opts) ->
%% @doc Extract the parameters from a chunk request. Supports both global offsets
%% and relative offset+parent ID pairs.
extract_chunk_params(Request, Opts) ->
Length = hb_maps:get(<<"length">>, Request, undefined, Opts),
Length = hb_maps:get(<<"length">>, Request, 1, Opts),
case hb_maps:find(<<"offset">>, Request, Opts) of
{ok, RelativeInfo} when is_map(RelativeInfo) ->
{ok, RelativeOffset} = hb_maps:find(<<"offset">>, RelativeInfo, Opts),
Expand Down Expand Up @@ -1912,6 +1913,12 @@ get_mid_chunk_pre_split_test() ->
),
ok.

extract_chunk_params_default_length_test() ->
?assertEqual(
{ok, 123, 1, undefined},
extract_chunk_params(#{ <<"offset">> => 123 }, #{})
).

get_pre_split_small_chunks_test() ->
TXID = <<"4FnBmvgWmqXWEEprjVqBsV5aRpAgF6_yJX_GTGsSZjY">>,
Opts = setup_arweave_index_opts([TXID]),
Expand Down
2 changes: 1 addition & 1 deletion src/dev_query_arweave.erl
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ annotate_offsets([], _StoreOpts, _LastOffset, _Ordinate, _Opts) -> [];
annotate_offsets([ID|IDs], StoreOpts, LastOffset, Ordinate, Opts) ->
{Offset, Annotated} =
case hb_store_arweave:read_offset(StoreOpts, ID) of
{ok, #{ <<"start-offset">> := StartOffset, <<"length">> := Length }} ->
{ok, #{ <<"offset">> := StartOffset, <<"length">> := Length }} ->
{
StartOffset,
#{
Expand Down
6 changes: 3 additions & 3 deletions src/dev_query_test_vectors.erl
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ transactions_query_ids_preserve_arweave_tx_id_test() ->
{ok, _Node, Opts} = test_env_with_blocks(1892487, 1892487),
ID = <<"mT7pIQx9ORnemXoIzWmKwymiZJxtOSvzxm3P44M9C1A">>,
?assertMatch(
{ok, #{ <<"start-offset">> := _ }},
{ok, #{ <<"offset">> := _ }},
hb_store_arweave:read_offset(hb_store_arweave:store_from_opts(Opts), ID)
),
?assertMatch(
Expand Down Expand Up @@ -772,9 +772,9 @@ transactions_query_cursor_by_offset_test() ->
EarlierID = <<"xBpOR2KOjYEgv5HmddMlAgYa-yMvfEVl-0XzRIfm2uY">>,
LaterID = <<"HVr7EpRhlPkbwdnoXKHf25p7BPa0qJOs6C7XueLthA0">>,
StoreOpts = hb_store_arweave:store_from_opts(Opts),
{ok, #{ <<"start-offset">> := EarlierOffset }} =
{ok, #{ <<"offset">> := EarlierOffset }} =
hb_store_arweave:read_offset(StoreOpts, EarlierID),
{ok, #{ <<"start-offset">> := LaterOffset }} =
{ok, #{ <<"offset">> := LaterOffset }} =
hb_store_arweave:read_offset(StoreOpts, LaterID),
Query =
<<"""
Expand Down