2019-12-18 18:30:38 +00:00
# include <graphene/chain/sidechain_address_evaluator.hpp>
# include <graphene/chain/database.hpp>
2020-08-14 14:02:33 +00:00
# include <graphene/chain/son_object.hpp>
2019-12-18 18:30:38 +00:00
# include <graphene/chain/sidechain_address_object.hpp>
# include <graphene/chain/hardfork.hpp>
namespace graphene { namespace chain {
void_result add_sidechain_address_evaluator : : do_evaluate ( const sidechain_address_add_operation & op )
{ try {
2020-08-14 14:02:33 +00:00
FC_ASSERT ( op . deposit_public_key . length ( ) > 0 & & op . deposit_address . length ( ) = = 0 & & op . deposit_address_data . length ( ) = = 0 , " User should add a valid deposit public key and a null deposit address " ) ;
const auto & sdpke_idx = db ( ) . get_index_type < sidechain_address_index > ( ) . indices ( ) . get < by_sidechain_and_deposit_public_key_and_expires > ( ) ;
FC_ASSERT ( sdpke_idx . find ( boost : : make_tuple ( op . sidechain , op . deposit_public_key , time_point_sec : : maximum ( ) ) ) = = sdpke_idx . end ( ) , " An active deposit key already exists " ) ;
return void_result ( ) ;
2019-12-18 18:30:38 +00:00
} FC_CAPTURE_AND_RETHROW ( ( op ) ) }
object_id_type add_sidechain_address_evaluator : : do_apply ( const sidechain_address_add_operation & op )
{ try {
2020-08-14 14:02:33 +00:00
const auto & sidechain_addresses_idx = db ( ) . get_index_type < sidechain_address_index > ( ) . indices ( ) . get < by_account_and_sidechain_and_expires > ( ) ;
const auto & addr_itr = sidechain_addresses_idx . find ( std : : make_tuple ( op . sidechain_address_account , op . sidechain , time_point_sec : : maximum ( ) ) ) ;
if ( addr_itr ! = sidechain_addresses_idx . end ( ) )
{
db ( ) . modify ( * addr_itr , [ & ] ( sidechain_address_object & sao ) {
sao . expires = db ( ) . head_block_time ( ) ;
} ) ;
}
2019-12-18 18:30:38 +00:00
const auto & new_sidechain_address_object = db ( ) . create < sidechain_address_object > ( [ & ] ( sidechain_address_object & obj ) {
obj . sidechain_address_account = op . sidechain_address_account ;
obj . sidechain = op . sidechain ;
2020-04-18 20:18:04 +00:00
obj . deposit_public_key = op . deposit_public_key ;
2020-08-14 14:02:33 +00:00
obj . deposit_address = " " ;
obj . deposit_address_data = " " ;
2020-04-18 20:18:04 +00:00
obj . withdraw_public_key = op . withdraw_public_key ;
[SON-260] Sidechain Token withdrawal (#286)
* Extend GPO.active_sons to contain votes and all public keys
* Introduce son_wallet_object
* son_wallet_object operations
* son_wallet_object operations
* son_wallet_object operations completed, basic tests added
* Create son_wallet_object on new set of SONs, to initiate primary wallet recreation
* son_wallet_object API and cli wallet commands
* Send RPC command to bitcoin node to recreate multisig wallet
* Send RPC command to bitcoin node to recreate multisig wallet
* Send RPC command to bitcoin node to recreate multisig wallet
* Wallet recreation by scheduled SON only, some cosmetic refactoring
* Wallet recreation by scheduled SON only, some cosmetic refactoring
* Updating wallet info through operation instead through database.modify() for persistance
* SON wallet transfer object and operations, for tracking assets deposit/withdrawal
* Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp
Co-Authored-By: gladcow <jahr@yandex.ru>
* Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp
Co-Authored-By: gladcow <jahr@yandex.ru>
* Fix #include <graphene/chain/son_wallet_transfer_object.hpp>
* SON wallet transfer object and operations, for tracking assets deposit/withdrawal
* SON wallet transfer object and operations, for tracking assets deposit/withdrawal
* Refactor primary wallet recreation
* Refactor primary wallet recreation
* PW recreation refactoring, prevent duplicated recreations, update wallet address through proposal
* PW recreation refactoring, prevent duplicated recreations, update wallet address through proposal
* Quickfix for checking payer in evaluator
* Quickfix for checking payer in evaluator
* Fix failing son_wallet_tests
- Check for son_btc_account is temporarely disabled
* Remove redundant file
* Squashed commit of the following:
commit a688bb93ed4e16232a907aa8c76e240c83c771bf
Author: obucinac <obucinac@users.noreply.github.com>
Date: Tue Feb 4 19:31:45 2020 +0100
son_wallet_object operations and multisig wallet recreation by RPC (#263)
* Extend GPO.active_sons to contain votes and all public keys
* Introduce son_wallet_object
* son_wallet_object operations
* Create son_wallet_object on new set of SONs, to initiate primary wallet recreation
* son_wallet_object API and cli wallet commands
* Send RPC command to bitcoin node to recreate multisig wallet
* Updating wallet info through operation instead through database.modify() for persistance
* Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp
* Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp
* Fix #include <graphene/chain/son_wallet_transfer_object.hpp>
* Refactor primary wallet recreation
* PW recreation refactoring, prevent duplicated recreations, update wallet address through proposal
* Quickfix for checking payer in evaluator
* Fix failing son_wallet_tests
- Check for son_btc_account is temporarely disabled
* Remove redundant file
Co-authored-by: gladcow <jahr@yandex.ru>
commit 6e61d6b055eb276757e426245a3a7c23a61b3854
Author: satyakoneru <satyakoneru.iiith@gmail.com>
Date: Tue Feb 4 00:14:39 2020 +1100
SON233 - Provide correct downtime metrics to user (#278)
* Remove duplicated item in CMakeLists.txt
* Issue tokens to the user who deposited Bitcoin, WIP...
* Add son_wallet_transfer_process_operation
* Issue tokens to the user who deposited Bitcoin, WIP...
* Support multiple SON nodes per software instance
* Add is_active_son guards for sidechain events processing
* Add is_active_son guards, fix sending proposals and aprovals
* Managing GRAPHENE_SON_ACCOUNT and issuing assets on Bitcoin deposit
* Fix bad param
* Fix aprovals on already approved or invalid proposals
* Move transfer inside son_wallet_transfer_process_operation
* Fix merging issue
* Add cmake command line option SUPPORT_MULTIPLE_SONS
* Skeleton of sidechain_net_handler_peerplays
* Skeleton of Peerplays network listener
* Temoprary disable account history tests for tracking accounts
* Full Peerplays listener, use GRAPHENE_SON_ACCOUNT instead son_btc_account
* Renaming son_wallet_transfer* to son_wallet_deposit*, introducing son_wallet_withdrawal*
* Extend sidechain_address_object to contain withdrawal addresses
- Withdrawal address is the address where system will send sidechain currencies
* Rename son_wallet_withdrawal* to son_wallet_withdraw*
* Some refactoring
* Withdrawal refactoring
* Withdrawal refactoring
Co-authored-by: gladcow <jahr@yandex.ru>
2020-02-23 16:33:43 +00:00
obj . withdraw_address = op . withdraw_address ;
2020-08-14 14:02:33 +00:00
obj . valid_from = db ( ) . head_block_time ( ) ;
obj . expires = time_point_sec : : maximum ( ) ;
2019-12-18 18:30:38 +00:00
} ) ;
return new_sidechain_address_object . id ;
} FC_CAPTURE_AND_RETHROW ( ( op ) ) }
void_result update_sidechain_address_evaluator : : do_evaluate ( const sidechain_address_update_operation & op )
{ try {
2020-08-14 14:02:33 +00:00
const auto & sidx = db ( ) . get_index_type < son_index > ( ) . indices ( ) . get < by_account > ( ) ;
const auto & son_obj = sidx . find ( op . payer ) ;
FC_ASSERT ( son_obj ! = sidx . end ( ) & & db ( ) . is_son_active ( son_obj - > id ) , " Non active SON trying to update deposit address object " ) ;
const auto & sdpke_idx = db ( ) . get_index_type < sidechain_address_index > ( ) . indices ( ) . get < by_sidechain_and_deposit_public_key_and_expires > ( ) ;
FC_ASSERT ( op . deposit_address . valid ( ) & & op . deposit_public_key . valid ( ) & & op . deposit_address_data . valid ( ) , " Update operation by SON is not valid " ) ;
FC_ASSERT ( ( * op . deposit_address ) . length ( ) > 0 & & ( * op . deposit_public_key ) . length ( ) > 0 & & ( * op . deposit_address_data ) . length ( ) > 0 , " SON should create a valid deposit address with valid deposit public key " ) ;
FC_ASSERT ( sdpke_idx . find ( boost : : make_tuple ( op . sidechain , * op . deposit_public_key , time_point_sec : : maximum ( ) ) ) ! = sdpke_idx . end ( ) , " Invalid update operation by SON " ) ;
FC_ASSERT ( db ( ) . get ( op . sidechain_address_id ) . sidechain_address_account = = op . sidechain_address_account , " Invalid sidechain address account " ) ;
2019-12-18 18:30:38 +00:00
const auto & idx = db ( ) . get_index_type < sidechain_address_index > ( ) . indices ( ) . get < by_id > ( ) ;
2020-08-14 14:02:33 +00:00
FC_ASSERT ( idx . find ( op . sidechain_address_id ) ! = idx . end ( ) , " Invalid sidechain address ID " ) ;
2019-12-18 18:30:38 +00:00
return void_result ( ) ;
} FC_CAPTURE_AND_RETHROW ( ( op ) ) }
object_id_type update_sidechain_address_evaluator : : do_apply ( const sidechain_address_update_operation & op )
{ try {
2020-08-14 14:02:33 +00:00
const auto & idx = db ( ) . get_index_type < sidechain_address_index > ( ) . indices ( ) . get < by_id > ( ) ;
auto itr = idx . find ( op . sidechain_address_id ) ;
if ( itr ! = idx . end ( ) )
{
// Case of change of Active SONs, store the outgoing address object with proper valid_from and expires updated
if ( itr - > deposit_address . length ( ) > 0 ) {
2020-09-23 13:43:28 +00:00
db ( ) . create < sidechain_address_object > ( [ & ] ( sidechain_address_object & obj ) {
2020-08-14 14:02:33 +00:00
obj . sidechain_address_account = op . sidechain_address_account ;
obj . sidechain = op . sidechain ;
obj . deposit_public_key = * op . deposit_public_key ;
obj . deposit_address = itr - > deposit_address ;
obj . deposit_address_data = itr - > deposit_address_data ;
obj . withdraw_public_key = * op . withdraw_public_key ;
obj . withdraw_address = * op . withdraw_address ;
obj . valid_from = itr - > valid_from ;
obj . expires = db ( ) . head_block_time ( ) ;
} ) ;
db ( ) . modify ( * itr , [ & ] ( sidechain_address_object & sao ) {
if ( op . deposit_address . valid ( ) ) sao . deposit_address = * op . deposit_address ;
if ( op . deposit_address_data . valid ( ) ) sao . deposit_address_data = * op . deposit_address_data ;
sao . valid_from = db ( ) . head_block_time ( ) ;
} ) ;
} else {
// Case of SON creating deposit address for a user input
db ( ) . modify ( * itr , [ & op ] ( sidechain_address_object & sao ) {
if ( op . deposit_address . valid ( ) ) sao . deposit_address = * op . deposit_address ;
if ( op . deposit_address_data . valid ( ) ) sao . deposit_address_data = * op . deposit_address_data ;
} ) ;
}
}
2019-12-18 18:30:38 +00:00
return op . sidechain_address_id ;
} FC_CAPTURE_AND_RETHROW ( ( op ) ) }
void_result delete_sidechain_address_evaluator : : do_evaluate ( const sidechain_address_delete_operation & op )
{ try {
FC_ASSERT ( db ( ) . get ( op . sidechain_address_id ) . sidechain_address_account = = op . sidechain_address_account ) ;
const auto & idx = db ( ) . get_index_type < sidechain_address_index > ( ) . indices ( ) . get < by_id > ( ) ;
FC_ASSERT ( idx . find ( op . sidechain_address_id ) ! = idx . end ( ) ) ;
return void_result ( ) ;
} FC_CAPTURE_AND_RETHROW ( ( op ) ) }
void_result delete_sidechain_address_evaluator : : do_apply ( const sidechain_address_delete_operation & op )
{ try {
const auto & idx = db ( ) . get_index_type < sidechain_address_index > ( ) . indices ( ) . get < by_id > ( ) ;
auto sidechain_address = idx . find ( op . sidechain_address_id ) ;
if ( sidechain_address ! = idx . end ( ) ) {
2020-08-14 14:02:33 +00:00
db ( ) . modify ( * sidechain_address , [ & ] ( sidechain_address_object & sao ) {
sao . expires = db ( ) . head_block_time ( ) ;
} ) ;
2019-12-18 18:30:38 +00:00
}
return void_result ( ) ;
} FC_CAPTURE_AND_RETHROW ( ( op ) ) }
} } // namespace graphene::chain