Packages

Various modules and helpers for working with Nimiq primitives in the Gleam programming language or as a CLI

Current section

Files

Jump to
nimiq_gleam src cli@new_transaction_command.erl
Raw

src/cli@new_transaction_command.erl

-module(cli@new_transaction_command).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([run/0]).
-file("src/cli/new_transaction_command.gleam", 23).
-spec fee_flag() -> glint:flag(integer()).
fee_flag() ->
_pipe = glint:int_flag(<<"fee"/utf8>>),
_pipe@1 = glint:flag_default(_pipe, 0),
glint:flag_help(
_pipe@1,
<<"Set the transaction's fee in luna. Default is 0."/utf8>>
).
-file("src/cli/new_transaction_command.gleam", 29).
-spec msg_flag() -> glint:flag(binary()).
msg_flag() ->
_pipe = glint:string_flag(<<"msg"/utf8>>),
_pipe@1 = glint:flag_help(
_pipe,
<<"Add a message to the transaction, maximum 64 bytes."/utf8>>
),
glint:flag_constraint(
_pipe@1,
fun(Msg) -> case erlang:byte_size(Msg) =< 64 of
true ->
{ok, Msg};
false ->
{error,
snag:new(
<<"msg must not be longer than 64 bytes"/utf8>>
)}
end end
).
-file("src/cli/new_transaction_command.gleam", 40).
-spec network_flag() -> glint:flag(integer()).
network_flag() ->
_pipe = glint:int_flag(<<"network"/utf8>>),
_pipe@1 = glint:flag_default(_pipe, 5),
_pipe@3 = glint:flag_constraint(
_pipe@1,
begin
_pipe@2 = [5, 24],
glint@constraint:one_of(_pipe@2)
end
),
glint:flag_help(
_pipe@3,
<<"Set the network ID. Albatross Testnet => 5, Albatross Mainnet => 24. Default is 5."/utf8>>
).
-file("src/cli/new_transaction_command.gleam", 50).
-spec private_key_flag() -> glint:flag(binary()).
private_key_flag() ->
_pipe = glint:string_flag(<<"sign-with"/utf8>>),
_pipe@1 = glint:flag_help(
_pipe,
<<"Set the private key to sign the transaction with."/utf8>>
),
glint:flag_constraint(
_pipe@1,
fun(Key) -> case gleam_stdlib:base16_decode(Key) of
{ok, _} ->
{ok, Key};
{error, _} ->
{error,
snag:new(
<<"private key must be 32 bytes in hex format"/utf8>>
)}
end end
).
-file("src/cli/new_transaction_command.gleam", 61).
-spec run() -> glint:command(nil).
run() ->
glint:command_help(
<<"Creates Nimiq transactions"/utf8>>,
fun() ->
glint:named_arg(
<<"SENDER"/utf8>>,
fun(Sender) ->
glint:named_arg(
<<"RECIPIENT"/utf8>>,
fun(Recipient) ->
glint:named_arg(
<<"VALUE_LUNA"/utf8>>,
fun(Value) ->
glint:flag(
fee_flag(),
fun(Fee) ->
glint:flag(
msg_flag(),
fun(Msg) ->
glint:named_arg(
<<"VALIDITY_START_HEIGHT"/utf8>>,
fun(
Validity_start_height
) ->
glint:flag(
network_flag(),
fun(Network_id) ->
glint:flag(
private_key_flag(
),
fun(
Private_key
) ->
glint:command(
fun(
Named,
_,
Flags
) ->
Sender@2 = case begin
_pipe = Sender(
Named
),
account@address:from_string(
_pipe
)
end of
{ok,
Sender@1} -> Sender@1;
_assert_fail ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"cli/new_transaction_command"/utf8>>,
function => <<"run"/utf8>>,
line => 75}
)
end,
Recipient@2 = case begin
_pipe@1 = Recipient(
Named
),
account@address:from_string(
_pipe@1
)
end of
{ok,
Recipient@1} -> Recipient@1;
_assert_fail@1 ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@1,
module => <<"cli/new_transaction_command"/utf8>>,
function => <<"run"/utf8>>,
line => 76}
)
end,
Value@2 = case begin
_pipe@2 = Value(
Named
),
_pipe@3 = gleam_stdlib:parse_int(
_pipe@2
),
gleam@result:map(
_pipe@3,
fun(Field@0) -> {coin, Field@0} end
)
end of
{ok,
Value@1} -> Value@1;
_assert_fail@2 ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@2,
module => <<"cli/new_transaction_command"/utf8>>,
function => <<"run"/utf8>>,
line => 77}
)
end,
Fee@2 = case begin
_pipe@4 = Fee(
Flags
),
gleam@result:map(
_pipe@4,
fun(Field@0) -> {coin, Field@0} end
)
end of
{ok,
Fee@1} -> Fee@1;
_assert_fail@3 ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@3,
module => <<"cli/new_transaction_command"/utf8>>,
function => <<"run"/utf8>>,
line => 78}
)
end,
Data = begin
_pipe@5 = Msg(
Flags
),
_pipe@6 = gleam@result:map(
_pipe@5,
fun gleam_stdlib:identity/1
),
gleam@result:unwrap(
_pipe@6,
<<>>
)
end,
Validity_start_height@2 = case begin
_pipe@7 = Validity_start_height(
Named
),
gleam_stdlib:parse_int(
_pipe@7
)
end of
{ok,
Validity_start_height@1} -> Validity_start_height@1;
_assert_fail@4 ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@4,
module => <<"cli/new_transaction_command"/utf8>>,
function => <<"run"/utf8>>,
line => 81}
)
end,
Network_id@2 = case begin
_pipe@8 = Network_id(
Flags
),
gleam@result:map(
_pipe@8,
fun(
Num
) ->
_pipe@9 = transaction@network_id:from_int(
Num
),
utils@misc:unwrap(
_pipe@9
)
end
)
end of
{ok,
Network_id@1} -> Network_id@1;
_assert_fail@5 ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@5,
module => <<"cli/new_transaction_command"/utf8>>,
function => <<"run"/utf8>>,
line => 83}
)
end,
Tx = transaction@transaction_builder:new_basic_with_data(
Sender@2,
Recipient@2,
Data,
Value@2,
Fee@2,
Validity_start_height@2,
Network_id@2,
none
),
_pipe@11 = case Private_key(
Flags
) of
{error,
_} ->
Tx;
{ok,
Private_key@1} ->
Private_key@3 = case begin
_pipe@10 = Private_key@1,
key@ed25519@private_key:from_hex(
_pipe@10
)
end of
{ok,
Private_key@2} -> Private_key@2;
_assert_fail@6 ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@6,
module => <<"cli/new_transaction_command"/utf8>>,
function => <<"run"/utf8>>,
line => 103}
)
end,
Public_key = key@ed25519@public_key:derive_key(
Private_key@3
),
Signature = key@ed25519@signature:create(
Private_key@3,
Public_key,
transaction@transaction:serialize_content(
Tx
)
),
Proof = transaction@signature_proof:single_sig(
{ed_dsa_public_key,
Public_key},
{ed_dsa_signature,
Signature}
),
transaction@transaction:set_signature_proof(
Tx,
Proof
)
end,
_pipe@12 = transaction@transaction:to_hex(
_pipe@11
),
_pipe@13 = utils@misc:unwrap(
_pipe@12
),
gleam_stdlib:println(
_pipe@13
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).