@@ -375,38 +375,45 @@ h(<<"GET">>, [<<"nodes">>, Chain], _Req) ->
375375 chain_nodes => get_nodes (binary_to_integer (Chain , 10 ))
376376 });
377377
378- h (<<" GET" >>, [<<" address" >>, TAddr , <<" statekeys" >>], _Req ) ->
378+ h (<<" GET" >>, [<<" address" >>, TAddr , <<" statekeys" >>], Req ) ->
379379 try
380380 Addr = case TAddr of
381381 <<" 0x" , Hex /binary >> -> hex :parse (Hex );
382382 _ -> naddress :decode (TAddr )
383383 end ,
384- Ledger = mledger :get (Addr ),
385- case Ledger =/= undefined of
386- false ->
387- err (
388- 10003 ,
389- <<" Not found" >>,
390- #{result => <<" not_found" >>},
391- #{http_code => 404 }
392- );
393- true ->
394- State = maps :get (state , Ledger , #{}),
395- S1 = maps :fold (
396- fun (K ,_ ,Acc ) ->
397- [<<" 0x" ,(hex :encode (K ))/binary >>|Acc ]
398- end , [], State ),
384+ case mledger :get_kpv (Addr ,vm ,'_' ) of
385+ undefined ->
386+ err (
387+ 10003 ,
388+ <<" Not found" >>,
389+ #{result => <<" not_found" >>},
390+ #{http_code => 404 }
391+ );
392+ {ok ,_VM } ->
393+ RawKeys = mledger :get_kpvs (Addr ,state ,'_' ),
394+
395+ S1 = case maps :get (req_format ,Req ) of
396+ <<" mp" >> ->
397+ lists :foldl (
398+ fun ({state ,K ,_ },Acc ) ->
399+ [K |Acc ]
400+ end , [], RawKeys );
401+ _ -> % default hex encode
402+ lists :foldl (
403+ fun ({state ,K ,_ },Acc ) ->
404+ [<<" 0x" ,(hex :encode (K ))/binary >>|Acc ]
405+ end , [], RawKeys )
406+ end ,
399407 {200 , [{" Content-Type" ," application/json" }],
400408 #{
401409 notice => <<" Only for debugging. Do not use it in scripts!!!" >>,
402410 keys => S1
403411 }
404412 }
405-
406413 end
407414 catch
408415 throw :{error , address_crc } ->
409- err (
416+ err (
410417 10004 ,
411418 <<" Invalid address" >>,
412419 #{result => <<" error" >>},
@@ -428,41 +435,47 @@ h(<<"GET">>, [<<"address">>, TAddr, <<"state",F/binary>>|Path], _Req) ->
428435 <<" 0x" , Hex /binary >> -> hex :parse (Hex );
429436 _ -> naddress :decode (TAddr )
430437 end ,
431- Ledger = mledger :get (Addr ),
432- case Ledger =/= undefined of
433- false ->
438+ case mledger :get_kpv (Addr ,vm ,'_' ) of
439+ undefined ->
434440 err (
435441 10003 ,
436442 <<" Not found" >>,
437443 #{result => <<" not_found" >>},
438444 #{http_code => 404 }
439445 );
440- true ->
441- State = maps :get (state , Ledger , #{}),
446+ {ok ,_VM } ->
442447 case Path of
443448 [] ->
444- ? LOG_INFO ( " F ~p " ,[ F ] ),
449+ RawKeys = mledger : get_kpvs ( Addr , state , '_' ),
445450 case F of <<>> ->
446- S1 = msgpack :pack (State ),
451+ KVs = lists :foldl (
452+ fun ({state ,K ,V }, A ) ->
453+ maps :put (K ,V ,A )
454+ end ,#{},RawKeys
455+ ),
456+ S1 = msgpack :pack (KVs ),
447457 {200 , [{" Content-Type" ," binary/octet-stream" }], S1 };
448458 <<" json" >> ->
449- S1 = maps : fold (
450- fun (K ,V ,Acc ) ->
451- maps :put (
452- base64 :encode (K ),
453- base64 :encode (V ),
454- Acc )
455- end , #{
456- notice => <<" Only for Sasha" >>
457- }, State ),
459+ S1 = lists : foldl (
460+ fun ({ state , K ,V } ,Acc ) ->
461+ maps :put (
462+ base64 :encode (K ),
463+ base64 :encode (V ),
464+ Acc )
465+ end , #{
466+ notice => <<" Only for Sasha" >>
467+ }, RawKeys ),
458468 {200 , [{" Content-Type" ," application/json" }], S1 }
459469 end ;
460470 [Key ] ->
461471 K = case Key of
462472 <<" 0x" , HexK /binary >> -> hex :parse (HexK );
463473 _ -> base64 :decode (Key )
464474 end ,
465- Val = maps :get (K ,State ,<<>>),
475+ Val = case mledger :get_kpv (Addr ,state ,K ) of
476+ undefined -> <<>>;
477+ {ok ,V1 } -> V1
478+ end ,
466479 {200 , [{" Content-Type" ," binary/octet-stream" }], Val }
467480 end
468481 end
@@ -490,17 +503,16 @@ h(<<"GET">>, [<<"address">>, TAddr, <<"code">>], _Req) ->
490503 <<" 0x" , Hex /binary >> -> hex :parse (Hex );
491504 _ -> naddress :decode (TAddr )
492505 end ,
493- Ledger = mledger :get (Addr ),
494- case Ledger =/= undefined of
495- false ->
506+ Ledger = mledger :get_kpv (Addr , code , [] ),
507+ case Ledger of
508+ undefined ->
496509 err (
497510 10003 ,
498511 <<" Not found" >>,
499512 #{result => <<" not_found" >>},
500513 #{http_code => 404 }
501514 );
502- true ->
503- Code = maps :get (code , Ledger , <<>>),
515+ {ok , Code } ->
504516 {200 , [{" Content-Type" ," binary/octet-stream" }], Code }
505517 end
506518 catch
0 commit comments