Merge pull request 'Doc update for hz_sophia and hz_aaci and some minor fixes' (#30) from spivee/docs into master
Reviewed-on: #30
This commit was merged in pull request #30.
This commit is contained in:
+70
-10
@@ -23,7 +23,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(hz).
|
||||
-vsn("0.9.1").
|
||||
-vsn("0.9.2").
|
||||
-author("Craig Everett <ceverett@tsuriai.jp>").
|
||||
-copyright("Craig Everett <ceverett@tsuriai.jp>").
|
||||
-license("GPL-3.0-or-later").
|
||||
@@ -125,13 +125,14 @@
|
||||
% "info" => contract_byte_array(),
|
||||
% "miner" => account_id(),
|
||||
% "nonce" => non_neg_integer(),
|
||||
% "pow" => [non_neg_integer()],
|
||||
% "prev_hash" => microblock_hash(),
|
||||
% "prev_key_hash" => keyblock_hash(),
|
||||
% "seal" => #{"data" => [int()],
|
||||
% "signature" => signature()}
|
||||
% "state_hash" => block_state_hash(),
|
||||
% "target" => non_neg_integer(),
|
||||
% "time" => non_neg_integer(),
|
||||
% "version" => 5}.
|
||||
% "version" => 1}.
|
||||
% </pre>
|
||||
-type microblock_header() :: #{string() => term()}.
|
||||
% <pre>
|
||||
@@ -353,7 +354,7 @@ top_height() ->
|
||||
|
||||
|
||||
-spec top_block() -> {ok, TopBlock} | {error, Reason}
|
||||
when TopBlock :: microblock_header(),
|
||||
when TopBlock :: microblock_header() | keyblock(),
|
||||
Reason :: chain_error().
|
||||
%% @doc
|
||||
%% Returns the header of the current top block.
|
||||
@@ -661,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}
|
||||
@@ -813,8 +815,10 @@ extract2(TarBaby) ->
|
||||
{ok, Source};
|
||||
{ok, Bundle} ->
|
||||
{project, Bundle};
|
||||
{error,invalid_tar_checksum} ->
|
||||
{ok, TarBaby};
|
||||
Error ->
|
||||
io:format("Dis chit happen: ~tp~n", [Error]),
|
||||
ok = io:format("erl_tar:extract/2 error: ~tp~n", [Error]),
|
||||
{ok, TarBaby}
|
||||
end.
|
||||
|
||||
@@ -1649,6 +1653,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
|
||||
@@ -1656,6 +1668,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),
|
||||
@@ -1675,10 +1696,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.
|
||||
@@ -1705,6 +1737,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,
|
||||
@@ -1817,6 +1865,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(),
|
||||
@@ -1895,6 +1947,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(),
|
||||
@@ -1909,6 +1967,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
|
||||
|
||||
Reference in New Issue
Block a user