Merge branch 'master' of github.com:cryptonomex/graphene

This commit is contained in:
Daniel Larimer 2015-07-06 16:50:36 -04:00
commit c537e41fcb
11 changed files with 303 additions and 206 deletions

View file

@ -54,6 +54,38 @@ namespace bpo = boost::program_options;
namespace detail { namespace detail {
genesis_state_type create_example_genesis() {
auto nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
dlog("Allocating all stake to ${key}", ("key", utilities::key_to_wif(nathan_key)));
genesis_state_type initial_state;
/*
fc::reflector<fee_schedule_type>::visit(
fee_schedule_type::fee_set_visitor{initial_state.initial_parameters.current_fees, 0});
*/
initial_state.initial_parameters.current_fees.set_all_fees(0);
secret_hash_type::encoder enc;
fc::raw::pack(enc, nathan_key);
fc::raw::pack(enc, secret_hash_type());
auto secret = secret_hash_type::hash(enc.result());
initial_state.initial_active_witnesses = 10;
for( int i = 0; i < initial_state.initial_active_witnesses; ++i )
{
auto name = "init"+fc::to_string(i);
initial_state.initial_accounts.emplace_back(name,
nathan_key.get_public_key(),
nathan_key.get_public_key(),
true);
initial_state.initial_committee_candidates.push_back({name});
initial_state.initial_witness_candidates.push_back({name, nathan_key.get_public_key(), secret});
}
initial_state.initial_accounts.emplace_back("nathan", nathan_key.get_public_key());
initial_state.initial_balances.push_back({nathan_key.get_public_key(),
GRAPHENE_SYMBOL,
GRAPHENE_MAX_SHARE_SUPPLY});
return initial_state;
}
class application_impl : public net::node_delegate class application_impl : public net::node_delegate
{ {
public: public:
@ -155,8 +187,9 @@ namespace detail {
bool clean = !fc::exists(_data_dir / "blockchain/dblock"); bool clean = !fc::exists(_data_dir / "blockchain/dblock");
fc::create_directories(_data_dir / "blockchain/dblock"); fc::create_directories(_data_dir / "blockchain/dblock");
auto nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
genesis_state_type initial_state; genesis_state_type initial_state;
/*
<<<<<<< HEAD
initial_state.initial_parameters.current_fees.set_all_fees(0); initial_state.initial_parameters.current_fees.set_all_fees(0);
secret_hash_type::encoder enc; secret_hash_type::encoder enc;
fc::raw::pack(enc, nathan_key); fc::raw::pack(enc, nathan_key);
@ -177,11 +210,14 @@ namespace detail {
initial_state.initial_balances.push_back({nathan_key.get_public_key(), initial_state.initial_balances.push_back({nathan_key.get_public_key(),
GRAPHENE_SYMBOL, GRAPHENE_SYMBOL,
GRAPHENE_MAX_SHARE_SUPPLY}); GRAPHENE_MAX_SHARE_SUPPLY});
=======
>>>>>>> b89ff4e6b1d732fbfe0cba20b4f41ea7df560f3c
*/
if( _options->count("genesis-json") ) if( _options->count("genesis-json") )
initial_state = fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>()) initial_state = fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>())
.as<genesis_state_type>(); .as<genesis_state_type>();
else else
dlog("Allocating all stake to ${key}", ("key", utilities::key_to_wif(nathan_key))); initial_state = create_example_genesis();
if( _options->count("resync-blockchain") ) if( _options->count("resync-blockchain") )
_chain_db->wipe(_data_dir / "blockchain", true); _chain_db->wipe(_data_dir / "blockchain", true);
@ -426,13 +462,11 @@ application::~application()
{ {
if( my->_p2p_network ) if( my->_p2p_network )
{ {
//ilog("Closing p2p node");
my->_p2p_network->close(); my->_p2p_network->close();
my->_p2p_network.reset(); my->_p2p_network.reset();
} }
if( my->_chain_db ) if( my->_chain_db )
{ {
//ilog("Closing chain database");
my->_chain_db->close(); my->_chain_db->close();
} }
} }
@ -451,6 +485,10 @@ void application::set_program_options(boost::program_options::options_descriptio
; ;
command_line_options.add(configuration_file_options); command_line_options.add(configuration_file_options);
command_line_options.add_options() command_line_options.add_options()
("create-genesis-json", bpo::value<boost::filesystem::path>(),
"Path to create a Genesis State at. If a well-formed JSON file exists at the path, it will be parsed and any "
"missing fields in a Genesis State will be added, and any unknown fields will be removed. If no file or an "
"invalid file is found, it will be replaced with an example Genesis State.")
("replay-blockchain", "Rebuild object graph by replaying all blocks") ("replay-blockchain", "Rebuild object graph by replaying all blocks")
("resync-blockchain", "Delete all blocks and re-sync with network from scratch") ("resync-blockchain", "Delete all blocks and re-sync with network from scratch")
; ;
@ -462,6 +500,31 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
{ {
my->_data_dir = data_dir; my->_data_dir = data_dir;
my->_options = &options; my->_options = &options;
if( options.count("create-genesis-json") )
{
fc::path genesis_out = options.at("create-genesis-json").as<boost::filesystem::path>();
genesis_state_type genesis_state = detail::create_example_genesis();
if( fc::exists(genesis_out) )
{
try {
genesis_state = fc::json::from_file(genesis_out).as<genesis_state_type>();
} catch(const fc::exception& e) {
std::cerr << "Unable to parse existing genesis file:\n" << e.to_string()
<< "\nWould you like to replace it? [y/N] ";
char response = std::cin.get();
if( toupper(response) != 'Y' )
return;
}
std::cerr << "Updating genesis state in file " << genesis_out.generic_string() << "\n";
} else {
std::cerr << "Creating example genesis state in file " << genesis_out.generic_string() << "\n";
}
fc::json::save_to_file(genesis_state, genesis_out);
std::exit(EXIT_SUCCESS);
}
} }
void application::startup() void application::startup()

View file

@ -20,59 +20,50 @@
#include <boost/rational.hpp> #include <boost/rational.hpp>
namespace graphene { namespace chain { namespace graphene { namespace chain {
bool operator < ( const asset& a, const asset& b )
bool operator == ( const price& a, const price& b )
{ {
return std::tie( a.asset_id, a.amount ) < std::tie( b.asset_id, b.amount); if( std::tie( a.base.asset_id, a.quote.asset_id ) != std::tie( b.base.asset_id, b.quote.asset_id ) )
} return false;
bool operator <= ( const asset& a, const asset& b )
{ const auto amult = fc::uint128( b.quote.amount.value ) * a.base.amount.value;
return std::tie( a.asset_id, a.amount ) <= std::tie( b.asset_id, b.amount); const auto bmult = fc::uint128( a.quote.amount.value ) * b.base.amount.value;
return amult == bmult;
} }
bool operator < ( const price& a, const price& b ) bool operator < ( const price& a, const price& b )
{ {
if( a.base.asset_id < b.base.asset_id ) return true; if( a.base.asset_id < b.base.asset_id ) return true;
if( a.base.asset_id > b.base.asset_id ) return false; if( a.base.asset_id > b.base.asset_id ) return false;
if( a.quote.asset_id < b.quote.asset_id ) return true; if( a.quote.asset_id < b.quote.asset_id ) return true;
if( a.quote.asset_id > b.quote.asset_id ) return false; if( a.quote.asset_id > b.quote.asset_id ) return false;
auto amult = fc::uint128(b.quote.amount.value) * a.base.amount.value;
auto bmult = fc::uint128(a.quote.amount.value) * b.base.amount.value; const auto amult = fc::uint128( b.quote.amount.value ) * a.base.amount.value;
assert( (a.to_real() < b.to_real()) == (amult < bmult) ); const auto bmult = fc::uint128( a.quote.amount.value ) * b.base.amount.value;
return amult < bmult; return amult < bmult;
} }
bool operator <= ( const price& a, const price& b ) bool operator <= ( const price& a, const price& b )
{ {
if( a.base.asset_id < b.base.asset_id ) return true; return (a == b) || (a < b);
if( a.base.asset_id > b.base.asset_id ) return false;
if( a.quote.asset_id < b.quote.asset_id ) return true;
if( a.quote.asset_id > b.quote.asset_id ) return false;
auto amult = fc::uint128(b.quote.amount.value) * a.base.amount.value;
auto bmult = fc::uint128(a.quote.amount.value) * b.base.amount.value;
assert( (a.to_real() <= b.to_real()) == (amult <= bmult) );
return amult <= bmult;
}
bool operator == ( const price& a, const price& b )
{
if( a.base.asset_id < b.base.asset_id ) return true;
if( a.base.asset_id > b.base.asset_id ) return false;
if( a.quote.asset_id < b.quote.asset_id ) return true;
if( a.quote.asset_id > b.quote.asset_id ) return false;
auto amult = fc::uint128(a.quote.amount.value) * b.base.amount.value;
auto bmult = fc::uint128(b.quote.amount.value) * a.base.amount.value;
return amult == bmult;
} }
bool operator != ( const price& a, const price& b ) bool operator != ( const price& a, const price& b )
{ {
return !(a==b); return !(a == b);
}
bool operator > ( const price& a, const price& b )
{
return !(a <= b);
} }
bool operator >= ( const price& a, const price& b ) bool operator >= ( const price& a, const price& b )
{ {
return !(a < b); return !(a < b);
} }
bool operator > ( const price& a, const price& b )
{
return !(a <= b);
}
asset operator * ( const asset& a, const price& b ) asset operator * ( const asset& a, const price& b )
{ {

View file

@ -140,6 +140,8 @@ void database::init_genesis(const genesis_state_type& genesis_state)
{ try { { try {
FC_ASSERT(genesis_state.initial_witness_candidates.size() > 0, FC_ASSERT(genesis_state.initial_witness_candidates.size() > 0,
"Cannot start a chain with zero witnesses."); "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(); _undo_db.disable();
struct auth_inhibitor { struct auth_inhibitor {
@ -252,24 +254,12 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create initial accounts // Create initial accounts
for( const auto& account : genesis_state.initial_accounts ) for( const auto& account : genesis_state.initial_accounts )
{ {
/*
key_id_type key_id = apply_operation(genesis_eval_state,
key_create_operation({asset(),
GRAPHENE_TEMP_ACCOUNT,
account.owner_key})).get<object_id_type>();
*/
account_create_operation cop; account_create_operation cop;
cop.name = account.name; cop.name = account.name;
cop.registrar = GRAPHENE_TEMP_ACCOUNT; cop.registrar = GRAPHENE_TEMP_ACCOUNT;
cop.owner = authority(1, account.owner_key, 1); cop.owner = authority(1, account.owner_key, 1);
if( account.owner_key != account.active_key ) if( account.owner_key != account.active_key )
{ {
/*
key_id = apply_operation(genesis_eval_state,
key_create_operation({asset(),
GRAPHENE_TEMP_ACCOUNT,
account.owner_key})).get<object_id_type>();
*/
cop.active = authority(1, account.owner_key, 1); cop.active = authority(1, account.owner_key, 1);
} else { } else {
cop.active = cop.owner; cop.active = cop.owner;
@ -286,21 +276,27 @@ void database::init_genesis(const genesis_state_type& genesis_state)
} }
} }
// Helper function to get account ID by name
const auto& accounts_by_name = get_index_type<account_index>().indices().get<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 get_account_id = [&accounts_by_name](const string& name) {
auto itr = accounts_by_name.find(name); auto itr = accounts_by_name.find(name);
FC_ASSERT(itr != accounts_by_name.end()); 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>();
auto get_asset_id = [&assets_by_symbol](const string& symbol) {
auto itr = assets_by_symbol.find(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(); return itr->get_id();
}; };
// Create initial assets // Create initial assets
const auto& assets_by_symbol = get_index_type<asset_index>().indices().get<by_symbol>();
auto get_asset_id = [&assets_by_symbol](const string& symbol) {
auto itr = assets_by_symbol.find(symbol);
FC_ASSERT(itr != assets_by_symbol.end());
return itr->get_id();
};
for( const genesis_state_type::initial_asset_type& asset : genesis_state.initial_assets ) for( const genesis_state_type::initial_asset_type& asset : genesis_state.initial_assets )
{ {
asset_dynamic_data_id_type dynamic_data_id; asset_dynamic_data_id_type dynamic_data_id;
@ -314,12 +310,6 @@ void database::init_genesis(const genesis_state_type& genesis_state)
int collateral_holder_number = 0; int collateral_holder_number = 0;
for( const auto& collateral_rec : asset.bitasset_options->collateral_records ) for( const auto& collateral_rec : asset.bitasset_options->collateral_records )
{ {
/*
key_id_type key_id = apply_operation(genesis_eval_state,
key_create_operation{{},
GRAPHENE_TEMP_ACCOUNT,
collateral_rec.owner}).get<object_id_type>();
*/
account_create_operation cop; account_create_operation cop;
cop.name = asset.symbol + "-collateral-holder-" + std::to_string(collateral_holder_number); cop.name = asset.symbol + "-collateral-holder-" + std::to_string(collateral_holder_number);
boost::algorithm::to_lower(cop.name); boost::algorithm::to_lower(cop.name);
@ -415,17 +405,11 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create initial witnesses and delegates // Create initial witnesses and delegates
std::for_each(genesis_state.initial_witness_candidates.begin(), genesis_state.initial_witness_candidates.end(), std::for_each(genesis_state.initial_witness_candidates.begin(), genesis_state.initial_witness_candidates.end(),
[&](const genesis_state_type::initial_witness_type& witness) { [&](const genesis_state_type::initial_witness_type& witness) {
/*
const key_object& signing_key = create<key_object>([&witness](key_object& k) {
k.key_data = witness.block_signing_key;
});
*/
witness_create_operation op; witness_create_operation op;
op.block_signing_key = witness.block_signing_key; op.block_signing_key = witness.block_signing_key;
op.initial_secret = witness.initial_secret; op.initial_secret = witness.initial_secret;
op.witness_account = get_account_id(witness.owner_name); op.witness_account = get_account_id(witness.owner_name);
apply_operation(genesis_eval_state, op).get<object_id_type>(); apply_operation(genesis_eval_state, op);
}); });
std::for_each(genesis_state.initial_committee_candidates.begin(), genesis_state.initial_committee_candidates.end(), std::for_each(genesis_state.initial_committee_candidates.begin(), genesis_state.initial_committee_candidates.end(),
[&](const genesis_state_type::initial_committee_member_type& member) { [&](const genesis_state_type::initial_committee_member_type& member) {
@ -459,10 +443,10 @@ void database::init_genesis(const genesis_state_type& genesis_state)
auto init_witnesses = get_global_properties().active_witnesses; auto init_witnesses = get_global_properties().active_witnesses;
_wso.scheduler = witness_scheduler(); _wso.scheduler = witness_scheduler();
_wso.scheduler._min_token_count = init_witnesses.size() / 2; _wso.scheduler._min_token_count = std::max(int(init_witnesses.size()) / 2, 1);
_wso.scheduler.update(init_witnesses); _wso.scheduler.update(init_witnesses);
for( size_t i=0; i<init_witnesses.size(); i++ ) for( size_t i=0; i<init_witnesses.size(); ++i )
_wso.scheduler.produce_schedule(rng); _wso.scheduler.produce_schedule(rng);
_wso.last_scheduling_block = 0; _wso.last_scheduling_block = 0;

View file

@ -143,16 +143,16 @@ void database::update_active_witnesses()
a.active.weight_threshold += 1; a.active.weight_threshold += 1;
}); });
modify( gpo, [&]( global_property_object& gp ){ modify(gpo, [&]( global_property_object& gp ){
gp.active_witnesses.clear(); gp.active_witnesses.clear();
gp.active_witnesses.reserve( wits.size() ); gp.active_witnesses.reserve(wits.size());
std::transform(wits.begin(), wits.end(), std::transform(wits.begin(), wits.end(),
std::inserter(gp.active_witnesses, gp.active_witnesses.end()), std::inserter(gp.active_witnesses, gp.active_witnesses.end()),
[](const witness_object& w) { [](const witness_object& w) {
return w.id; return w.id;
}); });
gp.witness_accounts.clear(); gp.witness_accounts.clear();
gp.witness_accounts.reserve( wits.size() ); gp.witness_accounts.reserve(wits.size());
std::transform(wits.begin(), wits.end(), std::transform(wits.begin(), wits.end(),
std::inserter(gp.witness_accounts, gp.witness_accounts.end()), std::inserter(gp.witness_accounts, gp.witness_accounts.end()),
[](const witness_object& w) { [](const witness_object& w) {
@ -161,11 +161,10 @@ void database::update_active_witnesses()
}); });
const witness_schedule_object& wso = witness_schedule_id_type()(*this); const witness_schedule_object& wso = witness_schedule_id_type()(*this);
modify( wso, [&]( witness_schedule_object& _wso ) modify(wso, [&](witness_schedule_object& _wso)
{ {
_wso.scheduler.update( gpo.active_witnesses ); _wso.scheduler.update(gpo.active_witnesses);
} ); });
} FC_CAPTURE_AND_RETHROW() } } FC_CAPTURE_AND_RETHROW() }
void database::update_active_delegates() void database::update_active_delegates()

View file

@ -16,8 +16,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#pragma once #pragma once
#include <graphene/chain/types.hpp>
#include <graphene/chain/config.hpp> #include <graphene/chain/config.hpp>
#include <graphene/chain/types.hpp>
namespace graphene { namespace chain { namespace graphene { namespace chain {
@ -42,20 +42,34 @@ namespace graphene { namespace chain {
return *this; return *this;
} }
asset operator -()const { return asset( -amount, asset_id ); } asset operator -()const { return asset( -amount, asset_id ); }
friend bool operator == ( const asset& a, const asset& b ) friend bool operator == ( const asset& a, const asset& b )
{ {
return tie(a.asset_id,a.amount) == tie(b.asset_id,b.amount); return std::tie( a.asset_id, a.amount ) == std::tie( b.asset_id, b.amount );
} }
friend bool operator >= ( const asset& a, const asset& b ) friend bool operator < ( const asset& a, const asset& b )
{ {
FC_ASSERT( a.asset_id == b.asset_id ); FC_ASSERT( a.asset_id == b.asset_id );
return a.amount >= b.amount; return a.amount < b.amount;
}
friend bool operator <= ( const asset& a, const asset& b )
{
return (a == b) || (a < b);
}
friend bool operator != ( const asset& a, const asset& b )
{
return !(a == b);
} }
friend bool operator > ( const asset& a, const asset& b ) friend bool operator > ( const asset& a, const asset& b )
{ {
FC_ASSERT( a.asset_id == b.asset_id ); return !(a <= b);
return a.amount > b.amount;
} }
friend bool operator >= ( const asset& a, const asset& b )
{
return !(a < b);
}
friend asset operator - ( const asset& a, const asset& b ) friend asset operator - ( const asset& a, const asset& b )
{ {
FC_ASSERT( a.asset_id == b.asset_id ); FC_ASSERT( a.asset_id == b.asset_id );
@ -66,7 +80,6 @@ namespace graphene { namespace chain {
FC_ASSERT( a.asset_id == b.asset_id ); FC_ASSERT( a.asset_id == b.asset_id );
return asset( a.amount + b.amount, a.asset_id ); return asset( a.amount + b.amount, a.asset_id );
} }
}; };
/** /**

View file

@ -63,58 +63,98 @@ bool is_valid_symbol( const string& symbol )
return true; return true;
} }
/** /**
* Valid names can contain [a, z], [0, 9], '.', and '-' * Names must comply with the following grammar (RFC 1035):
* They must start with [a, z] * <domain> ::= <subdomain> | " "
* They must end with [a, z] or [0, 9] * <subdomain> ::= <label> | <subdomain> "." <label>
* '.' must be followed by [a, z] * <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
* '-' must be followed by [a, z] or [0, 9] * <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
* <let-dig-hyp> ::= <let-dig> | "-"
* <let-dig> ::= <letter> | <digit>
*
* Which is equivalent to the following:
*
* <domain> ::= <subdomain> | " "
* <subdomain> ::= <label> ("." <label>)*
* <label> ::= <letter> [ [ <let-dig-hyp>+ ] <let-dig> ]
* <let-dig-hyp> ::= <let-dig> | "-"
* <let-dig> ::= <letter> | <digit>
*
* I.e. a valid name consists of a dot-separated sequence
* of one or more labels consisting of the following rules:
*
* - Each label is three characters or more
* - Each label begins with a letter
* - Each label ends with a letter or digit
* - Each label contains only letters, digits or hyphens
*
* In addition we require the following:
*
* - All letters are lowercase
* - Length is between (inclusive) GRAPHENE_MIN_ACCOUNT_NAME_LENGTH and GRAPHENE_MAX_ACCOUNT_NAME_LENGTH
*/ */
bool is_valid_name( const string& name ) bool is_valid_name( const string& name )
{ {
if( name.size() < GRAPHENE_MIN_ACCOUNT_NAME_LENGTH ) const size_t len = name.size();
if( len < GRAPHENE_MIN_ACCOUNT_NAME_LENGTH )
return false; return false;
if( name.size() > GRAPHENE_MAX_ACCOUNT_NAME_LENGTH ) if( len > GRAPHENE_MAX_ACCOUNT_NAME_LENGTH )
return false; return false;
if( !isalpha( name.front() ) ) size_t begin = 0;
return false; while( true )
if( !isalpha( name.back() ) && !isdigit( name.back() ) )
return false;
for( size_t i = 0; i < name.size(); ++i )
{ {
const auto c = name.at( i ); size_t end = name.find_first_of( '.', begin );
if( end == std::string::npos )
if( isalpha( c ) && islower( c ) ) end = len;
continue; if( end - begin < 3 )
return false;
if( isdigit( c ) ) switch( name[begin] )
continue; {
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
if( c == '.' ) case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p':
{ case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x':
const auto next = name.at( i + 1 ); case 'y': case 'z':
if( !isalpha( next ) ) break;
default:
return false;
}
switch( name[end-1] )
{
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p':
case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
case '8': case '9':
break;
default:
return false;
}
for( size_t i=begin+1; i<end-1; i++ )
{
switch( name[i] )
{
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p':
case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
case '8': case '9':
case '-':
break;
default:
return false; return false;
}
continue; }
} if( end == len )
break;
if( c == '-' ) begin = end+1;
{
const auto next = name.at( i + 1 );
if( !isalpha( next ) && !isdigit( next ) )
return false;
continue;
}
return false;
} }
return true; return true;
} }

View file

@ -36,10 +36,11 @@ void witness_plugin::plugin_set_program_options(
boost::program_options::options_description& config_file_options) boost::program_options::options_description& config_file_options)
{ {
auto default_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("nathan"))); auto default_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("nathan")));
string witness_id_example = fc::json::to_string(chain::witness_id_type());
command_line_options.add_options() command_line_options.add_options()
("enable-stale-production", bpo::bool_switch()->notifier([this](bool e){_production_enabled = e;}), "Enable block production, even if the chain is stale") ("enable-stale-production", bpo::bool_switch()->notifier([this](bool e){_production_enabled = e;}), "Enable block production, even if the chain is stale")
("witness-id,w", bpo::value<vector<string>>()->composing()->multitoken(), ("witness-id,w", bpo::value<vector<string>>()->composing()->multitoken(),
"ID of witness controlled by this node (e.g. \"1.7.0\", quotes are required, may specify multiple times)") ("ID of witness controlled by this node (e.g. " + witness_id_example + ", quotes are required, may specify multiple times)").c_str())
("private-key", bpo::value<vector<string>>()->composing()->multitoken()-> ("private-key", bpo::value<vector<string>>()->composing()->multitoken()->
DEFAULT_VALUE_VECTOR(std::make_pair(chain::public_key_type(default_priv_key.get_public_key()), graphene::utilities::key_to_wif(default_priv_key))), DEFAULT_VALUE_VECTOR(std::make_pair(chain::public_key_type(default_priv_key.get_public_key()), graphene::utilities::key_to_wif(default_priv_key))),
"Tuple of [PublicKey, WIF private key] (may specify multiple times)") "Tuple of [PublicKey, WIF private key] (may specify multiple times)")

View file

@ -64,7 +64,8 @@ database_fixture::database_fixture()
fc::raw::pack(enc, delegate_priv_key); fc::raw::pack(enc, delegate_priv_key);
fc::raw::pack(enc, secret_hash_type()); fc::raw::pack(enc, secret_hash_type());
auto secret = secret_hash_type::hash(enc.result()); auto secret = secret_hash_type::hash(enc.result());
for( int i = 0; i < 10; ++i ) genesis_state.initial_active_witnesses = 10;
for( int i = 0; i < genesis_state.initial_active_witnesses; ++i )
{ {
auto name = "init"+fc::to_string(i); auto name = "init"+fc::to_string(i);
genesis_state.initial_accounts.emplace_back(name, genesis_state.initial_accounts.emplace_back(name,

View file

@ -46,84 +46,87 @@ BOOST_FIXTURE_TEST_SUITE( basic_tests, database_fixture )
*/ */
BOOST_AUTO_TEST_CASE( valid_name_test ) BOOST_AUTO_TEST_CASE( valid_name_test )
{ {
BOOST_REQUIRE( is_valid_name( "a" ) ); BOOST_CHECK( !is_valid_name( "a" ) );
BOOST_REQUIRE( !is_valid_name( "A" ) ); BOOST_CHECK( !is_valid_name( "A" ) );
BOOST_REQUIRE( !is_valid_name( "0" ) ); BOOST_CHECK( !is_valid_name( "0" ) );
BOOST_REQUIRE( !is_valid_name( "." ) ); BOOST_CHECK( !is_valid_name( "." ) );
BOOST_REQUIRE( !is_valid_name( "-" ) ); BOOST_CHECK( !is_valid_name( "-" ) );
BOOST_REQUIRE( is_valid_name( "aa" ) ); BOOST_CHECK( !is_valid_name( "aa" ) );
BOOST_REQUIRE( !is_valid_name( "aA" ) ); BOOST_CHECK( !is_valid_name( "aA" ) );
BOOST_REQUIRE( is_valid_name( "a0" ) ); BOOST_CHECK( !is_valid_name( "a0" ) );
BOOST_REQUIRE( !is_valid_name( "a." ) ); BOOST_CHECK( !is_valid_name( "a." ) );
BOOST_REQUIRE( !is_valid_name( "a-" ) ); BOOST_CHECK( !is_valid_name( "a-" ) );
BOOST_REQUIRE( is_valid_name( "aaa" ) ); BOOST_CHECK( is_valid_name( "aaa" ) );
BOOST_REQUIRE( !is_valid_name( "aAa" ) ); BOOST_CHECK( !is_valid_name( "aAa" ) );
BOOST_REQUIRE( is_valid_name( "a0a" ) ); BOOST_CHECK( is_valid_name( "a0a" ) );
BOOST_REQUIRE( is_valid_name( "a.a" ) ); BOOST_CHECK( !is_valid_name( "a.a" ) );
BOOST_REQUIRE( is_valid_name( "a-a" ) ); BOOST_CHECK( is_valid_name( "a-a" ) );
BOOST_REQUIRE( is_valid_name( "aa0" ) ); BOOST_CHECK( is_valid_name( "aa0" ) );
BOOST_REQUIRE( !is_valid_name( "aA0" ) ); BOOST_CHECK( !is_valid_name( "aA0" ) );
BOOST_REQUIRE( is_valid_name( "a00" ) ); BOOST_CHECK( is_valid_name( "a00" ) );
BOOST_REQUIRE( !is_valid_name( "a.0" ) ); BOOST_CHECK( !is_valid_name( "a.0" ) );
BOOST_REQUIRE( is_valid_name( "a-0" ) ); BOOST_CHECK( is_valid_name( "a-0" ) );
BOOST_REQUIRE( is_valid_name( "aaa-bbb-1" ) ); BOOST_CHECK( is_valid_name( "aaa-bbb-ccc" ) );
BOOST_REQUIRE( !is_valid_name( "aaa-bbb.1" ) ); BOOST_CHECK( is_valid_name( "aaa-bbb.ccc" ) );
BOOST_REQUIRE( !is_valid_name( "aaa,bbb-1" ) ); BOOST_CHECK( !is_valid_name( "aaa,bbb-ccc" ) );
BOOST_REQUIRE( !is_valid_name( "aaa_bbb-1" ) ); BOOST_CHECK( !is_valid_name( "aaa_bbb-ccc" ) );
BOOST_REQUIRE( !is_valid_name( "aaa-BBB-1" ) ); BOOST_CHECK( !is_valid_name( "aaa-BBB-ccc" ) );
BOOST_REQUIRE( !is_valid_name( "1aaa-bbb" ) ); BOOST_CHECK( !is_valid_name( "1aaa-bbb" ) );
BOOST_REQUIRE( !is_valid_name( "-aaa-bbb-1" ) ); BOOST_CHECK( !is_valid_name( "-aaa-bbb-ccc" ) );
BOOST_REQUIRE( !is_valid_name( ".aaa-bbb-1" ) ); BOOST_CHECK( !is_valid_name( ".aaa-bbb-ccc" ) );
BOOST_REQUIRE( !is_valid_name( "/aaa-bbb-1" ) ); BOOST_CHECK( !is_valid_name( "/aaa-bbb-ccc" ) );
BOOST_REQUIRE( !is_valid_name( "aaa-bbb-1-" ) ); BOOST_CHECK( !is_valid_name( "aaa-bbb-ccc-" ) );
BOOST_REQUIRE( !is_valid_name( "aaa-bbb-1." ) ); BOOST_CHECK( !is_valid_name( "aaa-bbb-ccc." ) );
BOOST_REQUIRE( !is_valid_name( "aaa-bbb-1/" ) ); BOOST_CHECK( !is_valid_name( "aaa-bbb-ccc.." ) );
BOOST_CHECK( !is_valid_name( "aaa-bbb-ccc/" ) );
BOOST_REQUIRE( !is_valid_name( "aaa..bbb-1" ) ); BOOST_CHECK( !is_valid_name( "aaa..bbb-ccc" ) );
BOOST_REQUIRE( is_valid_name( "aaa.bbb-1" ) ); BOOST_CHECK( is_valid_name( "aaa.bbb-ccc" ) );
BOOST_REQUIRE( !is_valid_name( "aaa.bbb.1" ) ); BOOST_CHECK( is_valid_name( "aaa.bbb.ccc" ) );
BOOST_REQUIRE( !is_valid_name( "aaa--bbb--1" ) ); BOOST_CHECK( is_valid_name( "aaa--bbb--ccc" ) );
BOOST_REQUIRE( !is_valid_name( "xn--sandmnnchen-p8a.de" ) ); BOOST_CHECK( !is_valid_name( "xn--sandmnnchen-p8a.de" ) );
BOOST_REQUIRE( is_valid_name( "xn-sandmnnchen-p8a.de" ) ); BOOST_CHECK( is_valid_name( "xn--sandmnnchen-p8a.dex" ) );
BOOST_CHECK( !is_valid_name( "xn-sandmnnchen-p8a.de" ) );
BOOST_CHECK( is_valid_name( "xn-sandmnnchen-p8a.dex" ) );
BOOST_REQUIRE( is_valid_name( "this-label-has-less-than-64-char.acters-63-to-be-really-precise" ) ); BOOST_CHECK( is_valid_name( "this-label-has-less-than-64-char.acters-63-to-be-really-precise" ) );
BOOST_REQUIRE( !is_valid_name( "this-label-has-more-than-63-char.act.ers-64-to-be-really-precise" ) ); BOOST_CHECK( !is_valid_name( "this-label-has-more-than-63-char.act.ers-64-to-be-really-precise" ) );
BOOST_REQUIRE( !is_valid_name( "none.of.these.labels.has.more.than-63.chars--but.still.not.valid" ) ); BOOST_CHECK( !is_valid_name( "none.of.these.labels.has.more.than-63.chars--but.still.not.valid" ) );
} }
BOOST_AUTO_TEST_CASE( valid_symbol_test ) BOOST_AUTO_TEST_CASE( valid_symbol_test )
{ {
BOOST_REQUIRE( !is_valid_symbol( "A" ) ); BOOST_CHECK( !is_valid_symbol( "A" ) );
BOOST_REQUIRE( !is_valid_symbol( "a" ) ); BOOST_CHECK( !is_valid_symbol( "a" ) );
BOOST_REQUIRE( !is_valid_symbol( "0" ) ); BOOST_CHECK( !is_valid_symbol( "0" ) );
BOOST_REQUIRE( !is_valid_symbol( "." ) ); BOOST_CHECK( !is_valid_symbol( "." ) );
BOOST_REQUIRE( !is_valid_symbol( "AA" ) ); BOOST_CHECK( !is_valid_symbol( "AA" ) );
BOOST_REQUIRE( !is_valid_symbol( "Aa" ) ); BOOST_CHECK( !is_valid_symbol( "Aa" ) );
BOOST_REQUIRE( !is_valid_symbol( "A0" ) ); BOOST_CHECK( !is_valid_symbol( "A0" ) );
BOOST_REQUIRE( !is_valid_symbol( "A." ) ); BOOST_CHECK( !is_valid_symbol( "A." ) );
BOOST_REQUIRE( is_valid_symbol( "AAA" ) ); BOOST_CHECK( is_valid_symbol( "AAA" ) );
BOOST_REQUIRE( !is_valid_symbol( "AaA" ) ); BOOST_CHECK( !is_valid_symbol( "AaA" ) );
BOOST_REQUIRE( !is_valid_symbol( "A0A" ) ); BOOST_CHECK( !is_valid_symbol( "A0A" ) );
BOOST_REQUIRE( is_valid_symbol( "A.A" ) ); BOOST_CHECK( is_valid_symbol( "A.A" ) );
BOOST_REQUIRE( !is_valid_symbol( "A..A" ) ); BOOST_CHECK( !is_valid_symbol( "A..A" ) );
BOOST_REQUIRE( !is_valid_symbol( "A.A." ) ); BOOST_CHECK( !is_valid_symbol( "A.A." ) );
BOOST_REQUIRE( !is_valid_symbol( "A.A.A" ) ); BOOST_CHECK( !is_valid_symbol( "A.A.A" ) );
BOOST_REQUIRE( is_valid_symbol( "AAAAAAAAAAAAAAAA" ) ); BOOST_CHECK( is_valid_symbol( "AAAAAAAAAAAAAAAA" ) );
BOOST_REQUIRE( !is_valid_symbol( "AAAAAAAAAAAAAAAAA" ) ); BOOST_CHECK( !is_valid_symbol( "AAAAAAAAAAAAAAAAA" ) );
BOOST_REQUIRE( is_valid_symbol( "A.AAAAAAAAAAAAAA" ) ); BOOST_CHECK( is_valid_symbol( "A.AAAAAAAAAAAAAA" ) );
BOOST_REQUIRE( !is_valid_symbol( "A.AAAAAAAAAAAA.A" ) ); BOOST_CHECK( !is_valid_symbol( "A.AAAAAAAAAAAA.A" ) );
} }
BOOST_AUTO_TEST_CASE( price_test ) BOOST_AUTO_TEST_CASE( price_test )

View file

@ -41,7 +41,8 @@ genesis_state_type make_genesis() {
fc::raw::pack(enc, delegate_priv_key); fc::raw::pack(enc, delegate_priv_key);
fc::raw::pack(enc, secret_hash_type()); fc::raw::pack(enc, secret_hash_type());
auto secret = secret_hash_type::hash(enc.result()); auto secret = secret_hash_type::hash(enc.result());
for( int i = 0; i < 10; ++i ) genesis_state.initial_active_witnesses = 10;
for( int i = 0; i < genesis_state.initial_active_witnesses; ++i )
{ {
auto name = "init"+fc::to_string(i); auto name = "init"+fc::to_string(i);
genesis_state.initial_accounts.emplace_back(name, genesis_state.initial_accounts.emplace_back(name,
@ -584,19 +585,19 @@ BOOST_FIXTURE_TEST_CASE( limit_order_expiration, database_fixture )
BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture ) BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture )
{ try { { try {
generate_block(); generate_block();
const auto& from = account_id_type()(db); const auto& alice = account_id_type()(db);
ACTOR(to); ACTOR(bob);
asset amount(1000); asset amount(1000);
trx.set_expiration(db.head_block_time() + fc::minutes(1)); trx.set_expiration(db.head_block_time() + fc::minutes(1));
trx.operations.push_back(transfer_operation({ asset(), from.id, to.id, amount, memo_data() })); trx.operations.push_back(transfer_operation({ asset(), alice.id, bob.id, amount, memo_data() }));
for( auto& op : trx.operations ) op.visit(operation_set_fee(db.current_fee_schedule())); for( auto& op : trx.operations ) op.visit(operation_set_fee(db.current_fee_schedule()));
trx.validate(); trx.validate();
db.push_transaction(trx, ~0); db.push_transaction(trx, ~0);
trx.operations.clear(); trx.operations.clear();
trx.operations.push_back(transfer_operation({ asset(), to.id, from.id, amount, memo_data() })); trx.operations.push_back(transfer_operation({ asset(), bob.id, alice.id, amount, memo_data() }));
for( auto& op : trx.operations ) op.visit(operation_set_fee(db.current_fee_schedule())); for( auto& op : trx.operations ) op.visit(operation_set_fee(db.current_fee_schedule()));
trx.validate(); trx.validate();
@ -604,8 +605,8 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture )
BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception ); BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception );
BOOST_TEST_MESSAGE( "Verify that double-signing causes an exception" ); BOOST_TEST_MESSAGE( "Verify that double-signing causes an exception" );
trx.sign(to_private_key); trx.sign(bob_private_key);
trx.sign(to_private_key); trx.sign(bob_private_key);
BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception ); BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception );
BOOST_TEST_MESSAGE( "Verify that signing with an extra, unused key fails" ); BOOST_TEST_MESSAGE( "Verify that signing with an extra, unused key fails" );
@ -616,7 +617,7 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture )
BOOST_TEST_MESSAGE( "Verify that signing once with the proper key passes" ); BOOST_TEST_MESSAGE( "Verify that signing once with the proper key passes" );
trx.signatures.pop_back(); trx.signatures.pop_back();
db.push_transaction(trx, 0); db.push_transaction(trx, 0);
trx.sign(to_private_key); trx.sign(bob_private_key);
} FC_LOG_AND_RETHROW() } } FC_LOG_AND_RETHROW() }

View file

@ -981,6 +981,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test )
fc::temp_directory td; fc::temp_directory td;
genesis_state.initial_balances.push_back({generate_private_key("n").get_public_key(), GRAPHENE_SYMBOL, 1}); genesis_state.initial_balances.push_back({generate_private_key("n").get_public_key(), GRAPHENE_SYMBOL, 1});
genesis_state.initial_balances.push_back({generate_private_key("x").get_public_key(), GRAPHENE_SYMBOL, 1}); genesis_state.initial_balances.push_back({generate_private_key("x").get_public_key(), GRAPHENE_SYMBOL, 1});
// genesis_state.initial_vesting_balances.push_back({generate_private_key("v").get_public_key(), GRAPHENE_SYMBOL, 1});
// TODO: vesting genesis balances // TODO: vesting genesis balances
genesis_state.initial_accounts.emplace_back("n", generate_private_key("n").get_public_key()); genesis_state.initial_accounts.emplace_back("n", generate_private_key("n").get_public_key());