Unverified Commit 0c7e0a97 authored by Marc Nijdam's avatar Marc Nijdam Committed by GitHub
Browse files

Merge pull request #1256 from helium/jsc/jsonrpc-b58-fixes

Fix JSONRPC B58 translations for gateway txns.
parents 7e90707c dd1341d5
Showing with 17 additions and 11 deletions
+17 -11
......@@ -30,11 +30,11 @@ handle_rpc(<<"txn_queue">>, []) ->
end;
handle_rpc(<<"txn_add_gateway">>, #{ <<"owner">> := OwnerB58 } = Params) ->
try
Payer = case maps:get(payer, Params, undefined) of
undefined -> undefined;
PayerB58 -> ?B58_TO_BIN(PayerB58)
end,
{ok, Bin} = blockchain:add_gateway_txn(?B58_TO_BIN(OwnerB58), Payer),
Payer = optional_binary_to_list(
maps:get(payer, Params, undefined)
),
Owner = binary_to_list(OwnerB58),
{ok, Bin} = blockchain:add_gateway_txn(Owner, Payer),
B64 = base64:encode(Bin),
#{ <<"result">> => B64 }
catch
......@@ -46,17 +46,16 @@ handle_rpc(<<"txn_add_gateway">>, #{ <<"owner">> := OwnerB58 } = Params) ->
end;
handle_rpc(<<"txn_assert_location">>, #{ <<"owner">> := OwnerB58 } = Params) ->
try
Payer = case maps:get(payer, Params, undefined) of
undefined -> undefined;
PayerB58 -> ?B58_TO_BIN(PayerB58)
end,
Payer = optional_binary_to_list(
maps:get(payer, Params, undefined)
),
Owner = binary_to_list(OwnerB58),
H3String = case parse_location(Params) of
{error, _} = Err -> throw(Err);
{ok, S} -> S
end,
Nonce = maps:get(nonce, Params, 1),
{ok, Bin} = blockchain:assert_loc_txn(H3String, ?B58_TO_BIN(OwnerB58),
Payer, Nonce),
{ok, Bin} = blockchain:assert_loc_txn(H3String, Owner, Payer, Nonce),
B64 = base64:encode(Bin),
#{ <<"result">> => B64 }
catch
......@@ -69,6 +68,13 @@ handle_rpc(<<"txn_assert_location">>, #{ <<"owner">> := OwnerB58 } = Params) ->
handle_rpc(_, _) ->
?jsonrpc_error(method_not_found).
-spec optional_binary_to_list(undefined | binary()) -> undefined | string().
optional_binary_to_list(PossibleBinary) ->
case PossibleBinary of
undefined -> undefined;
Bin -> binary_to_list(Bin)
end.
parse_location(#{ <<"h3">> := H3 }) ->
try
%% h3 literally expects a string, not a binary string, so...
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment