Fix typos, add .gitignore
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
[{description, "Gajumaru Mining Pool Protocol (server- + client-side)"},
|
||||
{vsn, "0.1.0"},
|
||||
{registered, []},
|
||||
{application,
|
||||
{applications,
|
||||
[
|
||||
kernel
|
||||
, stdlib
|
||||
|
||||
+27
-10
@@ -36,7 +36,7 @@
|
||||
|
||||
-define(VSN0, <<"0.1">>).
|
||||
-define(VSN, ?VSN0).
|
||||
-define(PROTOCOL_JSON, pool_ws_json).
|
||||
-define(PROTOCOL_JSON, <<"pool_ws_json">>).
|
||||
-define(PROTOCOL, ?PROTOCOL_JSON).
|
||||
|
||||
-spec latest_version() -> version().
|
||||
@@ -54,14 +54,24 @@ versions() -> [?VSN0].
|
||||
%% List sorted highest priority first
|
||||
protocols(_Vsn) -> [?PROTOCOL].
|
||||
|
||||
validate(#{ connect := #{ pubkey := PK }} = Msg, _Vsn) ->
|
||||
validate(#{ connect := #{ pubkey := PK
|
||||
, protocols := Protocols
|
||||
, versions := Versions
|
||||
}} = Msg, _Vsn) ->
|
||||
valid({list, protocol}, Protocols),
|
||||
valid({list, version} , Versions),
|
||||
valid(pubkey, PK),
|
||||
Msg;
|
||||
validate(#{ connect_ack := #{ pubkey := PK
|
||||
validate(#{ connect_ack := #{ protocol := Protocol0
|
||||
, version := Version
|
||||
, pubkey := PK
|
||||
, edge_bits := EB }} = Msg, _Vsn) ->
|
||||
Protocol = binary_to_existing_atom(Protocol0, utf8),
|
||||
valid(protocol, Protocol),
|
||||
valid(version, Version),
|
||||
valid(pubkey, PK),
|
||||
valid(edgebits, EB),
|
||||
Msg;
|
||||
Msg#{ protocol => Protocol };
|
||||
validate(#{ nonces := #{ seq := Seq
|
||||
, n := N } } = Msg, _Vsn) ->
|
||||
valid(seq, Seq),
|
||||
@@ -151,18 +161,23 @@ encode_request(Req0, Id, ?PROTOCOL_JSON, Vsn) ->
|
||||
, <<"method">> => Method
|
||||
, <<"args">> => Args }).
|
||||
|
||||
encode_reply(Reply0, Id, ?PROTOCOL_JSON, Vsn) ->
|
||||
encode_reply(Reply0, Id, ?PROTOCOL_JSON, Vsn) when is_map(Reply0) ->
|
||||
Reply = validate(Reply0, Vsn),
|
||||
Msg = #{ <<"jsonrpc">> => <<"2.0">>
|
||||
, <<"id">> => Id
|
||||
, <<"result">> => Reply },
|
||||
json:encode(Msg);
|
||||
encode_reply(Reply, Id, ?PROTOCOL_JSON, _Vsn) ->
|
||||
Msg = case Reply of
|
||||
{error, Reason} ->
|
||||
#{ <<"jsonrpc">> => <<"2.0">>
|
||||
, <<"id">> => Id
|
||||
, <<"error">> => #{ <<"code">> => error_code(Reason)
|
||||
, <<"message">> => Reason }};
|
||||
Result ->
|
||||
ok ->
|
||||
#{ <<"jsonrpc">> => <<"2.0">>
|
||||
, <<"id">> => Id
|
||||
, <<"result">> => Result }
|
||||
, <<"result">> => <<"ok">> }
|
||||
end,
|
||||
json:encode(Msg).
|
||||
|
||||
@@ -197,7 +212,6 @@ decode_msg_(<<"solution">>, #{ <<"seq">> := Seq
|
||||
, <<"evidence">> := Evidence }) ->
|
||||
#{solution => #{ seq => Seq
|
||||
, nonce => Nonces
|
||||
, seq => Seq
|
||||
, evidence => Evidence}}.
|
||||
|
||||
valid(Type, Val) ->
|
||||
@@ -207,7 +221,10 @@ valid(Type, Val) ->
|
||||
false
|
||||
end.
|
||||
|
||||
valid_(pubkey, PK) -> ok_tuple(aeser_api:safe_decode(account_pubkey, PK));
|
||||
valid_({list,T}, Ps) -> lists:all(fun(X) -> valid_(T, X) end, Ps);
|
||||
valid_(protocol, P) -> is_binary(P);
|
||||
valid_(version, V) -> is_binary(V);
|
||||
valid_(pubkey, PK) -> ok_tuple(gmser_api_encoder:safe_decode(account_pubkey, PK));
|
||||
valid_(seq, Seq) -> pos_integer(Seq);
|
||||
valid_(edgebits, E) -> pos_integer(E);
|
||||
valid_(pos_int, I) -> pos_integer(I);
|
||||
@@ -218,7 +235,7 @@ valid_(nonces, Ns) ->
|
||||
_ ->
|
||||
false
|
||||
end;
|
||||
valid_(candidate, C) -> ok_tuple(aeser_api:safe_decode(bytearray, C)).
|
||||
valid_(candidate, C) -> ok_tuple(gmser_api_encoder:safe_decode(bytearray, C)).
|
||||
|
||||
ok_tuple(V) ->
|
||||
case V of
|
||||
|
||||
Reference in New Issue
Block a user