Skip to content

Commit 730668d

Browse files
committed
httpapi: serve lstore reqs
1 parent 8e12385 commit 730668d

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

apps/tpnode/src/tpnode_httpapi.erl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,48 @@ h(<<"GET">>, [<<"address">>, TAddr, <<"statekeys">>], Req) ->
432432
end;
433433

434434

435+
h(<<"GET">>, [<<"address">>, TAddr, <<"lstore">>|Path], _Req) ->
436+
try
437+
Addr=case TAddr of
438+
<<"0x", Hex/binary>> -> hex:parse(Hex);
439+
_ -> naddress:decode(TAddr)
440+
end,
441+
RawKeys=mledger:get_kpvs(Addr,lstore,'_'),
442+
MatchPath=fun M([],P) -> P;
443+
M([E1|R1],[E2|R2]) when E1==E2 ->
444+
M(R1,R2);
445+
M(_,_) -> false
446+
end,
447+
448+
S1=lists:foldl(
449+
fun({lstore,K,V},Acc) ->
450+
case MatchPath(Path,K) of
451+
false ->
452+
Acc;
453+
P ->
454+
settings:patch([#{<<"t">> => <<"set">>,
455+
<<"p">> =>P,
456+
<<"v">> =>V}],Acc)
457+
end
458+
end, #{}, RawKeys),
459+
{200, [{"Content-Type","application/json"}], S1}
460+
catch
461+
throw:{error, address_crc} ->
462+
err(
463+
10004,
464+
<<"Invalid address">>,
465+
#{result => <<"error">>},
466+
#{http_code => 400}
467+
);
468+
throw:bad_addr ->
469+
err(
470+
10005,
471+
<<"Invalid address (2)">>,
472+
#{result => <<"error">>},
473+
#{http_code => 400}
474+
)
475+
end;
476+
435477
h(<<"GET">>, [<<"address">>, TAddr, <<"state",F/binary>>|Path], _Req) ->
436478
try
437479
Addr=case TAddr of

0 commit comments

Comments
 (0)