37
37
#include < libsolutil/JSON.h>
38
38
#include < libsolutil/StringUtils.h>
39
39
40
+ #include < fmt/format.h>
41
+
40
42
#include < range/v3/algorithm/any_of.hpp>
41
43
#include < range/v3/view/enumerate.hpp>
42
44
@@ -101,24 +103,19 @@ AssemblyItem Assembly::createAssemblyItemFromJSON(Json::Value const& _json, std:
101
103
solRequire (
102
104
validMembers.count (member),
103
105
AssemblyImportException,
104
- " Unknown member '" + member + " '. Valid members are: " +
105
- solidity::util::joinHumanReadable (validMembers, " , " ) + " ."
106
+ fmt::format (
107
+ " Unknown member '{}'. Valid members are: {}." ,
108
+ member,
109
+ solidity::util::joinHumanReadable (validMembers, " , " )
110
+ )
106
111
);
107
112
solRequire (isOfType<std::string>(_json[" name" ]), AssemblyImportException, " Member 'name' missing or not of type string." );
108
113
solRequire (isOfTypeIfExists<int >(_json, " begin" ), AssemblyImportException, " Optional member 'begin' not of type int." );
109
114
solRequire (isOfTypeIfExists<int >(_json, " end" ), AssemblyImportException, " Optional member 'end' not of type int." );
110
115
solRequire (isOfTypeIfExists<int >(_json, " source" ), AssemblyImportException, " Optional member 'source' not of type int." );
111
116
solRequire (isOfTypeIfExists<std::string>(_json, " value" ), AssemblyImportException, " Optional member 'value' not of type string." );
112
- solRequire (
113
- isOfTypeIfExists<int >(_json, " modifierDepth" ),
114
- AssemblyImportException,
115
- " Optional member 'modifierDepth' not of type int."
116
- );
117
- solRequire (
118
- isOfTypeIfExists<std::string>(_json, " jumpType" ),
119
- AssemblyImportException,
120
- " Optional member 'jumpType' not of type string."
121
- );
117
+ solRequire (isOfTypeIfExists<int >(_json, " modifierDepth" ), AssemblyImportException, " Optional member 'modifierDepth' not of type int." );
118
+ solRequire (isOfTypeIfExists<std::string>(_json, " jumpType" ), AssemblyImportException, " Optional member 'jumpType' not of type string." );
122
119
123
120
std::string name = get<std::string>(_json[" name" ]);
124
121
solRequire (!name.empty (), AssemblyImportException, " Member 'name' is empty." );
@@ -508,7 +505,11 @@ Json::Value Assembly::assemblyJSON(std::map<std::string, unsigned> const& _sourc
508
505
return root;
509
506
}
510
507
511
- std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSON (Json::Value const & _json, std::vector<std::string> const & _sourceList, size_t _level)
508
+ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSON (
509
+ Json::Value const & _json,
510
+ std::vector<std::string> const & _sourceList,
511
+ size_t _level
512
+ )
512
513
{
513
514
solRequire (_json.isObject (), AssemblyImportException, " Supplied JSON is not an object." );
514
515
static std::set<std::string> const validMembers{" .code" , " .data" , " .auxdata" , " sourceList" };
@@ -528,7 +529,8 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
528
529
for (Json::Value const & sourceListItem: _json[" sourceList" ])
529
530
solRequire (sourceListItem.isString (), AssemblyImportException, " The 'sourceList' array contains an item that is not a string." );
530
531
}
531
- } else
532
+ }
533
+ else
532
534
solRequire (
533
535
!_json.isMember (" sourceList" ),
534
536
AssemblyImportException,
@@ -549,16 +551,16 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
549
551
);
550
552
sourceList.emplace_back (it.asString ());
551
553
}
552
- } else
554
+ }
555
+ else
553
556
sourceList = _sourceList;
554
557
555
558
result->importAssemblyItemsFromJSON (_json[" .code" ], sourceList);
556
559
if (_json[" .auxdata" ])
557
560
{
558
561
solRequire (_json[" .auxdata" ].isString (), AssemblyImportException, " Optional member '.auxdata' is not a string." );
559
- bytes auxdata{fromHex (_json[" .auxdata" ].asString ())};
560
- solRequire (!auxdata.empty (), AssemblyImportException, " Optional member '.auxdata' is not a valid hexadecimal string." );
561
- result->m_auxiliaryData = auxdata;
562
+ result->m_auxiliaryData = fromHex (_json[" .auxdata" ].asString ());
563
+ solRequire (!result->m_auxiliaryData .empty (), AssemblyImportException, " Optional member '.auxdata' is not a valid hexadecimal string." );
562
564
}
563
565
564
566
if (_json.isMember (" .data" ))
@@ -572,14 +574,11 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
572
574
Json::Value const & code = data[dataItemID];
573
575
if (code.isString ())
574
576
{
575
- if (!code.asString ().empty ())
576
- {
577
- bytes data_value{fromHex (code.asString ())};
578
- solRequire (
579
- !data_value.empty (),
580
- AssemblyImportException,
581
- " The value for key '" + dataItemID + " ' inside '.data' is not a valid hexadecimal string." );
582
- }
577
+ solRequire (
578
+ code.asString ().empty () || !fromHex (code.asString ()).empty (),
579
+ AssemblyImportException,
580
+ " The value for key '" + dataItemID + " ' inside '.data' is not a valid hexadecimal string."
581
+ );
583
582
result->m_data [h256 (fromHex (dataItemID))] = fromHex (code.asString ());
584
583
}
585
584
else if (code.isObject ())
@@ -603,7 +602,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
603
602
void Assembly::updatePaths (std::vector<Assembly*> const & _parents, std::vector<size_t > const & _absolutePathFromRoot)
604
603
{
605
604
size_t subId = 0 ;
606
- for (std::shared_ptr<Assembly> assembly: this -> m_subs )
605
+ for (std::shared_ptr<Assembly> assembly: m_subs)
607
606
{
608
607
std::vector<Assembly*> parents{_parents};
609
608
parents.push_back (this );
0 commit comments