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

Commit

Permalink
Implement transfer hotspot transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
jadeallenx committed Nov 5, 2020
1 parent f76bc24 commit 274faba
Show file tree
Hide file tree
Showing 7 changed files with 791 additions and 6 deletions.
6 changes: 6 additions & 0 deletions include/blockchain_vars.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,9 @@

%% Multi-key
-define(use_multi_keys, use_multi_keys).

%% transfer hotspot
%% This is the number of blocks after which a hotspot which hasn't had a
%% POC challenge for X blocks would be considered stale for the purposes
%% of a hotspot transfer. (We do not allow stale hotspots to be transferred.)
-define(transfer_hotspot_stale_poc_blocks, transfer_hotspot_stale_poc_blocks).
6 changes: 3 additions & 3 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
0},
{<<"exor_filter">>,
{git,"https://github.com/mpope9/exor_filter",
{ref,"7b7493b08a2feb7d8e3685f1fd6ffa36db0df8fa"}},
{ref,"b44086d6ad71deb34b935cbff2a3c376a7900652"}},
0},
{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},2},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
Expand All @@ -41,7 +41,7 @@
0},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"37dd23b7d59f5ae110ffd9cac7332304301ab811"}},
{ref,"09f4ae5764e940d490ac4e3f096be9c348ca4219"}},
0},
{<<"inert">>,
{git,"https://github.com/msantos/inert",
Expand All @@ -59,7 +59,7 @@
0},
{<<"libp2p">>,
{git,"https://github.com/helium/erlang-libp2p.git",
{ref,"a7ab7bfc8eeb8e9845e6ce5859e4c1db8fa80faf"}},
{ref,"edf8e052b99a13656c4d847cb30adb8bf21003df"}},
0},
{<<"libp2p_crypto">>,{pkg,<<"libp2p_crypto">>,<<"1.1.0">>},1},
{<<"merkerl">>,
Expand Down
29 changes: 29 additions & 0 deletions src/blockchain_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
calculate_dc_amount/2, calculate_dc_amount/3,
do_calculate_dc_amount/2,
deterministic_subset/3,
fold_condition_checks/1,

%% exports for simulations
free_space_path_loss/4,
Expand Down Expand Up @@ -470,6 +471,22 @@ poc_per_hop_max_witnesses(Ledger) ->
?POC_PER_HOP_MAX_WITNESSES
end.

%%--------------------------------------------------------------------
%% @doc Given a list of tuples of zero arity functions that return a
%% boolean and error tuples, evaluate each function. If a function
%% returns `false' then immediately return the associated error tuple.
%% Otherwise, if all conditions evaluate as `true', return `ok'.
%% @end
%%--------------------------------------------------------------------
-spec fold_condition_checks([{Condition :: fun(() -> boolean()),
Error :: {error, any()}}]) -> ok | {error, any()}.
fold_condition_checks(Conditions) ->
do_condition_check(Conditions, undefined, true).

do_condition_check(_Conditions, PrevErr, false) -> PrevErr;
do_condition_check([], _PrevErr, true) -> ok;
do_condition_check([{Condition, Error}|Tail], _PrevErr, true) ->
do_condition_check(Tail, Error, Condition()).

majority(N) ->
(N div 2) + 1.
Expand Down Expand Up @@ -588,4 +605,16 @@ count_votes_test() ->
?assertEqual(5, count_votes(Artifact, PKeys ++ [libp2p_crypto:pubkey_to_bin(PubKey5)], Sigs ++ [ExtraSig])),
ok.

fold_condition_checks_good_test() ->
Conditions = [{fun() -> true end, {error, true_isnt_true}},
{fun() -> 100 > 10 end, {error, one_hundred_greater_than_10}},
{fun() -> <<"blort">> == <<"blort">> end, {error, blort_isnt_blort}}],
?assertEqual(ok, fold_condition_checks(Conditions)).

fold_condition_checks_bad_test() ->
Bad = [{fun() -> true end, {error, true_isnt_true}},
{fun() -> 10 > 100 end, {error, '10_not_greater_than_100'}},
{fun() -> <<"blort">> == <<"blort">> end, {error, blort_isnt_blort}}],
?assertEqual({error, '10_not_greater_than_100'}, fold_condition_checks(Bad)).

-endif.
12 changes: 9 additions & 3 deletions src/transactions/blockchain_txn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
| blockchain_txn_update_gateway_oui_v1:txn_update_gateway_oui()
| blockchain_txn_price_oracle_v1:txn_price_oracle()
| blockchain_txn_gen_price_oracle_v1:txn_genesis_price_oracle()
| blockchain_txn_transfer_hotspot_v1:txn_transfer_hotspot()
| blockchain_txn_state_channel_close_v1:txn_state_channel_close().

-type before_commit_callback() :: fun((blockchain:blockchain(), blockchain_block:hash()) -> ok | {error, any()}).
Expand Down Expand Up @@ -108,7 +109,8 @@
{blockchain_txn_payment_v2, 19},
{blockchain_txn_state_channel_open_v1, 20},
{blockchain_txn_update_gateway_oui_v1, 21},
{blockchain_txn_state_channel_close_v1, 22}
{blockchain_txn_state_channel_close_v1, 22},
{blockchain_txn_transfer_hotspot_v1, 23}
]).

block_delay() ->
Expand Down Expand Up @@ -185,7 +187,9 @@ wrap_txn(#blockchain_txn_state_channel_close_v1_pb{}=Txn) ->
wrap_txn(#blockchain_txn_price_oracle_v1_pb{}=Txn) ->
#blockchain_txn_pb{txn={price_oracle_submission, Txn}};
wrap_txn(#blockchain_txn_gen_price_oracle_v1_pb{}=Txn) ->
#blockchain_txn_pb{txn={gen_price_oracle, Txn}}.
#blockchain_txn_pb{txn={gen_price_oracle, Txn}};
wrap_txn(#blockchain_txn_transfer_hotspot_v1_pb{}=Txn) ->
#blockchain_txn_pb{txn={transfer_hotspot, Txn}}.

-spec unwrap_txn(#blockchain_txn_pb{}) -> blockchain_txn:txn().
unwrap_txn(#blockchain_txn_pb{txn={bundle, #blockchain_txn_bundle_v1_pb{transactions=Txns} = Bundle}}) ->
Expand Down Expand Up @@ -564,7 +568,9 @@ type(#blockchain_txn_state_channel_close_v1_pb{}) ->
type(#blockchain_txn_price_oracle_v1_pb{}) ->
blockchain_txn_price_oracle_v1;
type(#blockchain_txn_gen_price_oracle_v1_pb{}) ->
blockchain_txn_gen_price_oracle_v1.
blockchain_txn_gen_price_oracle_v1;
type(#blockchain_txn_transfer_hotspot_v1_pb{}) ->
blockchain_txn_transfer_hotspot_v1.


-spec validate_fields([{{atom(), iodata() | undefined},
Expand Down
Loading

0 comments on commit 274faba

Please sign in to comment.