Issue #106 - Removing KeyObject

- this is a major refactor of the code and may have broken some behavior
in the wallet or witness nodes.
- this commit changes the serialization of operations
- the chain_tests pass
This commit is contained in:
Daniel Larimer 2015-07-02 01:52:45 -04:00
parent 07f621cd65
commit fefa0f65f8
53 changed files with 489 additions and 966 deletions

View file

@ -103,17 +103,6 @@ namespace graphene { namespace app {
return _db.get(dynamic_global_property_id_type());
}
vector<optional<key_object>> database_api::get_keys(const vector<key_id_type>& key_ids)const
{
vector<optional<key_object>> result; result.reserve(key_ids.size());
std::transform(key_ids.begin(), key_ids.end(), std::back_inserter(result),
[this](key_id_type id) -> optional<key_object> {
if(auto o = _db.find(id))
return *o;
return {};
});
return result;
}
vector<optional<account_object>> database_api::get_accounts(const vector<account_id_type>& account_ids)const
{
@ -599,15 +588,33 @@ namespace graphene { namespace app {
/**
* @return all accounts that referr to the key or account id in their owner or active authorities.
*/
vector<account_id_type> database_api::get_account_references( object_id_type key_or_account_id )const
vector<account_id_type> database_api::get_account_references( account_id_type account_id )const
{
const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const primary_index<account_index>&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
auto itr = refs.account_to_memberships.find(key_or_account_id);
auto itr = refs.account_to_account_memberships.find(account_id);
vector<account_id_type> result;
if( itr != refs.account_to_memberships.end() )
if( itr != refs.account_to_account_memberships.end() )
{
result.reserve( itr->second.size() );
for( auto item : itr->second ) result.push_back(item);
}
return result;
}
/**
* @return all accounts that referr to the key or account id in their owner or active authorities.
*/
vector<account_id_type> database_api::get_key_references( public_key_type key )const
{
const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const primary_index<account_index>&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
auto itr = refs.account_to_key_memberships.find(key);
vector<account_id_type> result;
if( itr != refs.account_to_key_memberships.end() )
{
result.reserve( itr->second.size() );
for( auto item : itr->second ) result.push_back(item);
@ -633,24 +640,6 @@ namespace graphene { namespace app {
return result;
}
/**
* @return all key_ids that have been registered for a given address.
*/
vector<key_id_type> database_api::get_keys_for_address( const address& a )const
{ try {
vector<key_id_type> result;
const auto& idx = _db.get_index_type<key_index>();
const auto& aidx = idx.indices().get<by_address>();
auto itr = aidx.find(a);
while( itr != aidx.end() && itr->key_address() == a )
{
result.push_back( itr->id );
++itr;
}
return result;
} FC_CAPTURE_AND_RETHROW( (a) ) }
vector<call_order_object> database_api::get_margin_positions( const account_id_type& id )const
{ try {
const auto& idx = _db.get_index_type<call_order_index>();

View file

@ -23,7 +23,6 @@
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/proposal_object.hpp>
@ -87,14 +86,6 @@ namespace graphene { namespace app {
* @brief Retrieve the current @ref dynamic_global_property_object
*/
dynamic_global_property_object get_dynamic_global_properties()const;
/**
* @brief Get a list of keys by ID
* @param key_ids IDs of the keys to retrieve
* @return The keys corresponding to the provided IDs
*
* This function has semantics identical to @ref get_objects
*/
vector<optional<key_object>> get_keys(const vector<key_id_type>& key_ids)const;
/**
* @brief Get a list of accounts by ID
* @param account_ids IDs of the accounts to retrieve
@ -286,12 +277,8 @@ namespace graphene { namespace app {
/**
* @return all accounts that referr to the key or account id in their owner or active authorities.
*/
vector<account_id_type> get_account_references( object_id_type key_or_account_id )const;
/**
* @return all key_ids that have been registered for a given address.
*/
vector<key_id_type> get_keys_for_address( const address& a )const;
vector<account_id_type> get_account_references( account_id_type account_id )const;
vector<account_id_type> get_key_references( public_key_type account_id )const;
/**
* @return all open margin positions for a given account id.
@ -443,7 +430,6 @@ FC_API(graphene::app::database_api,
(get_transaction)
(get_global_properties)
(get_dynamic_global_properties)
(get_keys)
(get_accounts)
(get_assets)
(lookup_account_names)
@ -471,7 +457,7 @@ FC_API(graphene::app::database_api,
(get_transaction_hex)
(get_proposed_transactions)
(get_account_references)
(get_keys_for_address)
(get_key_references)
(get_margin_positions)
(get_balance_objects)
)

View file

@ -27,7 +27,6 @@ add_library( graphene_chain
withdraw_permission_evaluator.cpp
worker_evaluator.cpp
key_object.cpp
account_object.cpp
asset_object.cpp
proposal_object.cpp

View file

@ -17,7 +17,6 @@
*/
#include <graphene/chain/database.hpp>
#include <graphene/chain/account_evaluator.hpp>
#include <graphene/chain/key_object.hpp>
#include <algorithm>
namespace graphene { namespace chain {
@ -26,26 +25,14 @@ void_result account_create_evaluator::do_evaluate( const account_create_operatio
{ try {
database& d = db();
FC_ASSERT( d.find_object(op.options.voting_account) );
FC_ASSERT( is_relative(op.options.memo_key) || d.find_object(op.options.memo_key) );
FC_ASSERT( fee_paying_account->is_lifetime_member() );
FC_ASSERT( op.referrer(d).is_member(d.head_block_time()) );
const auto& global_props = d.get_global_properties();
const auto& chain_params = global_props.parameters;
FC_ASSERT( op.owner.auths.size() <= chain_params.maximum_authority_membership );
FC_ASSERT( op.active.auths.size() <= chain_params.maximum_authority_membership );
check_relative_ids(op.owner);
check_relative_ids(op.active);
FC_ASSERT( d.find(key_id_type(get_relative_id(op.options.memo_key))) );
for( auto id : op.owner.auths )
{
FC_ASSERT( is_relative(id.first) || d.find_object(id.first) );
}
for( auto id : op.active.auths )
{
FC_ASSERT( is_relative(id.first) || d.find_object(id.first) );
}
verify_authority_accounts( op.owner );
verify_authority_accounts( op.active );
uint32_t max_vote_id = global_props.next_available_vote_id;
FC_ASSERT( op.options.num_witness <= chain_params.maximum_witness_count );
@ -89,11 +76,10 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio
obj.referrer_rewards_percentage = o.referrer_percent;
obj.name = o.name;
obj.owner = resolve_relative_ids(o.owner);
obj.active = resolve_relative_ids(o.active);
obj.owner = o.owner;
obj.active = o.active;
obj.statistics = stats_obj.id;
obj.options = o.options;
obj.options.memo_key = get_relative_id(obj.options.memo_key);
});
const auto& global_properties = db().get_global_properties();
@ -117,30 +103,13 @@ void_result account_update_evaluator::do_evaluate( const account_update_operatio
const auto& chain_params = db().get_global_properties().parameters;
if( o.owner )
{
FC_ASSERT( o.owner->auths.size() <= chain_params.maximum_authority_membership );
check_relative_ids(*o.owner);
for( auto id : o.owner->auths )
{
FC_ASSERT( is_relative(id.first) || db().find<object>(id.first) );
}
}
if( o.active )
{
FC_ASSERT( o.active->auths.size() <= chain_params.maximum_authority_membership );
check_relative_ids(*o.active);
for( auto id : o.active->auths )
{
FC_ASSERT( is_relative(id.first) || db().find<object>(id.first) );
}
}
if( o.owner ) verify_authority_accounts( *o.owner );
if( o.active ) verify_authority_accounts( *o.active );
acnt = &o.account(d);
if( o.new_options )
{
FC_ASSERT( d.find(key_id_type(get_relative_id(o.new_options->memo_key))) );
FC_ASSERT( o.new_options->num_witness <= chain_params.maximum_witness_count );
FC_ASSERT( o.new_options->num_committee <= chain_params.maximum_committee_count );
uint32_t max_vote_id = d.get_global_properties().next_available_vote_id;
@ -156,13 +125,9 @@ void_result account_update_evaluator::do_evaluate( const account_update_operatio
void_result account_update_evaluator::do_apply( const account_update_operation& o )
{ try {
db().modify( *acnt, [&](account_object& a){
if( o.owner ) a.owner = resolve_relative_ids(*o.owner);
if( o.active ) a.active = resolve_relative_ids(*o.active);
if( o.new_options )
{
a.options = *o.new_options;
a.options.memo_key = get_relative_id(a.options.memo_key);
}
if( o.owner ) a.owner = *o.owner;
if( o.active ) a.active = *o.active;
if( o.new_options ) a.options = *o.new_options;
});
return void_result();
} FC_CAPTURE_AND_RETHROW( (o) ) }

View file

@ -156,12 +156,17 @@ void account_object::options_type::validate() const
"May not specify fewer witnesses or committee members than the number voted for.");
}
set<object_id_type> account_member_index::get_members(const account_object& a)const
set<account_id_type> account_member_index::get_account_members(const account_object& a)const
{
set<object_id_type> result;
for( auto auth : a.owner.auths )
set<account_id_type> result;
for( auto auth : a.owner.account_auths )
result.insert(auth.first);
for( auto auth : a.active.auths )
return result;
}
set<public_key_type> account_member_index::get_key_members(const account_object& a)const
{
set<public_key_type> result;
for( auto auth : a.owner.key_auths )
result.insert(auth.first);
return result;
}
@ -171,9 +176,13 @@ void account_member_index::object_inserted(const object& obj)
assert( dynamic_cast<const account_object*>(&obj) ); // for debug only
const account_object& a = static_cast<const account_object&>(obj);
set<object_id_type> members = get_members(a);
for( auto item : members )
account_to_memberships[item].insert(obj.id);
auto account_members = get_account_members(a);
for( auto item : account_members )
account_to_account_memberships[item].insert(obj.id);
auto key_members = get_key_members(a);
for( auto item : key_members )
account_to_key_memberships[item].insert(obj.id);
}
void account_member_index::object_removed(const object& obj)
@ -181,40 +190,71 @@ void account_member_index::object_removed(const object& obj)
assert( dynamic_cast<const account_object*>(&obj) ); // for debug only
const account_object& a = static_cast<const account_object&>(obj);
set<object_id_type> members = get_members(a);
for( auto item : members )
account_to_memberships[item].erase( obj.id );
auto key_members = get_key_members(a);
for( auto item : key_members )
account_to_key_memberships[item].erase( obj.id );
auto account_members = get_account_members(a);
for( auto item : account_members )
account_to_account_memberships[item].erase( obj.id );
}
void account_member_index::about_to_modify(const object& before)
{
before_members.clear();
before_key_members.clear();
before_account_members.clear();
assert( dynamic_cast<const account_object*>(&before) ); // for debug only
const account_object& a = static_cast<const account_object&>(before);
before_members = get_members(a);
before_key_members = get_key_members(a);
before_account_members = get_account_members(a);
}
void account_member_index::object_modified(const object& after)
{
assert( dynamic_cast<const account_object*>(&after) ); // for debug only
const account_object& a = static_cast<const account_object&>(after);
set<object_id_type> after_members = get_members(a);
set<account_id_type> after_account_members = get_account_members(a);
vector<object_id_type> removed; removed.reserve(before_members.size());
std::set_difference(before_members.begin(), before_members.end(),
after_members.begin(), after_members.end(),
{
vector<account_id_type> removed; removed.reserve(before_account_members.size());
std::set_difference(before_account_members.begin(), before_account_members.end(),
after_account_members.begin(), after_account_members.end(),
std::inserter(removed, removed.end()));
for( auto itr = removed.begin(); itr != removed.end(); ++itr )
account_to_memberships[*itr].erase(after.id);
account_to_account_memberships[*itr].erase(after.id);
vector<object_id_type> added; added.reserve(after_members.size());
std::set_difference(after_members.begin(), after_members.end(),
before_members.begin(), before_members.end(),
vector<object_id_type> added; added.reserve(after_account_members.size());
std::set_difference(after_account_members.begin(), after_account_members.end(),
before_account_members.begin(), before_account_members.end(),
std::inserter(added, added.end()));
for( auto itr = added.begin(); itr != added.end(); ++itr )
account_to_memberships[*itr].insert(after.id);
account_to_account_memberships[*itr].insert(after.id);
}
{
set<public_key_type> after_key_members = get_key_members(a);
vector<public_key_type> removed; removed.reserve(before_key_members.size());
std::set_difference(before_key_members.begin(), before_key_members.end(),
after_key_members.begin(), after_key_members.end(),
std::inserter(removed, removed.end()));
for( auto itr = removed.begin(); itr != removed.end(); ++itr )
account_to_key_memberships[*itr].erase(after.id);
vector<public_key_type> added; added.reserve(after_key_members.size());
std::set_difference(after_key_members.begin(), after_key_members.end(),
before_key_members.begin(), before_key_members.end(),
std::inserter(added, added.end()));
for( auto itr = added.begin(); itr != added.end(); ++itr )
account_to_key_memberships[*itr].insert(after.id);
}
}
void account_referrer_index::object_inserted( const object& obj )

View file

@ -449,7 +449,7 @@ void_result asset_publish_feeds_evaluator::do_evaluate(const asset_publish_feed_
if( base.issuer == account_id_type() )
{
//It's a delegate-fed asset. Verify that publisher is an active delegate or witness.
FC_ASSERT(d.get(GRAPHENE_COMMITTEE_ACCOUNT).active.auths.count(o.publisher) ||
FC_ASSERT(d.get(GRAPHENE_COMMITTEE_ACCOUNT).active.account_auths.count(o.publisher) ||
d.get_global_properties().witness_accounts.count(o.publisher));
} else {
FC_ASSERT(bitasset.feeds.count(o.publisher));

View file

@ -20,7 +20,6 @@
#include <graphene/chain/block_summary_object.hpp>
#include <graphene/chain/global_property_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/transaction_object.hpp>
@ -271,7 +270,7 @@ signed_block database::_generate_block(
const auto& witness_obj = witness_id(*this);
if( !(skip & skip_delegate_signature) )
FC_ASSERT( witness_obj.signing_key(*this).key() == block_signing_private_key.get_public_key() );
FC_ASSERT( witness_obj.signing_key == block_signing_private_key.get_public_key() );
_pending_block.timestamp = when;
@ -621,7 +620,7 @@ const witness_object& database::validate_block_header( uint32_t skip, const sign
const witness_object& witness = next_block.witness(*this);
FC_ASSERT( secret_hash_type::hash(next_block.previous_secret) == witness.next_secret, "",
("previous_secret", next_block.previous_secret)("next_secret", witness.next_secret));
if( !(skip&skip_delegate_signature) ) FC_ASSERT( next_block.validate_signee( witness.signing_key(*this).key() ) );
if( !(skip&skip_delegate_signature) ) FC_ASSERT( next_block.validate_signee( witness.signing_key ) );
uint32_t slot_num = get_slot_at_time( next_block.timestamp );
FC_ASSERT( slot_num > 0 );

View file

@ -23,7 +23,6 @@
#include <graphene/chain/block_summary_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/global_property_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/balance_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/proposal_object.hpp>
@ -41,7 +40,6 @@
#include <graphene/chain/custom_evaluator.hpp>
#include <graphene/chain/delegate_evaluator.hpp>
#include <graphene/chain/global_parameters_evaluator.hpp>
#include <graphene/chain/key_evaluator.hpp>
#include <graphene/chain/limit_order_evaluator.hpp>
#include <graphene/chain/proposal_evaluator.hpp>
#include <graphene/chain/call_order_evaluator.hpp>
@ -62,7 +60,6 @@ namespace graphene { namespace chain {
void database::initialize_evaluators()
{
_operation_evaluators.resize(255);
register_evaluator<key_create_evaluator>();
register_evaluator<account_create_evaluator>();
register_evaluator<account_update_evaluator>();
register_evaluator<account_upgrade_evaluator>();
@ -113,13 +110,6 @@ void database::initialize_indexes()
acnt_index->add_secondary_index<account_member_index>();
acnt_index->add_secondary_index<account_referrer_index>();
// this is the fast effecient version for validation only
// add_index< primary_index<simple_index<key_object>> >();
// this is the slower version designed to aid GUI use. We will
// default to the "slow" version until we need a faster version.
add_index< primary_index<key_index> >();
add_index< primary_index<delegate_index> >();
add_index< primary_index<witness_index> >();
add_index< primary_index<limit_order_index > >();
@ -166,9 +156,6 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create blockchain accounts
fc::ecc::private_key null_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")));
create<key_object>( [&null_private_key](key_object& k) {
k.key_data = public_key_type(null_private_key.get_public_key());
});
create<account_balance_object>([](account_balance_object& b) {
b.balance = GRAPHENE_MAX_SHARE_SUPPLY;
});
@ -266,25 +253,29 @@ void database::init_genesis(const genesis_state_type& genesis_state)
{
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;
cop.name = account.name;
cop.registrar = GRAPHENE_TEMP_ACCOUNT;
cop.owner = authority(1, key_id, 1);
cop.owner = authority(1, account.owner_key, 1);
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, key_id, 1);
*/
cop.active = authority(1, account.owner_key, 1);
} else {
cop.active = cop.owner;
}
cop.options.memo_key = key_id;
cop.options.memo_key = account.owner_key;
account_id_type account_id(apply_operation(genesis_eval_state, cop).get<object_id_type>());
if( account.is_lifetime_member )
@ -325,15 +316,17 @@ void database::init_genesis(const genesis_state_type& genesis_state)
int collateral_holder_number = 0;
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;
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, key_id, 1);
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>();
@ -429,12 +422,14 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create initial witnesses and delegates
std::for_each(genesis_state.initial_witness_candidates.begin(), genesis_state.initial_witness_candidates.end(),
[&](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;
op.block_signing_key = signing_key.get_id();
op.block_signing_key = witness.block_signing_key;
op.initial_secret = witness.initial_secret;
op.witness_account = get_account_id(witness.owner_name);
apply_operation(genesis_eval_state, op).get<object_id_type>();

View file

@ -120,7 +120,7 @@ void database::update_active_witnesses()
uint64_t total_votes = 0;
map<account_id_type, uint64_t> weights;
a.active.weight_threshold = 0;
a.active.auths.clear();
a.active.clear();
for( const witness_object& wit : wits )
{
@ -135,7 +135,7 @@ void database::update_active_witnesses()
{
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
uint16_t votes = std::max((weight.second >> bits_to_drop), uint64_t(1) );
a.active.auths[weight.first] += votes;
a.active.account_auths[weight.first] += votes;
a.active.weight_threshold += votes;
}
@ -187,7 +187,7 @@ void database::update_active_delegates()
uint64_t total_votes = 0;
map<account_id_type, uint64_t> weights;
a.active.weight_threshold = 0;
a.active.auths.clear();
a.active.clear();
for( const delegate_object& del : delegates )
{
@ -202,7 +202,7 @@ void database::update_active_delegates()
{
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
uint16_t votes = std::max((weight.second >> bits_to_drop), uint64_t(1) );
a.active.auths[weight.first] += votes;
a.active.account_auths[weight.first] += votes;
a.active.weight_threshold += votes;
}

View file

@ -17,7 +17,6 @@
*/
#include <graphene/chain/delegate_evaluator.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/account_object.hpp>

View file

@ -18,7 +18,6 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/transaction_evaluation_state.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/delegate_object.hpp>
@ -85,6 +84,7 @@ database& generic_evaluator::db()const { return trx_state->db(); }
flat_set<account_id_type> active_auths;
flat_set<account_id_type> owner_auths;
op.visit(operation_get_required_auths(active_auths, owner_auths));
// idump((active_auths)(owner_auths)(op));
for( auto id : active_auths )
{
@ -97,41 +97,12 @@ database& generic_evaluator::db()const { return trx_state->db(); }
}
} FC_CAPTURE_AND_RETHROW( (op) ) }
object_id_type generic_evaluator::get_relative_id( object_id_type rel_id )const
void generic_evaluator::verify_authority_accounts( const authority& a )const
{
if( rel_id.space() == relative_protocol_ids )
{
FC_ASSERT( rel_id.instance() < trx_state->operation_results.size() );
// fetch the object just to make sure it exists.
auto r = trx_state->operation_results[rel_id.instance()].get<object_id_type>();
db().get_object( r ); // make sure it exists.
return r;
}
return rel_id;
}
void generic_evaluator::check_relative_ids(const authority& a)const
{
for( const auto& item : a.auths )
{
auto id = get_relative_id( item.first );
FC_ASSERT( id.type() == key_object_type || id.type() == account_object_type );
}
}
authority generic_evaluator::resolve_relative_ids(const authority& a)const
{
authority result;
result.auths.reserve( a.auths.size() );
result.weight_threshold = a.weight_threshold;
for( const auto& item : a.auths )
{
auto id = get_relative_id( item.first );
FC_ASSERT( id.type() == key_object_type || id.type() == account_object_type );
result.auths[id] = item.second;
}
return result;
const auto& chain_params = db().get_global_properties().parameters;
FC_ASSERT( a.num_auths() <= chain_params.maximum_authority_membership );
for( const auto& acnt : a.account_auths )
acnt.first(db());
}
} }

View file

@ -161,8 +161,7 @@ class database;
/// The memo key is the key this account will typically use to encrypt/sign transaction memos and other non-
/// validated account activities. This field is here to prevent confusion if the active authority has zero or
/// multiple keys in it.
object_id_type memo_key = key_id_type();
key_id_type get_memo_key()const { return memo_key; }
public_key_type memo_key;
/// If this field is set to an account ID other than 0, this account's votes will be ignored and its stake
/// will be counted as voting for the referenced account's selected votes instead.
account_id_type voting_account;
@ -252,7 +251,7 @@ class database;
static const uint8_t space_id = implementation_ids;
static const uint8_t type_id = meta_account_object_type;
key_id_type memo_key;
public_key_type memo_key;
delegate_id_type delegate_id; // optional
};
@ -270,12 +269,16 @@ class database;
/** given an account or key, map it to the set of accounts that reference it in an active or owner authority */
map< object_id_type, set<account_id_type> > account_to_memberships;
map< account_id_type, set<account_id_type> > account_to_account_memberships;
map< public_key_type, set<account_id_type> > account_to_key_memberships;
protected:
set<object_id_type> get_members( const account_object& a )const;
set<object_id_type> before_members;
set<account_id_type> get_account_members( const account_object& a )const;
set<public_key_type> get_key_members( const account_object& a )const;
set<account_id_type> before_account_members;
set<public_key_type> before_key_members;
};
/**

View file

@ -43,17 +43,17 @@ namespace graphene { namespace chain {
active = 1,
key = 2
};
void add_authority( key_id_type k, weight_type w )
void add_authority( const public_key_type& k, weight_type w )
{
auths[k] = w;
key_auths[k] = w;
}
void add_authority( const address& k, weight_type w )
{
address_auths[k] = w;
}
void add_authority( account_id_type k, weight_type w )
{
auths[k] = w;
}
void add_authority( relative_key_id_type k, weight_type w )
{
auths[k] = w;
account_auths[k] = w;
}
template<typename AuthType>
@ -68,24 +68,26 @@ namespace graphene { namespace chain {
add_authorities(auths...);
}
vector<key_id_type> get_keys() const
vector<public_key_type> get_keys() const
{
vector<key_id_type> result;
result.reserve( auths.size() );
for( const pair<object_id_type, weight_type>& item : auths )
{
if( item.first.type() == key_object_type )
result.push_back( item.first );
}
vector<public_key_type> result;
result.reserve( key_auths.size() );
for( const auto& k : key_auths )
result.push_back(k.first);
return result;
}
uint32_t num_auths()const { return account_auths.size() + key_auths.size(); }
void clear() { account_auths.clear(); key_auths.clear(); }
uint32_t weight_threshold = 0;
flat_map<object_id_type,weight_type> auths;
uint32_t weight_threshold = 0;
flat_map<account_id_type,weight_type> account_auths;
flat_map<public_key_type,weight_type> key_auths;
/** needed for backward compatibility only */
flat_map<address,weight_type> address_auths;
};
} } // namespace graphene::chain
FC_REFLECT( graphene::chain::authority, (weight_threshold)(auths) )
FC_REFLECT( graphene::chain::authority, (weight_threshold)(account_auths)(key_auths)(address_auths) )
FC_REFLECT_TYPENAME( graphene::chain::authority::classification )
FC_REFLECT_ENUM( graphene::chain::authority::classification, (owner)(active)(key) )

View file

@ -100,11 +100,9 @@ namespace graphene { namespace chain {
void pay_fee();
bool verify_authority(const account_object&, authority::classification);
object_id_type get_relative_id( object_id_type rel_id )const;
void check_relative_ids(const authority& a)const;
authority resolve_relative_ids( const authority& a )const;
void verify_authority_accounts( const authority& a )const;
asset fee_from_account;
share_type core_fee_paid;

View file

@ -1,45 +0,0 @@
/*
* Copyright (c) 2015, Cryptonomex, Inc.
* All rights reserved.
*
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
* are permitted until September 8, 2015, provided that the following conditions are met:
*
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <graphene/chain/evaluator.hpp>
namespace graphene { namespace chain {
class key_create_evaluator : public evaluator<key_create_evaluator>
{
public:
typedef key_create_operation operation_type;
object_id_type do_evaluate( const key_create_operation& op )
{
return object_id_type();
}
object_id_type do_apply( const key_create_operation& op )
{
new_key_object = &db().create<key_object>( [&]( key_object& obj ){
obj.key_data = op.key_data;
});
return new_key_object->id;
}
const key_object* new_key_object = nullptr;
};
} } // graphene::chain

View file

@ -1,67 +0,0 @@
/*
* Copyright (c) 2015, Cryptonomex, Inc.
* All rights reserved.
*
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
* are permitted until September 8, 2015, provided that the following conditions are met:
*
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <graphene/db/object.hpp>
#include <graphene/chain/address.hpp>
#include <fc/static_variant.hpp>
#include <graphene/chain/types.hpp>
#include <graphene/db/generic_index.hpp>
#include <boost/multi_index/composite_key.hpp>
namespace graphene { namespace chain {
typedef static_variant<address,public_key_type> address_or_key;
/**
* @class key_object
* @brief maps an ID to a public key or address
* @ingroup object
* @ingroup protocol
*/
class key_object : public graphene::db::abstract_object<key_object>
{
public:
static const uint8_t space_id = protocol_ids;
static const uint8_t type_id = key_object_type;
key_id_type get_id()const { return key_id_type( id.instance() ); }
address key_address()const;
const public_key_type& key()const { return key_data.get<public_key_type>(); }
address_or_key key_data;
};
struct by_address;
/**
* @ingroup object_index
*/
typedef multi_index_container<
key_object,
indexed_by<
hashed_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
hashed_non_unique< tag<by_address>, const_mem_fun<key_object, address, &key_object::key_address> >
>
> key_multi_index_type;
/**
* @ingroup object_index
*/
typedef generic_index<key_object, key_multi_index_type> key_index;
} }
FC_REFLECT_TYPENAME( graphene::chain::address_or_key )
FC_REFLECT_DERIVED( graphene::chain::key_object, (graphene::db::object), (key_data) )

View file

@ -157,23 +157,6 @@ namespace graphene { namespace chain {
}
};
/**
* @brief reserves a new ID to refer to a particular key or address.
* @ingroup operations
*/
struct key_create_operation
{
asset fee;
account_id_type fee_paying_account;
static_variant<address,public_key_type> key_data;
account_id_type fee_payer()const { return fee_paying_account; }
void get_required_auth(flat_set<account_id_type>& active_auth_set , flat_set<account_id_type>&)const;
share_type calculate_fee(const fee_schedule_type& k)const{ return k.key_create_fee; }
void validate()const;
void get_balance_delta(balance_accumulator& acc, const operation_result& result = asset())const { acc.adjust(fee_payer(), -fee); }
};
/**
* @ingroup operations
@ -368,7 +351,7 @@ namespace graphene { namespace chain {
/// The account which owns the delegate. This account pays the fee for this operation.
account_id_type witness_account;
string url;
object_id_type block_signing_key; // key_id_type or relative_key_id_type
public_key_type block_signing_key;
secret_hash_type initial_secret;
account_id_type fee_payer()const { return witness_account; }
@ -459,8 +442,8 @@ namespace graphene { namespace chain {
*/
struct memo_data
{
key_id_type from;
key_id_type to;
public_key_type from;
public_key_type to;
/**
* 64 bit nonce format:
* [ 8 bits | 56 bits ]
@ -1036,8 +1019,8 @@ namespace graphene { namespace chain {
flat_set<account_id_type> active_approvals_to_remove;
flat_set<account_id_type> owner_approvals_to_add;
flat_set<account_id_type> owner_approvals_to_remove;
flat_set<key_id_type> key_approvals_to_add;
flat_set<key_id_type> key_approvals_to_remove;
flat_set<public_key_type> key_approvals_to_add;
flat_set<public_key_type> key_approvals_to_remove;
account_id_type fee_payer()const { return fee_paying_account; }
void get_required_auth(flat_set<account_id_type>& active_auth_set, flat_set<account_id_type>& owner_auth_set)const;
@ -1422,7 +1405,6 @@ namespace graphene { namespace chain {
limit_order_create_operation,
limit_order_cancel_operation,
call_order_update_operation,
key_create_operation,
account_create_operation,
account_update_operation,
account_whitelist_operation,
@ -1586,11 +1568,6 @@ FC_REFLECT( graphene::chain::op_wrapper, (op) )
FC_REFLECT( graphene::chain::memo_message, (checksum)(text) )
FC_REFLECT( graphene::chain::memo_data, (from)(to)(nonce)(message) )
FC_REFLECT( graphene::chain::key_create_operation,
(fee)(fee_paying_account)
(key_data)
)
FC_REFLECT( graphene::chain::account_create_operation,
(fee)(registrar)
(referrer)(referrer_percent)

View file

@ -44,7 +44,7 @@ class proposal_object : public abstract_object<proposal_object>
flat_set<account_id_type> available_active_approvals;
flat_set<account_id_type> required_owner_approvals;
flat_set<account_id_type> available_owner_approvals;
flat_set<key_id_type> available_key_approvals;
flat_set<public_key_type> available_key_approvals;
bool is_authorized_to_execute(database& db)const;
};

View file

@ -140,8 +140,6 @@ namespace graphene { namespace chain {
signed_transaction( const transaction& trx = transaction() )
: transaction(trx){}
/** deprecated, TODO: remove when all references are gone */
void sign( key_id_type id, const private_key_type& key ) { sign(key); }
void sign( const private_key_type& key );
vector<signature_type> signatures;

View file

@ -40,8 +40,8 @@ namespace graphene { namespace chain {
database& db()const { FC_ASSERT( _db ); return *_db; }
bool signed_by(key_id_type id);
bool signed_by(const public_key_type& k);
bool signed_by(const address& k);
/// cached approval (accounts and keys)
flat_set<pair<object_id_type,authority::classification>> approved_by;

View file

@ -102,7 +102,6 @@ namespace graphene { namespace chain {
{
null_object_type,
base_object_type,
key_object_type,
account_object_type,
asset_object_type,
force_settlement_object_type,
@ -151,7 +150,6 @@ namespace graphene { namespace chain {
class witness_object;
class asset_object;
class force_settlement_object;
class key_object;
class limit_order_object;
class call_order_object;
class custom_object;
@ -163,7 +161,6 @@ namespace graphene { namespace chain {
class worker_object;
class balance_object;
typedef object_id< protocol_ids, key_object_type, key_object> key_id_type;
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
typedef object_id< protocol_ids, force_settlement_object_type, force_settlement_object> force_settlement_id_type;
@ -179,9 +176,6 @@ namespace graphene { namespace chain {
typedef object_id< protocol_ids, worker_object_type, worker_object> worker_id_type;
typedef object_id< protocol_ids, balance_object_type, balance_object> balance_id_type;
typedef object_id< relative_protocol_ids, key_object_type, key_object> relative_key_id_type;
typedef object_id< relative_protocol_ids, account_object_type, account_object> relative_account_id_type;
// implementation types
class global_property_object;
class dynamic_global_property_object;
@ -510,7 +504,6 @@ FC_REFLECT( graphene::chain::public_key_type::binary_key, (data)(check) )
FC_REFLECT_ENUM( graphene::chain::object_type,
(null_object_type)
(base_object_type)
(key_object_type)
(account_object_type)
(force_settlement_object_type)
(asset_object_type)
@ -628,7 +621,6 @@ FC_REFLECT( graphene::chain::chain_parameters,
FC_REFLECT_TYPENAME( graphene::chain::share_type )
FC_REFLECT_TYPENAME( graphene::chain::key_id_type )
FC_REFLECT_TYPENAME( graphene::chain::account_id_type )
FC_REFLECT_TYPENAME( graphene::chain::asset_id_type )
FC_REFLECT_TYPENAME( graphene::chain::force_settlement_id_type )
@ -642,8 +634,6 @@ FC_REFLECT_TYPENAME( graphene::chain::operation_history_id_type )
FC_REFLECT_TYPENAME( graphene::chain::withdraw_permission_id_type )
FC_REFLECT_TYPENAME( graphene::chain::vesting_balance_id_type )
FC_REFLECT_TYPENAME( graphene::chain::worker_id_type )
FC_REFLECT_TYPENAME( graphene::chain::relative_key_id_type )
FC_REFLECT_TYPENAME( graphene::chain::relative_account_id_type )
FC_REFLECT_TYPENAME( graphene::chain::global_property_id_type )
FC_REFLECT_TYPENAME( graphene::chain::dynamic_global_property_id_type )
FC_REFLECT_TYPENAME( graphene::chain::asset_dynamic_data_id_type )

View file

@ -32,7 +32,7 @@ namespace graphene { namespace chain {
static const uint8_t type_id = witness_object_type;
account_id_type witness_account;
key_id_type signing_key;
public_key_type signing_key;
secret_hash_type next_secret;
secret_hash_type last_secret;
share_type accumulated_income;

View file

@ -1,33 +0,0 @@
/*
* Copyright (c) 2015, Cryptonomex, Inc.
* All rights reserved.
*
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
* are permitted until September 8, 2015, provided that the following conditions are met:
*
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/types.hpp>
namespace graphene { namespace chain {
address key_object::key_address()const
{
switch( key_data.which() )
{
case address_or_key::tag<address>::value:
return key_data.get<address>();
case address_or_key::tag<public_key_type>::value:
default:
return key_data.get<public_key_type>();
}
}
} }

View file

@ -192,6 +192,16 @@ void account_update_operation::validate()const
FC_ASSERT( fee.amount >= 0 );
FC_ASSERT( account != account_id_type() );
FC_ASSERT( owner || active || new_options );
if( owner )
{
FC_ASSERT( owner->num_auths() != 0 );
FC_ASSERT( owner->address_auths.size() == 0 );
}
if( active )
{
FC_ASSERT( active->num_auths() != 0 );
FC_ASSERT( active->address_auths.size() == 0 );
}
if( new_options )
new_options->validate();
@ -236,24 +246,6 @@ share_type override_transfer_operation::calculate_fee( const fee_schedule_type&
}
struct key_data_validate
{
typedef void result_type;
void operator()( const address& a )const { FC_ASSERT( a != address() ); }
void operator()( const public_key_type& a )const { FC_ASSERT( a != public_key_type() ); }
};
void key_create_operation::get_required_auth(flat_set<account_id_type>& active_auth_set,
flat_set<account_id_type>&) const
{
active_auth_set.insert(fee_paying_account);
}
void key_create_operation::validate()const
{
FC_ASSERT( fee.amount >= 0 );
key_data.visit( key_data_validate() );
}
void account_create_operation::get_required_auth(flat_set<account_id_type>& active_auth_set,
flat_set<account_id_type>&) const
{
@ -265,13 +257,11 @@ void account_create_operation::validate()const
FC_ASSERT( fee.amount >= 0 );
FC_ASSERT( is_valid_name( name ) );
FC_ASSERT( referrer_percent <= GRAPHENE_100_PERCENT );
FC_ASSERT( !owner.auths.empty() );
auto pos = name.find( '/' );
if( pos != string::npos )
{
FC_ASSERT( owner.weight_threshold == 1 );
FC_ASSERT( owner.auths.size() == 1 );
}
FC_ASSERT( owner.num_auths() != 0 );
FC_ASSERT( owner.address_auths.size() == 0 );
// TODO: this asset causes many tests to fail, those tests should probably be updated
//FC_ASSERT( active.num_auths() != 0 );
FC_ASSERT( active.address_auths.size() == 0 );
options.validate();
}
@ -813,7 +803,7 @@ share_type vesting_balance_withdraw_operation::calculate_fee(const fee_schedule_
void memo_data::set_message( const fc::ecc::private_key& priv,
const fc::ecc::public_key& pub, const string& msg )
{
if( from )
if( from != public_key_type() )
{
uint64_t entropy = fc::sha224::hash(fc::ecc::private_key::generate())._hash[0];
entropy <<= 32;
@ -834,7 +824,7 @@ void memo_data::set_message( const fc::ecc::private_key& priv,
string memo_data::get_message( const fc::ecc::private_key& priv,
const fc::ecc::public_key& pub )const
{
if( from )
if( from != public_key_type() )
{
auto secret = priv.get_shared_secret(pub);
auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str());

View file

@ -18,7 +18,6 @@
#include <graphene/chain/proposal_evaluator.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/key_object.hpp>
namespace graphene { namespace chain {
@ -93,13 +92,16 @@ void_result proposal_update_evaluator::do_evaluate(const proposal_update_operati
FC_ASSERT( _proposal->available_owner_approvals.find(id) != _proposal->available_owner_approvals.end(),
"", ("id", id)("available", _proposal->available_owner_approvals) );
}
/* All authority checks happen outside of evaluators, TODO: verify this is checked elsewhere
*/
if( (d.get_node_properties().skip_flags & database::skip_authority_check) == 0 )
{
for( key_id_type id : o.key_approvals_to_add )
for( const auto& id : o.key_approvals_to_add )
{
FC_ASSERT( trx_state->signed_by(id) );
}
for( key_id_type id : o.key_approvals_to_remove )
for( const auto& id : o.key_approvals_to_remove )
{
FC_ASSERT( trx_state->signed_by(id) );
}
@ -122,9 +124,9 @@ void_result proposal_update_evaluator::do_apply(const proposal_update_operation&
p.available_active_approvals.erase(id);
for( account_id_type id : o.owner_approvals_to_remove )
p.available_owner_approvals.erase(id);
for( key_id_type id : o.key_approvals_to_add )
for( const auto& id : o.key_approvals_to_add )
p.available_key_approvals.insert(id);
for( key_id_type id : o.key_approvals_to_remove )
for( const auto& id : o.key_approvals_to_remove )
p.available_key_approvals.erase(id);
});

View file

@ -18,7 +18,6 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/key_object.hpp>
namespace graphene { namespace chain {
@ -37,8 +36,9 @@ bool proposal_object::is_authorized_to_execute(database& db) const
signed_transaction tmp;
dry_run_eval._trx = &tmp;
for( auto key_id : available_key_approvals )
dry_run_eval._sigs.insert( std::make_pair(key_id(db).key(),true) );
dry_run_eval._sigs.insert( std::make_pair(key_id,true) );
//insert into dry_run_eval->_trx.signatures
//dry_run_eval.signed_by.insert(available_key_approvals.begin(), available_key_approvals.end());

View file

@ -17,7 +17,6 @@
*/
#include <graphene/chain/transaction_evaluation_state.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/database.hpp>
@ -34,7 +33,7 @@ namespace graphene { namespace chain {
approved_by.find(make_pair(account.id, auth_class)) != approved_by.end() )
return true;
FC_ASSERT( account.id.instance() != 0 || _is_proposed_trx );
FC_ASSERT( account.id.instance() != 0 || _is_proposed_trx, "", ("account",account)("is_proposed",_is_proposed_trx) );
const authority* au = nullptr;
switch( auth_class )
@ -50,65 +49,55 @@ namespace graphene { namespace chain {
};
uint32_t total_weight = 0;
for( const auto& auth : au->auths )
for( const auto& auth : au->account_auths )
{
if( approved_by.find( std::make_pair(auth.first,auth_class) ) != approved_by.end() )
total_weight += auth.second;
else
{
const object& auth_item = _db->get_object( auth.first );
switch( auth_item.id.type() )
if( depth == GRAPHENE_MAX_SIG_CHECK_DEPTH )
{
case account_object_type:
{
if( depth == GRAPHENE_MAX_SIG_CHECK_DEPTH )
{
//elog("Failing authority verification due to recursion depth.");
return false;
}
if( check_authority( *dynamic_cast<const account_object*>( &auth_item ), auth_class, depth + 1 ) )
{
approved_by.insert( std::make_pair(auth_item.id,auth_class) );
total_weight += auth.second;
}
break;
}
case key_object_type:
{
if( signed_by( auth.first ) )
{
approved_by.insert( std::make_pair(auth_item.id,authority::key) );
total_weight += auth.second;
}
break;
}
default:
FC_ASSERT( !"Invalid Auth Object Type", "type:${type}", ("type",auth_item.id.type()) );
//elog("Failing authority verification due to recursion depth.");
return false;
}
const account_object& acnt = auth.first(*_db);
if( check_authority( acnt, auth_class, depth + 1 ) )
{
approved_by.insert( std::make_pair(acnt.id,auth_class) );
total_weight += auth.second;
}
}
if( total_weight >= au->weight_threshold )
{
approved_by.insert( std::make_pair(account.id, auth_class) );
return true;
}
}
for( const auto& key : au->key_auths )
{
if( signed_by( key.first ) )
total_weight += key.second;
}
for( const auto& key : au->address_auths )
{
if( signed_by( key.first ) )
total_weight += key.second;
}
if( total_weight >= au->weight_threshold )
{
approved_by.insert( std::make_pair(account.id, auth_class) );
return true;
}
return false;
}
bool transaction_evaluation_state::signed_by(key_id_type id)
{
assert(_trx);
assert(_db);
return signed_by(id(*_db).key());
}
bool transaction_evaluation_state::signed_by(const public_key_type& k)
{
assert(_db);
auto itr = _sigs.find(k);
if( itr != _sigs.end() )
return itr->second = true;
return false;
}
bool transaction_evaluation_state::signed_by(const address& k)
{
for( auto itr = _sigs.begin(); itr != _sigs.end(); ++itr )
if( itr->first == k ) return true;
return false;
}

View file

@ -5,7 +5,6 @@
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/global_property_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/proposal_object.hpp>
@ -48,9 +47,6 @@ const uint8_t force_settlement_object::type_id;
const uint8_t global_property_object::space_id;
const uint8_t global_property_object::type_id;
const uint8_t key_object::space_id;
const uint8_t key_object::type_id;
const uint8_t limit_order_object::space_id;
const uint8_t limit_order_object::type_id;

View file

@ -19,7 +19,6 @@
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/database.hpp>
namespace graphene { namespace chain {
@ -27,8 +26,6 @@ namespace graphene { namespace chain {
void_result witness_create_evaluator::do_evaluate( const witness_create_operation& op )
{ try {
FC_ASSERT(db().get(op.witness_account).is_lifetime_member());
object_id_type block_signing_key_id = get_relative_id(op.block_signing_key);
FC_ASSERT(block_signing_key_id.type() == key_object_type);
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
@ -39,14 +36,10 @@ object_id_type witness_create_evaluator::do_apply( const witness_create_operatio
vote_id = p.get_next_vote_id(vote_id_type::witness);
});
object_id_type block_signing_key_object_id = get_relative_id(op.block_signing_key);
FC_ASSERT(block_signing_key_object_id.type() == key_object_type);
key_id_type block_signing_key_id(block_signing_key_object_id.instance());
const auto& new_witness_object = db().create<witness_object>( [&]( witness_object& obj ){
obj.witness_account = op.witness_account;
obj.vote_id = vote_id;
obj.signing_key = block_signing_key_id;
obj.signing_key = op.block_signing_key;
obj.next_secret = op.initial_secret;
obj.url = op.url;
});

View file

@ -210,7 +210,7 @@ namespace graphene { namespace db {
fc::sha256 get_object_version()const
{
auto desc = get_type_description<object_type>();
std::string desc = "1.0";//get_type_description<object_type>();
return fc::sha256::hash(desc);
}

View file

@ -23,7 +23,6 @@
#include <graphene/chain/config.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/transaction_evaluation_state.hpp>
@ -43,8 +42,6 @@ class account_history_plugin_impl
{ }
virtual ~account_history_plugin_impl();
flat_set<key_id_type> get_keys_for_account(
const account_id_type& account_id );
/** this method is called as a callback after a block is applied
* and will process/index all operations that were applied in the block.
@ -72,11 +69,8 @@ struct operation_get_impacted_accounts
void add_authority( const authority& a )const
{
for( auto& item : a.auths )
{
if( item.first.type() == account_object_type )
_impacted.insert( item.first );
}
for( auto& item : a.account_auths )
_impacted.insert( item.first );
}
void operator()( const transfer_operation& o )const {
@ -86,7 +80,6 @@ struct operation_get_impacted_accounts
void operator()( const limit_order_create_operation& o )const { }
void operator()( const limit_order_cancel_operation& o )const { }
void operator()( const call_order_update_operation& o )const { }
void operator()( const key_create_operation& o )const { }
void operator()( const custom_operation& o )const { }
void operator()( const account_create_operation& o )const {

View file

@ -23,7 +23,6 @@
#include <graphene/chain/config.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/transaction_evaluation_state.hpp>

View file

@ -56,7 +56,7 @@ private:
boost::program_options::variables_map _options;
bool _production_enabled = false;
std::map<chain::key_id_type, fc::ecc::private_key> _private_keys;
std::map<chain::public_key_type, fc::ecc::private_key> _private_keys;
std::set<chain::witness_id_type> _witnesses;
fc::future<void> _block_production_task;
};

View file

@ -19,7 +19,6 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/time/time.hpp>
#include <graphene/utilities/key_conversion.hpp>
@ -36,13 +35,14 @@ void witness_plugin::plugin_set_program_options(
boost::program_options::options_description& command_line_options,
boost::program_options::options_description& config_file_options)
{
auto default_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("nathan")));
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")
("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)")
("private-key", bpo::value<vector<string>>()->composing()->multitoken()->
DEFAULT_VALUE_VECTOR(std::make_pair(chain::key_id_type(), graphene::utilities::key_to_wif(fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("nathan")))))),
"Tuple of [key ID, WIF private key] (may specify multiple times)")
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)")
;
config_file_options.add(command_line_options);
}
@ -62,7 +62,7 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m
const std::vector<std::string> key_id_to_wif_pair_strings = options["private-key"].as<std::vector<std::string>>();
for (const std::string& key_id_to_wif_pair_string : key_id_to_wif_pair_strings)
{
auto key_id_to_wif_pair = graphene::app::dejsonify<std::pair<chain::key_id_type, std::string> >(key_id_to_wif_pair_string);
auto key_id_to_wif_pair = graphene::app::dejsonify<std::pair<chain::public_key_type, std::string> >(key_id_to_wif_pair_string);
fc::optional<fc::ecc::private_key> private_key = graphene::utilities::wif_to_key(key_id_to_wif_pair.second);
if (!private_key)
{
@ -97,7 +97,7 @@ void witness_plugin::plugin_startup()
// Check if it's a duplicate key of one I do have
bool found_duplicate = false;
for( const auto& private_key : _private_keys )
if( chain::public_key_type(private_key.second.get_public_key()) == signing_key(database()).key_address() )
if( chain::public_key_type(private_key.second.get_public_key()) == signing_key )
{
ilog("Found duplicate key: ${k1} matches ${k2}; using this key to sign for ${w}",
("k1", private_key.first)("k2", signing_key)("w", wit));
@ -160,7 +160,7 @@ void witness_plugin::block_production_loop()
graphene::chain::witness_id_type scheduled_witness = db.get_scheduled_witness( slot ).first;
fc::time_point_sec scheduled_time = db.get_slot_time( slot );
fc::time_point_sec now = graphene::time::now();
graphene::chain::key_id_type scheduled_key = scheduled_witness( db ).signing_key;
graphene::chain::public_key_type scheduled_key = scheduled_witness( db ).signing_key;
auto is_scheduled = [&]()
{

View file

@ -16,7 +16,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/delegate_object.hpp>
@ -58,8 +57,6 @@ object* create_object( const variant& v )
case base_object_type:
return create_object_of_type< base_object >( v );
*/
case key_object_type:
return create_object_of_type< key_object >( v );
case account_object_type:
return create_object_of_type< account_object >( v );
case asset_object_type:

View file

@ -45,9 +45,8 @@ object* create_object( const variant& v );
struct plain_keys
{
map<key_id_type, string> keys;
map<address,string> extra_keys;
fc::sha512 checksum;
map<public_key_type, string> keys;
fc::sha512 checksum;
};
struct wallet_data
@ -82,7 +81,7 @@ struct wallet_data
vector<char> cipher_keys;
/** map an account to a set of extra keys that have been imported for that account */
map<account_id_type, vector<address> > extra_keys;
map<account_id_type, set<public_key_type> > extra_keys;
// map of account_name -> base58_private_key for
// incomplete account regs
@ -328,7 +327,7 @@ class wallet_api
* using \c import_key()
* @returns a map containing the private keys, indexed by their key_id
*/
map<key_id_type, string> dump_private_keys();
map<public_key_type, string> dump_private_keys();
/** Returns a list of all commands supported by the wallet API.
*
@ -962,7 +961,7 @@ class wallet_api
} }
FC_REFLECT( graphene::wallet::plain_keys, (keys)(extra_keys)(checksum) )
FC_REFLECT( graphene::wallet::plain_keys, (keys)(checksum) )
FC_REFLECT( graphene::wallet::wallet_data,
(my_accounts)

View file

@ -85,7 +85,6 @@ public:
void operator()(const transfer_operation& op)const;
void operator()(const account_create_operation& op)const;
void operator()(const account_update_operation& op)const;
void operator()(const key_create_operation& op)const;
void operator()(const asset_create_operation& op)const;
};
@ -226,11 +225,8 @@ private:
fc::optional<fc::ecc::private_key> witness_private_key = wif_to_key(wif_key);
FC_ASSERT(witness_private_key);
graphene::chain::address witness_key_address = graphene::chain::address(witness_private_key->get_public_key());
std::vector<key_id_type> registered_key_ids = _remote_db->get_keys_for_address(witness_key_address);
for (const key_id_type& id : registered_key_ids)
_keys[id] = wif_key;
auto pub_key = witness_private_key->get_public_key();
_keys[pub_key] = wif_key;
_wallet.pending_witness_registrations.erase(iter);
}
@ -490,7 +486,7 @@ public:
return _wallet_filename;
}
fc::ecc::private_key get_private_key(key_id_type id)const
fc::ecc::private_key get_private_key(const public_key_type& id)const
{
auto it = _keys.find(id);
FC_ASSERT( it != _keys.end() );
@ -502,61 +498,29 @@ public:
fc::ecc::private_key get_private_key_for_account(const account_object& account)const
{
vector<key_id_type> active_keys = account.active.get_keys();
vector<public_key_type> active_keys = account.active.get_keys();
if (active_keys.size() != 1)
FC_THROW("Expecting a simple authority with one active key");
return get_private_key(active_keys.front());
}
fc::ecc::public_key get_public_key(key_id_type id)const
{
vector<optional<key_object>> keys = _remote_db->get_keys( {id} );
FC_ASSERT( keys.size() == 1 );
FC_ASSERT( keys[0].valid() );
return keys[0]->key();
}
bool import_key(string account_name_or_id, string wif_key)
{
auto opt_priv_key = wif_to_key(wif_key);
FC_ASSERT( opt_priv_key.valid() );
graphene::chain::address wif_key_address = graphene::chain::address(
opt_priv_key->get_public_key() );
graphene::chain::public_key_type wif_pub_key = opt_priv_key->get_public_key();
_keys[wif_pub_key] = wif_key;
auto acnt = get_account( account_name_or_id );
flat_set<key_id_type> keys;
for( auto item : acnt.active.auths )
{
if( item.first.type() == key_object_type )
keys.insert( item.first );
}
for( auto item : acnt.owner.auths )
{
if( item.first.type() == key_object_type )
keys.insert( item.first );
}
keys.insert(acnt.options.get_memo_key());
if( _wallet.update_account(acnt) )
_remote_db->subscribe_to_objects([this](const fc::variant& v) {
_wallet.update_account(v.as<account_object>());
}, {acnt.id});
_wallet.extra_keys[acnt.id].insert(wif_pub_key);
auto opt_keys = _remote_db->get_keys( vector<key_id_type>(keys.begin(),keys.end()) );
for( const fc::optional<key_object>& opt_key : opt_keys )
{
// the requested key ID's should all exist because they are
// keys for an account
FC_ASSERT( opt_key.valid() );
// we do this check by address because key objects on the
// blockchain may not contain a key (i.e. are simply an address)
if( opt_key->key_address() == wif_key_address )
{
_keys[ opt_key->id ] = wif_key;
if( _wallet.update_account(acnt) )
_remote_db->subscribe_to_objects([this](const fc::variant& v) {
_wallet.update_account(v.as<account_object>());
}, {acnt.id});
return true;
}
}
ilog( "key not for account ${name}", ("name",account_name_or_id) );
return false;
}
bool load_wallet_file(string wallet_filename = "")
@ -725,41 +689,23 @@ public:
account_create_op.referrer = referrer_account_object.id;
account_create_op.referrer_percent = referrer_percent;
// get pay_from_account_id
key_create_operation owner_key_create_op;
owner_key_create_op.fee_paying_account = registrar_account_id;
owner_key_create_op.key_data = owner;
key_create_operation active_key_create_op;
active_key_create_op.fee_paying_account = registrar_account_id;
active_key_create_op.key_data = active;
// key_create_op.calculate_fee(db.current_fee_schedule());
// TODO: Check if keys already exist!!!
relative_key_id_type owner_rkid(0);
relative_key_id_type active_rkid(1);
account_create_op.registrar = registrar_account_id;
account_create_op.name = name;
account_create_op.owner = authority(1, owner_rkid, 1);
account_create_op.active = authority(1, active_rkid, 1);
account_create_op.options.memo_key = active_rkid;
account_create_op.owner = authority(1, owner, 1);
account_create_op.active = authority(1, active, 1);
account_create_op.options.memo_key = active;
signed_transaction tx;
tx.operations.push_back( owner_key_create_op );
tx.operations.push_back( active_key_create_op );
tx.operations.push_back( account_create_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
vector<key_id_type> paying_keys = registrar_account_object.active.get_keys();
vector<public_key_type> paying_keys = registrar_account_object.active.get_keys();
tx.validate();
for( key_id_type& key : paying_keys )
for( public_key_type& key : paying_keys )
{
auto it = _keys.find(key);
if( it != _keys.end() )
@ -769,7 +715,7 @@ public:
{
FC_ASSERT( false, "Malformed private key in _keys" );
}
tx.sign( key, *privkey );
tx.sign( *privkey );
}
}
@ -808,9 +754,7 @@ public:
{
fc::ecc::private_key derived_private_key = derive_private_key(key_to_wif(parent_key), key_index);
graphene::chain::public_key_type derived_public_key = derived_private_key.get_public_key();
graphene::chain::address derived_address(derived_public_key);
std::vector<key_id_type> registered_keys = _remote_db->get_keys_for_address(derived_address);
if (registered_keys.empty())
if( _keys.find(derived_public_key) == _keys.end() )
{
if (number_of_consecutive_unused_keys)
{
@ -862,32 +806,11 @@ public:
account_create_op.referrer = referrer_account_object.id;
account_create_op.referrer_percent = referrer_account_object.referrer_rewards_percentage;
// get pay_from_account_id
key_create_operation owner_key_create_op;
owner_key_create_op.fee_paying_account = registrar_account_id;
owner_key_create_op.key_data = owner_pubkey;
key_create_operation active_key_create_op;
active_key_create_op.fee_paying_account = registrar_account_id;
active_key_create_op.key_data = active_pubkey;
key_create_operation memo_key_create_op;
memo_key_create_op.fee_paying_account = registrar_account_id;
memo_key_create_op.key_data = memo_pubkey;
// key_create_op.calculate_fee(db.current_fee_schedule());
// TODO: Check if keys already exist!!!
relative_key_id_type owner_rkid(0);
relative_key_id_type active_rkid(1);
relative_key_id_type memo_rkid(2);
account_create_op.registrar = registrar_account_id;
account_create_op.name = account_name;
account_create_op.owner = authority(1, owner_rkid, 1);
account_create_op.active = authority(1, active_rkid, 1);
account_create_op.options.memo_key = memo_rkid;
account_create_op.owner = authority(1, owner_pubkey, 1);
account_create_op.active = authority(1, active_pubkey, 1);
account_create_op.options.memo_key = memo_pubkey;
// current_fee_schedule()
// find_account(pay_from_account)
@ -896,26 +819,23 @@ public:
signed_transaction tx;
tx.operations.push_back( owner_key_create_op );
tx.operations.push_back( active_key_create_op );
tx.operations.push_back( memo_key_create_op );
tx.operations.push_back( account_create_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
vector<key_id_type> paying_keys = registrar_account_object.active.get_keys();
vector<public_key_type> paying_keys = registrar_account_object.active.get_keys();
tx.set_expiration(get_dynamic_global_properties().head_block_id);
tx.validate();
for( key_id_type& key : paying_keys )
for( public_key_type& key : paying_keys )
{
auto it = _keys.find(key);
if( it != _keys.end() )
{
fc::optional< fc::ecc::private_key > privkey = wif_to_key( it->second );
FC_ASSERT( privkey.valid(), "Malformed private key in _keys" );
tx.sign( key, *privkey );
tx.sign( *privkey );
}
}
@ -1269,15 +1189,9 @@ public:
fc::ecc::private_key witness_private_key = derive_private_key(key_to_wif(active_private_key), witness_key_index);
graphene::chain::public_key_type witness_public_key = witness_private_key.get_public_key();
key_create_operation witness_key_create_op;
witness_key_create_op.fee_paying_account = witness_account.id;
witness_key_create_op.key_data = witness_public_key;
relative_key_id_type witness_relative_key_id(0);
witness_create_operation witness_create_op;
witness_create_op.witness_account = witness_account.id;
witness_create_op.block_signing_key = witness_relative_key_id;
witness_create_op.block_signing_key = witness_public_key;
witness_create_op.url = url;
secret_hash_type::encoder enc;
@ -1289,7 +1203,6 @@ public:
FC_THROW("Account ${owner_account} is already a witness", ("owner_account", owner_account));
signed_transaction tx;
tx.operations.push_back( witness_key_create_op );
tx.operations.push_back( witness_create_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
tx.validate();
@ -1437,15 +1350,15 @@ public:
i++;
}
flat_set< key_id_type > approving_key_set;
flat_set< public_key_type > approving_key_set;
for( account_id_type& acct_id : req_active_approvals )
{
const auto it = approving_account_lut.find( acct_id );
if( it == approving_account_lut.end() )
continue;
const account_object* acct = it->second;
vector<key_id_type> v_approving_keys = acct->active.get_keys();
for( const key_id_type& approving_key : v_approving_keys )
vector<public_key_type> v_approving_keys = acct->active.get_keys();
for( const public_key_type& approving_key : v_approving_keys )
approving_key_set.insert( approving_key );
}
for( account_id_type& acct_id : req_owner_approvals )
@ -1454,15 +1367,15 @@ public:
if( it == approving_account_lut.end() )
continue;
const account_object* acct = it->second;
vector<key_id_type> v_approving_keys = acct->owner.get_keys();
for( const key_id_type& approving_key : v_approving_keys )
vector<public_key_type> v_approving_keys = acct->owner.get_keys();
for( const public_key_type& approving_key : v_approving_keys )
approving_key_set.insert( approving_key );
}
tx.set_expiration(get_dynamic_global_properties().head_block_id);
for( key_id_type& key : approving_key_set )
for( public_key_type& key : approving_key_set )
{
auto it = _keys.find(key);
if( it != _keys.end() )
@ -1472,7 +1385,7 @@ public:
{
FC_ASSERT( false, "Malformed private key in _keys" );
}
tx.sign( key, *privkey );
tx.sign( *privkey );
}
}
@ -1571,7 +1484,7 @@ public:
xfer_op.memo->from = from_account.options.memo_key;
xfer_op.memo->to = to_account.options.memo_key;
xfer_op.memo->set_message(get_private_key(from_account.options.memo_key),
get_public_key(to_account.options.memo_key), memo);
to_account.options.memo_key, memo);
}
signed_transaction tx;
@ -1601,7 +1514,7 @@ public:
issue_op.memo->from = issuer.options.memo_key;
issue_op.memo->to = to.options.memo_key;
issue_op.memo->set_message(get_private_key(issuer.options.memo_key),
get_public_key(to.options.memo_key), memo);
to.options.memo_key, memo);
}
signed_transaction tx;
@ -1717,8 +1630,8 @@ public:
string _wallet_filename;
wallet_data _wallet;
map<key_id_type,string> _keys;
fc::sha512 _checksum;
map<public_key_type,string> _keys;
fc::sha512 _checksum;
fc::api<login_api> _remote_api;
fc::api<database_api> _remote_db;
@ -1748,13 +1661,11 @@ void operation_printer::operator()(const transfer_operation& op) const
out << " -- Unlock wallet to see memo.";
} else {
try {
optional<key_object> sender_key = wallet._remote_db->get_objects({op.memo->from}).front().as<optional<key_object>>();
FC_ASSERT(sender_key, "Sender key ${k} does not exist.", ("k", op.memo->from));
FC_ASSERT(wallet._keys.count(op.memo->to), "Memo is encrypted to a key ${k} not in this wallet.",
("k", op.memo->to));
auto my_key = wif_to_key(wallet._keys.at(op.memo->to));
FC_ASSERT(my_key, "Unable to recover private key to decrypt memo. Wallet may be corrupted.");
out << " -- Memo: " << op.memo->get_message(*my_key, sender_key->key());
out << " -- Memo: " << op.memo->get_message(*my_key, op.memo->from);
} catch (const fc::exception& e) {
out << " -- could not decrypt memo";
elog("Error when decrypting memo: ${e}", ("e", e.to_detail_string()));
@ -1776,25 +1687,6 @@ void operation_printer::operator()(const account_update_operation& op) const
fee(op.fee);
}
void operation_printer::operator()(const key_create_operation& op) const
{
out << "Register";
struct {
typedef void result_type;
ostream& out;
void operator()(const public_key_type& key) {
out << " key " << string(key);
}
void operator()(const address& addr) {
out << " address " << string(addr);
}
} printer{out};
op.key_data.visit(printer);
out << " as " << fc::json::to_string(result.get<object_id_type>());
fee(op.fee);
}
void operation_printer::operator()(const asset_create_operation& op) const
{
out << "Create ";
@ -2391,7 +2283,7 @@ signed_transaction wallet_api::import_balance( string name_or_id, const vector<s
} FC_CAPTURE_AND_RETHROW( (name_or_id) ) }
map<key_id_type, string> wallet_api::dump_private_keys()
map<public_key_type, string> wallet_api::dump_private_keys()
{
FC_ASSERT(!is_locked());
return my->_keys;

View file

@ -20,7 +20,6 @@
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/account_object.hpp>

View file

@ -18,7 +18,6 @@
#include <graphene/app/application.hpp>
#include <graphene/app/plugin.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/time/time.hpp>
#include <graphene/account_history/account_history_plugin.hpp>
@ -71,16 +70,14 @@ BOOST_AUTO_TEST_CASE( two_node_network )
trx.set_expiration(now + fc::seconds(30));
std::shared_ptr<chain::database> db2 = app2.chain_database();
trx.operations.push_back(key_create_operation({asset(),
trx.operations.push_back(assert_operation({asset(),
GRAPHENE_TEMP_ACCOUNT,
public_key_type(nathan_key.get_public_key())}));
{ fc::raw::pack( graphene::chain::pred::asset_symbol_eq_lit{asset_id_type(),"CORE"} ) } }));
trx.validate();
processed_transaction ptrx = app1.chain_database()->push_transaction(trx);
app1.p2p_node()->broadcast(graphene::net::trx_message(trx));
key_id_type nathan_key_id = ptrx.operation_results.front().get<object_id_type>();
fc::usleep(fc::milliseconds(250));
BOOST_CHECK(nathan_key_id(*app2.chain_database()).key_data.get<public_key_type>() == nathan_key.get_public_key());
ilog("Pushed transaction");
now += GRAPHENE_DEFAULT_BLOCK_INTERVAL;

View file

@ -17,7 +17,6 @@
*/
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/time/time.hpp>

View file

@ -50,6 +50,7 @@ database_fixture::database_fixture()
try {
auto ahplugin = app.register_plugin<graphene::account_history::account_history_plugin>();
auto mhplugin = app.register_plugin<graphene::market_history::market_history_plugin>();
delegate_pub_key = delegate_priv_key.get_public_key();
boost::program_options::variables_map options;
@ -80,7 +81,6 @@ database_fixture::database_fixture()
generate_block();
genesis_key(db); // attempt to deref
trx.set_expiration(db.head_block_time() + fc::minutes(1));
} catch ( const fc::exception& e )
{
@ -199,31 +199,31 @@ void database_fixture::verify_account_history_plugin_index( )const
app.get_plugin<graphene::account_history::account_history_plugin>("account_history");
if( pin->tracked_accounts().size() == 0 )
{
/*
vector< pair< account_id_type, address > > tuples_from_db;
const auto& primary_account_idx = db.get_index_type<account_index>().indices().get<by_id>();
flat_set< address > acct_addresses;
flat_set< public_key_type > acct_addresses;
acct_addresses.reserve( 2 * GRAPHENE_DEFAULT_MAX_AUTHORITY_MEMBERSHIP + 2 );
for( const account_object& acct : primary_account_idx )
{
account_id_type account_id = acct.id;
acct_addresses.clear();
for( const pair< object_id_type, weight_type >& auth : acct.owner.auths )
for( const pair< account_id_type, weight_type >& auth : acct.owner.account_auths )
{
if( auth.first.type() == key_object_type )
acct_addresses.insert( key_id_type( auth.first )(db).key_address() );
acct_addresses.insert( auth.first );
}
for( const pair< object_id_type, weight_type >& auth : acct.active.auths )
{
if( auth.first.type() == key_object_type )
acct_addresses.insert( key_id_type( auth.first )(db).key_address() );
acct_addresses.insert( auth.first );
}
acct_addresses.insert( acct.options.get_memo_key()(db).key_address() );
for( const address& addr : acct_addresses )
tuples_from_db.emplace_back( account_id, addr );
}
/*
vector< pair< account_id_type, address > > tuples_from_index;
tuples_from_index.reserve( tuples_from_db.size() );
const auto& key_account_idx =
@ -313,9 +313,9 @@ void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_i
account_create_operation database_fixture::make_account(
const std::string& name /* = "nathan" */,
key_id_type key /* = key_id_type() */
public_key_type key /* = key_id_type() */
)
{
{ try {
account_create_operation create_account;
create_account.registrar = account_id_type();
@ -339,14 +339,14 @@ account_create_operation database_fixture::make_account(
create_account.fee = create_account.calculate_fee(db.current_fee_schedule());
return create_account;
}
} FC_CAPTURE_AND_RETHROW() }
account_create_operation database_fixture::make_account(
const std::string& name,
const account_object& registrar,
const account_object& referrer,
uint8_t referrer_percent /* = 100 */,
key_id_type key /* = key_id_type() */
public_key_type key /* = public_key_type() */
)
{
try
@ -490,7 +490,7 @@ void database_fixture::issue_uia( const account_object& recipient, asset amount
const account_object& database_fixture::create_account(
const string& name,
const key_id_type& key /* = key_id_type() */
const public_key_type& key /* = public_key_type() */
)
{
trx.operations.push_back(make_account(name, key));
@ -506,7 +506,7 @@ const account_object& database_fixture::create_account(
const account_object& registrar,
const account_object& referrer,
uint8_t referrer_percent /* = 100 */,
const key_id_type& key /*= key_id_type()*/
const public_key_type& key /*= public_key_type()*/
)
{
try
@ -534,26 +534,20 @@ const account_object& database_fixture::create_account(
{
trx.operations.clear();
key_create_operation key_op;
key_op.fee_paying_account = registrar_id;
key_op.key_data = public_key_type( key.get_public_key() );
trx.operations.push_back( key_op );
account_create_operation account_create_op;
relative_key_id_type key_rkid(0);
account_create_op.registrar = registrar_id;
account_create_op.name = name;
account_create_op.owner = authority(1234, key_rkid, 1234);
account_create_op.active = authority(5678, key_rkid, 5678);
account_create_op.options.memo_key = key_rkid;
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[1].get<object_id_type>());
const account_object& result = db.get<account_object>(ptx.operation_results[0].get<object_id_type>());
trx.operations.clear();
return result;
}
@ -571,18 +565,17 @@ const delegate_object& database_fixture::create_delegate( const account_object&
return db.get<delegate_object>(ptx.operation_results[0].get<object_id_type>());
}
const witness_object&database_fixture::create_witness(account_id_type owner, key_id_type signing_key, const fc::ecc::private_key& signing_private_key)
const witness_object&database_fixture::create_witness(account_id_type owner, const fc::ecc::private_key& signing_private_key)
{
return create_witness(owner(db), signing_key, signing_private_key);
return create_witness(owner(db), signing_private_key);
}
const witness_object& database_fixture::create_witness( const account_object& owner, key_id_type signing_key,
const witness_object& database_fixture::create_witness( const account_object& owner,
const fc::ecc::private_key& signing_private_key )
{ try {
FC_ASSERT(db.get(signing_key).key_address() == public_key_type(signing_private_key.get_public_key()));
witness_create_operation op;
op.witness_account = owner.id;
op.block_signing_key = signing_key;
op.block_signing_key = signing_private_key.get_public_key();
secret_hash_type::encoder enc;
fc::raw::pack(enc, signing_private_key);
fc::raw::pack(enc, secret_hash_type());
@ -594,21 +587,6 @@ const witness_object& database_fixture::create_witness( const account_object& ow
return db.get<witness_object>(ptx.operation_results[0].get<object_id_type>());
} FC_CAPTURE_AND_RETHROW() }
const key_object& database_fixture::register_key( const public_key_type& key )
{
trx.operations.push_back(key_create_operation({asset(),account_id_type(), key}));
key_id_type new_key = db.push_transaction(trx, ~0).operation_results[0].get<object_id_type>();
trx.operations.clear();
return new_key(db);
}
const key_object& database_fixture::register_address( const address& addr )
{
trx.operations.push_back(key_create_operation({asset(), account_id_type(), addr}));
key_id_type new_key = db.push_transaction(trx, ~0).operation_results[0].get<object_id_type>();
trx.operations.clear();
return new_key(db);
}
uint64_t database_fixture::fund(
const account_object& account,
@ -619,9 +597,9 @@ uint64_t database_fixture::fund(
return get_balance(account, amount.asset_id(db));
}
void database_fixture::sign(signed_transaction& trx, key_id_type key_id, const fc::ecc::private_key& key)
void database_fixture::sign(signed_transaction& trx, const fc::ecc::private_key& key)
{
trx.sign( key_id, key );
trx.sign( key );
}
const limit_order_object*database_fixture::create_sell_order(account_id_type user, const asset& amount, const asset& recv)

View file

@ -19,7 +19,6 @@
#include <graphene/app/application.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/key_object.hpp>
#include <fc/io/json.hpp>
using namespace graphene::db;
@ -72,18 +71,18 @@ using namespace graphene::db;
#define INVOKE(test) ((struct test*)this)->test_method(); trx.clear()
#define PREP_ACTOR(name) \
fc::ecc::private_key name ## _private_key = generate_private_key(BOOST_PP_STRINGIZE(name)); \
key_id_type name ## _key_id = register_key(name ## _private_key.get_public_key()).get_id();
fc::ecc::private_key name ## _private_key = generate_private_key(BOOST_PP_STRINGIZE(name));
#define ACTOR(name) \
PREP_ACTOR(name) \
const auto& name = create_account(BOOST_PP_STRINGIZE(name), name ## _key_id); \
const auto& name = create_account(BOOST_PP_STRINGIZE(name), name ## _private_key.get_public_key()); \
account_id_type name ## _id = name.id; (void)name ## _id;
#define GET_ACTOR(name) \
fc::ecc::private_key name ## _private_key = generate_private_key(BOOST_PP_STRINGIZE(name)); \
const account_object& name = get_account(BOOST_PP_STRINGIZE(name)); \
account_id_type name ## _id = name.id; \
key_id_type name ## _key_id = name ## _id(db).active.auths.begin()->first;
(void)name ##_id
#define ACTORS_IMPL(r, data, elem) ACTOR(elem)
#define ACTORS(names) BOOST_PP_SEQ_FOR_EACH(ACTORS_IMPL, ~, names)
@ -97,15 +96,14 @@ struct database_fixture {
genesis_state_type genesis_state;
chain::database &db;
signed_transaction trx;
key_id_type genesis_key;
public_key_type genesis_key;
account_id_type genesis_account;
fc::ecc::private_key private_key = fc::ecc::private_key::generate();
fc::ecc::private_key delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
public_key_type delegate_pub_key;
fc::time_point_sec genesis_time = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
fc::time_point_sec now = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
const key_object* key1= nullptr;
const key_object* key2= nullptr;
const key_object* key3= nullptr;
optional<fc::temp_directory> data_dir;
bool skip_key_index_test = false;
uint32_t anon_acct_count;
@ -136,7 +134,7 @@ struct database_fixture {
account_create_operation make_account(
const std::string& name = "nathan",
key_id_type key = key_id_type()
public_key_type = public_key_type()
);
account_create_operation make_account(
@ -144,7 +142,7 @@ struct database_fixture {
const account_object& registrar,
const account_object& referrer,
uint8_t referrer_percent = 100,
key_id_type key = key_id_type()
public_key_type key = public_key_type()
);
void force_global_settle(const asset_object& what, const price& p);
@ -173,7 +171,7 @@ struct database_fixture {
const account_object& create_account(
const string& name,
const key_id_type& key = key_id_type()
const public_key_type& key = public_key_type()
);
const account_object& create_account(
@ -181,7 +179,7 @@ struct database_fixture {
const account_object& registrar,
const account_object& referrer,
uint8_t referrer_percent = 100,
const key_id_type& key = key_id_type()
const public_key_type& key = public_key_type()
);
const account_object& create_account(
@ -194,15 +192,11 @@ struct database_fixture {
const delegate_object& create_delegate( const account_object& owner );
const witness_object& create_witness(account_id_type owner,
key_id_type signing_key = key_id_type(),
const fc::ecc::private_key& signing_private_key = generate_private_key("null_key"));
const witness_object& create_witness(const account_object& owner,
key_id_type signing_key = key_id_type(),
const fc::ecc::private_key& signing_private_key = generate_private_key("null_key"));
const key_object& register_key( const public_key_type& key );
const key_object& register_address( const address& addr );
uint64_t fund( const account_object& account, const asset& amount = asset(500000) );
void sign( signed_transaction& trx, key_id_type key_id, const fc::ecc::private_key& key );
void sign( signed_transaction& trx, const fc::ecc::private_key& key );
const limit_order_object* create_sell_order( account_id_type user, const asset& amount, const asset& recv );
const limit_order_object* create_sell_order( const account_object& user, const asset& amount, const asset& recv );
asset cancel_limit_order( const limit_order_object& order );

View file

@ -23,7 +23,6 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/witness_schedule_object.hpp>
@ -84,10 +83,10 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
const int num_keys = 5;
vector< private_key_type > numbered_private_keys;
vector< vector< key_id_type > > numbered_key_id;
vector< vector< public_key_type > > numbered_key_id;
numbered_private_keys.reserve( num_keys );
numbered_key_id.push_back( vector<key_id_type>() );
numbered_key_id.push_back( vector<key_id_type>() );
numbered_key_id.push_back( vector<public_key_type>() );
numbered_key_id.push_back( vector<public_key_type>() );
for( int i=0; i<num_keys; i++ )
{
@ -96,12 +95,9 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
public_key_type pubkey = privkey.get_public_key();
address addr( pubkey );
key_id_type public_key_id = register_key( pubkey ).id;
key_id_type addr_id = register_address( addr ).id;
numbered_private_keys.push_back( privkey );
numbered_key_id[0].push_back( public_key_id );
numbered_key_id[1].push_back( addr_id );
numbered_key_id[0].push_back( pubkey );
//numbered_key_id[1].push_back( addr );
}
// each element of possible_key_sched is a list of exactly num_keys
@ -134,7 +130,7 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
std::cout << "update_account_keys: this test will take a few minutes...\n";
for( int use_addresses=0; use_addresses<2; use_addresses++ )
{
vector< key_id_type > key_ids = numbered_key_id[ use_addresses ];
vector< public_key_type > key_ids = numbered_key_id[ use_addresses ];
for( int num_owner_keys=1; num_owner_keys<=2; num_owner_keys++ )
{
for( int num_active_keys=1; num_active_keys<=2; num_active_keys++ )
@ -144,7 +140,7 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
{
auto it = key_sched_before.begin();
vector< const private_key_type* > owner_privkey;
vector< const key_id_type* > owner_keyid;
vector< const public_key_type* > owner_keyid;
owner_privkey.reserve( num_owner_keys );
trx.clear();
@ -154,17 +150,17 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
for( int owner_index=0; owner_index<num_owner_keys; owner_index++ )
{
int i = *(it++);
create_op.owner.auths[ key_ids[ i ] ] = 1;
create_op.owner.key_auths[ key_ids[ i ] ] = 1;
owner_privkey.push_back( &numbered_private_keys[i] );
owner_keyid.push_back( &key_ids[ i ] );
}
// size() < num_owner_keys is possible when some keys are duplicates
create_op.owner.weight_threshold = create_op.owner.auths.size();
create_op.owner.weight_threshold = create_op.owner.key_auths.size();
for( int active_index=0; active_index<num_active_keys; active_index++ )
create_op.active.auths[ key_ids[ *(it++) ] ] = 1;
create_op.active.key_auths[ key_ids[ *(it++) ] ] = 1;
// size() < num_active_keys is possible when some keys are duplicates
create_op.active.weight_threshold = create_op.active.auths.size();
create_op.active.weight_threshold = create_op.active.key_auths.size();
create_op.options.memo_key = key_ids[ *(it++) ] ;
create_op.registrar = sam_account_object.id;
@ -194,20 +190,20 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
update_op.new_options = create_op.options;
for( int owner_index=0; owner_index<num_owner_keys; owner_index++ )
update_op.owner->auths[ key_ids[ *(it++) ] ] = 1;
update_op.owner->key_auths[ key_ids[ *(it++) ] ] = 1;
// size() < num_owner_keys is possible when some keys are duplicates
update_op.owner->weight_threshold = update_op.owner->auths.size();
update_op.owner->weight_threshold = update_op.owner->key_auths.size();
for( int active_index=0; active_index<num_active_keys; active_index++ )
update_op.active->auths[ key_ids[ *(it++) ] ] = 1;
update_op.active->key_auths[ key_ids[ *(it++) ] ] = 1;
// size() < num_active_keys is possible when some keys are duplicates
update_op.active->weight_threshold = update_op.active->auths.size();
update_op.active->weight_threshold = update_op.active->key_auths.size();
FC_ASSERT( update_op.new_options.valid() );
update_op.new_options->memo_key = key_ids[ *(it++) ] ;
trx.operations.push_back( update_op );
for( int i=0; i<int(create_op.owner.weight_threshold); i++)
{
trx.sign( *owner_keyid[i], *owner_privkey[i] );
trx.sign( *owner_privkey[i] );
if( i < int(create_op.owner.weight_threshold-1) )
{
BOOST_REQUIRE_THROW(db.push_transaction(trx), fc::exception);

View file

@ -5,7 +5,6 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/proposal_object.hpp>

View file

@ -23,7 +23,6 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/proposal_object.hpp>
@ -40,14 +39,13 @@ BOOST_AUTO_TEST_CASE( simple_single_signature )
{ try {
try {
fc::ecc::private_key nathan_key = fc::ecc::private_key::generate();
const key_object& key = register_key(nathan_key.get_public_key());
const account_object& nathan = create_account("nathan", key.id);
const account_object& nathan = create_account("nathan", nathan_key.get_public_key());
const asset_object& core = asset_id_type()(db);
auto old_balance = fund(nathan);
transfer_operation op = {asset(),nathan.id, account_id_type(), core.amount(500)};
trx.operations.push_back(op);
sign(trx, key.id, nathan_key);
sign(trx, nathan_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_CHECK_EQUAL(get_balance(nathan, core), old_balance - 500);
@ -61,53 +59,47 @@ BOOST_AUTO_TEST_CASE( any_two_of_three )
{
try {
fc::ecc::private_key nathan_key1 = fc::ecc::private_key::regenerate(fc::digest("key1"));
const key_object& key1 = register_key(nathan_key1.get_public_key());
fc::ecc::private_key nathan_key2 = fc::ecc::private_key::regenerate(fc::digest("key2"));
const key_object& key2 = register_key(nathan_key2.get_public_key());
fc::ecc::private_key nathan_key3 = fc::ecc::private_key::regenerate(fc::digest("key3"));
const key_object& key3 = register_key(nathan_key3.get_public_key());
const account_object& nathan = create_account("nathan", key1.id);
const account_object& nathan = create_account("nathan", nathan_key1.get_public_key() );
const asset_object& core = asset_id_type()(db);
auto old_balance = fund(nathan);
this->key1 = &key1;
this->key2 = &key2;
this->key3 = &key3;
try {
account_update_operation op;
op.account = nathan.id;
op.active = authority(2, key1.get_id(), 1, key2.get_id(), 1, key3.get_id(), 1);
op.active = authority(2, public_key_type(nathan_key1.get_public_key()), 1, public_key_type(nathan_key2.get_public_key()), 1, public_key_type(nathan_key3.get_public_key()), 1);
op.owner = *op.active;
trx.operations.push_back(op);
sign(trx, key1.id,nathan_key1);
sign(trx, nathan_key1);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
trx.operations.clear();
trx.signatures.clear();
} FC_CAPTURE_AND_RETHROW ((nathan.active)(key1))
} FC_CAPTURE_AND_RETHROW ((nathan.active))
transfer_operation op = {asset(), nathan.id, account_id_type(), core.amount(500)};
trx.operations.push_back(op);
sign(trx, key1.id,nathan_key1);
sign(trx, nathan_key1);
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
sign(trx, key2.id,nathan_key2);
sign(trx, nathan_key2);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_CHECK_EQUAL(get_balance(nathan, core), old_balance - 500);
trx.signatures.clear();
sign(trx, key2.id,nathan_key2);
sign(trx, key3.id,nathan_key3);
sign(trx, nathan_key2);
sign(trx, nathan_key3);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_CHECK_EQUAL(get_balance(nathan, core), old_balance - 1000);
trx.signatures.clear();
sign(trx, key1.id,nathan_key1);
sign(trx, key3.id,nathan_key3);
sign(trx, nathan_key1);
sign(trx, nathan_key3);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_CHECK_EQUAL(get_balance(nathan, core), old_balance - 1500);
trx.signatures.clear();
//sign(trx, fc::ecc::private_key::generate());
sign(trx, key3.id,nathan_key3);
sign(trx,nathan_key3);
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
BOOST_CHECK_EQUAL(get_balance(nathan, core), old_balance - 1500);
} catch (fc::exception& e) {
@ -120,14 +112,12 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
{
try {
fc::ecc::private_key parent1_key = fc::ecc::private_key::generate();
const key_object& key1 = register_key(parent1_key.get_public_key());
fc::ecc::private_key parent2_key = fc::ecc::private_key::generate();
const key_object& key2 = register_key(parent2_key.get_public_key());
const auto& core = asset_id_type()(db);
BOOST_TEST_MESSAGE( "Creating parent1 and parent2 accounts" );
const account_object& parent1 = create_account("parent1", key1.id);
const account_object& parent2 = create_account("parent2", key2.id);
const account_object& parent1 = create_account("parent1", parent1_key.get_public_key());
const account_object& parent2 = create_account("parent2", parent2_key.get_public_key());
BOOST_TEST_MESSAGE( "Creating child account that requires both parent1 and parent2 to approve" );
{
@ -148,16 +138,16 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
BOOST_TEST_MESSAGE( "Attempting to transfer with parent1 signature, should fail" );
sign(trx, key1.id,parent1_key);
sign(trx,parent1_key);
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
trx.signatures.clear();
BOOST_TEST_MESSAGE( "Attempting to transfer with parent2 signature, should fail" );
sign(trx, key2.id,parent2_key);
sign(trx,parent2_key);
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
BOOST_TEST_MESSAGE( "Attempting to transfer with parent1 and parent2 signature, should succeed" );
sign(trx, key1.id,parent1_key);
sign(trx,parent1_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_CHECK_EQUAL(get_balance(child, core), old_balance - 500);
trx.operations.clear();
@ -165,17 +155,16 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
BOOST_TEST_MESSAGE( "Adding a key for the child that can override parents" );
fc::ecc::private_key child_key = fc::ecc::private_key::generate();
const key_object& child_key_obj = register_key(child_key.get_public_key());
{
account_update_operation op;
op.account = child.id;
op.active = authority(2, account_id_type(parent1.id), 1, account_id_type(parent2.id), 1,
child_key_obj.get_id(), 2);
public_key_type(child_key.get_public_key()), 2);
trx.operations.push_back(op);
sign(trx, key1.id,parent1_key);
sign(trx, key2.id,parent2_key);
sign(trx,parent1_key);
sign(trx,parent2_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_REQUIRE_EQUAL(child.active.auths.size(), 3);
BOOST_REQUIRE_EQUAL(child.active.num_auths(), 3);
trx.operations.clear();
trx.signatures.clear();
}
@ -185,21 +174,21 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
BOOST_TEST_MESSAGE( "Attempting transfer with no signatures, should fail" );
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
BOOST_TEST_MESSAGE( "Attempting transfer just parent1, should fail" );
sign(trx, key1.id,parent1_key);
sign(trx, parent1_key);
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
trx.signatures.clear();
BOOST_TEST_MESSAGE( "Attempting transfer just parent2, should fail" );
sign(trx, key2.id,parent2_key);
sign(trx, parent2_key);
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
BOOST_TEST_MESSAGE( "Attempting transfer both parents, should succeed" );
sign(trx, key1.id, parent1_key);
sign(trx, parent1_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_CHECK_EQUAL(get_balance(child, core), old_balance - 1000);
trx.signatures.clear();
BOOST_TEST_MESSAGE( "Attempting transfer with just child key, should succeed" );
sign(trx, child_key_obj.id, child_key);
sign(trx, child_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_CHECK_EQUAL(get_balance(child, core), old_balance - 1500);
trx.operations.clear();
@ -208,7 +197,6 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
BOOST_TEST_MESSAGE( "Creating grandparent account, parent1 now requires authority of grandparent" );
auto grandparent = create_account("grandparent");
fc::ecc::private_key grandparent_key = fc::ecc::private_key::generate();
const key_object& grandparent_key_obj = register_key(grandparent_key.get_public_key());
{
account_update_operation op;
op.account = parent1.id;
@ -216,7 +204,7 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
op.owner = *op.active;
trx.operations.push_back(op);
op.account = grandparent.id;
op.active = authority(1, grandparent_key_obj.get_id(), 1);
op.active = authority(1, public_key_type(grandparent_key.get_public_key()), 1);
op.owner = *op.active;
trx.operations.push_back(op);
PUSH_TX( db, trx, ~0 );
@ -226,8 +214,8 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
BOOST_TEST_MESSAGE( "Attempt to transfer using old parent keys, should fail" );
trx.operations.push_back(op);
sign(trx, key1.id, parent1_key);
sign(trx, key2.id, parent2_key);
sign(trx, parent1_key);
sign(trx, parent2_key);
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
trx.signatures.clear();
trx.sign( parent2_key );
@ -252,14 +240,14 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
BOOST_TEST_MESSAGE( "Create recursion depth failure" );
trx.operations.push_back(op);
sign(trx, key2.id,parent2_key);
sign(trx, grandparent_key_obj.id,grandparent_key);
sign(trx, key_id_type(), delegate_priv_key);
sign(trx, parent2_key);
sign(trx, grandparent_key);
sign(trx, delegate_priv_key);
//Fails due to recursion depth.
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
BOOST_TEST_MESSAGE( "verify child key can override recursion checks" );
trx.signatures.clear();
sign(trx, child_key_obj.id, child_key);
sign(trx, child_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
BOOST_CHECK_EQUAL(get_balance(child, core), old_balance - 2500);
trx.operations.clear();
@ -278,7 +266,7 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
}
trx.operations.push_back(op);
sign(trx, key2.id, parent2_key);
sign(trx, parent2_key);
//Fails due to recursion depth.
BOOST_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
} catch (fc::exception& e) {
@ -298,14 +286,15 @@ BOOST_AUTO_TEST_CASE( proposed_single_account )
fc::ecc::private_key nathan_key2 = fc::ecc::private_key::regenerate(fc::digest("key2"));
fc::ecc::private_key nathan_key3 = fc::ecc::private_key::regenerate(fc::digest("key3"));
const account_object& moneyman = create_account("moneyman");
const account_object& moneyman = create_account("moneyman", delegate_pub_key);
const account_object& nathan = get_account("nathan");
const asset_object& core = asset_id_type()(db);
transfer(account_id_type()(db), moneyman, core.amount(1000000));
//Following any_two_of_three, nathan's active authority is satisfied by any two of {key1,key2,key3}
proposal_create_operation op = {moneyman.get_id(), asset(),
BOOST_TEST_MESSAGE( "moneyman is creating proposal for nathan to transfer 100 CORE to moneyman" );
proposal_create_operation op = {moneyman.id, asset(),
{{transfer_operation{asset(),nathan.id, moneyman.get_id(), core.amount(100)}}},
db.head_block_time() + fc::days(1)};
asset nathan_start_balance = db.get_balance(nathan.get_id(), core.get_id());
@ -325,7 +314,9 @@ BOOST_AUTO_TEST_CASE( proposed_single_account )
trx.operations.push_back(op);
trx.set_expiration(db.head_block_id());
sign(trx, this->genesis_key, genesis_key);
//idump((moneyman));
trx.sign( delegate_priv_key );
const proposal_object& proposal = db.get<proposal_object>(PUSH_TX( db, trx ).operation_results.front().get<object_id_type>());
BOOST_CHECK_EQUAL(proposal.required_active_approvals.size(), 1);
@ -334,19 +325,19 @@ BOOST_AUTO_TEST_CASE( proposed_single_account )
BOOST_CHECK_EQUAL(proposal.available_owner_approvals.size(), 0);
BOOST_CHECK(*proposal.required_active_approvals.begin() == nathan.id);
trx.operations = {proposal_update_operation{account_id_type(), asset(), proposal.id,{nathan.id},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<key_id_type>{},flat_set<key_id_type>{}}};
trx.sign( this->genesis_key, genesis_key );
trx.operations = {proposal_update_operation{account_id_type(), asset(), proposal.id,{nathan.id},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<public_key_type>{},flat_set<public_key_type>{}}};
trx.sign( genesis_key );
//Genesis may not add nathan's approval.
BOOST_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
trx.operations = {proposal_update_operation{account_id_type(), asset(), proposal.id,{account_id_type()},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<key_id_type>{},flat_set<key_id_type>{}}};
trx.sign( key_id_type(), genesis_key );
trx.operations = {proposal_update_operation{account_id_type(), asset(), proposal.id,{account_id_type()},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<public_key_type>{},flat_set<public_key_type>{}}};
trx.sign( genesis_key );
//Genesis has no stake in the transaction.
BOOST_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
trx.signatures.clear();
trx.operations = {proposal_update_operation{nathan.id, asset(), proposal.id,{nathan.id},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<key_id_type>{},flat_set<key_id_type>{}}};
trx.sign( key3->id, nathan_key3 );
trx.sign( key2->id, nathan_key2 );
trx.operations = {proposal_update_operation{nathan.id, asset(), proposal.id,{nathan.id},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<public_key_type>{},flat_set<public_key_type>{}}};
trx.sign( nathan_key3 );
trx.sign( nathan_key2 );
// TODO: verify the key_id is proper...
//trx.signatures = {nathan_key3.sign_compact(trx.digest()), nathan_key2.sign_compact(trx.digest())};
@ -364,9 +355,7 @@ BOOST_AUTO_TEST_CASE( genesis_authority )
{ try {
fc::ecc::private_key nathan_key = fc::ecc::private_key::generate();
fc::ecc::private_key genesis_key = delegate_priv_key;
const auto& nathan_key_obj = register_key(nathan_key.get_public_key());
key_id_type nathan_key_id = nathan_key_obj.get_id();
const account_object nathan = create_account("nathan", nathan_key_obj.id);
const account_object nathan = create_account("nathan", nathan_key.get_public_key());
const auto& global_params = db.get_global_properties().parameters;
generate_block();
@ -377,8 +366,9 @@ BOOST_AUTO_TEST_CASE( genesis_authority )
p.parameters.genesis_proposal_review_period = fc::days(1).to_seconds();
});
BOOST_TEST_MESSAGE( "transfering 100000 CORE to nathan, signing with genesis key" );
trx.operations.push_back(transfer_operation({asset(), account_id_type(), nathan.id, asset(100000)}));
sign(trx, key_id_type(), genesis_key);
sign(trx, genesis_key);
BOOST_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
auto sign = [&] { trx.signatures.clear(); trx.sign(nathan_key); };
@ -412,35 +402,34 @@ BOOST_AUTO_TEST_CASE( genesis_authority )
generate_block();
BOOST_REQUIRE(db.find_object(prop.id));
BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 0);
BOOST_CHECK(!db.get<proposal_object>(prop.id).is_authorized_to_execute(db));
BOOST_TEST_MESSAGE( "Checking that the proposal is not authorized to execute" );
BOOST_REQUIRE(!db.get<proposal_object>(prop.id).is_authorized_to_execute(db));
trx.operations.clear();
trx.signatures.clear();
proposal_update_operation uop;
uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
uop.proposal = prop.id;
uop.key_approvals_to_add.emplace(genesis_key.get_public_key());
/*
uop.key_approvals_to_add.emplace(1);
uop.key_approvals_to_add.emplace(2);
uop.key_approvals_to_add.emplace(3);
uop.key_approvals_to_add.emplace(4);
uop.key_approvals_to_add.emplace(5);
uop.key_approvals_to_add.emplace(6);
*/
trx.operations.push_back(uop);
trx.sign(genesis_key);
/*
trx.signatures[key_id_type(2)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(3)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(4)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(5)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(6)] = trx.signatures[key_id_type(1)];
*/
db.push_transaction(trx);
BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 0);
BOOST_CHECK(db.get<proposal_object>(prop.id).is_authorized_to_execute(db));
generate_blocks(*prop.review_period_time);
uop.key_approvals_to_add = {key_id_type(7)};
uop.key_approvals_to_add = {genesis_key.get_public_key()}; // was 7
trx.operations.back() = uop;
trx.sign(key_id_type(7), genesis_key);
trx.sign( genesis_key);
// Should throw because the transaction is now in review.
BOOST_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
@ -453,7 +442,6 @@ BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture )
generate_block();
fc::ecc::private_key genesis_key = delegate_priv_key;
fc::ecc::private_key delegate_key = fc::ecc::private_key::generate();
auto delegate_key_object = register_key(delegate_key.get_public_key());
//Meet nathan. He has a little money.
const account_object* nathan = &create_account("nathan");
@ -469,7 +457,7 @@ BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture )
for( int i = 0; i < 15; ++i )
{
const auto& account = create_account("delegate" + fc::to_string(i+1), delegate_key_object.id);
const auto& account = create_account("delegate" + fc::to_string(i+1), delegate_key.get_public_key());
upgrade_to_lifetime_member(account);
delegates.insert(create_delegate(account).vote_id);
}
@ -488,7 +476,8 @@ BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture )
proposal_update_operation uop;
uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
uop.proposal = pid;
uop.key_approvals_to_add.emplace(1);
uop.key_approvals_to_add.emplace(delegate_pub_key);
/* TODO: what should this really be?
uop.key_approvals_to_add.emplace(2);
uop.key_approvals_to_add.emplace(3);
uop.key_approvals_to_add.emplace(4);
@ -497,6 +486,7 @@ BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture )
uop.key_approvals_to_add.emplace(7);
uop.key_approvals_to_add.emplace(8);
uop.key_approvals_to_add.emplace(9);
*/
trx.operations.back() = uop;
trx.sign(genesis_key);
PUSH_TX( db, trx );
@ -549,10 +539,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_two_accounts, database_fixture )
auto nathan_key = generate_private_key("nathan");
auto dan_key = generate_private_key("dan");
const key_object nathan_key_obj = register_key(nathan_key.get_public_key());
const key_object dan_key_obj = register_key(dan_key.get_public_key());
const account_object& nathan = create_account("nathan", nathan_key_obj.id );
const account_object& dan = create_account("dan", dan_key_obj.id );
const account_object& nathan = create_account("nathan", nathan_key.get_public_key() );
const account_object& dan = create_account("dan", dan_key.get_public_key() );
transfer(account_id_type()(db), nathan, asset(100000));
transfer(account_id_type()(db), dan, asset(100000));
@ -571,7 +559,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_two_accounts, database_fixture )
pop.fee_paying_account = nathan.get_id();
pop.expiration_time = db.head_block_time() + fc::days(1);
trx.operations.push_back(pop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
}
@ -588,7 +576,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_two_accounts, database_fixture )
uop.active_approvals_to_add.insert(nathan.get_id());
uop.fee_paying_account = nathan.get_id();
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
@ -597,9 +585,9 @@ BOOST_FIXTURE_TEST_CASE( proposal_two_accounts, database_fixture )
uop.active_approvals_to_add = {dan.get_id()};
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
BOOST_REQUIRE_THROW(PUSH_TX( db, trx ), fc::exception);
trx.sign(dan_key_obj.id,dan_key);
trx.sign(dan_key);
PUSH_TX( db, trx );
BOOST_CHECK(db.find_object(pid) == nullptr);
@ -612,10 +600,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture )
auto nathan_key = generate_private_key("nathan");
auto dan_key = generate_private_key("dan");
const auto& nathan_key_obj = register_key(nathan_key.get_public_key());
const auto& dan_key_obj = register_key(dan_key.get_public_key());
const account_object& nathan = create_account("nathan", nathan_key_obj.id );
const account_object& dan = create_account("dan", dan_key_obj.id );
const account_object& nathan = create_account("nathan", nathan_key.get_public_key() );
const account_object& dan = create_account("dan", dan_key.get_public_key() );
transfer(account_id_type()(db), nathan, asset(100000));
transfer(account_id_type()(db), dan, asset(100000));
@ -635,7 +621,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture )
pop.fee_paying_account = nathan.get_id();
pop.expiration_time = db.head_block_time() + fc::days(1);
trx.operations.push_back(pop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
}
@ -651,7 +637,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture )
uop.proposal = prop.id;
uop.active_approvals_to_add.insert(nathan.get_id());
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
BOOST_CHECK(!prop.is_authorized_to_execute(db));
@ -659,7 +645,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture )
std::swap(uop.active_approvals_to_add, uop.active_approvals_to_remove);
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
BOOST_CHECK(!prop.is_authorized_to_execute(db));
@ -672,7 +658,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture )
dop.fee_paying_account = nathan.get_id();
dop.proposal = pid;
trx.operations.push_back(dop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
BOOST_CHECK(db.find_object(pid) == nullptr);
BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 100000);
@ -685,10 +671,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture )
auto nathan_key = generate_private_key("nathan");
auto dan_key = generate_private_key("dan");
const key_object nathan_key_obj = register_key(nathan_key.get_public_key());
const key_object dan_key_obj = register_key(dan_key.get_public_key());
const account_object& nathan = create_account("nathan", nathan_key_obj.id );
const account_object& dan = create_account("dan", dan_key_obj.id );
const account_object& nathan = create_account("nathan", nathan_key.get_public_key() );
const account_object& dan = create_account("dan", dan_key.get_public_key() );
transfer(account_id_type()(db), nathan, asset(100000));
transfer(account_id_type()(db), dan, asset(100000));
@ -701,7 +685,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture )
account_update_operation uop;
uop.account = nathan.get_id();
uop.owner = authority(1, register_key(generate_private_key("nathan2").get_public_key()).get_id(), 1);
uop.owner = authority(1, public_key_type(generate_private_key("nathan2").get_public_key()), 1);
proposal_create_operation pop;
pop.proposed_ops.emplace_back(top);
@ -713,7 +697,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture )
pop.fee_paying_account = nathan.get_id();
pop.expiration_time = db.head_block_time() + fc::days(1);
trx.operations.push_back(pop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
}
@ -729,7 +713,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture )
uop.proposal = prop.id;
uop.owner_approvals_to_add.insert(nathan.get_id());
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
BOOST_CHECK(!prop.is_authorized_to_execute(db));
@ -737,7 +721,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture )
std::swap(uop.owner_approvals_to_add, uop.owner_approvals_to_remove);
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
BOOST_CHECK(!prop.is_authorized_to_execute(db));
@ -751,7 +735,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture )
dop.proposal = pid;
dop.using_owner_authority = true;
trx.operations.push_back(dop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
BOOST_CHECK(db.find_object(pid) == nullptr);
BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 100000);
@ -764,10 +748,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture )
auto nathan_key = generate_private_key("nathan");
auto dan_key = generate_private_key("dan");
const key_object nathan_key_obj = register_key(nathan_key.get_public_key());
const key_object dan_key_obj = register_key(dan_key.get_public_key());
const account_object& nathan = create_account("nathan", nathan_key_obj.id );
const account_object& dan = create_account("dan", dan_key_obj.id );
const account_object& nathan = create_account("nathan", nathan_key.get_public_key() );
const account_object& dan = create_account("dan", dan_key.get_public_key() );
transfer(account_id_type()(db), nathan, asset(100000));
transfer(account_id_type()(db), dan, asset(100000));
@ -780,7 +762,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture )
account_update_operation uop;
uop.account = nathan.get_id();
uop.owner = authority(1, register_key(generate_private_key("nathan2").get_public_key()).get_id(), 1);
uop.owner = authority(1, public_key_type(generate_private_key("nathan2").get_public_key()), 1);
proposal_create_operation pop;
pop.proposed_ops.emplace_back(top);
@ -792,7 +774,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture )
pop.fee_paying_account = nathan.get_id();
pop.expiration_time = db.head_block_time() + fc::days(1);
trx.operations.push_back(pop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
}
@ -807,10 +789,10 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture )
proposal_update_operation uop;
uop.fee_paying_account = nathan.get_id();
uop.proposal = prop.id;
uop.key_approvals_to_add.insert(dan.active.auths.begin()->first);
uop.key_approvals_to_add.insert(dan.active.key_auths.begin()->first);
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(dan_key_obj.id,dan_key);
trx.sign(nathan_key);
trx.sign(dan_key);
PUSH_TX( db, trx );
trx.clear();
BOOST_CHECK(!prop.is_authorized_to_execute(db));
@ -818,8 +800,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture )
std::swap(uop.key_approvals_to_add, uop.key_approvals_to_remove);
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(dan_key_obj.id,dan_key);
trx.sign(nathan_key);
trx.sign(dan_key);
PUSH_TX( db, trx );
trx.clear();
BOOST_CHECK(!prop.is_authorized_to_execute(db));
@ -829,8 +811,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture )
// Survive trx dupe check
trx.set_expiration(db.head_block_id(), 5);
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(dan_key_obj.id,dan_key);
trx.sign(nathan_key);
trx.sign(dan_key);
PUSH_TX( db, trx );
trx.clear();
BOOST_CHECK(!prop.is_authorized_to_execute(db));
@ -839,7 +821,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture )
uop.key_approvals_to_add.clear();
uop.owner_approvals_to_add.insert(nathan.get_id());
trx.operations.push_back(uop);
trx.sign(nathan_key_obj.id,nathan_key);
trx.sign(nathan_key);
PUSH_TX( db, trx );
trx.clear();
BOOST_CHECK(db.find_object(pid) == nullptr);
@ -884,19 +866,14 @@ BOOST_FIXTURE_TEST_CASE( max_authority_membership, database_fixture )
string seed = "this_is_a_key_" + std::to_string(i);
private_key_type privkey = generate_private_key( seed );
private_keys.push_back( privkey );
key_create_operation kc_op;
kc_op.fee_paying_account = sam_account_object.id;
kc_op.key_data = public_key_type( privkey.get_public_key() );
tx.operations.push_back( kc_op );
}
ptx = PUSH_TX( db, tx, ~0 );
vector<key_id_type> key_ids;
vector<public_key_type> key_ids;
key_ids.reserve( keys_to_create );
for( int i=0; i<keys_to_create; i++ )
key_ids.push_back( key_id_type( ptx.operation_results[i].get<object_id_type>() ) );
key_ids.push_back( private_keys[i].get_public_key() );
// now try registering accounts with n keys, 0 < n < 20
@ -911,7 +888,7 @@ BOOST_FIXTURE_TEST_CASE( max_authority_membership, database_fixture )
test_authority.weight_threshold = num_keys;
for( int i=0; i<num_keys; i++ )
test_authority.auths[ key_ids[i] ] = 1;
test_authority.key_auths[ key_ids[i] ] = 1;
auto check_tx = [&]( const authority& owner_auth,
const authority& active_auth )
@ -962,10 +939,8 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture )
account_object bob_account_object = create_account( "bob", bob_key );
account_object charlie_account_object = create_account( "charlie", charlie_key );
key_id_type alice_key_id = alice_account_object.options.memo_key;
// unneeded, comment it out to silence compiler warning
//key_id_type bob_key_id = bob_account_object.memo_key;
key_id_type charlie_key_id = charlie_account_object.options.memo_key;
uint32_t skip = database::skip_transaction_dupe_check;
@ -986,7 +961,7 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture )
trx.operations.push_back( xfer_op );
BOOST_TEST_MESSAGE( "Transfer signed by alice" );
trx.sign( alice_key_id, alice_key );
trx.sign(alice_key );
flat_set<account_id_type> active_set, owner_set;
xfer_op.get<transfer_operation>().get_required_auth(active_set, owner_set);

View file

@ -23,7 +23,6 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/witness_scheduler_rng.hpp>
@ -164,25 +163,14 @@ BOOST_AUTO_TEST_CASE( price_test )
BOOST_CHECK(dummy == dummy2);
}
BOOST_AUTO_TEST_CASE( serialization_tests )
{
key_object k;
k.id = object_id<protocol_ids, key_object_type>(unsigned_int(2));
BOOST_CHECK(fc::json::from_string(fc::json::to_string(k.id)).as<key_id_type>() == k.id);
BOOST_CHECK(fc::json::from_string(fc::json::to_string(k.id)).as<object_id_type>() == k.id);
BOOST_CHECK((fc::json::from_string(fc::json::to_string(k.id)).as<object_id<protocol_ids, key_object_type>>() == k.id));
public_key_type public_key = fc::ecc::private_key::generate().get_public_key();
k.key_data = address(public_key);
BOOST_CHECK(k.key_address() == address(public_key));
}
BOOST_AUTO_TEST_CASE( memo_test )
{ try {
memo_data m;
auto sender = generate_private_key("1");
auto receiver = generate_private_key("2");
m.from = 1;
m.to = 2;
m.from = sender.get_public_key();
m.to = receiver.get_public_key();
m.set_message(sender, receiver.get_public_key(), "Hello, world!");
BOOST_CHECK_EQUAL(m.get_message(receiver, sender.get_public_key()), "Hello, world!");
} FC_LOG_AND_RETHROW() }

View file

@ -23,7 +23,6 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/call_order_object.hpp>
@ -280,6 +279,7 @@ BOOST_AUTO_TEST_CASE( undo_pending )
db.open(data_dir.path(), make_genesis());
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
public_key_type delegate_pub_key = delegate_priv_key.get_public_key();
const graphene::db::index& account_idx = db.get_index(protocol_ids, account_object_type);
{
@ -298,7 +298,7 @@ BOOST_AUTO_TEST_CASE( undo_pending )
account_create_operation cop;
cop.registrar = GRAPHENE_TEMP_ACCOUNT;
cop.name = "nathan";
cop.owner = authority(1, key_id_type(), 1);
cop.owner = authority(1, delegate_pub_key, 1);
trx.operations.push_back(cop);
//trx.sign( delegate_priv_key );
PUSH_TX( db, trx );
@ -339,6 +339,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
public_key_type delegate_pub_key = delegate_priv_key.get_public_key();
const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type);
signed_transaction trx;
@ -347,7 +348,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
account_create_operation cop;
cop.registrar = GRAPHENE_TEMP_ACCOUNT;
cop.name = "nathan";
cop.owner = authority(1, key_id_type(), 1);
cop.owner = authority(1, delegate_pub_key, 1);
trx.operations.push_back(cop);
PUSH_TX( db1, trx );
@ -397,6 +398,7 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions )
auto skip_sigs = database::skip_transaction_signatures | database::skip_authority_check;
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
public_key_type delegate_pub_key = delegate_priv_key.get_public_key();
const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type);
signed_transaction trx;
@ -404,15 +406,15 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions )
account_id_type nathan_id = account_idx.get_next_id();
account_create_operation cop;
cop.name = "nathan";
cop.owner = authority(1, key_id_type(), 1);
cop.owner = authority(1, delegate_pub_key, 1);
trx.operations.push_back(cop);
trx.sign( key_id_type(), delegate_priv_key );
trx.sign( delegate_priv_key );
PUSH_TX( db1, trx, skip_sigs );
trx = decltype(trx)();
trx.set_expiration(db1.head_block_time() + fc::minutes(1));
trx.operations.push_back(transfer_operation({asset(), account_id_type(), nathan_id, asset(500)}));
trx.sign( key_id_type(), delegate_priv_key );
trx.sign( delegate_priv_key );
PUSH_TX( db1, trx, skip_sigs );
BOOST_CHECK_THROW(PUSH_TX( db1, trx, skip_sigs ), fc::exception);
@ -445,6 +447,7 @@ BOOST_AUTO_TEST_CASE( tapos )
const account_object& init1 = *db1.get_index_type<account_index>().indices().get<by_name>().find("init1");
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
public_key_type delegate_pub_key = delegate_priv_key.get_public_key();
const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type);
now += db1.block_interval();
@ -458,9 +461,9 @@ BOOST_AUTO_TEST_CASE( tapos )
account_create_operation cop;
cop.registrar = init1.id;
cop.name = "nathan";
cop.owner = authority(1, key_id_type(), 1);
cop.owner = authority(1, delegate_pub_key, 1);
trx.operations.push_back(cop);
trx.sign(key_id_type(2), delegate_priv_key);
trx.sign(delegate_priv_key);
db1.push_transaction(trx);
now += db1.block_interval();
b = db1.generate_block(now, db1.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing);
@ -471,12 +474,12 @@ BOOST_AUTO_TEST_CASE( tapos )
trx.clear();
trx.operations.push_back(transfer_operation({asset(), account_id_type(), nathan_id, asset(50)}));
trx.sign(key_id_type(2), delegate_priv_key);
trx.sign(delegate_priv_key);
//relative_expiration is 1, but ref block is 2 blocks old, so this should fail.
BOOST_REQUIRE_THROW(PUSH_TX( db1, trx, database::skip_transaction_signatures | database::skip_authority_check ), fc::exception);
trx.set_expiration(db1.head_block_id(), 2);
trx.signatures.clear();
trx.sign(key_id_type(2), delegate_priv_key);
trx.sign(delegate_priv_key);
db1.push_transaction(trx, database::skip_transaction_signatures | database::skip_authority_check);
} catch (fc::exception& e) {
edump((e.to_detail_string()));
@ -643,7 +646,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture )
get_account("init4").get_id(), get_account("init5").get_id(),
get_account("init6").get_id(), get_account("init7").get_id()};
trx.operations.push_back(uop);
trx.sign(get_account("init0").active.get_keys().front(),delegate_priv_key);
trx.sign(delegate_priv_key);
/*
trx.sign(get_account("init1").active.get_keys().front(),delegate_priv_key);
trx.sign(get_account("init2").active.get_keys().front(),delegate_priv_key);
@ -928,14 +931,14 @@ BOOST_FIXTURE_TEST_CASE( tapos_rollover, database_fixture )
xfer_tx.operations.push_back( xfer_op );
xfer_tx.set_expiration( db.head_block_id(), 0x1000 );
sign( xfer_tx, alice_key_id, alice_private_key );
sign( xfer_tx, alice_private_key );
PUSH_TX( db, xfer_tx, 0 );
generate_block();
BOOST_TEST_MESSAGE( "Sign new tx's" );
xfer_tx.set_expiration( db.head_block_id(), 0x1000 );
xfer_tx.signatures.clear();
sign( xfer_tx, alice_key_id, alice_private_key );
sign( xfer_tx, alice_private_key );
BOOST_TEST_MESSAGE( "Generate up to block 0x10010" );
generate_blocks( 0x110 );

View file

@ -22,7 +22,6 @@
#include <graphene/chain/operations.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <fc/crypto/digest.hpp>

View file

@ -71,12 +71,12 @@ BOOST_AUTO_TEST_CASE( cashback_test )
op.referrer = referrer_name ## _id; \
op.referrer_percent = referrer_rate*GRAPHENE_1_PERCENT; \
op.name = BOOST_PP_STRINGIZE(actor_name); \
op.options.memo_key = actor_name ## _key_id; \
op.active = authority(1, actor_name ## _key_id, 1); \
op.options.memo_key = actor_name ## _private_key.get_public_key(); \
op.active = authority(1, public_key_type(actor_name ## _private_key.get_public_key()), 1); \
op.owner = op.active; \
op.fee = op.calculate_fee(fees); \
trx.operations = {op}; \
trx.sign(registrar_name ## _key_id, registrar_name ## _private_key); \
trx.sign( registrar_name ## _private_key); \
actor_name ## _id = PUSH_TX( db, trx ).operation_results.front().get<object_id_type>(); \
trx.clear(); \
}

View file

@ -24,7 +24,6 @@
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
@ -324,7 +323,6 @@ BOOST_AUTO_TEST_CASE( create_account_test )
REQUIRE_THROW_WITH_VALUE(op, name, "aaaa.");
REQUIRE_THROW_WITH_VALUE(op, name, ".aaaa");
REQUIRE_THROW_WITH_VALUE(op, options.voting_account, account_id_type(999999999));
REQUIRE_THROW_WITH_VALUE(op, options.memo_key, key_id_type(999999999));
auto auth_bak = op.owner;
op.owner.add_authority(account_id_type(9999999999), 10);
@ -332,13 +330,9 @@ BOOST_AUTO_TEST_CASE( create_account_test )
op.owner = auth_bak;
BOOST_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
op.owner = auth_bak;
op.owner.add_authority(key_id_type(9999999999), 10);
trx.operations.back() = op;
BOOST_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
op.owner = auth_bak;
trx.operations.back() = op;
trx.sign(key_id_type(), delegate_priv_key);
trx.sign( delegate_priv_key);
trx.validate();
PUSH_TX( db, trx, ~0 );
@ -347,10 +341,10 @@ BOOST_AUTO_TEST_CASE( create_account_test )
BOOST_CHECK(nathan_account.id.type() == account_object_type);
BOOST_CHECK(nathan_account.name == "nathan");
BOOST_REQUIRE(nathan_account.owner.auths.size() == 1);
BOOST_CHECK(nathan_account.owner.auths.at(genesis_key) == 123);
BOOST_REQUIRE(nathan_account.active.auths.size() == 1);
BOOST_CHECK(nathan_account.active.auths.at(genesis_key) == 321);
BOOST_REQUIRE(nathan_account.owner.num_auths() == 1);
BOOST_CHECK(nathan_account.owner.key_auths.at(genesis_key) == 123);
BOOST_REQUIRE(nathan_account.active.num_auths() == 1);
BOOST_CHECK(nathan_account.active.key_auths.at(genesis_key) == 321);
BOOST_CHECK(nathan_account.options.voting_account == account_id_type());
BOOST_CHECK(nathan_account.options.memo_key == genesis_key);
@ -366,46 +360,36 @@ BOOST_AUTO_TEST_CASE( create_account_test )
BOOST_AUTO_TEST_CASE( update_account )
{
try {
INVOKE(create_account_test);
const account_object& nathan = get_account("nathan");
const account_object& nathan = create_account("nathan", delegate_pub_key);
const fc::ecc::private_key nathan_new_key = fc::ecc::private_key::generate();
const key_id_type key_id = db.get_index<key_object>().get_next_id();
const public_key_type key_id = nathan_new_key.get_public_key();
const auto& active_delegates = db.get_global_properties().active_delegates;
transfer(account_id_type()(db), nathan, asset(30000));
trx.operations.emplace_back(key_create_operation({asset(),nathan.id,address(nathan_new_key.get_public_key())}));
PUSH_TX( db, trx, ~0 );
trx.operations.clear();
account_update_operation op;
op.account = nathan.id;
op.owner = authority(2, key_id, 1, key_id_type(), 1);
op.active = authority(2, key_id, 1, key_id_type(), 1);
op.owner = authority(2, key_id, 1, delegate_pub_key, 1);
op.active = authority(2, key_id, 1, delegate_pub_key, 1);
op.new_options = nathan.options;
op.new_options->votes = flat_set<vote_id_type>({active_delegates[0](db).vote_id, active_delegates[5](db).vote_id});
op.new_options->num_committee = 2;
trx.operations.back() = op;
trx.operations.push_back(op);
BOOST_TEST_MESSAGE( "Updating account" );
PUSH_TX( db, trx, ~0 );
BOOST_CHECK(nathan.options.memo_key == key_id_type());
BOOST_CHECK(nathan.options.memo_key == delegate_pub_key);
BOOST_CHECK(nathan.active.weight_threshold == 2);
BOOST_CHECK(nathan.active.auths.size() == 2);
BOOST_CHECK(nathan.active.auths.at(key_id) == 1);
BOOST_CHECK(nathan.active.auths.at(key_id_type()) == 1);
BOOST_CHECK(nathan.active.num_auths() == 2);
BOOST_CHECK(nathan.active.key_auths.at(key_id) == 1);
BOOST_CHECK(nathan.active.key_auths.at(delegate_pub_key) == 1);
BOOST_CHECK(nathan.owner.weight_threshold == 2);
BOOST_CHECK(nathan.owner.auths.size() == 2);
BOOST_CHECK(nathan.owner.auths.at(key_id) == 1);
BOOST_CHECK(nathan.owner.auths.at(key_id_type()) == 1);
BOOST_CHECK(nathan.owner.num_auths() == 2);
BOOST_CHECK(nathan.owner.key_auths.at(key_id) == 1);
BOOST_CHECK(nathan.owner.key_auths.at(delegate_pub_key) == 1);
BOOST_CHECK(nathan.options.votes.size() == 2);
/** these votes are no longer tallied in real time
BOOST_CHECK(active_delegates[0](db).vote(db).total_votes == 30000);
BOOST_CHECK(active_delegates[1](db).vote(db).total_votes == 0);
BOOST_CHECK(active_delegates[4](db).vote(db).total_votes == 0);
BOOST_CHECK(active_delegates[5](db).vote(db).total_votes == 30000);
BOOST_CHECK(active_delegates[6](db).vote(db).total_votes == 0);
*/
transfer(account_id_type()(db), nathan, asset(3000000));
enable_fees();
@ -1117,12 +1101,13 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
generate_block();
// Make an account and upgrade it to prime, so that witnesses get some pay
create_account("nathan");
create_account("nathan", delegate_pub_key);
transfer(account_id_type()(db), get_account("nathan"), asset(10000000000));
generate_block();
const asset_object* core = &asset_id_type()(db);
const account_object* nathan = &get_account("nathan");
idump((*nathan));
enable_fees(105000000);
BOOST_CHECK_GT(db.current_fee_schedule().membership_lifetime_fee, 0);
// Based on the size of the reserve fund later in the test, the witness budget will be set to this value
@ -1148,6 +1133,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
} );
BOOST_CHECK_EQUAL(core->dynamic_asset_data_id(db).accumulated_fees.value, 0);
BOOST_TEST_MESSAGE( "Upgrading account" );
account_upgrade_operation uop;
uop.account_to_upgrade = nathan->get_id();
uop.upgrade_to_lifetime_member = true;
@ -1155,7 +1141,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
trx.operations.push_back(uop);
trx.visit(operation_set_fee(db.current_fee_schedule()));
trx.validate();
trx.sign(key_id_type(),delegate_priv_key);
trx.sign(delegate_priv_key);
db.push_transaction(trx);
trx.clear();
BOOST_CHECK_EQUAL(get_balance(*nathan, *core), 8950000000);
@ -1175,6 +1161,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
_dpo.next_maintenance_time = db.head_block_time() + 1;
} );
};
BOOST_TEST_MESSAGE( "Generating some blocks" );
// generate some blocks
while( db.head_block_num() < 30 )

View file

@ -20,7 +20,6 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/balance_object.hpp>
@ -43,12 +42,13 @@ BOOST_FIXTURE_TEST_SUITE( operation_tests, database_fixture )
BOOST_AUTO_TEST_CASE( withdraw_permission_create )
{ try {
//ACTORS((nathan)(dan))
//idump((nathan)(dan));
auto nathan_private_key = generate_private_key("nathan");
auto dan_private_key = generate_private_key("dan");
key_id_type nathan_key_id = register_key(nathan_private_key.get_public_key()).id;
key_id_type dan_key_id = register_key(dan_private_key.get_public_key()).id;
account_id_type nathan_id = create_account("nathan", nathan_key_id).id;
account_id_type dan_id = create_account("dan", dan_key_id).id;
account_id_type nathan_id = create_account("nathan", nathan_private_key.get_public_key()).id;
account_id_type dan_id = create_account("dan", dan_private_key.get_public_key()).id;
transfer(account_id_type(), nathan_id, asset(1000));
generate_block();
trx.set_expiration(db.head_block_time() + GRAPHENE_DEFAULT_MAX_TIME_UNTIL_EXPIRATION / 2);
@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_create )
REQUIRE_THROW_WITH_VALUE(op, withdrawal_period_sec, 1);
trx.operations.back() = op;
}
trx.sign(nathan_key_id, nathan_private_key);
trx.sign(nathan_private_key);
db.push_transaction( trx );
trx.clear();
} FC_LOG_AND_RETHROW() }
@ -85,7 +85,6 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test )
auto dan_private_key = generate_private_key("dan");
account_id_type nathan_id = get_account("nathan").id;
account_id_type dan_id = get_account("dan").id;
key_id_type dan_key_id = dan_id(db).active.auths.begin()->first;
withdraw_permission_id_type permit;
trx.set_expiration(db.head_block_time() + GRAPHENE_DEFAULT_MAX_TIME_UNTIL_EXPIRATION/2);
@ -172,7 +171,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test )
op.amount_to_withdraw = asset(1);
trx.clear();
trx.operations = {op};
trx.sign(dan_key_id, dan_private_key);
trx.sign(dan_private_key);
PUSH_TX( db, trx );
}
@ -215,7 +214,6 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_nominal_case )
auto dan_private_key = generate_private_key("dan");
account_id_type nathan_id = get_account("nathan").id;
account_id_type dan_id = get_account("dan").id;
key_id_type dan_key_id = dan_id(db).active.auths.begin()->first;
withdraw_permission_id_type permit;
trx.set_expiration(db.head_block_time() + GRAPHENE_DEFAULT_MAX_TIME_UNTIL_EXPIRATION/2);
@ -232,7 +230,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_nominal_case )
// ref_block_prefix is timestamp, so treat it as a rollable nonce
// so tx's have different txid's
trx.ref_block_prefix++;
trx.sign(dan_key_id, dan_private_key);
trx.sign(dan_private_key);
PUSH_TX( db, trx );
// tx's involving withdraw_permissions can't delete it even
// if no further withdrawals are possible
@ -257,7 +255,6 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_update )
auto nathan_private_key = generate_private_key("nathan");
account_id_type nathan_id = get_account("nathan").id;
account_id_type dan_id = get_account("dan").id;
key_id_type nathan_key_id = nathan_id(db).active.auths.begin()->first;
withdraw_permission_id_type permit;
trx.set_expiration(db.head_block_time() + GRAPHENE_DEFAULT_MAX_TIME_UNTIL_EXPIRATION/2);
@ -279,7 +276,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_update )
REQUIRE_THROW_WITH_VALUE(op, authorized_account, account_id_type(0));
REQUIRE_THROW_WITH_VALUE(op, period_start_time, db.head_block_time() - 50);
trx.operations.back() = op;
trx.sign(nathan_key_id, nathan_private_key);
trx.sign(nathan_private_key);
PUSH_TX( db, trx );
}
@ -303,7 +300,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_delete )
op.withdraw_from_account = get_account("nathan").id;
trx.set_expiration(db.head_block_id());
trx.operations.push_back(op);
trx.sign(get_account("nathan").active.auths.begin()->first, generate_private_key("nathan"));
trx.sign(generate_private_key("nathan"));
PUSH_TX( db, trx );
} FC_LOG_AND_RETHROW() }
@ -330,7 +327,7 @@ BOOST_AUTO_TEST_CASE( mia_feeds )
op.issuer = nathan_id;
op.new_feed_producers = {dan_id, ben_id, vikram_id};
trx.operations.push_back(op);
trx.sign(nathan_key_id, nathan_private_key);
trx.sign(nathan_private_key);
PUSH_TX( db, trx );
generate_block(database::skip_nothing);
}
@ -414,7 +411,7 @@ BOOST_AUTO_TEST_CASE( witness_create )
ACTOR(nathan);
upgrade_to_lifetime_member(nathan_id);
trx.clear();
witness_id_type nathan_witness_id = create_witness(nathan_id, nathan_key_id, nathan_private_key).id;
witness_id_type nathan_witness_id = create_witness(nathan_id, nathan_private_key).id;
// Give nathan some voting stake
transfer(genesis_account, nathan_id, asset(10000000));
generate_block();
@ -430,7 +427,7 @@ BOOST_AUTO_TEST_CASE( witness_create )
op.new_options->num_committee = std::count_if(op.new_options->votes.begin(), op.new_options->votes.end(),
[](vote_id_type id) { return id.type() == vote_id_type::committee; });
trx.operations.push_back(op);
trx.sign(nathan_key_id, nathan_private_key);
trx.sign(nathan_private_key);
PUSH_TX( db, trx );
trx.clear();
}
@ -541,7 +538,7 @@ BOOST_AUTO_TEST_CASE( global_settle_test )
REQUIRE_THROW_WITH_VALUE(op, asset_to_settle, asset_id_type(100));
REQUIRE_THROW_WITH_VALUE(op, issuer, account_id_type(2));
trx.operations.back() = op;
trx.sign(nathan_key_id, nathan_private_key);
trx.sign(nathan_private_key);
PUSH_TX( db, trx );
}
@ -578,7 +575,7 @@ BOOST_AUTO_TEST_CASE( worker_create_test )
REQUIRE_THROW_WITH_VALUE(op, work_begin_date, db.head_block_time() - 10);
REQUIRE_THROW_WITH_VALUE(op, work_end_date, op.work_begin_date);
trx.operations.back() = op;
trx.sign(nathan_key_id, nathan_private_key);
trx.sign(nathan_private_key);
PUSH_TX( db, trx );
}
@ -633,7 +630,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test )
op.owner = nathan_id;
trx.set_expiration(db.head_block_id());
trx.operations.push_back(op);
trx.sign(nathan_key_id, nathan_private_key);
trx.sign( nathan_private_key);
PUSH_TX( db, trx );
trx.signatures.clear();
REQUIRE_THROW_WITH_VALUE(op, amount, asset(1));
@ -668,7 +665,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test )
trx.set_expiration(db.head_block_id());
REQUIRE_THROW_WITH_VALUE(op, amount, asset(501));
trx.operations.back() = op;
trx.sign(nathan_key_id, nathan_private_key);
trx.sign( nathan_private_key);
PUSH_TX( db, trx );
trx.signatures.clear();
trx.clear();
@ -701,7 +698,7 @@ BOOST_AUTO_TEST_CASE( refund_worker_test )
REQUIRE_THROW_WITH_VALUE(op, work_begin_date, db.head_block_time() - 10);
REQUIRE_THROW_WITH_VALUE(op, work_end_date, op.work_begin_date);
trx.operations.back() = op;
trx.sign(nathan_key_id, nathan_private_key);
trx.sign( nathan_private_key);
PUSH_TX( db, trx );
trx.clear();
}
@ -774,7 +771,7 @@ BOOST_AUTO_TEST_CASE( burn_worker_test )
REQUIRE_THROW_WITH_VALUE(op, work_begin_date, db.head_block_time() - 10);
REQUIRE_THROW_WITH_VALUE(op, work_end_date, op.work_begin_date);
trx.operations.back() = op;
trx.sign(nathan_key_id, nathan_private_key);
trx.sign( nathan_private_key);
PUSH_TX( db, trx );
trx.clear();
}
@ -954,11 +951,9 @@ BOOST_AUTO_TEST_CASE( assert_op_test )
// create some objects
auto nathan_private_key = generate_private_key("nathan");
public_key_type nathan_public_key = nathan_private_key.get_public_key();
key_id_type nathan_key_id = register_key(nathan_public_key).id;
account_id_type nathan_id = create_account("nathan", nathan_key_id).id;
account_id_type nathan_id = create_account("nathan", nathan_public_key).id;
assert_operation op;
decltype(key_object::key_data) lit_key = nathan_public_key;
// nathan checks that his public key is equal to the given value.
op.fee_paying_account = nathan_id;
@ -968,13 +963,13 @@ BOOST_AUTO_TEST_CASE( assert_op_test )
predicate(pred::account_name_eq_lit{ nathan_id, "nathan" })
));
trx.operations.push_back(op);
trx.sign(nathan_key_id, nathan_private_key);
trx.sign(nathan_private_key);
PUSH_TX( db, trx );
// nathan checks that his public key is not equal to the given value (fail)
op.predicates.back() = fc::raw::pack(predicate(pred::account_name_eq_lit{ nathan_id, "dan" }));
trx.operations.back() = op;
trx.sign(nathan_key_id, nathan_private_key);
trx.sign(nathan_private_key);
BOOST_CHECK_THROW( PUSH_TX( db, trx ), fc::exception );
} FC_LOG_AND_RETHROW()
}

View file

@ -21,7 +21,6 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/key_object.hpp>
#include <fc/crypto/digest.hpp>
#include <fc/reflect/variant.hpp>

View file

@ -24,7 +24,6 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <fc/crypto/digest.hpp>