diff --git a/src/hz.erl b/src/hz.erl index 8756608..7a72fac 100644 --- a/src/hz.erl +++ b/src/hz.erl @@ -662,9 +662,10 @@ dry_run(TX, Accounts, KBHash) -> request("/v3/dry_run", JSON). -dry_run_map(Map) -> - JSON = zj:binary_encode(Map), - request("/v3/dry_run", JSON). +% TODO +%dry_run_map(Map) -> +% JSON = zj:binary_encode(Map), +% request("/v3/dry_run", JSON). -spec decode_bytearray_fate(EncodedStr) -> {ok, Result} | {error, Reason} @@ -1643,6 +1644,14 @@ convert([], [], _, Terms, []) -> convert([], [], _, _, Errors) -> {error, Errors}. +-spec sign_tx(Unsigned, SecKey) -> Result + when Unsigned :: string(), + SecKey :: binary(), + Result :: {ok, SignedTX} | {error, Reason} + SignedTX :: binary(), + Reason :: chain_error(). +%% @doc +%% Signs transaction data with the provided secret key for the currently selected network. sign_tx(Unsigned, SecKey) -> case network_id() of @@ -1650,6 +1659,15 @@ sign_tx(Unsigned, SecKey) -> Error -> Error end. + +-spec sign_tx(Unsigned, SecKey, NetworkID) -> SignedTX + when Unsigned :: string(), + SecKey :: binary(), + NetworkID :: string(), + SignedTX :: binary(). +%% @doc +%% Signs transaction data with the provided secret key using the provided network ID. + sign_tx(Unsigned, SecKey, MNetworkID) -> UnsignedBin = unicode:characters_to_binary(Unsigned), NetworkID = unicode:characters_to_binary(MNetworkID), @@ -1669,10 +1687,21 @@ sign_tx(Unsigned, SecKey, MNetworkID) -> gmser_api_encoder:encode(transaction, SignedTX). -spend(SenderID, SecKey, ReceipientID, Amount, Payload) -> +-spec spend(SenderID, SecKey, RecipientID, Amount, Payload) -> {ok, Result} | {error, Reason} + when SenderID :: string(), + SecKey :: binary(), + RecipientID :: string(), + Amount :: non_neg_integer(), + Payload :: binary(), + Result :: term(), % FIXME + Reason :: chain_error() | string(). +%% @doc +%% Forms a spend transaction and submits it to the chain. + +spend(SenderID, SecKey, RecipientID, Amount, Payload) -> case status() of {ok, #{"top_block_height" := Height, "network_id" := NetworkID}} -> - spend(SenderID, SecKey, ReceipientID, Amount, Payload, Height, NetworkID); + spend(SenderID, SecKey, RecipientID, Amount, Payload, Height, NetworkID); Error -> Error end. @@ -1699,6 +1728,22 @@ spend(SenderID, SecKey, RecipientID, Amount, Payload, Height, NetworkID) -> end. +-spec spend(SenderID, SecKey, RecipientID, Amount, + GasPrice, Gas, TTL, Nonce, Payload, NetworkID) -> {ok, Result} | {error, Reason} + when SenderID :: string(), + SecKey :: binary(), + RecipientID :: string(), + Amount :: non_neg_integer(), + GasPrice :: pos_integer(), + Gas :: pos_integer(), + TTL :: non_neg_integer(), + Nonce :: non_neg_integer(), + Payload :: binary(), + Result :: term(), % FIXME + Reason :: chain_error() | string(). +%% @doc +%% Forms a spend transaction and submits it to the chain. + spend(SenderID, SecKey, RecipientID, @@ -1811,6 +1856,10 @@ spend3(DSenderID, when Message :: binary(), SecKey :: binary(), Sig :: binary(). +%% @doc +%% Accepts a string to be signed, prepends the prefix `"Gajumaru Signed Message:\n"', +%% encodes the string with `vencode/1', then hashes the encoded message and signs the +%% hash. sign_message(Message, SecKey) -> Prefix = message_sig_prefix(), @@ -1889,6 +1938,12 @@ eu(N, Size) -> when Binary :: binary(), SecKey :: binary(), Sig :: binary(). +%% @doc +%% This procedure signs an arbitrary binary blob with a special binary prefix +%% attached. The reason for the binary prefix is to prevent signing of dangerous +%% binaries which could be used to authorized dangerous actions on chain. +%% The signature target becomes: `<<"Gajumaru Signed Binary:", Binary/binary>>' +%% before being hashed, and then the resulting hash is signed. sign_binary(Binary, SecKey) -> Prefix = binary_sig_prefix(), @@ -1903,6 +1958,8 @@ sign_binary(Binary, SecKey) -> PubKey :: pubkey(), Result :: {ok, Outcome :: boolean()} | {error, Reason :: term()}. +%% @doc +%% Verifies a signature created with the `sign_binary/2' function. verify_bin_signature(Sig, Binary, PubKey) -> case gmser_api_encoder:decode(PubKey) of diff --git a/src/hz_fetcher.erl b/src/hz_fetcher.erl index 0cf8414..37f931e 100644 --- a/src/hz_fetcher.erl +++ b/src/hz_fetcher.erl @@ -1,3 +1,11 @@ +%%% @private +%%% Hakuzaru Request Fetcher +%%% +%%% This module defines the request workers. +%%% Each request to a remote chain node is handled by a worker that is spawned +%%% to handle it and terminates on completion. +%%% @end + -module(hz_fetcher). -vsn("0.9.1"). -author("Craig Everett ").