basic grids demo seems to work...
This commit is contained in:
@@ -238,6 +238,7 @@ route(Sock, get, Route, Request, Received) ->
|
||||
end;
|
||||
route(Sock, post, Route, Request, Received) ->
|
||||
case Route of
|
||||
<<"/grids-spend">> -> grids_spend(Sock, Request) , Received;
|
||||
<<"/wfcin">> -> wfcin(Sock, Request) , Received;
|
||||
_ -> fd_httpd_utils:http_err(Sock, 404) , Received
|
||||
end;
|
||||
@@ -319,6 +320,36 @@ ws_echo_loop(Sock, Frames, Received) ->
|
||||
error(Error)
|
||||
end.
|
||||
|
||||
%% ------------------------------
|
||||
%% grids
|
||||
%% ------------------------------
|
||||
|
||||
grids_spend(Sock, #request{enctype = json,
|
||||
body = B = #{"network_id" := NetId,
|
||||
"recipient" := Recipient,
|
||||
"amount" := Amount,
|
||||
"payload" := Payload}}) ->
|
||||
tell("grids_spend good request: ~tp", [B]),
|
||||
RespObj =
|
||||
case fd_gridsd:mk_spend(NetId, Recipient, Amount, unicode:characters_to_binary(Payload)) of
|
||||
{ok, URL, PNG} ->
|
||||
#{"ok" => true,
|
||||
"result" => #{"url" => URL,
|
||||
"png_base64" => unicode:characters_to_list(base64:encode(PNG))}};
|
||||
{error, String} ->
|
||||
#{"ok" => false,
|
||||
"error" => String}
|
||||
end,
|
||||
Body = zj:encode(RespObj),
|
||||
% update cache with new context
|
||||
Response = #response{headers = [{"content-type", "application/json"}],
|
||||
body = Body},
|
||||
fd_httpd_utils:respond(Sock, Response);
|
||||
grids_spend(Sock, Request) ->
|
||||
tell("grids_spend: bad request: ~tp", [Request]),
|
||||
fd_httpd_utils:http_err(Sock, 400).
|
||||
|
||||
|
||||
|
||||
%% ------------------------------
|
||||
%% wfc
|
||||
|
||||
Reference in New Issue
Block a user