Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #180 from helium/andymck/extend-follower-gateway-r…
Browse files Browse the repository at this point in the history
…esp-payload

add additional params to gateway resp
  • Loading branch information
andymck authored Oct 10, 2022
2 parents 661f2d8 + a31de31 commit 6643c7c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.18.1">>},1},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"81fe0a4de38aad4e1a9044623769724419725389"}},
{ref,"1a1a4ae82a898620d96cb486ed76d3857d3ed8f2"}},
0},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},3},
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},2},
Expand Down
33 changes: 24 additions & 9 deletions src/helium_follower_service.erl
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,24 @@ find_gateway(Chain, Ctx, Req) ->
{ok, Height} = blockchain_ledger_v1:current_height(Ledger),
case blockchain_ledger_v1:find_gateway_info(PubKeyBin, Ledger) of
{ok, GwInfo} ->
Location = case blockchain_ledger_gateway_v2:location(GwInfo) of
undefined -> <<>>;
H3 -> h3:to_string(H3)
end,
{ok, #follower_gateway_resp_v1_pb{height=Height, address = PubKeyBin, location=Location,
owner = blockchain_ledger_gateway_v2:owner_address(GwInfo)}, Ctx};
_ ->
{ok, #follower_gateway_resp_v1_pb{height=Height, address = PubKeyBin, location = <<>>,
owner = <<>>}, Ctx}
{Location, Region} =
case blockchain_ledger_gateway_v2:location(GwInfo) of
undefined -> {<<>>, undefined};
H3 ->
case blockchain_region_v1:h3_to_region(H3, Ledger) of
{ok, R} -> {h3:to_string(H3), normalize_region(R)};
_ -> {h3:to_string(H3), undefined}
end
end,
{ok, #follower_gateway_resp_v1_pb{
height=Height,
address = PubKeyBin,
location=Location,
owner = blockchain_ledger_gateway_v2:owner_address(GwInfo),
staking_mode = blockchain_ledger_gateway_v2:mode(GwInfo),
gain = blockchain_ledger_gateway_v2:gain(GwInfo),
region = Region
}, Ctx}
end.

-spec subnetwork_last_reward_height(blockchain:chain() | undefined, ctx:ctx(), follower_pb:follower_subnetwork_last_reward_height_req_v1_pb()) ->
Expand Down Expand Up @@ -253,3 +262,9 @@ validate_txn_filters(TxnFilters0) ->
is_blockchain_txn(Module) ->
ModInfo = Module:module_info(attributes),
lists:any(fun({behavior, [blockchain_txn]}) -> true; (_) -> false end, ModInfo).

%% blockchain_region_v1 returns region as an atom with a 'region_' prefix, ie
%% 'region_us915' etc, we need it without the prefix and capitalised to
%% be compatible with the proto
normalize_region(V) ->
list_to_atom(string:to_upper(string:slice(atom_to_list(V), 7))).

0 comments on commit 6643c7c

Please sign in to comment.