Compare commits
3 Commits
master
...
uw-multipl
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1619e3fb38 | ||
![]() |
2e2804c6aa | ||
![]() |
ea7914048a |
@ -3,7 +3,7 @@
|
||||
{plugins, [rebar3_hex]}.
|
||||
{deps, [
|
||||
{gmserialization, {git, "https://git.qpq.swiss/QPQ-AG/gmserialization.git",
|
||||
{ref, "ac64e01b0f"}}}
|
||||
{ref, "bff07885fb"}}}
|
||||
]}.
|
||||
|
||||
{xref_checks, [undefined_function_calls, undefined_functions,
|
||||
|
@ -8,5 +8,5 @@
|
||||
1},
|
||||
{<<"gmserialization">>,
|
||||
{git,"https://git.qpq.swiss/QPQ-AG/gmserialization.git",
|
||||
{ref,"ac64e01b0f675c1a34c70a827062f381920742db"}},
|
||||
{ref,"bff07885fb9fd328db4d1ae2cd27b118b57dd929"}},
|
||||
0}].
|
||||
|
@ -93,16 +93,19 @@ validate(#{ get_nonces := #{ seq := Seq
|
||||
valid(seq, Seq),
|
||||
valid(pos_integer, N),
|
||||
Msg;
|
||||
validate(#{ new_server := #{ host := Host, port := Port, keep := Keep }} = Msg, _Vsn) ->
|
||||
valid(string, Host),
|
||||
valid(pos_ind, Port),
|
||||
valid(boolean, Keep),
|
||||
Msg;
|
||||
validate(#{ nonces := #{seq := Seq, nonces := Ns}} = Msg, _vsn) ->
|
||||
valid(seq, Seq),
|
||||
valid(nonces, Ns),
|
||||
Msg;
|
||||
validate(#{ solution := #{ seq := Seq
|
||||
, nonce := Nonce
|
||||
, evidence := Evidence } } = Msg, _Vsn) ->
|
||||
validate(#{ solutions := #{ seq := Seq
|
||||
, found := Solutions } } = Msg, _Vsn) ->
|
||||
valid(seq, Seq),
|
||||
valid(nonce, Nonce),
|
||||
valid(evidence, Evidence),
|
||||
valid(solutions, Solutions),
|
||||
Msg;
|
||||
validate(#{ solution_accepted := #{ seq := Seq }} = Msg, _Vsn) ->
|
||||
valid(seq, Seq),
|
||||
@ -255,6 +258,10 @@ decode_msg_(<<"connect">>, #{ <<"protocols">> := Protos
|
||||
, type => Type
|
||||
, nonces => Nonces
|
||||
}};
|
||||
decode_msg_(<<"new_server">>, #{ <<"host">> := Host
|
||||
, <<"port">> := Port
|
||||
, <<"keep">> := Keep }) ->
|
||||
#{new_server => #{host => Host, port => Port, keep => Keep}};
|
||||
decode_msg_(<<"get_nonces">>, #{ <<"seq">> := Seq
|
||||
, <<"n">> := N }) ->
|
||||
#{get_nonces => #{seq => Seq, n => N}};
|
||||
@ -268,12 +275,15 @@ decode_msg_(<<"candidate">>, #{ <<"candidate">> := C
|
||||
, nonces => Nonces
|
||||
, seq => Seq
|
||||
, edge_bits => EdgeBits }};
|
||||
decode_msg_(<<"solution">>, #{ <<"seq">> := Seq
|
||||
, <<"nonce">> := Nonce
|
||||
, <<"evidence">> := Evidence }) ->
|
||||
#{solution => #{ seq => Seq
|
||||
, nonce => Nonce
|
||||
, evidence => Evidence}};
|
||||
decode_msg_(<<"solutions">>, #{ <<"seq">> := Seq
|
||||
, <<"found">> := Found }) ->
|
||||
Solutions = lists:map(
|
||||
fun(#{ <<"nonce">> := Nonce
|
||||
, <<"evidence">> := Evidence }) ->
|
||||
#{nonce => Nonce, evidence => Evidence}
|
||||
end, Found),
|
||||
#{solutions => #{ seq => Seq
|
||||
, found => Solutions }};
|
||||
decode_msg_(<<"solution_accepted">>, #{<<"seq">> := Seq}) ->
|
||||
#{solution_accepted => #{seq => Seq}};
|
||||
decode_msg_(<<"no_solution">>, #{ <<"seq">> := Seq
|
||||
@ -296,8 +306,14 @@ valid_(seq, Seq) -> pos_integer(Seq);
|
||||
valid_(target, T) -> pos_integer(T);
|
||||
valid_(edge_bits, E) -> pos_integer(E);
|
||||
valid_(pos_int, I) -> pos_integer(I);
|
||||
valid_(string, S) -> is_binary(S);
|
||||
valid_(boolean, B) -> is_boolean(B);
|
||||
valid_(contract, Id) -> ok_tuple(gmser_api_encoder:safe_defode(contract_pubkey, Id));
|
||||
valid_(type, T) -> lists:member(T, [miner, monitor]);
|
||||
valid_(solutions, S) -> lists:all(fun(#{nonce := N, evidence := Evd}) ->
|
||||
valid_(pos_int, N),
|
||||
valid_({list, pos_int}, Evd)
|
||||
end, S);
|
||||
valid_(nonces, Ns) ->
|
||||
case Ns of
|
||||
[N] -> pos_integer(N);
|
||||
|
Loading…
x
Reference in New Issue
Block a user