BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
witness_evaluator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
30 
31 namespace graphene { namespace chain {
32 
34 { try {
35  FC_ASSERT(db().get(op.witness_account).is_lifetime_member());
36  return void_result();
37 } FC_CAPTURE_AND_RETHROW( (op) ) }
38 
40 { try {
41  database& _db = db();
42  vote_id_type vote_id;
43  _db.modify( _db.get_global_properties(), [&vote_id](global_property_object& p) {
44  vote_id = vote_id_type(vote_id_type::witness, p.next_available_vote_id++);
45  });
46 
47  const auto& new_witness_object = _db.create<witness_object>( [&op,&vote_id]( witness_object& obj ){
48  obj.witness_account = op.witness_account;
49  obj.signing_key = op.block_signing_key;
50  obj.vote_id = vote_id;
51  obj.url = op.url;
52  });
53  return new_witness_object.id;
54 } FC_CAPTURE_AND_RETHROW( (op) ) }
55 
57 { try {
58  FC_ASSERT(db().get(op.witness).witness_account == op.witness_account);
59  return void_result();
60 } FC_CAPTURE_AND_RETHROW( (op) ) }
61 
63 { try {
64  database& _db = db();
65  _db.modify(
66  _db.get(op.witness),
67  [&op]( witness_object& wit )
68  {
69  if( op.new_url.valid() )
70  wit.url = *op.new_url;
71  if( op.new_signing_key.valid() )
72  wit.signing_key = *op.new_signing_key;
73  });
74  return void_result();
75 } FC_CAPTURE_AND_RETHROW( (op) ) }
76 
77 } } // graphene::chain
FC_CAPTURE_AND_RETHROW
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
graphene::chain::witness_object::url
string url
Definition: witness_object.hpp:41
graphene::db::object::id
object_id_type id
Definition: object.hpp:69
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
graphene::db::object_database::get
const T & get(const object_id_type &id) const
Definition: object_database.hpp:119
database.hpp
graphene::chain::witness_object::vote_id
vote_id_type vote_id
Definition: witness_object.hpp:39
graphene::chain::witness_object::witness_account
account_id_type witness_account
Definition: witness_object.hpp:35
graphene::db::object_database::create
const T & create(F &&constructor)
Definition: object_database.hpp:63
graphene::protocol::vote_id_type
An ID for some votable object.
Definition: vote.hpp:51
graphene::protocol::witness_create_operation::witness_account
account_id_type witness_account
The account which owns the witness. This account pays the fee for this operation.
Definition: witness.hpp:43
graphene::protocol::witness_create_operation
Create a witness object, as a bid to hold a witness position on the network.
Definition: witness.hpp:37
graphene::protocol::witness_update_operation::witness_account
account_id_type witness_account
The account which owns the witness. This account pays the fee for this operation.
Definition: witness.hpp:66
graphene::protocol::witness_update_operation
Update a witness object's URL and block signing key.
Definition: witness.hpp:55
graphene::chain::witness_create_evaluator::do_evaluate
void_result do_evaluate(const witness_create_operation &o)
Definition: witness_evaluator.cpp:33
graphene::protocol::witness_update_operation::witness
witness_id_type witness
The witness object to update.
Definition: witness.hpp:64
graphene::chain::witness_update_evaluator::do_evaluate
void_result do_evaluate(const witness_update_operation &o)
Definition: witness_evaluator.cpp:56
account_object.hpp
graphene::chain::witness_update_evaluator::do_apply
void_result do_apply(const witness_update_operation &o)
Definition: witness_evaluator.cpp:62
committee_member_object.hpp
vote.hpp
graphene::chain::generic_evaluator::db
database & db() const
Definition: evaluator.cpp:39
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
witness_evaluator.hpp
graphene::db::object_id_type
Definition: object_id.hpp:30
graphene::chain::global_property_object
Maintains global state information (committee_member list, current fees)
Definition: global_property_object.hpp:40
graphene::chain::witness_object
Definition: witness_object.hpp:32
graphene::chain::witness_create_evaluator::do_apply
object_id_type do_apply(const witness_create_operation &o)
Definition: witness_evaluator.cpp:39
graphene::chain::database::get_global_properties
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:47
witness_object.hpp
graphene::protocol::void_result
Definition: base.hpp:86
graphene
Definition: api.cpp:48
graphene::db::object_database::modify
void modify(const T &obj, const Lambda &m)
Definition: object_database.hpp:99