CLI wallet commands to add/remove account's active key
This commit is contained in:
parent
fdcf090730
commit
3f4fc67e40
2 changed files with 159 additions and 0 deletions
|
|
@ -62,6 +62,11 @@ struct brain_key_info
|
|||
public_key_type pub_key;
|
||||
};
|
||||
|
||||
enum authority_type
|
||||
{
|
||||
owner,
|
||||
active
|
||||
};
|
||||
|
||||
/**
|
||||
* Contains the confirmation receipt the sender must give the receiver and
|
||||
|
|
@ -740,6 +745,41 @@ class wallet_api
|
|||
uint32_t referrer_percent,
|
||||
bool broadcast = false);
|
||||
|
||||
/** Updates account public keys
|
||||
*
|
||||
* @param name the name of the existing account
|
||||
* @param old_owner the owner key for the named account to be replaced
|
||||
* @param new_owner the owner key for the named account to be set as new
|
||||
* @param old_active the active key for the named account to be replaced
|
||||
* @param new_active the active key for the named account to be set as new
|
||||
* @param broadcast true to broadcast the transaction on the network
|
||||
* @returns the signed transaction updating account public keys
|
||||
*/
|
||||
signed_transaction update_account_keys(string name,
|
||||
public_key_type old_owner,
|
||||
public_key_type new_owner,
|
||||
public_key_type old_active,
|
||||
public_key_type new_active,
|
||||
bool broadcast = false);
|
||||
|
||||
/**
|
||||
* This method updates the key of an authority for an exisiting account.
|
||||
* Warning: You can create impossible authorities using this method. The method
|
||||
* will fail if you create an impossible owner authority, but will allow impossible
|
||||
* active and posting authorities.
|
||||
*
|
||||
* @param account_name The name of the account whose authority you wish to update
|
||||
* @param type The authority type. e.g. owner or active
|
||||
* @param key The public key to add to the authority
|
||||
* @param weight The weight the key should have in the authority. A weight of 0 indicates the removal of the key.
|
||||
* @param broadcast true if you wish to broadcast the transaction.
|
||||
*/
|
||||
signed_transaction update_account_auth_key(string account_name,
|
||||
authority_type type,
|
||||
public_key_type key,
|
||||
weight_type weight,
|
||||
bool broadcast);
|
||||
|
||||
/**
|
||||
* Upgrades an account to prime status.
|
||||
* This makes the account holder a 'lifetime member'.
|
||||
|
|
@ -2433,6 +2473,8 @@ FC_REFLECT( graphene::wallet::brain_key_info,
|
|||
(pub_key)
|
||||
)
|
||||
|
||||
FC_REFLECT_ENUM( graphene::wallet::authority_type, (owner)(active) )
|
||||
|
||||
FC_REFLECT( graphene::wallet::exported_account_keys, (account_name)(encrypted_private_keys)(public_keys) )
|
||||
|
||||
FC_REFLECT( graphene::wallet::exported_keys, (password_checksum)(account_keys) )
|
||||
|
|
@ -2496,6 +2538,8 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(derive_owner_keys_from_brain_key)
|
||||
(get_private_key_from_password)
|
||||
(register_account)
|
||||
(update_account_keys)
|
||||
(update_account_auth_key)
|
||||
(upgrade_account)
|
||||
(create_account_with_brain_key)
|
||||
(sell_asset)
|
||||
|
|
|
|||
|
|
@ -1335,6 +1335,102 @@ public:
|
|||
} FC_CAPTURE_AND_RETHROW( (name)(owner)(active)(registrar_account)(referrer_account)(referrer_percent)(broadcast) ) }
|
||||
|
||||
|
||||
signed_transaction update_account_keys(string name,
|
||||
public_key_type old_owner,
|
||||
public_key_type new_owner,
|
||||
public_key_type old_active,
|
||||
public_key_type new_active,
|
||||
bool broadcast)
|
||||
{ try {
|
||||
FC_ASSERT( !self.is_locked() );
|
||||
account_object account_obj = get_account(name);
|
||||
|
||||
authority owner = account_obj.owner;
|
||||
owner.key_auths[new_owner] = owner.key_auths[old_owner];
|
||||
owner.key_auths.erase(old_owner);
|
||||
|
||||
authority active = account_obj.active;
|
||||
active.key_auths[new_active] = active.key_auths[old_active];
|
||||
active.key_auths.erase(old_active);
|
||||
|
||||
signed_transaction tx;
|
||||
account_update_operation op;
|
||||
|
||||
op.account = account_obj.get_id();
|
||||
op.owner = owner;
|
||||
op.active = active;
|
||||
|
||||
ilog("account_update_operation: ${op}", ("op", op));
|
||||
|
||||
tx.operations = {op};
|
||||
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees );
|
||||
tx.validate();
|
||||
|
||||
return sign_transaction( tx, broadcast );
|
||||
} FC_CAPTURE_AND_RETHROW( (name) ) }
|
||||
|
||||
|
||||
signed_transaction update_account_auth_key(string account_name,
|
||||
authority_type type,
|
||||
public_key_type key,
|
||||
weight_type weight,
|
||||
bool broadcast)
|
||||
{
|
||||
FC_ASSERT( !is_locked() );
|
||||
account_object account_obj = get_account(account_name);
|
||||
|
||||
account_update_operation op;
|
||||
op.account = account_obj.get_id();
|
||||
|
||||
authority new_auth;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case( owner ):
|
||||
new_auth = account_obj.owner;
|
||||
break;
|
||||
case( active ):
|
||||
new_auth = account_obj.active;
|
||||
break;
|
||||
}
|
||||
|
||||
if( weight == 0 ) // Remove the key
|
||||
{
|
||||
new_auth.key_auths.erase( key );
|
||||
}
|
||||
else
|
||||
{
|
||||
new_auth.add_authority( key, weight );
|
||||
}
|
||||
|
||||
if( new_auth.is_impossible() )
|
||||
{
|
||||
if ( type == owner )
|
||||
{
|
||||
FC_ASSERT( false, "Owner authority change would render account irrecoverable." );
|
||||
}
|
||||
|
||||
wlog( "Authority is now impossible." );
|
||||
}
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case( owner ):
|
||||
op.owner = new_auth;
|
||||
break;
|
||||
case( active ):
|
||||
op.active = new_auth;
|
||||
break;
|
||||
}
|
||||
|
||||
signed_transaction tx;
|
||||
tx.operations.push_back(op);
|
||||
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees );
|
||||
tx.validate();
|
||||
|
||||
return sign_transaction( tx, broadcast );
|
||||
}
|
||||
|
||||
signed_transaction upgrade_account(string name, bool broadcast)
|
||||
{ try {
|
||||
FC_ASSERT( !self.is_locked() );
|
||||
|
|
@ -5536,6 +5632,25 @@ map<public_key_type, string> wallet_api::dump_private_keys()
|
|||
return my->_keys;
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::update_account_keys(string name,
|
||||
public_key_type old_owner,
|
||||
public_key_type new_owner,
|
||||
public_key_type old_active,
|
||||
public_key_type new_active,
|
||||
bool broadcast )
|
||||
{
|
||||
return my->update_account_keys(name, old_owner, new_owner, old_active, new_active, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::update_account_auth_key(string account_name,
|
||||
authority_type type,
|
||||
public_key_type key,
|
||||
weight_type weight,
|
||||
bool broadcast)
|
||||
{
|
||||
return my->update_account_auth_key(account_name, type, key, weight, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::upgrade_account( string name, bool broadcast )
|
||||
{
|
||||
return my->upgrade_account(name,broadcast);
|
||||
|
|
|
|||
Loading…
Reference in a new issue