File tree Expand file tree Collapse file tree 4 files changed +17
-16
lines changed
Expand file tree Collapse file tree 4 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -434,12 +434,9 @@ static void performOp(
434434 bool repairBool;
435435 conn.from >> repairBool;
436436 auto repair = RepairFlag{repairBool};
437- std::shared_ptr<const Provenance> provenance;
438- if (conn.features .contains (WorkerProto::featureProvenance)) {
439- auto s = readString (conn.from );
440- if (!s.empty ())
441- provenance = Provenance::from_json_str (s);
442- }
437+ auto provenance = conn.features .contains (WorkerProto::featureProvenance)
438+ ? Provenance::from_json_str_optional (readString (conn.from ))
439+ : nullptr ;
443440
444441 logger->startWork ();
445442 auto pathInfo = [&]() {
@@ -920,11 +917,9 @@ static void performOp(
920917 conn.from >> info.registrationTime >> info.narSize >> info.ultimate ;
921918 info.sigs = readStrings<StringSet>(conn.from );
922919 info.ca = ContentAddress::parseOpt (readString (conn.from ));
923- if (conn.features .contains (WorkerProto::featureProvenance)) {
924- auto s = readString (conn.from );
925- if (!s.empty ())
926- info.provenance = Provenance::from_json_str (s);
927- }
920+ info.provenance = conn.features .contains (WorkerProto::featureProvenance)
921+ ? Provenance::from_json_str_optional (readString (conn.from ))
922+ : nullptr ;
928923 conn.from >> repair >> dontCheckSigs;
929924 if (!trusted && dontCheckSigs)
930925 dontCheckSigs = false ;
Original file line number Diff line number Diff line change @@ -304,11 +304,8 @@ UnkeyedValidPathInfo WorkerProto::Serialise<UnkeyedValidPathInfo>::read(const St
304304 info.sigs = readStrings<StringSet>(conn.from );
305305 info.ca = ContentAddress::parseOpt (readString (conn.from ));
306306 }
307- if (conn.provenance ) {
308- auto s = readString (conn.from );
309- if (!s.empty ())
310- info.provenance = Provenance::from_json_str (s);
311- }
307+ if (conn.provenance )
308+ info.provenance = Provenance::from_json_str_optional (readString (conn.from ));
312309 return info;
313310}
314311
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ struct Provenance
1313{
1414 static ref<const Provenance> from_json_str (std::string_view);
1515
16+ static std::shared_ptr<const Provenance> from_json_str_optional (std::string_view);
17+
1618 static ref<const Provenance> from_json (const nlohmann::json & json);
1719
1820 std::string to_json_str () const ;
Original file line number Diff line number Diff line change @@ -29,6 +29,13 @@ ref<const Provenance> Provenance::from_json_str(std::string_view s)
2929 return from_json (nlohmann::json::parse (s));
3030}
3131
32+ std::shared_ptr<const Provenance> Provenance::from_json_str_optional (std::string_view s)
33+ {
34+ if (s.empty ())
35+ return nullptr ;
36+ return Provenance::from_json_str (s);
37+ }
38+
3239ref<const Provenance> Provenance::from_json (const nlohmann::json & json)
3340{
3441 auto & obj = getObject (json);
You can’t perform that action at this time.
0 commit comments