Progress #98: Add public key to balance_claim_operation
This commit is contained in:
parent
1c8e31c34a
commit
5f5d819a1f
5 changed files with 38 additions and 44 deletions
|
|
@ -21,7 +21,15 @@ public:
|
||||||
database& d = db();
|
database& d = db();
|
||||||
balance = &op.balance_to_claim(d);
|
balance = &op.balance_to_claim(d);
|
||||||
|
|
||||||
FC_ASSERT(trx_state->signed_by( balance->owner, true /*maybe pts*/ ));
|
FC_ASSERT(op.balance_owner_key == balance->owner ||
|
||||||
|
pts_address(op.balance_owner_key, false, 56) == balance->owner ||
|
||||||
|
pts_address(op.balance_owner_key, true, 56) == balance->owner ||
|
||||||
|
pts_address(op.balance_owner_key, false, 0) == balance->owner ||
|
||||||
|
pts_address(op.balance_owner_key, true, 0) == balance->owner,
|
||||||
|
"balance_owner_key does not match balance's owner");
|
||||||
|
if( !(d.get_node_properties().skip_flags & (database::skip_authority_check |
|
||||||
|
database::skip_transaction_signatures)) )
|
||||||
|
FC_ASSERT(trx_state->signed_by(op.balance_owner_key));
|
||||||
FC_ASSERT(op.total_claimed.asset_id == balance->asset_type());
|
FC_ASSERT(op.total_claimed.asset_id == balance->asset_type());
|
||||||
|
|
||||||
if( balance->vesting_policy.valid() ) {
|
if( balance->vesting_policy.valid() ) {
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,7 @@ namespace graphene { namespace chain {
|
||||||
asset fee;
|
asset fee;
|
||||||
account_id_type deposit_to_account;
|
account_id_type deposit_to_account;
|
||||||
balance_id_type balance_to_claim;
|
balance_id_type balance_to_claim;
|
||||||
|
public_key_type balance_owner_key;
|
||||||
asset total_claimed;
|
asset total_claimed;
|
||||||
|
|
||||||
account_id_type fee_payer()const { return deposit_to_account; }
|
account_id_type fee_payer()const { return deposit_to_account; }
|
||||||
|
|
@ -1651,7 +1652,8 @@ FC_REFLECT( graphene::chain::custom_operation, (fee)(payer)(required_auths)(id)(
|
||||||
FC_REFLECT( graphene::chain::assert_operation, (fee)(fee_paying_account)(predicates)(required_auths) )
|
FC_REFLECT( graphene::chain::assert_operation, (fee)(fee_paying_account)(predicates)(required_auths) )
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::void_result, )
|
FC_REFLECT( graphene::chain::void_result, )
|
||||||
FC_REFLECT( graphene::chain::balance_claim_operation, (fee)(deposit_to_account)(balance_to_claim)(total_claimed) )
|
FC_REFLECT( graphene::chain::balance_claim_operation,
|
||||||
|
(fee)(deposit_to_account)(balance_to_claim)(balance_owner_key)(total_claimed) )
|
||||||
|
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::operation )
|
FC_REFLECT_TYPENAME( graphene::chain::operation )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::operation_result )
|
FC_REFLECT_TYPENAME( graphene::chain::operation_result )
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,8 @@ namespace graphene { namespace chain {
|
||||||
struct signed_transaction;
|
struct signed_transaction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Place holder for state tracked while processing a
|
* Place holder for state tracked while processing a transaction. This class provides helper methods that are
|
||||||
* transaction. This class provides helper methods
|
* common to many different operations and also tracks which keys have signed the transaction
|
||||||
* that are common to many different operations and
|
|
||||||
* also tracks which keys have signed the transaction
|
|
||||||
*/
|
*/
|
||||||
class transaction_evaluation_state
|
class transaction_evaluation_state
|
||||||
{
|
{
|
||||||
|
|
@ -36,26 +34,24 @@ namespace graphene { namespace chain {
|
||||||
transaction_evaluation_state( database* db = nullptr )
|
transaction_evaluation_state( database* db = nullptr )
|
||||||
:_db(db){}
|
:_db(db){}
|
||||||
|
|
||||||
bool check_authority( const account_object&, authority::classification auth_class = authority::active, int depth = 0 );
|
bool check_authority(const account_object&,
|
||||||
|
authority::classification auth_class = authority::active,
|
||||||
|
int depth = 0);
|
||||||
|
|
||||||
database& db()const { FC_ASSERT( _db ); return *_db; }
|
database& db()const { FC_ASSERT( _db ); return *_db; }
|
||||||
|
|
||||||
bool signed_by( key_id_type id );
|
bool signed_by(key_id_type id);
|
||||||
bool signed_by( const address& a, bool maybe_pts = false );
|
bool signed_by(const public_key_type& k);
|
||||||
|
|
||||||
/** derived from signatures on transaction
|
/// cached approval (accounts and keys)
|
||||||
flat_set<address> signed_by;
|
flat_set<pair<object_id_type,authority::classification>> approved_by;
|
||||||
*/
|
|
||||||
/** cached approval (accounts and keys) */
|
/// Used to look up new objects using transaction relative IDs
|
||||||
flat_set< pair<object_id_type,authority::classification> > approved_by;
|
vector<operation_result> operation_results;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to lookup new objects using transaction relative IDs
|
* When an address is referenced via check authority it is flagged as being used, all addresses must be
|
||||||
*/
|
* flagged as being used or the transaction will fail.
|
||||||
vector<operation_result> operation_results;
|
|
||||||
|
|
||||||
/** When an address is referenced via check authority it is flagged as being used,
|
|
||||||
* all addresses must be flagged as being used or the transaction will fail.
|
|
||||||
*/
|
*/
|
||||||
flat_map<public_key_type, bool> _sigs;
|
flat_map<public_key_type, bool> _sigs;
|
||||||
const signed_transaction* _trx = nullptr;
|
const signed_transaction* _trx = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -94,35 +94,21 @@ namespace graphene { namespace chain {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool transaction_evaluation_state::signed_by( key_id_type id )
|
bool transaction_evaluation_state::signed_by(key_id_type id)
|
||||||
{
|
{
|
||||||
assert(_trx);
|
assert(_trx);
|
||||||
assert(_db);
|
assert(_db);
|
||||||
//wdump((_sigs)(id(*_db).key_address())(*_trx) );
|
|
||||||
auto itr = _sigs.find( id(*_db).key() );
|
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() )
|
if( itr != _sigs.end() )
|
||||||
return itr->second = true;
|
return itr->second = true;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool transaction_evaluation_state::signed_by( const address& a, bool maybe_pts )
|
|
||||||
{
|
|
||||||
if( _db->get_node_properties().skip_flags & (database::skip_authority_check|database::skip_transaction_signatures) )
|
|
||||||
return true;
|
|
||||||
for( auto itr = _sigs.begin(); itr != _sigs.end(); ++itr )
|
|
||||||
{
|
|
||||||
if( itr->first == a ) return itr->second = true;
|
|
||||||
if( maybe_pts )
|
|
||||||
{
|
|
||||||
//pts normal
|
|
||||||
if( pts_address( itr->first, false, 56 ) == a ) return itr->second = true;
|
|
||||||
//pts compressed
|
|
||||||
if( pts_address( itr->first, true, 56 ) == a ) return itr->second = true;
|
|
||||||
// btc normal
|
|
||||||
if( pts_address( itr->first, false, 0 ) == a ) return itr->second = true;
|
|
||||||
// btc compressed
|
|
||||||
if( pts_address( itr->first, true, 0 ) == a ) return itr->second = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -993,12 +993,14 @@ BOOST_AUTO_TEST_CASE( balance_object_test )
|
||||||
op.deposit_to_account = db.get_index_type<account_index>().indices().get<by_name>().find("n")->get_id();
|
op.deposit_to_account = db.get_index_type<account_index>().indices().get<by_name>().find("n")->get_id();
|
||||||
op.total_claimed = asset(1);
|
op.total_claimed = asset(1);
|
||||||
op.balance_to_claim = balance_id_type(1);
|
op.balance_to_claim = balance_id_type(1);
|
||||||
|
op.balance_owner_key = generate_private_key("x").get_public_key();
|
||||||
trx.operations = {op};
|
trx.operations = {op};
|
||||||
trx.sign(generate_private_key("n"));
|
trx.sign(generate_private_key("n"));
|
||||||
// Fail because I'm claiming from an address which hasn't signed
|
// Fail because I'm claiming from an address which hasn't signed
|
||||||
BOOST_CHECK_THROW(db.push_transaction(trx), fc::exception);
|
BOOST_CHECK_THROW(db.push_transaction(trx), fc::exception);
|
||||||
trx.clear();
|
trx.clear();
|
||||||
op.balance_to_claim = balance_id_type();
|
op.balance_to_claim = balance_id_type();
|
||||||
|
op.balance_owner_key = generate_private_key("n").get_public_key();
|
||||||
trx.operations = {op};
|
trx.operations = {op};
|
||||||
trx.sign(generate_private_key("n"));
|
trx.sign(generate_private_key("n"));
|
||||||
db.push_transaction(trx);
|
db.push_transaction(trx);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue