Added check for approving son_wallet_withdraw_process_operation
This commit is contained in:
parent
34cbd82d0c
commit
cef6a534a1
13 changed files with 106 additions and 19 deletions
|
|
@ -2104,6 +2104,8 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
|||
p.pending_parameters->extensions.value.son_heartbeat_frequency = p.parameters.extensions.value.son_heartbeat_frequency;
|
||||
if( !p.pending_parameters->extensions.value.son_down_time.valid() )
|
||||
p.pending_parameters->extensions.value.son_down_time = p.parameters.extensions.value.son_down_time;
|
||||
if( !p.pending_parameters->extensions.value.son_bitcoin_min_tx_confirmations.valid() )
|
||||
p.pending_parameters->extensions.value.son_bitcoin_min_tx_confirmations = p.parameters.extensions.value.son_bitcoin_min_tx_confirmations;
|
||||
p.parameters = std::move(*p.pending_parameters);
|
||||
p.pending_parameters.reset();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,11 +57,10 @@ namespace graphene { namespace chain {
|
|||
optional < uint32_t > son_deregister_time = SON_DEREGISTER_TIME;
|
||||
optional < uint32_t > son_heartbeat_frequency = SON_HEARTBEAT_FREQUENCY;
|
||||
optional < uint32_t > son_down_time = SON_DOWN_TIME;
|
||||
optional < uint16_t > son_bitcoin_min_tx_confirmations = SON_BITCOIN_MIN_TX_CONFIRMATIONS;
|
||||
|
||||
optional < account_id_type > son_account;
|
||||
optional < asset_id_type > btc_asset;
|
||||
|
||||
optional < uint16_t > son_bitcoin_min_tx_confirmations;
|
||||
};
|
||||
|
||||
struct chain_parameters
|
||||
|
|
@ -208,9 +207,9 @@ FC_REFLECT( graphene::chain::parameter_extension,
|
|||
(son_deregister_time)
|
||||
(son_heartbeat_frequency)
|
||||
(son_down_time)
|
||||
(son_bitcoin_min_tx_confirmations)
|
||||
(son_account)
|
||||
(btc_asset)
|
||||
(son_bitcoin_min_tx_confirmations)
|
||||
)
|
||||
|
||||
FC_REFLECT( graphene::chain::chain_parameters,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace graphene { namespace chain {
|
|||
|
||||
son_id_type son_id;
|
||||
fc::time_point_sec timestamp;
|
||||
uint32_t block_num;
|
||||
sidechain_type sidechain;
|
||||
std::string sidechain_uid;
|
||||
std::string sidechain_transaction_id;
|
||||
|
|
@ -47,7 +48,7 @@ namespace graphene { namespace chain {
|
|||
|
||||
FC_REFLECT(graphene::chain::son_wallet_deposit_create_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT(graphene::chain::son_wallet_deposit_create_operation, (fee)(payer)
|
||||
(son_id) (timestamp) (sidechain)
|
||||
(son_id) (timestamp) (block_num) (sidechain)
|
||||
(sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_currency) (sidechain_amount)
|
||||
(peerplays_from) (peerplays_to) (peerplays_asset) )
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace graphene { namespace chain {
|
|||
|
||||
son_id_type son_id;
|
||||
fc::time_point_sec timestamp;
|
||||
uint32_t block_num;
|
||||
sidechain_type sidechain;
|
||||
std::string peerplays_uid;
|
||||
std::string peerplays_transaction_id;
|
||||
|
|
@ -46,7 +47,7 @@ namespace graphene { namespace chain {
|
|||
|
||||
FC_REFLECT(graphene::chain::son_wallet_withdraw_create_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT(graphene::chain::son_wallet_withdraw_create_operation, (fee)(payer)
|
||||
(son_id) (timestamp) (sidechain)
|
||||
(son_id) (timestamp) (block_num) (sidechain)
|
||||
(peerplays_uid) (peerplays_transaction_id) (peerplays_from) (peerplays_asset)
|
||||
(withdraw_sidechain) (withdraw_address) (withdraw_currency) (withdraw_amount) )
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace graphene { namespace chain {
|
|||
static const uint8_t type_id = son_wallet_deposit_object_type;
|
||||
|
||||
time_point_sec timestamp;
|
||||
uint32_t block_num;
|
||||
sidechain_type sidechain = sidechain_type::unknown;
|
||||
std::string sidechain_uid;
|
||||
std::string sidechain_transaction_id;
|
||||
|
|
@ -61,7 +62,7 @@ namespace graphene { namespace chain {
|
|||
} } // graphene::chain
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::son_wallet_deposit_object, (graphene::db::object),
|
||||
(timestamp) (sidechain)
|
||||
(timestamp) (block_num) (sidechain)
|
||||
(sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_currency) (sidechain_amount)
|
||||
(peerplays_from) (peerplays_to) (peerplays_asset)
|
||||
(expected_reports) (received_reports)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace graphene { namespace chain {
|
|||
static const uint8_t type_id = son_wallet_withdraw_object_type;
|
||||
|
||||
time_point_sec timestamp;
|
||||
uint32_t block_num;
|
||||
sidechain_type sidechain = sidechain_type::unknown;
|
||||
std::string peerplays_uid;
|
||||
std::string peerplays_transaction_id;
|
||||
|
|
@ -60,7 +61,7 @@ namespace graphene { namespace chain {
|
|||
} } // graphene::chain
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::son_wallet_withdraw_object, (graphene::db::object),
|
||||
(timestamp) (sidechain)
|
||||
(timestamp) (block_num) (sidechain)
|
||||
(peerplays_uid) (peerplays_transaction_id) (peerplays_from) (peerplays_asset)
|
||||
(withdraw_sidechain) (withdraw_address) (withdraw_currency) (withdraw_amount)
|
||||
(expected_reports) (received_reports)
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de
|
|||
if (itr == idx.end()) {
|
||||
const auto& new_son_wallet_deposit_object = db().create<son_wallet_deposit_object>( [&]( son_wallet_deposit_object& swdo ){
|
||||
swdo.timestamp = op.timestamp;
|
||||
swdo.block_num = op.block_num;
|
||||
swdo.sidechain = op.sidechain;
|
||||
swdo.sidechain_uid = op.sidechain_uid;
|
||||
swdo.sidechain_transaction_id = op.sidechain_transaction_id;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w
|
|||
if (itr == idx.end()) {
|
||||
const auto& new_son_wallet_withdraw_object = db().create<son_wallet_withdraw_object>( [&]( son_wallet_withdraw_object& swwo ){
|
||||
swwo.timestamp = op.timestamp;
|
||||
swwo.block_num = op.block_num;
|
||||
swwo.sidechain = op.sidechain;
|
||||
swwo.peerplays_uid = op.peerplays_uid;
|
||||
swwo.peerplays_transaction_id = op.peerplays_transaction_id;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ struct info_for_vin {
|
|||
|
||||
struct sidechain_event_data {
|
||||
fc::time_point_sec timestamp;
|
||||
uint32_t block_num;
|
||||
sidechain_type sidechain;
|
||||
std::string sidechain_uid;
|
||||
std::string sidechain_transaction_id;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public:
|
|||
std::string decodepsbt(std::string const &tx_psbt);
|
||||
std::string decoderawtransaction(std::string const &tx_hex);
|
||||
std::string encryptwallet(const std::string &passphrase);
|
||||
uint64_t estimatesmartfee();
|
||||
uint64_t estimatesmartfee(uint16_t conf_target = 128);
|
||||
std::string finalizepsbt(std::string const &tx_psbt);
|
||||
std::string getaddressinfo(const std::string &address);
|
||||
std::string getblock(const std::string &block_hash, int32_t verbosity = 2);
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ bool sidechain_net_handler::approve_proposal(const proposal_id_type &proposal_id
|
|||
void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_data &sed) {
|
||||
ilog("sidechain_event_data:");
|
||||
ilog(" timestamp: ${timestamp}", ("timestamp", sed.timestamp));
|
||||
ilog(" block_num: ${block_num}", ("block_num", sed.block_num));
|
||||
ilog(" sidechain: ${sidechain}", ("sidechain", sed.sidechain));
|
||||
ilog(" sidechain_uid: ${uid}", ("uid", sed.sidechain_uid));
|
||||
ilog(" sidechain_transaction_id: ${transaction_id}", ("transaction_id", sed.sidechain_transaction_id));
|
||||
|
|
@ -99,6 +100,7 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
|||
op.payer = plugin.get_son_object(son_id).son_account;
|
||||
op.son_id = son_id;
|
||||
op.timestamp = sed.timestamp;
|
||||
op.block_num = sed.block_num;
|
||||
op.sidechain = sed.sidechain;
|
||||
op.sidechain_uid = sed.sidechain_uid;
|
||||
op.sidechain_transaction_id = sed.sidechain_transaction_id;
|
||||
|
|
@ -138,6 +140,7 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
|||
op.payer = plugin.get_son_object(son_id).son_account;
|
||||
op.son_id = son_id;
|
||||
op.timestamp = sed.timestamp;
|
||||
op.block_num = sed.block_num;
|
||||
op.sidechain = sed.sidechain;
|
||||
op.peerplays_uid = sed.sidechain_uid;
|
||||
op.peerplays_transaction_id = sed.sidechain_transaction_id;
|
||||
|
|
@ -176,6 +179,8 @@ void sidechain_net_handler::process_proposals() {
|
|||
const auto po = idx.find(proposal_id);
|
||||
if (po != idx.end()) {
|
||||
|
||||
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", (*po).id)("son_id", plugin.get_current_son_id()));
|
||||
|
||||
if (po->available_active_approvals.find(plugin.get_current_son_object().son_account) != po->available_active_approvals.end()) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -187,6 +192,8 @@ void sidechain_net_handler::process_proposals() {
|
|||
int32_t op_idx_0 = po->proposed_transaction.operations[0].which();
|
||||
chain::operation op = po->proposed_transaction.operations[0];
|
||||
|
||||
ilog("Proposal operation[0]: ${op}", ("op", op));
|
||||
|
||||
switch (op_idx_0) {
|
||||
case chain::operation::tag<chain::son_wallet_update_operation>::value: {
|
||||
should_process = true;
|
||||
|
|
@ -221,7 +228,12 @@ void sidechain_net_handler::process_proposals() {
|
|||
|
||||
default:
|
||||
should_process = false;
|
||||
ilog("==================================================");
|
||||
ilog("Proposal not processed ${po}", ("po", *po));
|
||||
ilog("==================================================");
|
||||
}
|
||||
} else {
|
||||
ilog("Proposal operations count > 1: ${po}", ("po", *po));
|
||||
}
|
||||
|
||||
if (should_process) {
|
||||
|
|
@ -334,13 +346,13 @@ void sidechain_net_handler::process_sidechain_transactions() {
|
|||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, false));
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
|
||||
ilog("Sidechain transaction to process: ${sto}", ("sto", sto));
|
||||
ilog("Sidechain transaction to process: ${sto}", ("sto", sto.id));
|
||||
|
||||
bool complete = false;
|
||||
std::string processed_sidechain_tx = process_sidechain_transaction(sto, complete);
|
||||
|
||||
if (processed_sidechain_tx.empty()) {
|
||||
wlog("Sidechain transaction not processed: ${sto}", ("sto", sto));
|
||||
wlog("Sidechain transaction not processed: ${sto}", ("sto", sto.id));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -367,13 +379,13 @@ void sidechain_net_handler::send_sidechain_transactions() {
|
|||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, true, false));
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
|
||||
ilog("Sidechain transaction to send: ${sto}", ("sto", sto));
|
||||
ilog("Sidechain transaction to send: ${sto}", ("sto", sto.id));
|
||||
|
||||
std::string sidechain_transaction = "";
|
||||
bool sent = send_sidechain_transaction(sto, sidechain_transaction);
|
||||
|
||||
if (!sent) {
|
||||
wlog("Sidechain transaction not sent: ${sto}", ("sto", sto));
|
||||
wlog("Sidechain transaction not sent: ${sto}", ("sto", sto.id));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -300,14 +300,12 @@ std::string bitcoin_rpc_client::encryptwallet(const std::string &passphrase) {
|
|||
return "";
|
||||
}
|
||||
|
||||
uint64_t bitcoin_rpc_client::estimatesmartfee() {
|
||||
static const auto confirmation_target_blocks = 6;
|
||||
|
||||
uint64_t bitcoin_rpc_client::estimatesmartfee(uint16_t conf_target) {
|
||||
const auto body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"estimatesmartfee\", "
|
||||
"\"method\": \"estimatesmartfee\", \"params\": [") +
|
||||
std::to_string(confirmation_target_blocks) + std::string("] }");
|
||||
"\"method\": \"estimatesmartfee\", \"params\": [" +
|
||||
std::to_string(conf_target) + std::string("] }"));
|
||||
|
||||
const auto reply = send_post_request(body);
|
||||
const auto reply = send_post_request(body, true);
|
||||
|
||||
if (reply.body.empty()) {
|
||||
wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));
|
||||
|
|
@ -870,6 +868,8 @@ sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
|
|||
|
||||
bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) {
|
||||
|
||||
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id()));
|
||||
|
||||
bool should_approve = false;
|
||||
|
||||
const chain::global_property_object &gpo = database.get_global_properties();
|
||||
|
|
@ -929,6 +929,11 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po)
|
|||
break;
|
||||
}
|
||||
|
||||
case chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value: {
|
||||
should_approve = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case chain::operation::tag<chain::sidechain_transaction_create_operation>::value: {
|
||||
should_approve = true;
|
||||
break;
|
||||
|
|
@ -1505,6 +1510,7 @@ void sidechain_net_handler_bitcoin::handle_event(const std::string &event_data)
|
|||
|
||||
sidechain_event_data sed;
|
||||
sed.timestamp = database.head_block_time();
|
||||
sed.block_num = database.head_block_num();
|
||||
sed.sidechain = addr_itr->sidechain;
|
||||
sed.sidechain_uid = sidechain_uid;
|
||||
sed.sidechain_transaction_id = v.out.hash_tx;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,67 @@ sidechain_net_handler_peerplays::~sidechain_net_handler_peerplays() {
|
|||
}
|
||||
|
||||
bool sidechain_net_handler_peerplays::process_proposal(const proposal_object &po) {
|
||||
return true;
|
||||
|
||||
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id()));
|
||||
|
||||
bool should_approve = false;
|
||||
|
||||
const chain::global_property_object &gpo = database.get_global_properties();
|
||||
|
||||
if (po.proposed_transaction.operations.size() == 1) {
|
||||
int32_t op_idx_0 = po.proposed_transaction.operations[0].which();
|
||||
chain::operation op = po.proposed_transaction.operations[0];
|
||||
|
||||
switch (op_idx_0) {
|
||||
|
||||
case chain::operation::tag<chain::son_wallet_update_operation>::value: {
|
||||
should_approve = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case chain::operation::tag<chain::son_wallet_deposit_process_operation>::value: {
|
||||
should_approve = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value: {
|
||||
son_wallet_withdraw_id_type swwo_id = op.get<son_wallet_withdraw_process_operation>().son_wallet_withdraw_id;
|
||||
const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>();
|
||||
const auto swwo = idx.find(swwo_id);
|
||||
if (swwo != idx.end()) {
|
||||
|
||||
uint32_t swwo_block_num = swwo->block_num;
|
||||
std::string swwo_peerplays_transaction_id = swwo->peerplays_transaction_id;
|
||||
uint32_t swwo_op_idx = std::stoll(swwo->peerplays_uid.substr(swwo->peerplays_uid.find_last_of("-") + 1));
|
||||
|
||||
const auto &block = database.fetch_block_by_number(swwo_block_num);
|
||||
|
||||
for (const auto &tx : block->transactions) {
|
||||
if (tx.id().str() == swwo_peerplays_transaction_id) {
|
||||
operation op = tx.operations[swwo_op_idx];
|
||||
transfer_operation t_op = op.get<transfer_operation>();
|
||||
|
||||
should_approve = (t_op.to == gpo.parameters.son_account()) &&
|
||||
(swwo->peerplays_from == t_op.from) &&
|
||||
(swwo->peerplays_asset == t_op.amount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case chain::operation::tag<chain::sidechain_transaction_create_operation>::value: {
|
||||
should_approve = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
should_approve = false;
|
||||
}
|
||||
}
|
||||
|
||||
return should_approve;
|
||||
}
|
||||
|
||||
void sidechain_net_handler_peerplays::process_primary_wallet() {
|
||||
|
|
@ -73,6 +133,7 @@ void sidechain_net_handler_peerplays::on_applied_block(const signed_block &b) {
|
|||
|
||||
sidechain_event_data sed;
|
||||
sed.timestamp = database.head_block_time();
|
||||
sed.block_num = database.head_block_num();
|
||||
sed.sidechain = sidechain_type::peerplays;
|
||||
sed.sidechain_uid = sidechain_uid;
|
||||
sed.sidechain_transaction_id = trx.id().str();
|
||||
|
|
|
|||
Loading…
Reference in a new issue