Fix typos, add .gitignore
This commit is contained in:
parent
3a061f057c
commit
f789e9e945
28
.gitignore
vendored
Normal file
28
.gitignore
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
.rebar3
|
||||
.eunit
|
||||
*.o
|
||||
*.beam
|
||||
*.plt
|
||||
*.swp
|
||||
*.swo
|
||||
.erlang.cookie
|
||||
.directory
|
||||
ebin
|
||||
log
|
||||
erl_crash.dump
|
||||
.rebar
|
||||
logs
|
||||
_build
|
||||
REVISION
|
||||
VERSION
|
||||
*.erl~
|
||||
*.aes~
|
||||
data/mnesia
|
||||
_checkouts/
|
||||
tmp/
|
||||
rebar3.crashdump
|
||||
eqc-lib
|
||||
eqc
|
||||
eunit_report/*.xml
|
||||
.history
|
||||
.vscode
|
@ -2,12 +2,14 @@
|
||||
{erl_opts, [debug_info]}.
|
||||
{plugins, [rebar3_hex]}.
|
||||
{deps, [
|
||||
{ranch, "2.2.0"},
|
||||
{enoise, {git, "https://git.qpq.swiss/QPQ-AG/enoise.git", {ref, "8acbce9"}}}
|
||||
{gmserialization, {git, "https://git.qpq.swiss/QPQ-AG/gmserialization.git",
|
||||
{ref, "ac64e01b0f"}}}
|
||||
]}.
|
||||
|
||||
{xref_checks, [undefined_function_calls, undefined_functions,
|
||||
locals_not_used,
|
||||
deprecated_function_calls, deprecated_functions]}.
|
||||
|
||||
{dialyzer, [{warnings, [unknown]}]}.
|
||||
{dialyzer, [ {warnings, [unknown]}
|
||||
, {plt_apps, all_deps}
|
||||
, {base_plt_apps, [erts, kernel, stdlib]} ]}.
|
||||
|
12
rebar.lock
Normal file
12
rebar.lock
Normal file
@ -0,0 +1,12 @@
|
||||
[{<<"base58">>,
|
||||
{git,"https://git.qpq.swiss/QPQ-AG/erl-base58.git",
|
||||
{ref,"e6aa62eeae3d4388311401f06e4b939bf4e94b9c"}},
|
||||
1},
|
||||
{<<"enacl">>,
|
||||
{git,"https://git.qpq.swiss/QPQ-AG/enacl.git",
|
||||
{ref,"4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}},
|
||||
1},
|
||||
{<<"gmserialization">>,
|
||||
{git,"https://git.qpq.swiss/QPQ-AG/gmserialization.git",
|
||||
{ref,"ac64e01b0f675c1a34c70a827062f381920742db"}},
|
||||
0}].
|
@ -3,7 +3,7 @@
|
||||
[{description, "Gajumaru Mining Pool Protocol (server- + client-side)"},
|
||||
{vsn, "0.1.0"},
|
||||
{registered, []},
|
||||
{application,
|
||||
{applications,
|
||||
[
|
||||
kernel
|
||||
, stdlib
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user