Improved contract loading validation.

This commit is contained in:
Ravin Perera
2019-10-04 17:02:17 +05:30
parent 8c8793da21
commit e109e1be47
8 changed files with 105 additions and 61 deletions

View File

@@ -8,34 +8,40 @@
#include "conf.h"
#include "crypto.h"
#include "usr/usr.h"
#include "proc.h"
using namespace std;
using namespace shared;
int parse_cmd(int argc, char **argv);
int main(int argc, char **argv)
{
if (!parse_cmd(argc, argv))
if (parse_cmd(argc, argv) != 0)
return -1;
if (conf::ctx.command == "version")
{
cout << _HP_VERSION_ << endl;
}
else if (conf::ctx.command == "new")
{
if (conf::create_contract() != 0 || crypto::init() != 0)
return -1;
}
else
{
bool initSuccess = conf::init(argc, argv) && crypto::init();
if (!initSuccess)
{
cerr << "Init error\n";
if (conf::init() != 0)
return -1;
}
if (conf::ctx.command == "run")
if (conf::ctx.command == "rekey")
{
usr::init();
//Clear the keys. crpyto::init will init the keys.
if (conf::clear_keys() != 0 || crypto::init() != 0)
return -1;
}
else if (conf::ctx.command == "run")
{
if (crypto::init() != 0 || usr::init() != 0)
return -1;
}
}
@@ -58,13 +64,14 @@ int parse_cmd(int argc, char **argv)
else
{
conf::set_contract_dir_paths(argv[2]);
return 1;
return 0;
}
}
else if (command == "version")
{
if (argc == 2)
return 1;
return 0;
}
}
@@ -74,5 +81,5 @@ int parse_cmd(int argc, char **argv)
cout << "hpcore <command> <contract dir> (command = run | new | rekey)\n";
cout << "Example: hpcore run ~/mycontract\n";
return 0;
return -1;
}