Compare commits
No commits in common. "master" and "uw-msg-format-tweaks" have entirely different histories.
master
...
uw-msg-for
@ -3,7 +3,7 @@
|
|||||||
{plugins, [rebar3_hex]}.
|
{plugins, [rebar3_hex]}.
|
||||||
{deps, [
|
{deps, [
|
||||||
{gmserialization, {git, "https://git.qpq.swiss/QPQ-AG/gmserialization.git",
|
{gmserialization, {git, "https://git.qpq.swiss/QPQ-AG/gmserialization.git",
|
||||||
{ref, "0288719ae1"}}}
|
{ref, "ac64e01b0f"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{xref_checks, [undefined_function_calls, undefined_functions,
|
{xref_checks, [undefined_function_calls, undefined_functions,
|
||||||
|
@ -8,5 +8,5 @@
|
|||||||
1},
|
1},
|
||||||
{<<"gmserialization">>,
|
{<<"gmserialization">>,
|
||||||
{git,"https://git.qpq.swiss/QPQ-AG/gmserialization.git",
|
{git,"https://git.qpq.swiss/QPQ-AG/gmserialization.git",
|
||||||
{ref,"0288719ae15814f3a53114c657502a24376bebfa"}},
|
{ref,"ac64e01b0f675c1a34c70a827062f381920742db"}},
|
||||||
0}].
|
0}].
|
||||||
|
@ -60,10 +60,9 @@ validate(#{ connect := #{ pubkey := PK
|
|||||||
, versions := Versions
|
, versions := Versions
|
||||||
, pool_id := PoolId
|
, pool_id := PoolId
|
||||||
, extra_pubkeys := Extra
|
, extra_pubkeys := Extra
|
||||||
, type := Type0
|
, type := Type
|
||||||
, nonces := Nonces
|
, nonces := Nonces
|
||||||
}} = Msg, _Vsn) ->
|
}} = Msg, _Vsn) ->
|
||||||
Type = to_atom(Type0),
|
|
||||||
valid({list, protocol}, Protocols),
|
valid({list, protocol}, Protocols),
|
||||||
valid({list, version} , Versions),
|
valid({list, version} , Versions),
|
||||||
valid(pubkey, PK),
|
valid(pubkey, PK),
|
||||||
@ -92,7 +91,7 @@ validate(#{ candidate := #{ seq := Seq
|
|||||||
validate(#{ get_nonces := #{ seq := Seq
|
validate(#{ get_nonces := #{ seq := Seq
|
||||||
, n := N }} = Msg, _Vsn) ->
|
, n := N }} = Msg, _Vsn) ->
|
||||||
valid(seq, Seq),
|
valid(seq, Seq),
|
||||||
valid(pos_int, N),
|
valid(pos_integer, N),
|
||||||
Msg;
|
Msg;
|
||||||
validate(#{ new_server := #{ host := Host, port := Port, keep := Keep }} = Msg, _Vsn) ->
|
validate(#{ new_server := #{ host := Host, port := Port, keep := Keep }} = Msg, _Vsn) ->
|
||||||
valid(string, Host),
|
valid(string, Host),
|
||||||
@ -298,10 +297,10 @@ decode_msg_(<<"no_solution">>, #{ <<"seq">> := Seq
|
|||||||
, nonce => Nonce }}.
|
, nonce => Nonce }}.
|
||||||
|
|
||||||
valid(Type, Val) ->
|
valid(Type, Val) ->
|
||||||
try true = valid_(Type, Val)
|
try valid_(Type, Val)
|
||||||
catch
|
catch
|
||||||
error:_ ->
|
error:_ ->
|
||||||
error({invalid, {Type, Val}})
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
valid_({list,T}, Ps) -> lists:all(fun(X) -> valid_(T, X) end, Ps);
|
valid_({list,T}, Ps) -> lists:all(fun(X) -> valid_(T, X) end, Ps);
|
||||||
@ -309,13 +308,12 @@ valid_(protocol, P) -> is_binary(P);
|
|||||||
valid_(version, V) -> is_binary(V);
|
valid_(version, V) -> is_binary(V);
|
||||||
valid_(pubkey, PK) -> ok_tuple(gmser_api_encoder:safe_decode(account_pubkey, PK));
|
valid_(pubkey, PK) -> ok_tuple(gmser_api_encoder:safe_decode(account_pubkey, PK));
|
||||||
valid_(seq, Seq) -> pos_integer(Seq);
|
valid_(seq, Seq) -> pos_integer(Seq);
|
||||||
valid_(nonce, Nonce) -> pos_integer(Nonce);
|
|
||||||
valid_(target, T) -> pos_integer(T);
|
valid_(target, T) -> pos_integer(T);
|
||||||
valid_(edge_bits, E) -> pos_integer(E);
|
valid_(edge_bits, E) -> pos_integer(E);
|
||||||
valid_(pos_int, I) -> pos_integer(I);
|
valid_(pos_int, I) -> pos_integer(I);
|
||||||
valid_(string, S) -> is_binary(S);
|
valid_(string, S) -> is_binary(S);
|
||||||
valid_(boolean, B) -> is_boolean(B);
|
valid_(boolean, B) -> is_boolean(B);
|
||||||
valid_(contract, Id) -> ok_tuple(gmser_api_encoder:safe_decode(contract_pubkey, Id));
|
valid_(contract, Id) -> ok_tuple(gmser_api_encoder:safe_defode(contract_pubkey, Id));
|
||||||
valid_(type, T) -> lists:member(T, [miner, monitor]);
|
valid_(type, T) -> lists:member(T, [miner, monitor]);
|
||||||
valid_(solutions, S) -> lists:all(fun(#{nonce := N, evidence := Evd}) ->
|
valid_(solutions, S) -> lists:all(fun(#{nonce := N, evidence := Evd}) ->
|
||||||
valid_(pos_int, N),
|
valid_(pos_int, N),
|
||||||
@ -338,8 +336,3 @@ ok_tuple(V) ->
|
|||||||
|
|
||||||
pos_integer(I) ->
|
pos_integer(I) ->
|
||||||
is_integer(I) andalso I >= 0.
|
is_integer(I) andalso I >= 0.
|
||||||
|
|
||||||
to_atom(A) when is_atom(A) ->
|
|
||||||
A;
|
|
||||||
to_atom(B) when is_binary(B) ->
|
|
||||||
binary_to_existing_atom(B, utf8).
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user