Skip to content

Commit

Permalink
added new app admin function
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiabbasi committed Feb 20, 2024
1 parent 4c25230 commit eeee93b
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions contracts/tonomy/src/tonomy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,67 @@ namespace tonomysystem
row.version = 1; });
}

void newappadmin(
name user_name,
string app_name,
string description,
checksum256 username_hash,
string logo_url,
string origin,
public_key key) {
eosio::require_auth(user_name);
checksum256 description_hash = eosio::sha256(description.c_str(), description.length());

// use the password_key public key for the owner authority
authority key_authority = create_authority_with_key(key);
key_authority.accounts.push_back({.permission = create_eosio_code_permission_level(get_self()), .weight = 1});

// If the account name exists, this will fail
newaccount_action newaccountaction("eosio"_n, {get_self(), "active"_n});
newaccountaction.send(get_self(), user_name, key_authority, key_authority);

// Check the username is not already taken
auto apps_by_username_hash_itr = _apps.get_index<"usernamehash"_n>();
const auto username_itr = apps_by_username_hash_itr.find(username_hash);
if (username_itr != apps_by_username_hash_itr.end())
{
throwError("TCON1001", "This app username is already taken");
}

// Check the origin is not already taken
auto origin_hash = eosio::sha256(origin.c_str(), std::strlen(origin.c_str()));
auto apps_by_origin_hash_itr = _apps.get_index<"originhash"_n>();
const auto origin_itr = apps_by_origin_hash_itr.find(origin_hash);
if (origin_itr != apps_by_origin_hash_itr.end())
{
throwError("TCON1002", "This app origin is already taken");
}

tonomy::resource_config_table _resource_config(get_self(), get_self().value);
auto config = _resource_config.get();
config.total_cpu_weight_allocated = this->initial_cpu_weight_allocation;
config.total_net_weight_allocated = this->initial_net_weight_allocation;
_resource_config.set(config, get_self());

// Store the password_salt and hashed username in table
_apps.emplace(get_self(), [&](auto &app_itr)
{
app_itr.account_name = user_name;
app_itr.app_name = app_name;
app_itr.description = description;
app_itr.logo_url = logo_url;
app_itr.origin = origin;
app_itr.username_hash = username_hash; });

// Store the account type in the account_type table
account_type_table account_type(get_self(), get_self().value);
account_type.emplace(get_self(), [&](auto &row)
{
row.account_name = user_name;
row.acc_type = enum_account_type::App;
row.version = 1; });
}

void tonomy::adminsetapp(
name account_name,
string app_name,
Expand Down

0 comments on commit eeee93b

Please sign in to comment.