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,9 +505,13 @@ 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
- auto result = std::make_shared<Assembly>(langutil:: EVMVersion() , _level == 0 , " " );
514
+ auto result = std::make_shared<Assembly>(EVMVersion{} , _level == 0 /* _creation */ , " " /* _name */ );
514
515
if (_json.isNull ())
515
516
return std::make_pair (result, std::vector<std::string>());
516
517
@@ -532,7 +533,8 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
532
533
for (Json::Value const & sourceListItem: _json[" sourceList" ])
533
534
solRequire (sourceListItem.isString (), AssemblyImportException, " The 'sourceList' array contains an item that is not a string." );
534
535
}
535
- } else
536
+ }
537
+ else
536
538
solRequire (
537
539
!_json.isMember (" sourceList" ),
538
540
AssemblyImportException,
@@ -552,16 +554,16 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
552
554
);
553
555
sourceList.emplace_back (it.asString ());
554
556
}
555
- } else
557
+ }
558
+ else
556
559
sourceList = _sourceList;
557
560
558
561
result->importAssemblyItemsFromJSON (_json[" .code" ], sourceList);
559
562
if (_json[" .auxdata" ])
560
563
{
561
564
solRequire (_json[" .auxdata" ].isString (), AssemblyImportException, " Optional member '.auxdata' is not a string." );
562
- bytes auxdata{fromHex (_json[" .auxdata" ].asString ())};
563
- solRequire (!auxdata.empty (), AssemblyImportException, " Optional member '.auxdata' is not a valid hexadecimal string." );
564
- result->m_auxiliaryData = auxdata;
565
+ result->m_auxiliaryData = fromHex (_json[" .auxdata" ].asString ());
566
+ solRequire (!result->m_auxiliaryData .empty (), AssemblyImportException, " Optional member '.auxdata' is not a valid hexadecimal string." );
565
567
}
566
568
567
569
if (_json.isMember (" .data" ))
@@ -575,14 +577,11 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
575
577
Json::Value const & code = data[dataItemID];
576
578
if (code.isString ())
577
579
{
578
- if (!code.asString ().empty ())
579
- {
580
- bytes data_value{fromHex (code.asString ())};
581
- solRequire (
582
- !data_value.empty (),
583
- AssemblyImportException,
584
- " Member '.data' contains a value for '" + dataItemID + " ' that is not a valid hexadecimal string." );
585
- }
580
+ solRequire (
581
+ code.asString ().empty () || !fromHex (code.asString ()).empty (),
582
+ AssemblyImportException,
583
+ " Member '.data' contains a value for '" + dataItemID + " ' that is not a valid hexadecimal string."
584
+ );
586
585
result->m_data [h256 (fromHex (dataItemID))] = fromHex (code.asString ());
587
586
}
588
587
else if (code.isObject ())
@@ -606,7 +605,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
606
605
void Assembly::updatePaths (std::vector<Assembly*> const & _parents, std::vector<size_t > const & _absolutePathFromRoot)
607
606
{
608
607
size_t subId = 0 ;
609
- for (std::shared_ptr<Assembly> assembly: this -> m_subs )
608
+ for (std::shared_ptr<Assembly> assembly: m_subs)
610
609
{
611
610
std::vector<Assembly*> parents{_parents};
612
611
parents.push_back (this );
0 commit comments