fix encoding of solutions msg

This commit is contained in:
Ulf Wiger 2025-03-23 22:00:20 +01:00
parent ea7914048a
commit 2e2804c6aa

View File

@ -173,17 +173,6 @@ encode(#{reply := Reply0}, P, V) when is_map(Reply0) ->
{Id, Reply} = maps:take(id, Reply0),
encode_reply(Reply, Id, P, V).
encode_msg(#{solutions := #{}} = Msg0, ?PROTOCOL_JSON, Vsn) ->
#{solutions := #{ seq := Seq
, found := Found }} = validate(Msg0, Vsn),
EncFound = lists:map(
fun(#{ nonce := Nonce
, evidence := Evidence }) ->
#{ <<"n">> => Nonce
, <<"e">> => Evidence }
end, Found),
json_encode(#{ <<"solutions">> => #{ <<"seq">> => Seq
, <<"found">> => EncFound }});
encode_msg(Msg0, ?PROTOCOL_JSON, Vsn) ->
Msg = validate(Msg0, Vsn),
[{Method, Args}] = maps:to_list(Msg),
@ -289,12 +278,12 @@ decode_msg_(<<"candidate">>, #{ <<"candidate">> := C
decode_msg_(<<"solutions">>, #{ <<"seq">> := Seq
, <<"found">> := Found }) ->
Solutions = lists:map(
fun(#{ <<"n">> := Nonce
, <<"e">> := Evidence }) ->
fun(#{ <<"nonce">> := Nonce
, <<"evidence">> := Evidence }) ->
#{nonce => Nonce, evidence => Evidence}
end, Found),
#{solution => #{ seq => Seq
, found => Solutions }};
#{solutions => #{ seq => Seq
, found => Solutions }};
decode_msg_(<<"solution_accepted">>, #{<<"seq">> := Seq}) ->
#{solution_accepted => #{seq => Seq}};
decode_msg_(<<"no_solution">>, #{ <<"seq">> := Seq