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

This commit is contained in:
Daniel Larimer 2015-07-23 14:17:24 -04:00
commit efe948ceaf
11 changed files with 199 additions and 137 deletions

View file

@ -2,6 +2,21 @@ file(GLOB HEADERS "include/graphene/chain/*.hpp")
## SORT .cpp by most likely to change / break compile
add_library( graphene_chain
# As database takes the longest to compile, start it first
database.cpp
# db_balance.cpp
# db_block.cpp
# db_debug.cpp
# db_getter.cpp
# db_init.cpp
# db_maint.cpp
# db_management.cpp
# db_market.cpp
# db_update.cpp
# db_witness_schedule.cpp
protocol/types.cpp
protocol/address.cpp
protocol/asset.cpp
@ -22,6 +37,7 @@ add_library( graphene_chain
protocol/block.cpp
protocol/fee_schedule.cpp
protocol/confidential.cpp
protocol/vote.cpp
pts_address.cpp
@ -48,19 +64,6 @@ add_library( graphene_chain
fork_database.cpp
block_database.cpp
database.cpp
# db_balance.cpp
# db_block.cpp
# db_debug.cpp
# db_getter.cpp
# db_init.cpp
# db_maint.cpp
# db_management.cpp
# db_market.cpp
# db_update.cpp
# db_witness_schedule.cpp
${HEADERS}
)

View file

@ -20,6 +20,7 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <graphene/chain/protocol/vote.hpp>
#include <graphene/chain/transaction_evaluation_state.hpp>
#include <fc/smart_ref_impl.hpp>
@ -36,7 +37,7 @@ object_id_type committee_member_create_evaluator::do_apply( const committee_memb
{ try {
vote_id_type vote_id;
db().modify(db().get_global_properties(), [&vote_id](global_property_object& p) {
vote_id = p.get_next_vote_id(vote_id_type::committee);
vote_id = get_next_vote_id(p, vote_id_type::committee);
});
const auto& new_del_object = db().create<committee_member_object>( [&]( committee_member_object& obj ){
@ -47,8 +48,6 @@ object_id_type committee_member_create_evaluator::do_apply( const committee_memb
return new_del_object.id;
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result committee_member_update_global_parameters_evaluator::do_evaluate(const committee_member_update_global_parameters_operation& o)
{ try {
FC_ASSERT(trx_state->_is_proposed_trx);

View file

@ -48,10 +48,6 @@ namespace graphene { namespace chain {
flat_set<account_id_type> witness_accounts; // updated once per maintenance interval
fc::sha256 chain_id;
vote_id_type get_next_vote_id(vote_id_type::vote_type type) {
return vote_id_type(type, next_available_vote_id++);
}
};
/**

View file

@ -1,5 +1,6 @@
#pragma once
#include <graphene/chain/protocol/base.hpp>
#include <graphene/chain/protocol/vote.hpp>
namespace graphene { namespace chain {

View file

@ -16,6 +16,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <graphene/chain/protocol/base.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <fc/smart_ref_fwd.hpp>

View file

@ -149,9 +149,6 @@ namespace graphene { namespace chain {
meta_account_object_type
};
struct chain_parameters;
//typedef fc::unsigned_int object_id_type;
//typedef uint64_t object_id_type;
class account_object;
@ -221,101 +218,6 @@ namespace graphene { namespace chain {
typedef fc::ripemd160 secret_hash_type;
typedef uint16_t weight_type;
/**
* @brief An ID for some votable object
*
* This class stores an ID for a votable object. The ID is comprised of two fields: a type, and an instance. The
* type field stores which kind of object is being voted on, and the instance stores which specific object of that
* type is being referenced by this ID.
*
* A value of vote_id_type is implicitly convertible to an unsigned 32-bit integer containing only the instance. It
* may also be implicitly assigned from a uint32_t, which will update the instance. It may not, however, be
* implicitly constructed from a uint32_t, as in this case, the type would be unknown.
*
* On the wire, a vote_id_type is represented as a 32-bit integer with the type in the lower 8 bits and the instance
* in the upper 24 bits. This means that types may never exceed 8 bits, and instances may never exceed 24 bits.
*
* In JSON, a vote_id_type is represented as a string "type:instance", i.e. "1:5" would be type 1 and instance 5.
*
* @note In the Graphene protocol, vote_id_type instances are unique across types; that is to say, if an object of
* type 1 has instance 4, an object of type 0 may not also have instance 4. In other words, the type is not a
* namespace for instances; it is only an informational field.
*/
struct vote_id_type
{
/// Lower 8 bits are type; upper 24 bits are instance
uint32_t content;
enum vote_type
{
committee,
witness,
worker,
VOTE_TYPE_COUNT
};
/// Default constructor. Sets type and instance to 0
vote_id_type():content(0){}
/// Construct this vote_id_type with provided type and instance
vote_id_type(vote_type type, uint32_t instance = 0)
: content(instance<<8 | type)
{}
/// Construct this vote_id_type from a serial string in the form "type:instance"
explicit vote_id_type(const std::string& serial)
{
auto colon = serial.find(':');
if( colon != string::npos )
*this = vote_id_type(vote_type(std::stoul(serial.substr(0, colon))), std::stoul(serial.substr(colon+1)));
}
/// Set the type of this vote_id_type
void set_type(vote_type type)
{
content &= 0xffffff00;
content |= type & 0xff;
}
/// Get the type of this vote_id_type
vote_type type()const
{
return vote_type(content & 0xff);
}
/// Set the instance of this vote_id_type
void set_instance(uint32_t instance)
{
assert(instance < 0x01000000);
content &= 0xff;
content |= instance << 8;
}
/// Get the instance of this vote_id_type
uint32_t instance()const
{
return content >> 8;
}
vote_id_type& operator =(vote_id_type other)
{
content = other.content;
return *this;
}
/// Set the instance of this vote_id_type
vote_id_type& operator =(uint32_t instance)
{
set_instance(instance);
return *this;
}
/// Get the instance of this vote_id_type
operator uint32_t()const
{
return instance();
}
/// Convert this vote_id_type to a serial string in the form "type:instance"
explicit operator std::string()const
{
return std::to_string(type()) + ":" + std::to_string(instance());
}
};
struct public_key_type
{
struct binary_key
@ -345,14 +247,7 @@ namespace fc
{
void to_variant( const graphene::chain::public_key_type& var, fc::variant& vo );
void from_variant( const fc::variant& var, graphene::chain::public_key_type& vo );
void to_variant( const graphene::chain::vote_id_type& var, fc::variant& vo );
void from_variant( const fc::variant& var, graphene::chain::vote_id_type& vo );
}
FC_REFLECT_TYPENAME( graphene::chain::vote_id_type::vote_type )
FC_REFLECT_TYPENAME( fc::flat_set<graphene::chain::vote_id_type> )
FC_REFLECT_ENUM( graphene::chain::vote_id_type::vote_type, (witness)(committee)(worker)(VOTE_TYPE_COUNT) )
FC_REFLECT( graphene::chain::vote_id_type, (content) )
FC_REFLECT( graphene::chain::public_key_type, (key_data) )
FC_REFLECT( graphene::chain::public_key_type::binary_key, (data)(check) )

View file

@ -0,0 +1,146 @@
/*
* 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 <cassert>
#include <cstdint>
#include <string>
#include <fc/container/flat.hpp>
#include <fc/reflect/reflect.hpp>
namespace graphene { namespace chain {
/**
* @brief An ID for some votable object
*
* This class stores an ID for a votable object. The ID is comprised of two fields: a type, and an instance. The
* type field stores which kind of object is being voted on, and the instance stores which specific object of that
* type is being referenced by this ID.
*
* A value of vote_id_type is implicitly convertible to an unsigned 32-bit integer containing only the instance. It
* may also be implicitly assigned from a uint32_t, which will update the instance. It may not, however, be
* implicitly constructed from a uint32_t, as in this case, the type would be unknown.
*
* On the wire, a vote_id_type is represented as a 32-bit integer with the type in the lower 8 bits and the instance
* in the upper 24 bits. This means that types may never exceed 8 bits, and instances may never exceed 24 bits.
*
* In JSON, a vote_id_type is represented as a string "type:instance", i.e. "1:5" would be type 1 and instance 5.
*
* @note In the Graphene protocol, vote_id_type instances are unique across types; that is to say, if an object of
* type 1 has instance 4, an object of type 0 may not also have instance 4. In other words, the type is not a
* namespace for instances; it is only an informational field.
*/
struct vote_id_type
{
/// Lower 8 bits are type; upper 24 bits are instance
uint32_t content;
enum vote_type
{
committee,
witness,
worker,
VOTE_TYPE_COUNT
};
/// Default constructor. Sets type and instance to 0
vote_id_type():content(0){}
/// Construct this vote_id_type with provided type and instance
vote_id_type(vote_type type, uint32_t instance = 0)
: content(instance<<8 | type)
{}
/// Construct this vote_id_type from a serial string in the form "type:instance"
explicit vote_id_type(const std::string& serial)
{
auto colon = serial.find(':');
if( colon != std::string::npos )
*this = vote_id_type(vote_type(std::stoul(serial.substr(0, colon))), std::stoul(serial.substr(colon+1)));
}
/// Set the type of this vote_id_type
void set_type(vote_type type)
{
content &= 0xffffff00;
content |= type & 0xff;
}
/// Get the type of this vote_id_type
vote_type type()const
{
return vote_type(content & 0xff);
}
/// Set the instance of this vote_id_type
void set_instance(uint32_t instance)
{
assert(instance < 0x01000000);
content &= 0xff;
content |= instance << 8;
}
/// Get the instance of this vote_id_type
uint32_t instance()const
{
return content >> 8;
}
vote_id_type& operator =(vote_id_type other)
{
content = other.content;
return *this;
}
/// Set the instance of this vote_id_type
vote_id_type& operator =(uint32_t instance)
{
set_instance(instance);
return *this;
}
/// Get the instance of this vote_id_type
operator uint32_t()const
{
return instance();
}
/// Convert this vote_id_type to a serial string in the form "type:instance"
explicit operator std::string()const
{
return std::to_string(type()) + ":" + std::to_string(instance());
}
};
class global_property_object;
vote_id_type get_next_vote_id( global_property_object& gpo, vote_id_type::vote_type type );
} } // graphene::chain
namespace fc
{
class variant;
void to_variant( const graphene::chain::vote_id_type& var, fc::variant& vo );
void from_variant( const fc::variant& var, graphene::chain::vote_id_type& vo );
} // fc
FC_REFLECT_TYPENAME( graphene::chain::vote_id_type::vote_type )
FC_REFLECT_TYPENAME( fc::flat_set<graphene::chain::vote_id_type> )
FC_REFLECT_ENUM( graphene::chain::vote_id_type::vote_type, (witness)(committee)(worker)(VOTE_TYPE_COUNT) )
FC_REFLECT( graphene::chain::vote_id_type, (content) )

View file

@ -121,13 +121,4 @@ namespace fc
vo = graphene::chain::public_key_type( var.as_string() );
}
void to_variant(const graphene::chain::vote_id_type& var, variant& vo)
{
vo = string(var);
}
void from_variant(const variant& var, graphene::chain::vote_id_type& vo)
{
vo = graphene::chain::vote_id_type(var.as_string());
}
} // fc

View file

@ -0,0 +1,28 @@
#include <graphene/chain/global_property_object.hpp>
#include <graphene/chain/protocol/vote.hpp>
#include <fc/variant.hpp>
namespace graphene { namespace chain {
vote_id_type get_next_vote_id( global_property_object& gpo, vote_id_type::vote_type type )
{
return vote_id_type( type, gpo.next_available_vote_id++ );
}
} } // graphene::chain
namespace fc
{
void to_variant(const graphene::chain::vote_id_type& var, variant& vo)
{
vo = string(var);
}
void from_variant(const variant& var, graphene::chain::vote_id_type& vo)
{
vo = graphene::chain::vote_id_type(var.as_string());
}
} // fc

View file

@ -20,6 +20,7 @@
#include <graphene/chain/committee_member_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/protocol/vote.hpp>
namespace graphene { namespace chain {
@ -33,7 +34,7 @@ object_id_type witness_create_evaluator::do_apply( const witness_create_operatio
{ try {
vote_id_type vote_id;
db().modify(db().get_global_properties(), [&vote_id](global_property_object& p) {
vote_id = p.get_next_vote_id(vote_id_type::witness);
vote_id = get_next_vote_id(p, vote_id_type::witness);
});
const auto& new_witness_object = db().create<witness_object>( [&]( witness_object& obj ){

View file

@ -19,6 +19,7 @@
#include <graphene/chain/worker_evaluator.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/protocol/vote.hpp>
namespace graphene { namespace chain {
@ -74,8 +75,8 @@ object_id_type worker_create_evaluator::do_apply(const worker_create_evaluator::
database& d = db();
vote_id_type for_id, against_id;
d.modify(d.get_global_properties(), [&for_id, &against_id](global_property_object& p) {
for_id = p.get_next_vote_id(vote_id_type::worker);
against_id = p.get_next_vote_id(vote_id_type::worker);
for_id = get_next_vote_id(p, vote_id_type::worker);
against_id = get_next_vote_id(p, vote_id_type::worker);
});
return d.create<worker_object>([&](worker_object& w) {