const account_object& database_fixture::create_account( const string& name, const private_key_type& key, const account_id_type& registrar_id /* = account_id_type() */, const account_id_type& referrer_id /* = account_id_type() */, uint8_t referrer_percent /* = 100 */ ) { try { trx.operations.clear(); account_create_operation account_create_op; account_create_op.registrar = registrar_id; account_create_op.name = name; account_create_op.owner = authority(1234, public_key_type(key.get_public_key()), 1234); account_create_op.active = authority(5678, public_key_type(key.get_public_key()), 5678); account_create_op.options.memo_key = key.get_public_key(); trx.operations.push_back( account_create_op ); trx.validate(); processed_transaction ptx = db.push_transaction(trx, ~0); //wdump( (ptx) ); const account_object& result = db.get<account_object>(ptx.operation_results[0].get<object_id_type>()); trx.operations.clear(); return result; } FC_CAPTURE_AND_RETHROW( (name)(registrar_id)(referrer_id) ) }
const account_object &database_fixture::account_create( const string &name, const string &creator, const private_key_type &creator_key, const share_type &fee, const public_key_type &key, const public_key_type &post_key, const string &json_metadata ) { try { account_create_operation op; op.new_account_name = name; op.creator = creator; op.fee = fee; op.owner = authority(1, key, 1); op.active = authority(1, key, 1); op.posting = authority(1, post_key, 1); op.memo_key = key; op.json_metadata = json_metadata; trx.operations.push_back(op); trx.set_expiration(db.head_block_time() + STEEMIT_MAX_TIME_UNTIL_EXPIRATION); trx.sign(creator_key, db.get_chain_id()); trx.validate(); db.push_transaction(trx, 0); trx.operations.clear(); trx.signatures.clear(); const account_object &acct = db.get_account(name); return acct; } FC_CAPTURE_AND_RETHROW((name)(creator)) }
std::string Srs::codeString() const { if (!hasCode()) throw std::runtime_error("No SRS code found"); std::string s(authority() + ':' + horizontal()); if (hasVerticalCode()) s += '+' + vertical(); return s; }
/* net_path = "//" authority [ abs_path ] */ std::string net_path() { std::string s = "//"; s += authority(); if(rand(2)) s += abs_path(); return s; }
void channel::handle_inactivity(const code& ec) { if (stopped()) return; log::debug(LOG_NETWORK) << "Channel inactivity timeout [" << authority() << "]"; stop(error::channel_timeout); }
void channel::handle_expiration(const code& ec) { if (stopped()) return; log::debug(LOG_NETWORK) << "Channel lifetime expired [" << authority() << "]"; stop(error::channel_timeout); }
std::string uri() { //switch(rand(4)) switch(1) { case 0: return abs_uri(); case 1: return abs_path(); case 2: return authority(); default: case 3: break; } return "*"; }
void channel::handle_revival(const code& ec) { if (stopped()) return; // Nothing to do, no handler registered. if (!revival_handler_) return; log::debug(LOG_NETWORK) << "Channel revival invoked [" << authority() << "]"; revival_handler_(ec); reset_revival(); }
bool Topology::authenticateRootTopology(const Dictionary &rt) { try { std::string signer(rt.signingIdentity()); if (!signer.length()) return false; Identity signerId(signer); std::map< Address,Identity >::const_iterator authority(ZT_DEFAULTS.rootTopologyAuthorities.find(signerId.address())); if (authority == ZT_DEFAULTS.rootTopologyAuthorities.end()) return false; if (signerId != authority->second) return false; return rt.verify(authority->second); } catch ( ... ) { return false; } }
void web_crawler::job_cache(const size_t id) { while (!urls.empty()) { std::unique_lock<std::mutex> lck(mutex_); std::cout<< id << "waiting..."<< num_memory_items_ - pages.size() <<std::endl; this->cv.wait(lck, [this] {return this->pages.size() > this->num_memory_items_;}); auto item = *pages.begin(); pages.erase(pages.begin()); lck.unlock(); const auto addr = to_base64(item.first.string()); boost::filesystem::create_directory(authority(item.first)); const auto& page = item.second; std::cout<< id << " saving to " << "cache/" + addr <<std::endl; std::ofstream ofs("cache/" + addr); std::copy(page.begin(), page.end(), std::ostreambuf_iterator<char>(ofs)); } }
/** * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] * * foo://[email protected]:8042/over/there?name=ferret#nose * \_/ \_______________________/\_________/ \_________/ \__/ * | | | | | * scheme authority path query fragment */ inline std::tstring_t Uri::uri() const { std::tstring_t sRv; std::tstring_t temp; temp = scheme(); if (!temp.empty()) { sRv += xT(""); sRv += temp; } temp = authority(); if (!temp.empty()) { sRv += xT(":"); sRv += temp; } temp = path(); if (!temp.empty()) { sRv += xT(""); sRv += temp; } temp = query(); if (!temp.empty()) { sRv += xT("?"); sRv += temp; } temp = fragment(); if (!temp.empty()) { sRv += xT("#"); sRv += temp; } return sRv; }
// main constructor for uri, expects the uri from the request and the host // from the headers uri::uri(std::string r,std::string h) { // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] // http://dobby.com/fooburger/doohicky.html?a=sturgess#wacky // schm auth path query fragment size_t pos,pos2,begin=0; valid=false; scheme="http"; //std::cerr << "uri(" << r << ',' << h << ")\n"; auth=authority(h); if((pos=r.find('?',begin))!=std::string::npos){ if((pos2=r.find('#',begin))!=std::string::npos){ path=r.substr(begin,pos); query=r.substr(pos+1,pos2); fragment=r.substr(pos2+1); }else{ path=r.substr(begin,pos); query=r.substr(pos+1); } }else{ path=r.substr(begin); } }
void link_check::do_url( const string & url, const string & library_name, const path & source_path, bool no_link_errors, bool allow_external_content, std::string::const_iterator contents_begin, std::string::const_iterator url_start ) // precondition: source_path.is_complete() { if(!no_link_errors && url.empty()) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Empty URL.", ln ); return; } // Decode ampersand encoded characters. string decoded_url = is_css(source_path) ? url : decode_ampersands(url); if(decoded_url.empty()) { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid URL (invalid ampersand encodings): " + url, ln ); } return; } boost::smatch m; if(!boost::regex_match(decoded_url, m, url_decompose_regex)) { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid URL: " + decoded_url, ln ); } return; } bool scheme_matched = m[2].matched, authority_matched = m[4].matched, //query_matched = m[7].matched, fragment_matched = m[9].matched; std::string scheme(m[2]), authority(m[4]), url_path(m[5]), //query(m[7]), fragment(m[9]); // Check for external content if(!allow_external_content && (authority_matched || scheme_matched)) { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "External content: " + decoded_url, ln ); } } // Protocol checks if(scheme_matched) { if(scheme == "http" || scheme == "https") { // All http links should have a hostname. Generally if they don't // it's by mistake. If they shouldn't, then a protocol isn't // required. if(!authority_matched) { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "No hostname: " + decoded_url, ln ); } } return; } else if(scheme == "file") { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid URL (hardwired file): " + decoded_url, ln ); } } else if(scheme == "mailto" || scheme == "ftp" || scheme == "news" || scheme == "javascript") { if ( !no_link_errors && is_css(source_path) ) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid protocol for css: " + decoded_url, ln ); } } else { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Unknown protocol: '" + scheme + "' in url: " + decoded_url, ln ); } } return; } // Hostname without protocol. if(authority_matched) { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid URL (hostname without protocol): " + decoded_url, ln ); } } // Check the fragment identifier if ( fragment_matched ) { if ( is_css(source_path) ) { if ( !no_link_errors ) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Fragment link in CSS: " + decoded_url, ln ); } } else { if ( !no_link_errors && fragment.find( '#' ) != string::npos ) { ++m_bookmark_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid bookmark: " + decoded_url, ln ); } else if ( !no_link_errors && url_path.empty() && !fragment.empty() // w3.org recommends case-sensitive broken bookmark checking // since some browsers do a case-sensitive match. && bookmarks.find(decode_percents(fragment)) == bookmarks.end() ) { ++m_broken_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Unknown bookmark: " + decoded_url, ln ); } } // No more to do if it's just a fragment identifier if(url_path.empty()) return; } // Detect characters banned by RFC2396: if ( !no_link_errors && decoded_url.find_first_of( " <>\"{}|\\^[]'" ) != string::npos ) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid character in URL: " + decoded_url, ln ); } // Check that we actually have a path. if(url_path.empty()) { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid URL (empty path in relative url): " + decoded_url, ln ); } } // Decode percent encoded characters. string decoded_path = decode_percents(url_path); if(decoded_path.empty()) { if(!no_link_errors) { ++m_invalid_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Invalid URL (invalid character encodings): " + decoded_url, ln ); } return; } // strip url of references to current dir if ( decoded_path[0]=='.' && decoded_path[1]=='/' ) decoded_path.erase( 0, 2 ); // url is relative source_path.branch() // convert to target_path, which is_complete() path target_path; try { target_path = source_path.branch_path() /= path( decoded_path ); } catch ( const fs::filesystem_error & ) { if(!no_link_errors) { int ln = std::count( contents_begin, url_start, '\n' ) + 1; ++m_invalid_errors; error( library_name, source_path, "Invalid URL (error resolving path): " + decoded_url, ln ); } return; } // create a m_paths entry if necessary std::pair< const string, int > entry( relative_to( target_path, search_root_path() ), 0 ); m_path_map::iterator itr( m_paths.find( entry.first ) ); if ( itr == m_paths.end() ) { if ( fs::exists( target_path ) ) entry.second = m_present; itr = m_paths.insert( entry ).first; } // itr now points to the m_paths entry itr->second |= m_linked_to; // if target isn't present, the link is broken if ( !no_link_errors && (itr->second & m_present) == 0 ) { ++m_broken_errors; int ln = std::count( contents_begin, url_start, '\n' ) + 1; error( library_name, source_path, "Broken link: " + decoded_url, ln ); } }
void get_required_authorities( vector<authority>& a )const { a.push_back( authority( 1, balance_owner_key, 1 ) ); }
void database::init_genesis(const genesis_state_type& genesis_state) { try { FC_ASSERT( genesis_state.initial_timestamp != time_point_sec(), "Must initialize genesis timestamp." ); FC_ASSERT( genesis_state.initial_timestamp.sec_since_epoch() % GRAPHENE_DEFAULT_BLOCK_INTERVAL == 0, "Genesis timestamp must be divisible by GRAPHENE_DEFAULT_BLOCK_INTERVAL." ); FC_ASSERT(genesis_state.initial_witness_candidates.size() > 0, "Cannot start a chain with zero witnesses."); FC_ASSERT(genesis_state.initial_active_witnesses <= genesis_state.initial_witness_candidates.size(), "initial_active_witnesses is larger than the number of candidate witnesses."); _undo_db.disable(); struct auth_inhibitor { auth_inhibitor(database& db) : db(db), old_flags(db.node_properties().skip_flags) { db.node_properties().skip_flags |= skip_authority_check; } ~auth_inhibitor() { db.node_properties().skip_flags = old_flags; } private: database& db; uint32_t old_flags; } inhibitor(*this); transaction_evaluation_state genesis_eval_state(this); flat_index<block_summary_object>& bsi = get_mutable_index_type< flat_index<block_summary_object> >(); bsi.resize(0xffff+1); // Create blockchain accounts fc::ecc::private_key null_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); create<account_balance_object>([](account_balance_object& b) { b.balance = GRAPHENE_MAX_SHARE_SUPPLY; }); const account_object& committee_account = create<account_object>( [&](account_object& n) { n.membership_expiration_date = time_point_sec::maximum(); n.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; n.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; n.owner.weight_threshold = 1; n.active.weight_threshold = 1; n.name = "committee-account"; n.statistics = create<account_statistics_object>( [&](account_statistics_object& s){ s.owner = n.id; }).id; }); FC_ASSERT(committee_account.get_id() == GRAPHENE_COMMITTEE_ACCOUNT); FC_ASSERT(create<account_object>([this](account_object& a) { a.name = "witness-account"; a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id; a.owner.weight_threshold = 1; a.active.weight_threshold = 1; a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_WITNESS_ACCOUNT; a.membership_expiration_date = time_point_sec::maximum(); a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; }).get_id() == GRAPHENE_WITNESS_ACCOUNT); FC_ASSERT(create<account_object>([this](account_object& a) { a.name = "relaxed-committee-account"; a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id; a.owner.weight_threshold = 1; a.active.weight_threshold = 1; a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_RELAXED_COMMITTEE_ACCOUNT; a.membership_expiration_date = time_point_sec::maximum(); a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; }).get_id() == GRAPHENE_RELAXED_COMMITTEE_ACCOUNT); FC_ASSERT(create<account_object>([this](account_object& a) { a.name = "null-account"; a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id; a.owner.weight_threshold = 1; a.active.weight_threshold = 1; a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_NULL_ACCOUNT; a.membership_expiration_date = time_point_sec::maximum(); a.network_fee_percentage = 0; a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT; }).get_id() == GRAPHENE_NULL_ACCOUNT); FC_ASSERT(create<account_object>([this](account_object& a) { a.name = "temp-account"; a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id; a.owner.weight_threshold = 0; a.active.weight_threshold = 0; a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_TEMP_ACCOUNT; a.membership_expiration_date = time_point_sec::maximum(); a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; }).get_id() == GRAPHENE_TEMP_ACCOUNT); FC_ASSERT(create<account_object>([this](account_object& a) { a.name = "proxy-to-self"; a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id; a.owner.weight_threshold = 1; a.active.weight_threshold = 1; a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_NULL_ACCOUNT; a.membership_expiration_date = time_point_sec::maximum(); a.network_fee_percentage = 0; a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT; }).get_id() == GRAPHENE_PROXY_TO_SELF_ACCOUNT); // Create more special accounts while( true ) { uint64_t id = get_index<account_object>().get_next_id().instance(); if( id >= genesis_state.immutable_parameters.num_special_accounts ) break; const account_object& acct = create<account_object>([&](account_object& a) { a.name = "special-account-" + std::to_string(id); a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id; a.owner.weight_threshold = 1; a.active.weight_threshold = 1; a.registrar = a.lifetime_referrer = a.referrer = id; a.membership_expiration_date = time_point_sec::maximum(); a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; }); FC_ASSERT( acct.get_id() == account_id_type(id) ); remove( acct ); } // Create core asset const asset_dynamic_data_object& dyn_asset = create<asset_dynamic_data_object>([&](asset_dynamic_data_object& a) { a.current_supply = GRAPHENE_MAX_SHARE_SUPPLY; }); const asset_object& core_asset = create<asset_object>( [&]( asset_object& a ) { a.symbol = GRAPHENE_SYMBOL; a.options.max_supply = genesis_state.max_core_supply; a.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS; a.options.flags = 0; a.options.issuer_permissions = 0; a.issuer = GRAPHENE_NULL_ACCOUNT; a.options.core_exchange_rate.base.amount = 1; a.options.core_exchange_rate.base.asset_id = 0; a.options.core_exchange_rate.quote.amount = 1; a.options.core_exchange_rate.quote.asset_id = 0; a.dynamic_asset_data_id = dyn_asset.id; }); assert( asset_id_type(core_asset.id) == asset().asset_id ); assert( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) ); // Create more special assets while( true ) { uint64_t id = get_index<asset_object>().get_next_id().instance(); if( id >= genesis_state.immutable_parameters.num_special_assets ) break; const asset_dynamic_data_object& dyn_asset = create<asset_dynamic_data_object>([&](asset_dynamic_data_object& a) { a.current_supply = 0; }); const asset_object& asset_obj = create<asset_object>( [&]( asset_object& a ) { a.symbol = "SPECIAL" + std::to_string( id ); a.options.max_supply = 0; a.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS; a.options.flags = 0; a.options.issuer_permissions = 0; a.issuer = GRAPHENE_NULL_ACCOUNT; a.options.core_exchange_rate.base.amount = 1; a.options.core_exchange_rate.base.asset_id = 0; a.options.core_exchange_rate.quote.amount = 1; a.options.core_exchange_rate.quote.asset_id = 0; a.dynamic_asset_data_id = dyn_asset.id; }); FC_ASSERT( asset_obj.get_id() == asset_id_type(id) ); remove( asset_obj ); } chain_id_type chain_id = genesis_state.compute_chain_id(); // Create global properties create<global_property_object>([&](global_property_object& p) { p.parameters = genesis_state.initial_parameters; // Set fees to zero initially, so that genesis initialization needs not pay them // We'll fix it at the end of the function p.parameters.current_fees->zero_all_fees(); }); create<dynamic_global_property_object>([&](dynamic_global_property_object& p) { p.time = genesis_state.initial_timestamp; p.dynamic_flags = 0; p.witness_budget = 0; p.recent_slots_filled = fc::uint128::max_value(); }); FC_ASSERT( (genesis_state.immutable_parameters.min_witness_count & 1) == 1, "min_witness_count must be odd" ); FC_ASSERT( (genesis_state.immutable_parameters.min_committee_member_count & 1) == 1, "min_committee_member_count must be odd" ); create<chain_property_object>([&](chain_property_object& p) { p.chain_id = chain_id; p.immutable_parameters = genesis_state.immutable_parameters; } ); create<block_summary_object>([&](block_summary_object&) {}); // Create initial accounts for( const auto& account : genesis_state.initial_accounts ) { account_create_operation cop; cop.name = account.name; cop.registrar = GRAPHENE_TEMP_ACCOUNT; cop.owner = authority(1, account.owner_key, 1); if( account.active_key == public_key_type() ) { cop.active = cop.owner; cop.options.memo_key = account.owner_key; } else { cop.active = authority(1, account.active_key, 1); cop.options.memo_key = account.active_key; } account_id_type account_id(apply_operation(genesis_eval_state, cop).get<object_id_type>()); if( account.is_lifetime_member ) { account_upgrade_operation op; op.account_to_upgrade = account_id; op.upgrade_to_lifetime_member = true; apply_operation(genesis_eval_state, op); } } // Helper function to get account ID by name const auto& accounts_by_name = get_index_type<account_index>().indices().get<by_name>(); auto get_account_id = [&accounts_by_name](const string& name) { auto itr = accounts_by_name.find(name); FC_ASSERT(itr != accounts_by_name.end(), "Unable to find account '${acct}'. Did you forget to add a record for it to initial_accounts?", ("acct", name)); return itr->get_id(); }; // Helper function to get asset ID by symbol const auto& assets_by_symbol = get_index_type<asset_index>().indices().get<by_symbol>(); const auto get_asset_id = [&assets_by_symbol](const string& symbol) { auto itr = assets_by_symbol.find(symbol); // TODO: This is temporary for handling BTS snapshot if( symbol == "BTS" ) itr = assets_by_symbol.find(GRAPHENE_SYMBOL); FC_ASSERT(itr != assets_by_symbol.end(), "Unable to find asset '${sym}'. Did you forget to add a record for it to initial_assets?", ("sym", symbol)); return itr->get_id(); }; map<asset_id_type, share_type> total_supplies; map<asset_id_type, share_type> total_debts; // Create initial assets for( const genesis_state_type::initial_asset_type& asset : genesis_state.initial_assets ) { asset_id_type new_asset_id = get_index_type<asset_index>().get_next_id(); total_supplies[ new_asset_id ] = 0; asset_dynamic_data_id_type dynamic_data_id; optional<asset_bitasset_data_id_type> bitasset_data_id; if( asset.is_bitasset ) { int collateral_holder_number = 0; total_debts[ new_asset_id ] = 0; for( const auto& collateral_rec : asset.collateral_records ) { account_create_operation cop; cop.name = asset.symbol + "-collateral-holder-" + std::to_string(collateral_holder_number); boost::algorithm::to_lower(cop.name); cop.registrar = GRAPHENE_TEMP_ACCOUNT; cop.owner = authority(1, collateral_rec.owner, 1); cop.active = cop.owner; account_id_type owner_account_id = apply_operation(genesis_eval_state, cop).get<object_id_type>(); modify( owner_account_id(*this).statistics(*this), [&]( account_statistics_object& o ) { o.total_core_in_orders = collateral_rec.collateral; }); create<call_order_object>([&](call_order_object& c) { c.borrower = owner_account_id; c.collateral = collateral_rec.collateral; c.debt = collateral_rec.debt; c.call_price = price::call_price(chain::asset(c.debt, new_asset_id), chain::asset(c.collateral, core_asset.id), GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); }); total_supplies[ 0 ] += collateral_rec.collateral; total_debts[ new_asset_id ] += collateral_rec.debt; ++collateral_holder_number; } bitasset_data_id = create<asset_bitasset_data_object>([&](asset_bitasset_data_object& b) { b.options.short_backing_asset = core_asset.id; b.options.minimum_feeds = GRAPHENE_DEFAULT_MINIMUM_FEEDS; }).id; } dynamic_data_id = create<asset_dynamic_data_object>([&](asset_dynamic_data_object& d) { d.accumulated_fees = asset.accumulated_fees; }).id; total_supplies[ new_asset_id ] += asset.accumulated_fees; create<asset_object>([&](asset_object& a) { a.symbol = asset.symbol; a.options.description = asset.description; a.precision = asset.precision; string issuer_name = asset.issuer_name; a.issuer = get_account_id(issuer_name); a.options.max_supply = asset.max_supply; a.options.flags = witness_fed_asset; a.options.issuer_permissions = charge_market_fee | global_settle | witness_fed_asset | committee_fed_asset; a.dynamic_asset_data_id = dynamic_data_id; a.bitasset_data_id = bitasset_data_id; }); } // Create initial balances share_type total_allocation; for( const auto& handout : genesis_state.initial_balances ) { const auto asset_id = get_asset_id(handout.asset_symbol); create<balance_object>([&handout,&get_asset_id,total_allocation,asset_id](balance_object& b) { b.balance = asset(handout.amount, asset_id); b.owner = handout.owner; }); total_supplies[ asset_id ] += handout.amount; } // Create initial vesting balances for( const genesis_state_type::initial_vesting_balance_type& vest : genesis_state.initial_vesting_balances ) { const auto asset_id = get_asset_id(vest.asset_symbol); create<balance_object>([&](balance_object& b) { b.owner = vest.owner; b.balance = asset(vest.amount, asset_id); linear_vesting_policy policy; policy.begin_timestamp = vest.begin_timestamp; policy.vesting_cliff_seconds = 0; policy.vesting_duration_seconds = vest.vesting_duration_seconds; policy.begin_balance = vest.begin_balance; b.vesting_policy = std::move(policy); }); total_supplies[ asset_id ] += vest.amount; } if( total_supplies[ 0 ] > 0 ) { adjust_balance(GRAPHENE_COMMITTEE_ACCOUNT, -get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{})); } else { total_supplies[ 0 ] = GRAPHENE_MAX_SHARE_SUPPLY; } const auto& idx = get_index_type<asset_index>().indices().get<by_symbol>(); auto it = idx.begin(); bool has_imbalanced_assets = false; while( it != idx.end() ) { if( it->bitasset_data_id.valid() ) { auto supply_itr = total_supplies.find( it->id ); auto debt_itr = total_debts.find( it->id ); FC_ASSERT( supply_itr != total_supplies.end() ); FC_ASSERT( debt_itr != total_debts.end() ); if( supply_itr->second != debt_itr->second ) { has_imbalanced_assets = true; elog( "Genesis for asset ${aname} is not balanced\n" " Debt is ${debt}\n" " Supply is ${supply}\n", ("debt", debt_itr->second) ("supply", supply_itr->second) ); } } ++it; } FC_ASSERT( !has_imbalanced_assets ); // Save tallied supplies for( const auto& item : total_supplies ) { const auto asset_id = item.first; const auto total_supply = item.second; modify( get( asset_id ), [ & ]( asset_object& asset ) { modify( get( asset.dynamic_asset_data_id ), [ & ]( asset_dynamic_data_object& asset_data ) { asset_data.current_supply = total_supply; } ); } ); } // Create special witness account const witness_object& wit = create<witness_object>([&](witness_object& w) {}); FC_ASSERT( wit.id == GRAPHENE_NULL_WITNESS ); remove(wit); // Create initial witnesses std::for_each(genesis_state.initial_witness_candidates.begin(), genesis_state.initial_witness_candidates.end(), [&](const genesis_state_type::initial_witness_type& witness) { witness_create_operation op; op.witness_account = get_account_id(witness.owner_name); op.block_signing_key = witness.block_signing_key; apply_operation(genesis_eval_state, op); }); // Create initial committee members std::for_each(genesis_state.initial_committee_candidates.begin(), genesis_state.initial_committee_candidates.end(), [&](const genesis_state_type::initial_committee_member_type& member) { committee_member_create_operation op; op.committee_member_account = get_account_id(member.owner_name); apply_operation(genesis_eval_state, op); }); // Create initial workers std::for_each(genesis_state.initial_worker_candidates.begin(), genesis_state.initial_worker_candidates.end(), [&](const genesis_state_type::initial_worker_type& worker) { worker_create_operation op; op.owner = get_account_id(worker.owner_name); op.work_begin_date = genesis_state.initial_timestamp; op.work_end_date = time_point_sec::maximum(); op.daily_pay = worker.daily_pay; op.name = "Genesis-Worker-" + worker.owner_name; op.initializer = vesting_balance_worker_initializer{uint16_t(0)}; apply_operation(genesis_eval_state, std::move(op)); }); // Set active witnesses modify(get_global_properties(), [&](global_property_object& p) { for( uint32_t i = 1; i <= genesis_state.initial_active_witnesses; ++i ) { p.active_witnesses.insert(i); p.witness_accounts.insert(get(witness_id_type(i)).witness_account); } }); // Enable fees modify(get_global_properties(), [&genesis_state](global_property_object& p) { p.parameters.current_fees = genesis_state.initial_parameters.current_fees; }); // Create witness scheduler create<witness_schedule_object>([&]( witness_schedule_object& wso ) { for( const witness_id_type& wid : get_global_properties().active_witnesses ) wso.current_shuffled_witnesses.push_back( wid ); }); debug_dump(); _undo_db.enable(); } FC_CAPTURE_AND_RETHROW() }
void get_required_authorities(vector<authority> &a) const { if (new_owner_key) { a.push_back(authority(1, *new_owner_key, 1)); } }
bool operator == ( const authority& a, const shared_authority& b ) { return a == authority( b ); }
bool operator == ( const shared_authority& a, const authority& b ) { return authority( a ) == b; }
// // Main driver // int main(int argc, char *argv[]) { // clear the umask - we know what we're doing secdebug("SS", "starting umask was 0%o", ::umask(0)); ::umask(0); // tell the keychain (client) layer to turn off the server interface SecKeychainSetServerMode(); // program arguments (preset to defaults) bool debugMode = false; const char *bootstrapName = NULL; const char* messagingName = SECURITY_MESSAGES_NAME; bool doFork = false; bool reExecute = false; int workerTimeout = 0; int maxThreads = 0; bool waitForClients = true; bool mdsIsInstalled = false; const char *authorizationConfig = "/etc/authorization"; const char *tokenCacheDir = "/var/db/TokenCache"; const char *entropyFile = "/var/db/SystemEntropyCache"; const char *equivDbFile = EQUIVALENCEDBPATH; const char *smartCardOptions = getenv("SMARTCARDS"); uint32_t keychainAclDefault = CSSM_ACL_KEYCHAIN_PROMPT_INVALID | CSSM_ACL_KEYCHAIN_PROMPT_UNSIGNED; unsigned int verbose = 0; // check for the Installation-DVD environment and modify some default arguments if found if (access("/etc/rc.cdrom", F_OK) == 0) { // /etc/rc.cdrom exists SECURITYD_INSTALLMODE(); smartCardOptions = "off"; // needs writable directories that aren't } // parse command line arguments extern char *optarg; extern int optind; int arg; while ((arg = getopt(argc, argv, "a:c:de:E:imN:s:t:T:uvWX")) != -1) { switch (arg) { case 'a': authorizationConfig = optarg; break; case 'c': tokenCacheDir = optarg; break; case 'd': debugMode = true; break; case 'e': equivDbFile = optarg; break; case 'E': entropyFile = optarg; break; case 'i': keychainAclDefault &= ~CSSM_ACL_KEYCHAIN_PROMPT_INVALID; break; case 'm': mdsIsInstalled = true; break; case 'N': bootstrapName = optarg; break; case 's': smartCardOptions = optarg; break; case 't': if ((maxThreads = atoi(optarg)) < 0) maxThreads = 0; break; case 'T': if ((workerTimeout = atoi(optarg)) < 0) workerTimeout = 0; break; case 'W': waitForClients = false; break; case 'u': keychainAclDefault &= ~CSSM_ACL_KEYCHAIN_PROMPT_UNSIGNED; break; case 'v': verbose++; break; case 'X': doFork = true; reExecute = true; break; default: usage(argv[0]); } } // take no non-option arguments if (optind < argc) usage(argv[0]); // figure out the bootstrap name if (!bootstrapName) { bootstrapName = getenv(SECURITYSERVER_BOOTSTRAP_ENV); if (!bootstrapName) { bootstrapName = SECURITYSERVER_BOOTSTRAP_NAME; } else { messagingName = bootstrapName; } } else { messagingName = bootstrapName; } // configure logging first if (debugMode) { Syslog::open(bootstrapName, LOG_AUTHPRIV, LOG_PERROR); Syslog::notice("%s started in debug mode", argv[0]); } else { Syslog::open(bootstrapName, LOG_AUTHPRIV, LOG_CONS); } // if we're not running as root in production mode, fail // in debug mode, issue a warning if (uid_t uid = getuid()) { #if defined(NDEBUG) Syslog::alert("Tried to run securityd as user %d: aborted", uid); fprintf(stderr, "You are not allowed to run securityd\n"); exit(1); #else fprintf(stderr, "securityd is unprivileged (uid=%d); some features may not work.\n", uid); #endif //NDEBUG } // turn into a properly diabolical daemon unless debugMode is on if (!debugMode && getppid() != 1) { if (!Daemon::incarnate(doFork)) exit(1); // can't daemonize if (reExecute && !Daemon::executeSelf(argv)) exit(1); // can't self-execute } // arm signal handlers; code below may generate signals we want to see if (signal(SIGCHLD, handleSignals) == SIG_ERR || signal(SIGINT, handleSignals) == SIG_ERR || signal(SIGTERM, handleSignals) == SIG_ERR || signal(SIGPIPE, handleSignals) == SIG_ERR #if !defined(NDEBUG) || signal(SIGUSR1, handleSignals) == SIG_ERR #endif //NDEBUG || signal(SIGUSR2, handleSignals) == SIG_ERR) { perror("signal"); exit(1); } // create an Authorization engine Authority authority(authorizationConfig); // introduce all supported ACL subject types new AnyAclSubject::Maker(); new PasswordAclSubject::Maker(); new ProtectedPasswordAclSubject::Maker(); new PromptedAclSubject::Maker(); new ThresholdAclSubject::Maker(); new CommentAclSubject::Maker(); new ProcessAclSubject::Maker(); new CodeSignatureAclSubject::Maker(); new KeychainPromptAclSubject::Maker(keychainAclDefault); new PreAuthorizationAcls::OriginMaker(); new PreAuthorizationAcls::SourceMaker(); // establish the code equivalents database CodeSignatures codeSignatures(equivDbFile); // create the main server object and register it Server server(authority, codeSignatures, bootstrapName); // Remember the primary service port to send signal events to gMainServerPort = server.primaryServicePort(); // set server configuration from arguments, if specified if (workerTimeout) server.timeout(workerTimeout); if (maxThreads) server.maxThreads(maxThreads); server.floatingThread(true); server.waitForClients(waitForClients); server.verbosity(verbose); // add the RNG seed timer # if defined(NDEBUG) EntropyManager entropy(server, entropyFile); # else if (getuid() == 0) new EntropyManager(server, entropyFile); # endif // create a smartcard monitor to manage external token devices gPCSC = new PCSCMonitor(server, tokenCacheDir, scOptions(smartCardOptions)); // create the RootSession object (if -d, give it graphics and tty attributes) RootSession rootSession(debugMode ? (sessionHasGraphicAccess | sessionHasTTY) : 0, server); // create a monitor thread to watch for audit session events AuditMonitor audits(gMainServerPort); audits.run(); // install MDS (if needed) and initialize the local CSSM server.loadCssm(mdsIsInstalled); // create the shared memory notification hub new SharedMemoryListener(messagingName, kSharedMemoryPoolSize); // okay, we're ready to roll SECURITYD_INITIALIZED((char*)bootstrapName); Syslog::notice("Entering service"); // go server.run(); // fell out of runloop (should not happen) Syslog::alert("Aborting"); return 1; }
void operator()( const balance_claim_operation& o )const { result.push_back( authority( 1, o.balance_owner_key, 1 ) ); }