-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_dataset.cpp
62 lines (54 loc) · 2.12 KB
/
build_dataset.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Build dataset from smart-contract-sanctuary-ethereum
https://github.com/tintinweb/smart-contract-sanctuary-ethereum/tree/master/contracts/mainnet
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <json/json.hpp>
#include "processor/common.h"
#include "utils/file_utils.h"
#include "utils/string_utils.h"
#include "utils/shell_utils.h"
const std::string kSanctuaryPath = "/mnt/d/smart-contract-sanctuary-ethereum/contracts/rinkeby/";
const std::string kDestPath = "/home/yuanye/graduation/Dataset/";
int main() {
std::string contracts;
svc::FileUtils::ReadFileToString(kSanctuaryPath + "contracts.json", contracts);
std::vector<std::string> contract_vec = svc::StringUtils::SplitString(contracts, '\n');
int counter = 0;
for (auto &contract_json : contract_vec) {
counter++;
if (counter % 10000 == 1) {
std::cout << counter << "/" << contract_vec.size() << std::endl;
}
nlohmann::json contract;
try {
contract = nlohmann::json::parse(contract_json);
} catch(...) {
std::cout << "error " << std::endl;
continue;
}
std::string address = contract["address"];
std::string version = contract["compiler"];
std::string name = contract["name"];
// compiler: 0.5.x | v0.5.x
if (version[0] != '0') {
version = version.substr(1);
}
std::string source_dictory = svc::StringUtils::StrToLower(address.substr(2, 2));
std::string source_file = kSanctuaryPath + source_dictory + "/" + address.substr(2) + "_" + name + ".sol";
if (!svc::FileUtils::IsFileExists(source_file)) {
continue;
}
if (version[2] == '4') {
// svc::ShellUtils::RunCommand("cp " + source_file + " " + kDestPath + "4/");
} else if (version[2] == '5') {
// svc::ShellUtils::RunCommand("cp " + source_file + " " + kDestPath + "5/");
} else if (version[2] == '6') {
svc::ShellUtils::RunCommand("cp " + source_file + " " + kDestPath + "6/");
}
}
return 0;
}