Expand and upgrade genesis tools

parent fe24f670
Pipeline #31122903 passed with stages
in 49 minutes and 42 seconds
......@@ -60,4 +60,7 @@ $(DEPS_DIR)/elixir/ebin:
no-bad-mix-app-files:
$(verbose) rm -rf $(DEPS_DIR)/elixir/lib/mix/test
.PHONY: no-bad-mix-app-files
filter-genesis-txs:
@$(SHELL_ERL) -pa $(SHELL_PATHS) -noshell -eval 'ercoin_genesis:filter_genesis_txs(), halt()'
.PHONY: filter-genesis-txs no-bad-mix-app-files
......@@ -10,7 +10,7 @@
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% @reference <a href="https://hackage.haskell.org/package/burnt-explorer-1.0.0">burnt-explorer 1.0.0</a> — it is assumed that it is used to generate files containing burnt BlackCoin outputs.
%% @reference <a href="https://hackage.haskell.org/package/burnt-explorer-2.0.0">burnt-explorer 2.0.0</a> — it is assumed that it is used to generate files containing burnt BlackCoin outputs.
-module(ercoin_genesis).
-compile({parse_transform, category}).
......@@ -21,6 +21,9 @@
data_to_genesis_json/2,
initial_distribution/2,
initial_data/5,
filter_genesis_txs/0,
line_to_score/1,
payload_from_script_hex/1,
sk_to_priv_validator_json/1]).
-import(
......@@ -113,6 +116,8 @@ sk_to_priv_validator_json(SK) ->
-spec payload_from_script_hex(string()) -> datum:option(binary()).
payload_from_script_hex(ScriptHex) ->
case hexstr_to_bin(ScriptHex) of
<<?OP_RETURN, Length, Payload2:Length/binary>> when Length >= 1, Length =< 75 ->
unit(Payload2);
<<?OP_RETURN, ?OP_PUSHDATA1, Length, Payload2:Length/binary>> ->
unit(Payload2);
<<?OP_RETURN, ?OP_PUSHDATA2, Length:2/unit:8, Payload2:Length/binary>> ->
......@@ -123,11 +128,6 @@ payload_from_script_hex(ScriptHex) ->
fail("Script not recognized.")
end.
-spec amount_str_to_satoshis(string()) -> non_neg_integer().
amount_str_to_satoshis(AmountStr) ->
{ok, [AmountFloat], []} = io_lib:fread("~f", AmountStr),
round(AmountFloat * ?SATOSHIS_IN_BLK).
-spec payload_amount_to_score(binary(), non_neg_integer()) -> datum:option(score()).
payload_amount_to_score(
<<"Ercoin "/utf8,
......@@ -169,11 +169,31 @@ payload_amount_to_score(_, _) ->
-spec line_to_score(string()) -> datum:option(score()).
line_to_score(Line) ->
[_, _, AmountStr, ScriptHex|_] = string:split(Line, " ", all),
[_, _, _, _, _, AmountStr, ScriptHex|_] = string:split(Line, ",", all),
[option ||
Payload <- payload_from_script_hex(ScriptHex),
Amount =< amount_str_to_satoshis(AmountStr),
payload_amount_to_score(Payload, Amount)].
payload_amount_to_score(Payload, list_to_integer(AmountStr))].
-spec filter_lines(fun((string()) -> datum:option(any()))) -> ok.
%% @doc Filter lines from stdin which mean something to the provided function. Output to stdout.
filter_lines(F) ->
case io:get_line("") of
eof ->
ok;
Line ->
ok =
case F(string:trim(Line)) of
undefined ->
ok;
_ ->
io:format("~s", [Line])
end,
?FUNCTION_NAME(F)
end.
-spec filter_genesis_txs() -> ok.
filter_genesis_txs() ->
filter_lines(fun line_to_score/1).
-spec extract_from_file_lines(file:io_device(), fun((string()) -> datum:option(T))) -> list(T).
%% @doc Extract data from file using a specified function. Returns a list in reversed order.
......@@ -273,7 +293,7 @@ initial_data_without_votes(Accounts, VotesEndTimestamp, StartingTimestamp) ->
-spec line_to_vote_tx(string()) -> datum:option(vote_tx()).
line_to_vote_tx(Line) ->
[_, _, _, ScriptHex|_] = string:split(Line, " ", all),
[_, _, _, _, _, _, ScriptHex|_] = string:split(Line, ",", all),
case payload_from_script_hex(ScriptHex) of
undefined ->
fail("No payload.");
......
Markdown is supported
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