diff --git a/contracts/sysio.system/include/sysio.system/sysio.system.hpp b/contracts/sysio.system/include/sysio.system/sysio.system.hpp index f6797e8..dc3d3cf 100644 --- a/contracts/sysio.system/include/sysio.system/sysio.system.hpp +++ b/contracts/sysio.system/include/sysio.system/sysio.system.hpp @@ -282,6 +282,29 @@ namespace sysiosystem { SYSLIB_SERIALIZE( producer_info2, (owner)(votepay_share)(last_votepay_share_update) ) }; + + // Defines 'domain_info' structure to be stored in 'domains' table (jovi-update) + struct [[sysio::table, sysio::contract("sysio.system")]] domain_info { + uint64_t key; // Unique primary key for the table + name account_name; // Name of the account (domain) + name creator; // Creator of the domain + time_point created_at; // Timestamp of domain creation + + // Primary key + uint64_t primary_key() const { return key; } + + // Secondary index to retrieve by creator + uint64_t by_creator() const { return creator.value; } + + // Serialization macro + SYSLIB_SERIALIZE(domain_info, (key)(account_name)(creator)(created_at)) +}; + +// Define the multi-index table +typedef sysio::multi_index<"domains"_n, domain_info, + indexed_by<"bycreator"_n, const_mem_fun> +> domains_t; + // Voter info. Voter info stores information about the voter: // - `owner` the voter // - `proxy` the proxy set by the voter, if any diff --git a/contracts/sysio.system/src/sysio.system.cpp b/contracts/sysio.system/src/sysio.system.cpp index faf3e60..5e2c9cd 100644 --- a/contracts/sysio.system/src/sysio.system.cpp +++ b/contracts/sysio.system/src/sysio.system.cpp @@ -432,44 +432,57 @@ namespace sysiosystem { * who can create accounts with the creator's name as a suffix. * */ - void native::newaccount( const name& creator, - const name& new_account_name, - ignore owner, - ignore active ) { - - if( creator != get_self() ) { - uint64_t tmp = new_account_name.value >> 4; - bool has_dot = false; - - for( uint32_t i = 0; i < 12; ++i ) { - has_dot |= !(tmp & 0x1f); - tmp >>= 5; - } - if( has_dot ) { // or is less than 12 characters + void native::newaccount( const name& creator, + const name& new_account_name, + ignore owner, + ignore active ) { + if (creator != get_self()) { + uint64_t tmp = new_account_name.value >> 4; + bool has_dot = false; + + for (uint32_t i = 0; i < 12; ++i) { + has_dot |= !(tmp & 0x1f); + tmp >>= 5; + } + if (has_dot) { auto suffix = new_account_name.suffix(); - if( suffix == new_account_name ) { - name_bid_table bids(get_self(), get_self().value); - auto current = bids.find( new_account_name.value ); - check( current != bids.end(), "no active bid for name" ); - check( current->high_bidder == creator, "only highest bidder can claim" ); - check( current->high_bid < 0, "auction for name is not closed yet" ); - bids.erase( current ); + if (suffix == new_account_name) { + name_bid_table bids(get_self(), get_self().value); + auto current = bids.find(new_account_name.value); + check(current != bids.end(), "no active bid for name"); + check(current->high_bidder == creator, "only highest bidder can claim"); + check(current->high_bid < 0, "auction for name is not closed yet"); + bids.erase(current); } else { - check( creator == suffix, "only suffix may create this account" ); + check(creator == suffix, "only suffix may create this account"); } - } - } + } + } - // user_resources_table userres( get_self(), new_account_name.value ); + // user_resources_table userres( get_self(), new_account_name.value ); - // userres.emplace( new_account_name, [&]( auto& res ) { - // res.owner = new_account_name; - // res.net_weight = asset( 0, system_contract::get_core_symbol() ); - // res.cpu_weight = asset( 0, system_contract::get_core_symbol() ); - // }); + // userres.emplace( new_account_name, [&]( auto& res ) { + // res.owner = new_account_name; + // res.net_weight = asset( 0, system_contract::get_core_symbol() ); + // res.cpu_weight = asset( 0, system_contract::get_core_symbol() ); + // }); - set_resource_limits( new_account_name, 0, 0, 0 ); - } + + // Add the account to the domains table + domains_t domains(get_self(), get_self().value); + auto existing = domains.find(new_account_name.value); + check(existing == domains.end(), "Account already exists in the domains table"); + + domains.emplace(get_self(), [&](auto& row) { + row.key = domains.available_primary_key(); + row.account_name = new_account_name; + row.creator = creator; + row.created_at = time_point(current_time_point()); + }); + + // Set initial resource limits for the new account + set_resource_limits(new_account_name, 0, 0, 0); +} void native::setabi( const name& acnt, const std::vector& abi, const binary_extension& memo ) {