BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface 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
void modify(const T &obj, const Lambda &m)
witness_id_type witness
The witness object to update.
Definition: witness.hpp:64
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:56
Create a witness object, as a bid to hold a witness position on the network.Accounts which wish to be...
Definition: witness.hpp:37
bool valid() const
Definition: optional.hpp:186
optional< public_key_type > new_signing_key
The new block signing key.
Definition: witness.hpp:70
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:44
const T & get(object_id_type id) const
void_result do_apply(const witness_update_operation &o)
object_id_type id
Definition: object.hpp:73
optional< string > new_url
The new URL.
Definition: witness.hpp:68
Update a witness object&#39;s URL and block signing key.
Definition: witness.hpp:55
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:478
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
void_result do_evaluate(const witness_update_operation &o)
void_result do_evaluate(const witness_create_operation &o)
account_id_type witness_account
The account which owns the witness. This account pays the fee for this operation. ...
Definition: witness.hpp:43
An ID for some votable object.
Definition: vote.hpp:51
object_id_type do_apply(const witness_create_operation &o)
account_id_type witness_account
The account which owns the witness. This account pays the fee for this operation. ...
Definition: witness.hpp:66
Maintains global state information (committee_member list, current fees)This is an implementation det...
const T & create(F &&constructor)