Deposit address enhancements
This commit is contained in:
parent
129d5ebf86
commit
501495d995
16 changed files with 230 additions and 79 deletions
|
|
@ -1938,7 +1938,8 @@ vector<optional<sidechain_address_object>> database_api_impl::get_sidechain_addr
|
|||
const auto& sidechain_addresses_range = _db.get_index_type<sidechain_address_index>().indices().get<by_account>().equal_range(account);
|
||||
std::for_each(sidechain_addresses_range.first, sidechain_addresses_range.second,
|
||||
[&result] (const sidechain_address_object& sao) {
|
||||
result.push_back(sao);
|
||||
if( sao.expires == time_point_sec::maximum() )
|
||||
result.push_back(sao);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1954,7 +1955,8 @@ vector<optional<sidechain_address_object>> database_api_impl::get_sidechain_addr
|
|||
const auto& sidechain_addresses_range = _db.get_index_type<sidechain_address_index>().indices().get<by_sidechain>().equal_range(sidechain);
|
||||
std::for_each(sidechain_addresses_range.first, sidechain_addresses_range.second,
|
||||
[&result] (const sidechain_address_object& sao) {
|
||||
result.push_back(sao);
|
||||
if( sao.expires == time_point_sec::maximum() )
|
||||
result.push_back(sao);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1966,8 +1968,8 @@ fc::optional<sidechain_address_object> database_api::get_sidechain_address_by_ac
|
|||
|
||||
fc::optional<sidechain_address_object> database_api_impl::get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const
|
||||
{
|
||||
const auto& idx = _db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
|
||||
auto itr = idx.find( boost::make_tuple( account, sidechain ) );
|
||||
const auto& idx = _db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain_and_expires>();
|
||||
auto itr = idx.find( boost::make_tuple( account, sidechain, time_point_sec::maximum() ) );
|
||||
if( itr != idx.end() )
|
||||
return *itr;
|
||||
return {};
|
||||
|
|
|
|||
|
|
@ -240,6 +240,28 @@ bool database::is_son_dereg_valid( son_id_type son_id )
|
|||
(head_block_time() - son->statistics(*this).last_down_timestamp >= fc::seconds(get_global_properties().parameters.son_deregister_time())));
|
||||
}
|
||||
|
||||
bool database::is_son_active( son_id_type son_id )
|
||||
{
|
||||
const auto& son_idx = get_index_type<son_index>().indices().get< by_id >();
|
||||
auto son = son_idx.find( son_id );
|
||||
if(son == son_idx.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const global_property_object& gpo = get_global_properties();
|
||||
vector<son_id_type> active_son_ids;
|
||||
active_son_ids.reserve(gpo.active_sons.size());
|
||||
std::transform(gpo.active_sons.begin(), gpo.active_sons.end(),
|
||||
std::inserter(active_son_ids, active_son_ids.end()),
|
||||
[](const son_info& swi) {
|
||||
return swi.son_id;
|
||||
});
|
||||
|
||||
auto it_son = std::find(active_son_ids.begin(), active_son_ids.end(), son_id);
|
||||
return (it_son != active_son_ids.end());
|
||||
}
|
||||
|
||||
const account_statistics_object& database::get_account_stats_by_owner( account_id_type owner )const
|
||||
{
|
||||
auto& idx = get_index_type<account_stats_index>().indices().get<by_owner>();
|
||||
|
|
|
|||
|
|
@ -307,6 +307,7 @@ namespace graphene { namespace chain {
|
|||
fc::optional<operation> create_son_deregister_proposal( son_id_type son_id, account_id_type paying_son );
|
||||
signed_transaction create_signed_transaction( const fc::ecc::private_key& signing_private_key, const operation& op );
|
||||
bool is_son_dereg_valid( son_id_type son_id );
|
||||
bool is_son_active( son_id_type son_id );
|
||||
const witness_schedule_object& get_witness_schedule_object()const;
|
||||
|
||||
time_point_sec head_block_time()const;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ namespace graphene { namespace chain {
|
|||
string deposit_address_data;
|
||||
string withdraw_public_key;
|
||||
string withdraw_address;
|
||||
time_point_sec valid_from;
|
||||
time_point_sec expires;
|
||||
|
||||
sidechain_address_object() :
|
||||
sidechain(sidechain_type::bitcoin),
|
||||
|
|
@ -38,10 +40,10 @@ namespace graphene { namespace chain {
|
|||
|
||||
struct by_account;
|
||||
struct by_sidechain;
|
||||
struct by_deposit_public_key;
|
||||
struct by_sidechain_and_deposit_public_key_and_expires;
|
||||
struct by_withdraw_public_key;
|
||||
struct by_account_and_sidechain;
|
||||
struct by_sidechain_and_deposit_address;
|
||||
struct by_account_and_sidechain_and_expires;
|
||||
struct by_sidechain_and_deposit_address_and_expires;
|
||||
using sidechain_address_multi_index_type = multi_index_container<
|
||||
sidechain_address_object,
|
||||
indexed_by<
|
||||
|
|
@ -54,22 +56,27 @@ namespace graphene { namespace chain {
|
|||
ordered_non_unique< tag<by_sidechain>,
|
||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>
|
||||
>,
|
||||
ordered_non_unique< tag<by_deposit_public_key>,
|
||||
member<sidechain_address_object, std::string, &sidechain_address_object::deposit_public_key>
|
||||
ordered_unique< tag<by_sidechain_and_deposit_public_key_and_expires>,
|
||||
composite_key<sidechain_address_object,
|
||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
||||
member<sidechain_address_object, std::string, &sidechain_address_object::deposit_public_key>,
|
||||
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
||||
>,
|
||||
ordered_non_unique< tag<by_withdraw_public_key>,
|
||||
member<sidechain_address_object, std::string, &sidechain_address_object::withdraw_public_key>
|
||||
>,
|
||||
ordered_unique< tag<by_account_and_sidechain>,
|
||||
ordered_unique< tag<by_account_and_sidechain_and_expires>,
|
||||
composite_key<sidechain_address_object,
|
||||
member<sidechain_address_object, account_id_type, &sidechain_address_object::sidechain_address_account>,
|
||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>
|
||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
||||
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
||||
>
|
||||
>,
|
||||
ordered_unique< tag<by_sidechain_and_deposit_address>,
|
||||
ordered_unique< tag<by_sidechain_and_deposit_address_and_expires>,
|
||||
composite_key<sidechain_address_object,
|
||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
||||
member<sidechain_address_object, std::string, &sidechain_address_object::deposit_address>
|
||||
member<sidechain_address_object, std::string, &sidechain_address_object::deposit_address>,
|
||||
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
||||
>
|
||||
>
|
||||
>
|
||||
|
|
|
|||
|
|
@ -8,48 +8,84 @@ namespace graphene { namespace chain {
|
|||
|
||||
void_result add_sidechain_address_evaluator::do_evaluate(const sidechain_address_add_operation& op)
|
||||
{ try{
|
||||
|
||||
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
|
||||
FC_ASSERT( idx.find(boost::make_tuple(op.sidechain_address_account, op.sidechain)) == idx.end(), "Duplicated item" );
|
||||
return void_result();
|
||||
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();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
object_id_type add_sidechain_address_evaluator::do_apply(const sidechain_address_add_operation& op)
|
||||
{ try {
|
||||
const auto &sidechain_addresses_idx = database.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(sed.peerplays_from, op.sidechain, time_point_sec::maximum()));
|
||||
if (addr_itr != sidechain_addresses_idx.end())
|
||||
{
|
||||
db().modify(*addr_itr, [&op](sidechain_address_object &sao) {
|
||||
sao.expires = db().head_block_time();
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
obj.deposit_public_key = op.deposit_public_key;
|
||||
obj.deposit_address = op.deposit_address;
|
||||
obj.deposit_address_data = op.deposit_address_data;
|
||||
obj.deposit_address = "";
|
||||
obj.deposit_address_data = "";
|
||||
obj.withdraw_public_key = op.withdraw_public_key;
|
||||
obj.withdraw_address = op.withdraw_address;
|
||||
obj.valid_from = db().head_block_time();
|
||||
obj.expires = time_point_sec::maximum();
|
||||
});
|
||||
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 {
|
||||
FC_ASSERT(db().get(op.sidechain_address_id).sidechain_address_account == op.sidechain_address_account);
|
||||
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" );
|
||||
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_id>();
|
||||
FC_ASSERT( idx.find(op.sidechain_address_id) != idx.end() );
|
||||
FC_ASSERT( idx.find(op.sidechain_address_id) != idx.end(), "Invalid sidechain address ID" );
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
object_id_type update_sidechain_address_evaluator::do_apply(const sidechain_address_update_operation& op)
|
||||
{ try {
|
||||
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())
|
||||
{
|
||||
db().modify(*itr, [&op](sidechain_address_object &sao) {
|
||||
if(op.deposit_public_key.valid()) sao.deposit_public_key = *op.deposit_public_key;
|
||||
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;
|
||||
if(op.withdraw_public_key.valid()) sao.withdraw_public_key = *op.withdraw_public_key;
|
||||
if(op.withdraw_address.valid()) sao.withdraw_address = *op.withdraw_address;
|
||||
});
|
||||
}
|
||||
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) {
|
||||
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;
|
||||
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, [&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;
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
return op.sidechain_address_id;
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
|
|
@ -66,7 +102,9 @@ void_result delete_sidechain_address_evaluator::do_apply(const sidechain_address
|
|||
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()) {
|
||||
db().remove(*sidechain_address);
|
||||
db().modify(*sidechain_address, [](sidechain_address_object &sao) {
|
||||
sao.expires = db().head_block_time();
|
||||
});
|
||||
}
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public:
|
|||
|
||||
void process_proposals();
|
||||
void process_active_sons_change();
|
||||
void create_deposit_addresses();
|
||||
void process_deposits();
|
||||
void process_withdrawals();
|
||||
void process_sidechain_transactions();
|
||||
|
|
@ -41,6 +42,7 @@ public:
|
|||
virtual bool process_proposal(const proposal_object &po) = 0;
|
||||
virtual void process_primary_wallet() = 0;
|
||||
virtual void process_sidechain_addresses() = 0;
|
||||
virtual bool create_deposit_address(const sidechain_address_object &sao) = 0;
|
||||
virtual bool process_deposit(const son_wallet_deposit_object &swdo) = 0;
|
||||
virtual bool process_withdrawal(const son_wallet_withdraw_object &swwo) = 0;
|
||||
virtual std::string process_sidechain_transaction(const sidechain_transaction_object &sto) = 0;
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ public:
|
|||
bool process_proposal(const proposal_object &po);
|
||||
void process_primary_wallet();
|
||||
void process_sidechain_addresses();
|
||||
bool create_deposit_address(const sidechain_address_object &sao);
|
||||
bool process_deposit(const son_wallet_deposit_object &swdo);
|
||||
bool process_withdrawal(const son_wallet_withdraw_object &swwo);
|
||||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public:
|
|||
bool process_proposal(const proposal_object &po);
|
||||
void process_primary_wallet();
|
||||
void process_sidechain_addresses();
|
||||
bool create_deposit_address(const sidechain_address_object &sao);
|
||||
bool process_deposit(const son_wallet_deposit_object &swdo);
|
||||
bool process_withdrawal(const son_wallet_withdraw_object &swwo);
|
||||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public:
|
|||
bool create_handler(sidechain_type sidechain, const boost::program_options::variables_map &options);
|
||||
void process_proposals();
|
||||
void process_active_sons_change();
|
||||
void create_deposit_addresses();
|
||||
void process_deposits();
|
||||
void process_withdrawals();
|
||||
void process_sidechain_transactions();
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ public:
|
|||
|
||||
void process_proposals();
|
||||
void process_active_sons_change();
|
||||
void create_deposit_addresses();
|
||||
void process_deposits();
|
||||
void process_withdrawals();
|
||||
void process_sidechain_transactions();
|
||||
|
|
@ -415,6 +416,8 @@ void peerplays_sidechain_plugin_impl::son_processing() {
|
|||
|
||||
process_active_sons_change();
|
||||
|
||||
create_deposit_addresses();
|
||||
|
||||
process_deposits();
|
||||
|
||||
process_withdrawals();
|
||||
|
|
@ -596,6 +599,10 @@ void peerplays_sidechain_plugin_impl::process_active_sons_change() {
|
|||
net_manager->process_active_sons_change();
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::create_deposit_addresses() {
|
||||
net_manager->create_deposit_addresses();
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::process_deposits() {
|
||||
net_manager->process_deposits();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -216,8 +216,8 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
|||
// Withdrawal request
|
||||
if (withdraw_condition) {
|
||||
// BTC Payout only (for now)
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain_type::bitcoin));
|
||||
const auto &sidechain_addresses_idx = database.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(sed.peerplays_from, sidechain_type::bitcoin, time_point_sec::maximum()));
|
||||
if (addr_itr == sidechain_addresses_idx.end())
|
||||
return;
|
||||
|
||||
|
|
@ -359,6 +359,30 @@ void sidechain_net_handler::process_active_sons_change() {
|
|||
process_sidechain_addresses();
|
||||
}
|
||||
|
||||
void sidechain_net_handler::create_deposit_addresses() {
|
||||
if (database.get_global_properties().active_sons.size() < database.get_chain_properties().immutable_parameters.min_son_count) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address_and_expires>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, "", time_point_sec::maximum()));
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_address_object &sao) {
|
||||
if (sao.id == object_id_type(0, 0, 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ilog("sidechain deposit address to create: ${sao}", ("sao", sao));
|
||||
|
||||
bool create_address_result = create_deposit_address(sao);
|
||||
|
||||
if (!create_address_result) {
|
||||
wlog("Deposit address not created: ${sao}", ("sao", sao));
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void sidechain_net_handler::process_deposits() {
|
||||
if (database.get_global_properties().active_sons.size() < database.get_chain_properties().immutable_parameters.min_son_count) {
|
||||
return;
|
||||
|
|
@ -372,8 +396,8 @@ void sidechain_net_handler::process_deposits() {
|
|||
return;
|
||||
}
|
||||
//Ignore the deposits which are not valid anymore, considered refunds.
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address>();
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, swdo.sidechain_to));
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address_and_expires>();
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, swdo.sidechain_to, time_point_sec::maximum()));
|
||||
if (addr_itr == sidechain_addresses_idx.end()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1349,39 +1349,84 @@ void sidechain_net_handler_bitcoin::process_sidechain_addresses() {
|
|||
const auto &sidechain_addresses_by_sidechain_range = sidechain_addresses_by_sidechain_idx.equal_range(sidechain);
|
||||
std::for_each(sidechain_addresses_by_sidechain_range.first, sidechain_addresses_by_sidechain_range.second,
|
||||
[&](const sidechain_address_object &sao) {
|
||||
auto usr_pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(sao.deposit_public_key)));
|
||||
if (sao.expires == time_point_sec::maximum()) {
|
||||
auto usr_pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(sao.deposit_public_key)));
|
||||
|
||||
btc_one_or_weighted_multisig_address addr(usr_pubkey, pubkeys, network_type);
|
||||
std::string address_data = "{ \"redeemScript\": \"" + fc::to_hex(addr.get_redeem_script()) +
|
||||
"\", \"witnessScript\": \"" + fc::to_hex(addr.get_witness_script()) + "\" }";
|
||||
btc_one_or_weighted_multisig_address addr(usr_pubkey, pubkeys, network_type);
|
||||
std::string address_data = "{ \"redeemScript\": \"" + fc::to_hex(addr.get_redeem_script()) +
|
||||
"\", \"witnessScript\": \"" + fc::to_hex(addr.get_witness_script()) + "\" }";
|
||||
|
||||
if (addr.get_address() != sao.deposit_address) {
|
||||
sidechain_address_update_operation op;
|
||||
op.payer = plugin.get_current_son_object().son_account;
|
||||
op.sidechain_address_id = sao.id;
|
||||
op.sidechain_address_account = sao.sidechain_address_account;
|
||||
op.sidechain = sao.sidechain;
|
||||
op.deposit_public_key = sao.deposit_public_key;
|
||||
op.deposit_address = addr.get_address();
|
||||
op.deposit_address_data = address_data;
|
||||
op.withdraw_public_key = sao.withdraw_public_key;
|
||||
op.withdraw_address = sao.withdraw_address;
|
||||
if (addr.get_address() != sao.deposit_address) {
|
||||
sidechain_address_update_operation op;
|
||||
op.payer = plugin.get_current_son_object().son_account;
|
||||
op.sidechain_address_id = sao.id;
|
||||
op.sidechain_address_account = sao.sidechain_address_account;
|
||||
op.sidechain = sao.sidechain;
|
||||
op.deposit_public_key = sao.deposit_public_key;
|
||||
op.deposit_address = addr.get_address();
|
||||
op.deposit_address_data = address_data;
|
||||
op.withdraw_public_key = sao.withdraw_public_key;
|
||||
op.withdraw_address = sao.withdraw_address;
|
||||
|
||||
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op);
|
||||
try {
|
||||
trx.validate();
|
||||
database.push_transaction(trx, database::validation_steps::skip_block_size_check);
|
||||
if (plugin.app().p2p_node())
|
||||
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
|
||||
return true;
|
||||
} catch (fc::exception e) {
|
||||
elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
|
||||
return false;
|
||||
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op);
|
||||
try {
|
||||
trx.validate();
|
||||
database.push_transaction(trx, database::validation_steps::skip_block_size_check);
|
||||
if (plugin.app().p2p_node())
|
||||
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
|
||||
return true;
|
||||
} catch (fc::exception e) {
|
||||
elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool sidechain_net_handler_bitcoin::create_deposit_address(const sidechain_address_object &sao) {
|
||||
using namespace bitcoin;
|
||||
|
||||
const chain::global_property_object &gpo = database.get_global_properties();
|
||||
std::vector<std::pair<fc::ecc::public_key, uint16_t>> pubkeys;
|
||||
for (auto &son : gpo.active_sons) {
|
||||
std::string pub_key_str = son.sidechain_public_keys.at(sidechain_type::bitcoin);
|
||||
auto pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str)));
|
||||
pubkeys.push_back(std::make_pair(pubkey, son.weight));
|
||||
}
|
||||
|
||||
auto usr_pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(sao.deposit_public_key)));
|
||||
|
||||
btc_one_or_weighted_multisig_address addr(usr_pubkey, pubkeys, network_type);
|
||||
std::string address_data = "{ \"redeemScript\": \"" + fc::to_hex(addr.get_redeem_script()) +
|
||||
"\", \"witnessScript\": \"" + fc::to_hex(addr.get_witness_script()) + "\" }";
|
||||
|
||||
if (addr.get_address() != sao.deposit_address) {
|
||||
sidechain_address_update_operation op;
|
||||
op.payer = plugin.get_current_son_object().son_account;
|
||||
op.sidechain_address_id = sao.id;
|
||||
op.sidechain_address_account = sao.sidechain_address_account;
|
||||
op.sidechain = sao.sidechain;
|
||||
op.deposit_public_key = sao.deposit_public_key;
|
||||
op.deposit_address = addr.get_address();
|
||||
op.deposit_address_data = address_data;
|
||||
op.withdraw_public_key = sao.withdraw_public_key;
|
||||
op.withdraw_address = sao.withdraw_address;
|
||||
|
||||
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op);
|
||||
try {
|
||||
trx.validate();
|
||||
database.push_transaction(trx, database::validation_steps::skip_block_size_check);
|
||||
if (plugin.app().p2p_node())
|
||||
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
|
||||
return true;
|
||||
} catch (fc::exception e) {
|
||||
elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool sidechain_net_handler_bitcoin::process_deposit(const son_wallet_deposit_object &swdo) {
|
||||
|
||||
if (proposal_exists(chain::operation::tag<chain::son_wallet_deposit_process_operation>::value, swdo.id)) {
|
||||
|
|
@ -1779,11 +1824,11 @@ void sidechain_net_handler_bitcoin::handle_event(const std::string &event_data)
|
|||
if (block != "") {
|
||||
const auto &vins = extract_info_from_block(block);
|
||||
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address>();
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address_and_expires>();
|
||||
|
||||
for (const auto &v : vins) {
|
||||
// !!! EXTRACT DEPOSIT ADDRESS FROM SIDECHAIN ADDRESS OBJECT
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, v.address));
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, v.address, time_point_sec::maximum()));
|
||||
if (addr_itr == sidechain_addresses_idx.end())
|
||||
continue;
|
||||
|
||||
|
|
@ -1813,8 +1858,8 @@ void sidechain_net_handler_bitcoin::handle_event(const std::string &event_data)
|
|||
|
||||
std::string sidechain_net_handler_bitcoin::get_redeemscript_for_userdeposit(const std::string &user_address) {
|
||||
using namespace bitcoin;
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address>();
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, user_address));
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address_and_expires>();
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, user_address, time_point_sec::maximum()));
|
||||
if (addr_itr == sidechain_addresses_idx.end()) {
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,6 +127,10 @@ void sidechain_net_handler_peerplays::process_sidechain_addresses() {
|
|||
return;
|
||||
}
|
||||
|
||||
bool sidechain_net_handler_peerplays::create_deposit_address(const sidechain_address_object &sao) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sidechain_net_handler_peerplays::process_deposit(const son_wallet_deposit_object &swdo) {
|
||||
|
||||
const chain::global_property_object &gpo = database.get_global_properties();
|
||||
|
|
|
|||
|
|
@ -51,6 +51,12 @@ void sidechain_net_manager::process_active_sons_change() {
|
|||
}
|
||||
}
|
||||
|
||||
void sidechain_net_manager::create_deposit_addresses() {
|
||||
for (size_t i = 0; i < net_handlers.size(); i++) {
|
||||
net_handlers.at(i)->create_deposit_addresses();
|
||||
}
|
||||
}
|
||||
|
||||
void sidechain_net_manager::process_deposits() {
|
||||
for (size_t i = 0; i < net_handlers.size(); i++) {
|
||||
net_handlers.at(i)->process_deposits();
|
||||
|
|
|
|||
|
|
@ -1440,7 +1440,6 @@ class wallet_api
|
|||
* @param account the name or id of the account who owns the address
|
||||
* @param sidechain a sidechain to whom address belongs
|
||||
* @param deposit_public_key sidechain public key used for deposit address
|
||||
* @param deposit_address sidechain address for deposits
|
||||
* @param withdraw_public_key sidechain public key used for withdraw address
|
||||
* @param withdraw_address sidechain address for withdrawals
|
||||
* @param broadcast true to broadcast the transaction on the network
|
||||
|
|
@ -1449,7 +1448,6 @@ class wallet_api
|
|||
signed_transaction add_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string deposit_address,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast = false);
|
||||
|
|
@ -1461,7 +1459,6 @@ class wallet_api
|
|||
* @param account the name or id of the account who owns the address
|
||||
* @param sidechain a sidechain to whom address belongs
|
||||
* @param deposit_public_key sidechain public key used for deposit address
|
||||
* @param deposit_address sidechain address for deposits
|
||||
* @param withdraw_public_key sidechain public key used for withdraw address
|
||||
* @param withdraw_address sidechain address for withdrawals
|
||||
* @param broadcast true to broadcast the transaction on the network
|
||||
|
|
@ -1470,7 +1467,6 @@ class wallet_api
|
|||
signed_transaction update_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string deposit_address,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast = false);
|
||||
|
|
|
|||
|
|
@ -2080,7 +2080,6 @@ public:
|
|||
signed_transaction add_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string deposit_address,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast /* = false */)
|
||||
|
|
@ -2092,7 +2091,6 @@ public:
|
|||
op.sidechain_address_account = sidechain_address_account_id;
|
||||
op.sidechain = sidechain;
|
||||
op.deposit_public_key = deposit_public_key;
|
||||
op.deposit_address = deposit_address;
|
||||
op.withdraw_public_key = withdraw_public_key;
|
||||
op.withdraw_address = withdraw_address;
|
||||
|
||||
|
|
@ -2107,7 +2105,6 @@ public:
|
|||
signed_transaction update_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string deposit_address,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast /* = false */)
|
||||
|
|
@ -2123,7 +2120,6 @@ public:
|
|||
op.sidechain_address_account = sidechain_address_account_id;
|
||||
op.sidechain = sidechain;
|
||||
op.deposit_public_key = deposit_public_key;
|
||||
op.deposit_address = deposit_address;
|
||||
op.withdraw_public_key = withdraw_public_key;
|
||||
op.withdraw_address = withdraw_address;
|
||||
|
||||
|
|
@ -4804,23 +4800,21 @@ vector<optional<son_wallet_object>> wallet_api::get_son_wallets(uint32_t limit)
|
|||
signed_transaction wallet_api::add_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string deposit_address,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast /* = false */)
|
||||
{
|
||||
return my->add_sidechain_address(account, sidechain, deposit_public_key, deposit_address, withdraw_public_key, withdraw_address, broadcast);
|
||||
return my->add_sidechain_address(account, sidechain, deposit_public_key, withdraw_public_key, withdraw_address, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::update_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string deposit_address,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast /* = false */)
|
||||
{
|
||||
return my->update_sidechain_address(account, sidechain, deposit_public_key, deposit_address, withdraw_public_key, withdraw_address, broadcast);
|
||||
return my->update_sidechain_address(account, sidechain, deposit_public_key, withdraw_public_key, withdraw_address, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::delete_sidechain_address(string account,
|
||||
|
|
|
|||
Loading…
Reference in a new issue