Compare commits

...

73 commits

Author SHA1 Message Date
Vlad Dobromyslov
96de2fb9ca Merge branch 'beatrice' into develop 2024-01-22 07:51:36 +03:00
Vlad Dobromyslov
3a55497bc3 Merge branch 'master' into beatrice 2024-01-22 07:50:11 +03:00
Vlad Dobromyslov
c08bdb7a02 Merge branch 'bug/576-new-libbitoin-version' into 'develop'
#576 - new libbitcoin version

See merge request PBSA/peerplays!262
2024-01-17 07:40:23 +00:00
Vlad Dobromyslov
afba60faaa #576 - new libbitcoin version 2024-01-15 15:35:12 +03:00
Vlad Dobromyslov
24b0327eb6 Merge branch 'feature/573-vote_recharge_gpos' into 'develop'
#573 - add vote_recharge_gpos function

See merge request PBSA/peerplays!261
2024-01-04 06:07:38 +00:00
Vlad Dobromyslov
52209dbbeb #573 - add vote_recharge_gpos function 2024-01-04 06:07:38 +00:00
Vlad Dobromyslov
0bdb826450 Merge branch 'bug/575-libbitcoin' into 'develop'
Fix memory leak in libbitcoin

See merge request PBSA/peerplays!260
2023-12-18 09:02:20 +00:00
Vlad Dobromyslov
4d161ceeb2 Fix memory leak in libbitcoin 2023-12-18 09:02:20 +00:00
Vlad Dobromyslov
fef5131a96 Merge branch 'bug/574-lookup_vote_ids' into 'develop'
#574 - Fix lookup_vote_ids for worker

See merge request PBSA/peerplays!258
2023-12-11 08:30:26 +00:00
Vlad Dobromyslov
a818edc08d #574 - Fix lookup_vote_ids for worker 2023-12-11 08:43:57 +03:00
Bobinson K B
8667155f24 Merge branch 'feature/571-restricted-symbols' into 'develop'
Feature/571 restricted symbols

See merge request PBSA/peerplays!257
2023-11-22 12:12:57 +00:00
Vlad Dobromyslov
0390556770 Feature/571 restricted symbols 2023-11-22 12:12:56 +00:00
Vlad Dobromyslov
87250fb20f Merge branch 'feature/570' into 'develop'
Resolve Fix the README to point to correct path on docker hub

See merge request PBSA/peerplays!256
2023-11-09 07:43:13 +00:00
Bobinson K B
d8e49a4d86 Resolve Fix the README to point to correct path on docker hub 2023-11-09 07:43:13 +00:00
Vlad Dobromyslov
726f9818f6 Merge branch 'feature/560-override-transfer' into 'develop'
#560 - Override Transfer

See merge request PBSA/peerplays!247
2023-11-08 19:22:11 +00:00
baris g
f679588274 #560 - Override Transfer 2023-11-08 19:22:11 +00:00
Vlad Dobromyslov
d5e0f2a53f Merge branch 'feature/569-testnet-genesis' into 'develop'
#569 - TESTNET build should connect to current test net

See merge request PBSA/peerplays!255
2023-11-08 14:05:56 +00:00
Christopher Sanborn
cb916a0473 #569 - TESTNET build should connect to current test net 2023-11-08 14:05:56 +00:00
Bobinson K B
07dad6bcf2 Merge branch 'docs/readme-build-subdirectory' into 'develop'
Update README.md - Build Peerplays in build sub-directory.

See merge request PBSA/peerplays!252
2023-11-03 07:43:38 +00:00
Bharathi Chandrasekaran
64682a079c Update README.md - Build Peerplays in build sub-directory. 2023-11-02 15:51:48 +00:00
Vlad Dobromyslov
664379a8c1 Merge branch 'beatrice' into develop 2023-10-04 15:37:54 +03:00
Vlad Dobromyslov
b79df7db07 Set HARDFORK_SON_FOR_ETHEREUM_TIME to 24 of October 2023-10-04 15:34:35 +03:00
Vlad Dobromyslov
b6e4fc5c3c Merge branch 'bug/562-fix-libbitcoin-build' into 'develop'
#562 - Point to libbitcoin tag v3.8.0

See merge request PBSA/peerplays!248
2023-10-03 10:56:46 +00:00
Vlad Dobromyslov
f6c6ac2cc8 #562 - Point to libbitcoin tag v3.8.0 2023-10-03 11:57:09 +03:00
Vlad Dobromyslov
56e15b8e80 Merge branch 'beatrice' into develop
Conflicts are resolved:
  libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp
2023-08-23 15:29:30 +03:00
Vlad Dobromyslov
60207813b0 Merge branch 'bug/559-withdraw-native-asset' into 'develop'
#559 - Don't create withdraw operation if we use native asset

See merge request PBSA/peerplays!245
2023-08-22 11:08:47 +00:00
Vlad Dobromyslov
18589ab198 #559 - Don't create withdraw operation if we use native asset 2023-08-22 12:11:56 +03:00
Vlad Dobromyslov
c1aa13192d Merge branch 'bug/558-schedule_son_processing' into 'develop'
#558 - Fix schedule_son_processing before fully sync

See merge request PBSA/peerplays!244
2023-08-09 13:28:19 +00:00
Vlad Dobromyslov
1520585b17 #558 - Fix schedule_son_processing before fully sync 2023-08-09 14:21:39 +03:00
Vlad Dobromyslov
c055445e6a Merge branch 'bug/556-split-vote_ids' into 'develop'
#556 split vote ids fix

See merge request PBSA/peerplays!243
2023-08-01 12:12:01 +00:00
Vlad Dobromyslov
675eba96bb #556 split vote ids fix 2023-08-01 12:12:01 +00:00
Vlad Dobromyslov
270751cb86 Merge branch 'bug/555-e2e-tests' into 'develop'
#555 - set test-e2e as manual

See merge request PBSA/peerplays!241
2023-07-17 09:33:13 +00:00
Vlad Dobromyslov
8e2d3cf2f6 #555 - set test-e2e as manual 2023-07-17 10:06:14 +03:00
Vlad Dobromyslov
9d687b97d2 Merge branch 'feature/554-DB_VERSION' into 'develop'
#554 - new DB_VERSION

See merge request PBSA/peerplays!239
2023-07-13 11:47:04 +00:00
Vlad Dobromyslov
113790d956 #554 - new DB_VERSION 2023-07-13 09:39:57 +03:00
Vlad Dobromyslov
e24de4f199 Merge branch 'feature/552-son-eth-hf-time' into 'develop'
#552 - NEW HARDFORK TIME FOR SON ETH

See merge request PBSA/peerplays!237
2023-07-06 15:32:52 +00:00
Vlad Dobromyslov
15ebbfe6bb #552 - NEW HARDFORK TIME FOR SON ETH 2023-07-06 15:38:20 +03:00
Vlad Dobromyslov
917e09a80b Merge branch 'bug/551-son-account-operations-count' into 'develop'
#551 - fix is_son_dereg_valid funtion

See merge request PBSA/peerplays!236
2023-07-03 19:50:59 +00:00
Vlad Dobromyslov
646b421308 #551 - fix is_son_dereg_valid funtion 2023-07-03 18:37:54 +03:00
Vlad Dobromyslov
dd2a531364 Merge branch 'bug/548-balance-discrepancies-blind-transfer' into 'develop'
#548 - Fix blind_transfer before and after ETH HARDFORK

See merge request PBSA/peerplays!234
2023-07-01 11:51:01 +00:00
Vlad Dobromyslov
ae0a895daf #548 - Fix blind_transfer before and after ETH HARDFORK 2023-07-01 11:51:01 +00:00
Vlad Dobromyslov
8530228189 Merge branch 'feature/remove-image-e2e-tests' into 'develop'
Remove unneeded docker images at the end of the pipeline

See merge request PBSA/peerplays!233
2023-06-30 18:33:26 +00:00
Milo M
85fb3fee67 Remove unneeded docker images at the end of the pipeline 2023-06-30 18:33:26 +00:00
Vlad Dobromyslov
2c9fd332d4 Merge branch 'bug/548-balance-discrepancies' into 'develop'
Fix balance discrepancies

See merge request PBSA/peerplays!231
2023-06-19 09:58:13 +00:00
Vlad Dobromyslov
fb01043e55 Fix balance discrepancies 2023-06-19 09:58:12 +00:00
Vlad Dobromyslov
a1186372d2 Merge branch 'bug/550-son_schedule_object' into 'develop'
#550 - update schedule for sidechain type

See merge request PBSA/peerplays!229
2023-06-08 05:28:30 +00:00
Vlad Dobromyslov
3a51723e51 #550 - update schedule for sidechain type 2023-06-08 05:28:30 +00:00
Vlad Dobromyslov
f23244cde0 Merge branch 'bug/549-testnet-sync' into 'develop'
Fix #549 testnet sync

See merge request PBSA/peerplays!228
2023-06-05 09:24:05 +00:00
Vlad Dobromyslov
fee7bc99fa Fix #549 testnet sync 2023-06-05 09:24:04 +00:00
Vlad Dobromyslov
6cf31b1075 Add develop branch to build target 2023-06-05 12:22:54 +03:00
Vlad Dobromyslov
97eaf4575a Merge branch 'beatrice' into develop
Conflicts are resolved:
	.gitlab-ci.yml
2023-06-05 09:32:07 +03:00
Vlad Dobromyslov
d367c308b8 Merge branch 'feature/python-e2e-tests-jm' into 'develop'
Python e2e test

See merge request PBSA/peerplays!221
2023-05-15 10:53:07 +00:00
Milos Milosevic
838a9820f1 Right order of the steps 2023-04-26 13:22:19 +02:00
Vlad Dobromyslov
3e1f38d972 Merge branch 'bug/530-eth-deposit_address' into 'develop'
#530 - fix ETH deposit_address

See merge request PBSA/peerplays!222
2023-04-21 07:15:16 +00:00
Vlad Dobromyslov
dfd3dfae09 #530 - fix ETH deposit_address 2023-04-21 09:21:17 +03:00
Milos Milosevic
1f72b4fbd6 Remove symbolic-ref call 2023-04-21 00:35:02 +02:00
Milos Milosevic
3ee2439d5b Revert changes on Dockerfile 2023-04-20 14:15:30 +02:00
Milos Milosevic
cfecfb457b Pull propper image 2023-04-19 00:23:54 +02:00
Milos Milosevic
25bbacaa88 Add docker prune before run 2023-04-18 16:17:48 +02:00
Milos Milosevic
0175a7d0ec Try the full flow 2023-04-18 13:27:00 +02:00
Milos Milosevic
fd492ca196 Run tests in the end 2023-04-18 12:53:12 +02:00
Milos Milosevic
2a6c917e4c Try through python 2023-04-18 11:14:20 +02:00
Milos Milosevic
6fe15f27b0 Try with rename 2023-04-18 09:47:10 +02:00
Milos Milosevic
d2374aeed9 Try via command line again 2023-04-18 08:13:20 +02:00
Milos Milosevic
6f792db52d Passing locally 2023-04-18 00:22:26 +02:00
Milos Milosevic
1b61016693 docker login still needed 2023-04-17 22:45:05 +02:00
Milos Milosevic
0f375777c2 Quick exec 2023-04-17 22:37:26 +02:00
Milos Milosevic
a2ce65e1ef Add pull image 2023-04-17 08:52:41 +02:00
Milos Milosevic
432876a677 Try different approach 2023-04-16 23:49:51 +02:00
Vlad Dobromyslov
948e7dd5e4 Merge branch 'bug/524-eth-mainnet-tr' into 'develop'
Bug/524-eth-mainnet-tr

See merge request PBSA/peerplays!219
2023-03-29 09:38:55 +00:00
Vlad Dobromyslov
b21f9c4282 Bug/524-eth-mainnet-tr 2023-03-29 09:38:54 +00:00
Vlad Dobromyslov
1586531e13 Merge branch 'bug/develop-518-last_voting_time' into 'develop'
#518 - update update_vote_time when voting for SON

See merge request PBSA/peerplays!217
2023-03-17 09:31:24 +00:00
Vlad Dobromyslov
8e0e20eb6f #518 - update update_vote_time when voting for SON 2023-03-17 11:33:33 +03:00
14 changed files with 1042 additions and 10417 deletions

View file

@ -1,4 +1,5 @@
# Defines Peerplays library target.
set(CMAKE_POLICY_DEFAULT_CMP0057 NEW)
project( Peerplays )
cmake_minimum_required( VERSION 2.8.12 )
@ -9,6 +10,9 @@ set( GUI_CLIENT_EXECUTABLE_NAME Peerplays )
set( CUSTOM_URL_SCHEME "gcs" )
set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" )
add_definitions("-DBOOST_ALLOW_DEPRECATED_HEADERS")
add_definitions("-DBOOST_BIND_GLOBAL_PLACEHOLDERS")
# http://stackoverflow.com/a/18369825
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)

View file

@ -57,9 +57,9 @@ WORKDIR /home/peerplays/src
#===============================================================================
RUN \
wget https://boostorg.jfrog.io/artifactory/main/release/1.72.0/source/boost_1_72_0.tar.gz && \
tar -xzf boost_1_72_0.tar.gz && \
cd boost_1_72_0 && \
wget https://sourceforge.net/projects/boost/files/boost/1.73.0/boost_1_73_0.tar.gz && \
tar -xzf boost_1_73_0.tar.gz && \
cd boost_1_73_0 && \
./bootstrap.sh && \
./b2 install && \
ldconfig && \
@ -134,8 +134,11 @@ RUN \
libsodium-dev
RUN \
git clone --branch version3.8.0 --depth 1 https://gitlab.com/PBSA/peerplays-1.0/libbitcoin-explorer.git && \
cd libbitcoin-explorer && \
git clone https://github.com/libbitcoin/libbitcoin-build.git && \
cd libbitcoin-build && \
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d && \
./generate3.sh && \
cd ../libbitcoin-explorer && \
./install.sh && \
ldconfig && \
rm -rf /home/peerplays/src/*

View file

@ -57,9 +57,9 @@ WORKDIR /home/peerplays/src
#===============================================================================
RUN \
wget https://boostorg.jfrog.io/artifactory/main/release/1.72.0/source/boost_1_72_0.tar.gz && \
tar -xzf boost_1_72_0.tar.gz && \
cd boost_1_72_0 && \
wget https://sourceforge.net/projects/boost/files/boost/1.73.0/boost_1_73_0.tar.gz && \
tar -xzf boost_1_73_0.tar.gz && \
cd boost_1_73_0 && \
./bootstrap.sh && \
./b2 install && \
ldconfig && \
@ -134,8 +134,11 @@ RUN \
libsodium-dev
RUN \
git clone --branch version3.8.0 --depth 1 https://gitlab.com/PBSA/peerplays-1.0/libbitcoin-explorer.git && \
cd libbitcoin-explorer && \
git clone https://github.com/libbitcoin/libbitcoin-build.git && \
cd libbitcoin-build && \
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d && \
./generate3.sh && \
cd ../libbitcoin-explorer && \
./install.sh && \
ldconfig && \
rm -rf /home/peerplays/src/*

View file

@ -22,9 +22,9 @@ sudo apt-get install \
Boost libraries setup:
```
wget https://boostorg.jfrog.io/artifactory/main/release/1.72.0/source/boost_1_72_0.tar.gz
tar -xzf boost_1_72_0.tar.gz boost_1_72_0
cd boost_1_72_0
wget https://sourceforge.net/projects/boost/files/boost/1.73.0/boost_1_73_0.tar.gz
tar -xzf boost_1_73_0.tar.gz boost_1_73_0
cd boost_1_73_0
./bootstrap.sh
./b2
sudo ./b2 install
@ -77,8 +77,11 @@ sudo ldconfig
libbitcoin-explorer setup:
```
git clone --branch version3.8.0 --depth 1 https://gitlab.com/PBSA/peerplays-1.0/libbitcoin-explorer.git
cd libbitcoin-explorer
git clone https://github.com/libbitcoin/libbitcoin-build.git
cd libbitcoin-build
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d
./generate3.sh
cd ../libbitcoin-explorer
sudo ./install.sh
sudo ldconfig
```
@ -114,10 +117,14 @@ cd peerplays
git submodule update --init --recursive
# If you want to build Mainnet node
cmake -DCMAKE_BUILD_TYPE=Release
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
# If you want to build Testnet node
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_PEERPLAYS_TESTNET=1
mkdir build-testnet
cd build-testnet
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_PEERPLAYS_TESTNET=1 ..
# Update -j flag depending on your current system specs;
# Recommended 4GB of RAM per 1 CPU core
@ -143,7 +150,7 @@ sudo usermod -a -G docker $USER
### Official docker image for Peerplas Mainnet
```
docker pull datasecuritynode/peerplays:latest
docker pull peerplays/peerplays:latest
```
### Building docker images manually

File diff suppressed because it is too large Load diff

View file

@ -366,10 +366,9 @@ vector<operation_history_object> history_api::get_account_history(const std::str
_app.elasticsearch_thread = std::make_shared<fc::thread>("elasticsearch");
return _app.elasticsearch_thread->async([&es, &account, &stop, &limit, &start]() {
return es->get_account_history(account, stop, limit, start);
},
"thread invoke for method " BOOST_PP_STRINGIZE(method_name))
.wait();
return es->get_account_history(account, stop, limit, start);
},
"thread invoke for method " BOOST_PP_STRINGIZE(method_name)).wait();
}
}

View file

@ -836,6 +836,11 @@ void application::set_program_options(boost::program_options::options_descriptio
std::vector<string> seed_nodes = {
#ifdef BUILD_PEERPLAYS_TESTNET
"134.209.113.44:19777",
"165.232.84.196:19777",
"24.199.104.149:19777",
"92.119.90.95:19777",
"test-api.i9networks.net.br:19777"
#else
"51.222.110.110:9777",
"95.216.90.243:9777",

View file

@ -13,10 +13,10 @@
namespace graphene { namespace peerplays_sidechain {
libbitcoin_client::libbitcoin_client(std::string url) :
libbitcoin_client::libbitcoin_client(const std::string &url) :
obelisk_client(LIBBITCOIN_SERVER_TIMEOUT, LIBBITCOIN_SERVER_RETRIES) {
std::string reg_expr = "^((?P<Protocol>https|http|tcp):\\/\\/)?(?P<Host>[a-zA-Z0-9\\-\\.]+)(:(?P<Port>\\d{1,5}))?(?P<Target>\\/.+)?";
const std::string reg_expr = "^((?P<Protocol>https|http|tcp):\\/\\/)?(?P<Host>[a-zA-Z0-9\\-\\.]+)(:(?P<Port>\\d{1,5}))?(?P<Target>\\/.+)?";
boost::xpressive::sregex sr = boost::xpressive::sregex::compile(reg_expr);
boost::xpressive::smatch sm;
@ -38,10 +38,10 @@ libbitcoin_client::libbitcoin_client(std::string url) :
}
}
uint16_t port_num = std::stoi(port);
std::string final_url = protocol + "://" + host;
const auto port_num = static_cast<uint16_t>(std::stoi(port));
const std::string final_url = protocol + "://" + host;
libbitcoin::config::endpoint address(final_url, port_num);
const libbitcoin::config::endpoint address(final_url, port_num);
libbitcoin::client::connection_type connection;
connection.retries = LIBBITCOIN_SERVER_RETRIES;
@ -54,22 +54,20 @@ libbitcoin_client::libbitcoin_client(std::string url) :
is_connected = true;
}
std::string libbitcoin_client::send_transaction(std::string tx) {
std::string libbitcoin_client::send_transaction(const std::string &tx) {
std::string res;
auto error_handler = [&](const std::error_code &ec) {
auto error_handler = [](const std::error_code &ec) {
elog("error on sending bitcoin transaction ${error_code}", ("error_code", ec.message()));
};
auto result_handler = [&](libbitcoin::code result_code) {
auto result_handler = [&res](libbitcoin::code result_code) {
ilog("result code on sending transaction ${result_code}", ("result_code", result_code.message()));
res = std::to_string(result_code.value());
};
libbitcoin::explorer::config::transaction transaction(tx);
libbitcoin::chain::transaction trx;
const libbitcoin::explorer::config::transaction transaction(tx);
// This validates the tx, submits it to local tx pool, and notifies peers.
obelisk_client.transaction_pool_broadcast(error_handler, result_handler, transaction);
@ -78,22 +76,22 @@ std::string libbitcoin_client::send_transaction(std::string tx) {
return res;
}
libbitcoin::chain::output::list libbitcoin_client::get_transaction(std::string tx_id, std::string &tx_hash, uint32_t &confirmitions) {
libbitcoin::chain::output::list libbitcoin_client::get_transaction(const std::string &tx_id, std::string &tx_hash, uint32_t &confirmitions) {
libbitcoin::chain::output::list outs;
auto error_handler = [&](const std::error_code &ec) {
auto error_handler = [&tx_id](const std::error_code &ec) {
elog("error on fetch_trx_by_hash: ${hash} ${error_code}", ("hash", tx_id)("error_code", ec.message()));
};
auto transaction_handler = [&](const libbitcoin::chain::transaction &tx_handler) {
auto transaction_handler = [&tx_hash, &confirmitions, &outs](const libbitcoin::chain::transaction &tx_handler) {
tx_hash = libbitcoin::config::hash256(tx_handler.hash(false)).to_string();
// TODO try to find this value (confirmitions)
confirmitions = 1;
outs = tx_handler.outputs();
};
libbitcoin::hash_digest hash = libbitcoin::config::hash256(tx_id);
const libbitcoin::hash_digest hash = libbitcoin::config::hash256(tx_id);
// obelisk_client.blockchain_fetch_transaction (error_handler, transaction_handler,hash);
obelisk_client.blockchain_fetch_transaction2(error_handler, transaction_handler, hash);
@ -103,14 +101,14 @@ libbitcoin::chain::output::list libbitcoin_client::get_transaction(std::string t
return outs;
}
std::vector<list_unspent_replay> libbitcoin_client::listunspent(std::string address, double amount) {
std::vector<list_unspent_replay> libbitcoin_client::listunspent(const std::string &address, double amount) {
std::vector<list_unspent_replay> result;
auto error_handler = [&](const std::error_code &ec) {
auto error_handler = [](const std::error_code &ec) {
elog("error on list_unspent ${error_code}", ("error_code", ec.message()));
};
auto replay_handler = [&](const libbitcoin::chain::points_value &points) {
auto replay_handler = [&result](const libbitcoin::chain::points_value &points) {
for (auto &point : points.points) {
list_unspent_replay output;
output.hash = libbitcoin::config::hash256(point.hash()).to_string();
@ -120,8 +118,8 @@ std::vector<list_unspent_replay> libbitcoin_client::listunspent(std::string addr
}
};
libbitcoin::wallet::payment_address payment_address(address);
uint64_t satoshi = 100000000 * amount;
const libbitcoin::wallet::payment_address payment_address(address);
const auto satoshi = static_cast<uint64_t>(100000000 * amount);
obelisk_client.blockchain_fetch_unspent_outputs(error_handler,
replay_handler, payment_address, satoshi, libbitcoin::wallet::select_outputs::algorithm::individual);
@ -135,12 +133,12 @@ bool libbitcoin_client::get_is_test_net() {
bool result = false;
auto error_handler = [&](const std::error_code &ec) {
auto error_handler = [](const std::error_code &ec) {
elog("error on fetching genesis block ${error_code}", ("error_code", ec.message()));
};
auto block_header_handler = [&](const libbitcoin::chain::header &block_header) {
std::string hash_str = libbitcoin::config::hash256(block_header.hash()).to_string();
auto block_header_handler = [&result](const libbitcoin::chain::header &block_header) {
const std::string hash_str = libbitcoin::config::hash256(block_header.hash()).to_string();
if (hash_str == GENESIS_TESTNET_HASH || hash_str == GENESIS_REGTEST_HASH) {
result = true;
}
@ -152,7 +150,7 @@ bool libbitcoin_client::get_is_test_net() {
return result;
}
uint64_t libbitcoin_client::get_fee_from_trx(libbitcoin::chain::transaction trx) {
uint64_t libbitcoin_client::get_fee_from_trx(const libbitcoin::chain::transaction &trx) {
bool general_fee_est_error = false;
if (trx.is_coinbase()) {
@ -169,15 +167,15 @@ uint64_t libbitcoin_client::get_fee_from_trx(libbitcoin::chain::transaction trx)
// fetch the trx to get total input value
uint64_t total_input_value = 0;
auto transaction_handler = [&](const libbitcoin::chain::transaction &tx_handler) {
auto transaction_handler = [&prev_out_trxs, &total_input_value](const libbitcoin::chain::transaction &tx_handler) {
std::vector<uint32_t> indexes = prev_out_trxs[tx_handler.hash()];
for (auto &index : indexes) {
for (const auto &index : indexes) {
total_input_value += tx_handler.outputs()[index].value();
}
};
auto error_handler = [&](const std::error_code &ec) {
auto error_handler = [&general_fee_est_error](const std::error_code &ec) {
elog("error on fetching trx ${error_code}", ("error_code", ec.message()));
general_fee_est_error = true;
};
@ -201,12 +199,12 @@ uint64_t libbitcoin_client::get_fee_from_trx(libbitcoin::chain::transaction trx)
}
}
uint64_t libbitcoin_client::get_average_fee_from_trxs(std::vector<libbitcoin::chain::transaction> trx_list) {
uint64_t libbitcoin_client::get_average_fee_from_trxs(const std::vector<libbitcoin::chain::transaction> &trx_list) {
std::vector<uint64_t> fee_per_trxs;
for (auto &trx : trx_list) {
uint64_t fee = get_fee_from_trx(trx);
const uint64_t fee = get_fee_from_trx(trx);
if (fee > 0) {
fee_per_trxs.emplace_back(fee);
}

View file

@ -5,13 +5,13 @@
#include <bitcoin/system/chain/block.hpp>
#include <boost/signals2.hpp>
#include <mutex>
#define LIBBITCOIN_SERVER_TIMEOUT (10)
#define LIBBITCOIN_SERVER_RETRIES (100)
#define DEAFULT_LIBBITCOIN_TRX_FEE (20000)
#define MAX_TRXS_IN_MEMORY_POOL (30000)
#define MAX_TRXS_IN_MEMORY_POOL (10000)
#define MIN_TRXS_IN_BUCKET (100)
#define MAX_THREADS (5)
#define GENESIS_MAINNET_HASH "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
#define GENESIS_TESTNET_HASH "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
@ -19,9 +19,6 @@
namespace graphene { namespace peerplays_sidechain {
typedef std::function<void(const libbitcoin::chain::block &)>
block_update_handler;
struct list_unspent_replay {
std::string hash;
uint64_t value;
@ -30,12 +27,12 @@ struct list_unspent_replay {
class libbitcoin_client {
public:
libbitcoin_client(std::string url);
std::string send_transaction(const std::string tx);
libbitcoin::chain::output::list get_transaction(std::string tx_id, std::string &tx_hash, uint32_t &confirmitions);
std::vector<list_unspent_replay> listunspent(std::string address, double amount);
uint64_t get_average_fee_from_trxs(std::vector<libbitcoin::chain::transaction> trx_list);
uint64_t get_fee_from_trx(libbitcoin::chain::transaction trx);
explicit libbitcoin_client(const std::string &url);
std::string send_transaction(const std::string &tx);
libbitcoin::chain::output::list get_transaction(const std::string &tx_id, std::string &tx_hash, uint32_t &confirmitions);
std::vector<list_unspent_replay> listunspent(const std::string &address, double amount);
uint64_t get_average_fee_from_trxs(const std::vector<libbitcoin::chain::transaction> &trx_list);
uint64_t get_fee_from_trx(const libbitcoin::chain::transaction &trx);
bool get_is_test_net();
private:

View file

@ -3,6 +3,8 @@
#include <mutex>
#include <vector>
#include <boost/bind.hpp>
using namespace boost::placeholders;
#include <boost/program_options.hpp>
#include <graphene/chain/proposal_object.hpp>

View file

@ -63,6 +63,7 @@ public:
std::string label;
};
virtual ~bitcoin_client_base() = default;
virtual uint64_t estimatesmartfee(uint16_t conf_target = 1) = 0;
virtual std::vector<info_for_vin> getblock(const block_data &block, int32_t verbosity = 2) = 0;
virtual btc_tx getrawtransaction(const std::string &txid, const bool verbose = false) = 0;
@ -70,8 +71,8 @@ public:
virtual std::string getblockchaininfo() = 0;
virtual std::vector<btc_txout> listunspent_by_address_and_amount(const std::string &address, double transfer_amount, const uint32_t minconf = 1, const uint32_t maxconf = 9999999) = 0;
virtual std::string sendrawtransaction(const std::string &tx_hex) = 0;
virtual void importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan = true) {
;
virtual void importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan = true){
//! Default implementation does nothing
};
virtual std::string loadwallet(const std::string &filename) {
return "";
@ -96,44 +97,37 @@ protected:
};
class bitcoin_rpc_client : public bitcoin_client_base, public rpc_client {
public:
public:
bitcoin_rpc_client(const std::vector<rpc_credentials> &_credentials, bool _debug_rpc_calls, bool _simulate_connection_reselection);
uint64_t estimatesmartfee(uint16_t conf_target = 1);
std::vector<info_for_vin> getblock(const block_data &block, int32_t verbosity = 2);
btc_tx getrawtransaction(const std::string &txid, const bool verbose = false);
void getnetworkinfo();
std::string getblockchaininfo();
void importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan = true);
uint64_t estimatesmartfee(uint16_t conf_target = 1) final;
std::vector<info_for_vin> getblock(const block_data &block, int32_t verbosity = 2) final;
btc_tx getrawtransaction(const std::string &txid, const bool verbose = false) final;
void getnetworkinfo() final;
std::string getblockchaininfo() final;
void importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan = true) final;
std::vector<btc_txout> listunspent(const uint32_t minconf = 1, const uint32_t maxconf = 9999999);
std::vector<btc_txout> listunspent_by_address_and_amount(const std::string &address, double transfer_amount, const uint32_t minconf = 1, const uint32_t maxconf = 9999999);
std::string loadwallet(const std::string &filename);
std::string sendrawtransaction(const std::string &tx_hex);
std::string walletlock();
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
std::vector<btc_txout> listunspent_by_address_and_amount(const std::string &address, double transfer_amount, const uint32_t minconf = 1, const uint32_t maxconf = 9999999) final;
std::string loadwallet(const std::string &filename) final;
std::string sendrawtransaction(const std::string &tx_hex) final;
std::string walletlock() final;
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60) final;
virtual uint64_t ping(rpc_connection &conn) const override;
uint64_t ping(rpc_connection &conn) const final;
private:
std::string ip;
std::string user;
std::string password;
std::string wallet_name;
std::string wallet_password;
uint32_t bitcoin_major_version;
};
class bitcoin_libbitcoin_client : public bitcoin_client_base, public libbitcoin_client {
public:
bitcoin_libbitcoin_client(std::string url);
uint64_t estimatesmartfee(uint16_t conf_target = 1);
std::vector<info_for_vin> getblock(const block_data &block, int32_t verbosity = 2);
btc_tx getrawtransaction(const std::string &txid, const bool verbose = false);
void getnetworkinfo();
std::string getblockchaininfo();
std::vector<btc_txout> listunspent_by_address_and_amount(const std::string &address, double transfer_amount, const uint32_t minconf = 1, const uint32_t maxconf = 9999999);
std::string sendrawtransaction(const std::string &tx_hex);
explicit bitcoin_libbitcoin_client(const std::string &url);
uint64_t estimatesmartfee(uint16_t conf_target = 1) final;
std::vector<info_for_vin> getblock(const block_data &block, int32_t verbosity = 2) final;
btc_tx getrawtransaction(const std::string &txid, const bool verbose = false) final;
void getnetworkinfo() final;
std::string getblockchaininfo() final;
std::vector<btc_txout> listunspent_by_address_and_amount(const std::string &address, double transfer_amount, const uint32_t minconf = 1, const uint32_t maxconf = 9999999) final;
std::string sendrawtransaction(const std::string &tx_hex) final;
private:
bool is_test_net = false;
@ -145,13 +139,13 @@ private:
class zmq_listener_base {
public:
virtual ~zmq_listener_base(){};
zmq_listener_base(std::string _ip, uint32_t _block_zmq_port, uint32_t _trx_zmq_port = 0) {
ip = _ip;
block_zmq_port = _block_zmq_port;
trx_zmq_port = _trx_zmq_port;
stopped = false;
};
zmq_listener_base(const std::string &_ip, uint32_t _block_zmq_port, uint32_t _trx_zmq_port = 0) :
ip(_ip),
block_zmq_port(_block_zmq_port),
trx_zmq_port(_trx_zmq_port),
stopped(false){};
virtual ~zmq_listener_base() = default;
virtual void start() = 0;
boost::signals2::signal<void(const block_data &)> block_event_received;
boost::signals2::signal<void(const libbitcoin::chain::transaction &)> trx_event_received;
@ -167,9 +161,9 @@ protected:
class zmq_listener : public zmq_listener_base {
public:
zmq_listener(std::string _ip, uint32_t _block_zmq_port, uint32_t _trx_zmq_port = 0);
virtual ~zmq_listener();
void start();
zmq_listener(const std::string &_ip, uint32_t _block_zmq_port, uint32_t _trx_zmq_port = 0);
~zmq_listener() final;
void start() final;
private:
void handle_zmq();
@ -181,9 +175,9 @@ private:
class zmq_listener_libbitcoin : public zmq_listener_base {
public:
zmq_listener_libbitcoin(std::string _ip, uint32_t _block_zmq_port = 9093, uint32_t _trx_zmq_port = 9094);
virtual ~zmq_listener_libbitcoin();
void start();
zmq_listener_libbitcoin(const std::string &_ip, uint32_t _block_zmq_port = 9093, uint32_t _trx_zmq_port = 9094);
~zmq_listener_libbitcoin() final;
void start() final;
private:
void handle_block();
@ -192,6 +186,7 @@ private:
libbitcoin::protocol::zmq::context block_context;
libbitcoin::protocol::zmq::socket block_socket;
libbitcoin::protocol::zmq::poller block_poller;
libbitcoin::protocol::zmq::context trx_context;
libbitcoin::protocol::zmq::socket trx_socket;
libbitcoin::protocol::zmq::poller trx_poller;
@ -202,17 +197,17 @@ private:
class sidechain_net_handler_bitcoin : public sidechain_net_handler {
public:
sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
virtual ~sidechain_net_handler_bitcoin();
~sidechain_net_handler_bitcoin() final;
bool process_proposal(const proposal_object &po);
void process_primary_wallet();
void process_sidechain_addresses();
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);
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
virtual optional<asset> estimate_withdrawal_transaction_fee() const override;
bool process_proposal(const proposal_object &po) final;
void process_primary_wallet() final;
void process_sidechain_addresses() final;
bool process_deposit(const son_wallet_deposit_object &swdo) final;
bool process_withdrawal(const son_wallet_withdraw_object &swwo) final;
std::string process_sidechain_transaction(const sidechain_transaction_object &sto) final;
std::string send_sidechain_transaction(const sidechain_transaction_object &sto) final;
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) final;
optional<asset> estimate_withdrawal_transaction_fee() const final;
private:
std::vector<rpc_credentials> _rpc_credentials;
@ -229,10 +224,16 @@ private:
fc::future<void> on_changed_objects_task;
bitcoin::bitcoin_address::network network_type;
uint32_t bitcoin_major_version;
std::mutex event_handler_mutex;
typedef std::lock_guard<decltype(event_handler_mutex)> scoped_lock;
using scoped_lock = std::lock_guard<decltype(event_handler_mutex)>;
boost::asio::io_context io_context_block;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work_guard_block;
boost::thread_group thread_pool_block;
boost::asio::io_context io_context_trx;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work_guard_trx;
boost::thread_group thread_pool_trx;
std::string create_primary_wallet_address(const std::vector<son_sidechain_info> &son_pubkeys);
@ -240,7 +241,7 @@ private:
std::string create_deposit_transaction(const son_wallet_deposit_object &swdo);
std::string create_withdrawal_transaction(const son_wallet_withdraw_object &swwo);
std::string create_transaction(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs, std::string &redeem_script);
std::string create_transaction(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs, const std::string &redeem_script);
std::string sign_transaction(const sidechain_transaction_object &sto);
std::string send_transaction(const sidechain_transaction_object &sto);
@ -249,6 +250,8 @@ private:
std::string get_redeemscript_for_userdeposit(const std::string &user_address);
void on_changed_objects(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts);
void on_changed_objects_cb(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts);
void init_thread_pool(boost::asio::io_context &io_context, boost::thread_group &thread_pool, int num_threads);
};
}} // namespace graphene::peerplays_sidechain

View file

@ -54,8 +54,8 @@ uint64_t bitcoin_rpc_client::estimatesmartfee(uint16_t conf_target) {
}
std::vector<info_for_vin> bitcoin_rpc_client::getblock(const block_data &block, int32_t verbosity) {
std::string params = std::string("[\"") + block.block_hash + std::string("\",") + std::to_string(verbosity) + std::string("]");
std::string str = send_post_request("getblock", params, debug_rpc_calls);
const std::string params = std::string("[\"") + block.block_hash + std::string("\",") + std::to_string(verbosity) + std::string("]");
const std::string str = send_post_request("getblock", params, debug_rpc_calls);
std::vector<info_for_vin> result;
if (str.empty()) {
@ -66,7 +66,7 @@ std::vector<info_for_vin> bitcoin_rpc_client::getblock(const block_data &block,
boost::property_tree::ptree json;
boost::property_tree::read_json(ss, json);
auto json_result = json.get_child_optional("result");
const auto json_result = json.get_child_optional("result");
for (const auto &tx_child : json_result.get().get_child("tx")) {
const auto &tx = tx_child.second;
@ -103,8 +103,8 @@ std::vector<info_for_vin> bitcoin_rpc_client::getblock(const block_data &block,
}
void bitcoin_rpc_client::getnetworkinfo() {
std::string params = std::string("[]");
std::string str = send_post_request("getnetworkinfo", params, debug_rpc_calls);
static const std::string params = std::string("[]");
const std::string str = send_post_request("getnetworkinfo", params, debug_rpc_calls);
std::stringstream network_info_ss(str);
boost::property_tree::ptree network_info_json;
@ -115,8 +115,8 @@ void bitcoin_rpc_client::getnetworkinfo() {
}
btc_tx bitcoin_rpc_client::getrawtransaction(const std::string &txid, const bool verbose) {
std::string params = std::string("[\"") + txid + std::string("\",") + (verbose ? "true" : "false") + std::string("]");
std::string str = send_post_request("getrawtransaction", params, debug_rpc_calls);
const std::string params = std::string("[\"") + txid + std::string("\",") + (verbose ? "true" : "false") + std::string("]");
const std::string str = send_post_request("getrawtransaction", params, debug_rpc_calls);
btc_tx tx;
@ -126,10 +126,10 @@ btc_tx bitcoin_rpc_client::getrawtransaction(const std::string &txid, const bool
if (tx_json.count("error") && tx_json.get_child("error").empty()) {
std::string tx_txid = tx_json.get<std::string>("result.txid");
uint32_t tx_confirmations = tx_json.get<uint32_t>("result.confirmations");
const std::string tx_txid = tx_json.get<std::string>("result.txid");
const uint32_t tx_confirmations = tx_json.get<uint32_t>("result.confirmations");
tx.tx_txid = tx_txid;
tx.tx_txid = std::move(tx_txid);
tx.tx_confirmations = tx_confirmations;
for (auto &input : tx_json.get_child("result.vout")) {
@ -332,14 +332,14 @@ bool bitcoin_rpc_client::walletpassphrase(const std::string &passphrase, uint32_
else
return true;
}
bitcoin_libbitcoin_client::bitcoin_libbitcoin_client(std::string url) :
bitcoin_libbitcoin_client::bitcoin_libbitcoin_client(const std::string &url) :
libbitcoin_client(url) {
estimate_fee_ext = std::unique_ptr<estimate_fee_external>(new estimate_fee_external());
}
uint64_t bitcoin_libbitcoin_client::estimatesmartfee(uint16_t conf_target) {
std::vector<std::pair<std::string, uint64_t>> fees = estimate_fee_ext->get_fee_external(conf_target);
const std::vector<std::pair<std::string, uint64_t>> fees = estimate_fee_ext->get_fee_external(conf_target);
std::vector<uint64_t> accumulated_fees;
for (auto &external_fees : fees) {
if (external_fees.second != 0) {
@ -357,28 +357,30 @@ uint64_t bitcoin_libbitcoin_client::estimatesmartfee(uint16_t conf_target) {
std::vector<info_for_vin> bitcoin_libbitcoin_client::getblock(const block_data &block, int32_t verbosity) {
std::unique_lock<std::mutex> lck(libbitcoin_event_mutex);
{
std::unique_lock<std::mutex> lck(libbitcoin_event_mutex);
// estimate fee
const auto &block_trxs = block.block.transactions();
std::vector<libbitcoin::chain::transaction> bucket_trxs;
for (auto &mem_pool_trx : trx_memory_pool) {
for (auto &trx : block_trxs) {
if (mem_pool_trx.hash() == trx.hash()) {
bucket_trxs.emplace_back(mem_pool_trx);
break;
// estimate fee
const auto &block_trxs = block.block.transactions();
std::vector<libbitcoin::chain::transaction> bucket_trxs;
for (auto &mem_pool_trx : trx_memory_pool) {
for (auto &trx : block_trxs) {
if (mem_pool_trx.hash() == trx.hash()) {
bucket_trxs.emplace_back(mem_pool_trx);
break;
}
}
}
}
uint64_t average_fee = get_average_fee_from_trxs(bucket_trxs);
if (average_fee > 0 && bucket_trxs.size() >= MIN_TRXS_IN_BUCKET) {
current_internal_fee = average_fee;
}
const uint64_t average_fee = get_average_fee_from_trxs(bucket_trxs);
if (average_fee > 0 && bucket_trxs.size() >= MIN_TRXS_IN_BUCKET) {
current_internal_fee = average_fee;
}
// We could consider accumulation which could spread to multiple blocks for better metric
// for now we only keep tracking for not confirmed transaction until we get next block
trx_memory_pool.clear();
// We could consider accumulation which could spread to multiple blocks for better metric
// for now we only keep tracking for not confirmed transaction until we get next block
trx_memory_pool.clear();
}
std::vector<info_for_vin> result;
@ -481,8 +483,8 @@ std::string bitcoin_libbitcoin_client::getblockchaininfo() {
std::vector<btc_txout> bitcoin_libbitcoin_client::listunspent_by_address_and_amount(const std::string &address, double transfer_amount, const uint32_t minconf, const uint32_t maxconf) {
std::vector<btc_txout> result;
std::vector<list_unspent_replay> outputs = listunspent(address, transfer_amount);
for (auto &output : outputs) {
const std::vector<list_unspent_replay> outputs = listunspent(address, transfer_amount);
for (const auto &output : outputs) {
btc_txout txo;
txo.txid_ = output.hash;
txo.out_num_ = output.index;
@ -494,12 +496,12 @@ std::vector<btc_txout> bitcoin_libbitcoin_client::listunspent_by_address_and_amo
}
std::string bitcoin_libbitcoin_client::sendrawtransaction(const std::string &tx_hex) {
std::string res = send_transaction(tx_hex);
const std::string res = send_transaction(tx_hex);
return res;
}
uint64_t bitcoin_rpc_client::ping(rpc_connection &conn) const {
std::string str = send_post_request(conn, "getblockcount", "[]", debug_rpc_calls);
const std::string str = send_post_request(conn, "getblockcount", "[]", debug_rpc_calls);
if (str.length() > 0)
return std::stoll(str);
return std::numeric_limits<uint64_t>::max();
@ -507,7 +509,7 @@ uint64_t bitcoin_rpc_client::ping(rpc_connection &conn) const {
// =============================================================================
zmq_listener::zmq_listener(std::string _ip, uint32_t _zmq_block_port, uint32_t _zmq_trx_port) :
zmq_listener::zmq_listener(const std::string &_ip, uint32_t _zmq_block_port, uint32_t _zmq_trx_port) :
zmq_listener_base(_ip, _zmq_block_port, _zmq_trx_port),
ctx(1),
socket(ctx, ZMQ_SUB) {
@ -577,7 +579,7 @@ void zmq_listener::handle_zmq() {
// =============================================================================
zmq_listener_libbitcoin::zmq_listener_libbitcoin(std::string _ip, uint32_t _block_zmq_port, uint32_t _trx_zmq_port) :
zmq_listener_libbitcoin::zmq_listener_libbitcoin(const std::string &_ip, uint32_t _block_zmq_port, uint32_t _trx_zmq_port) :
zmq_listener_base(_ip, _block_zmq_port, _trx_zmq_port),
block_socket(block_context, libbitcoin::protocol::zmq::socket::role::subscriber),
trx_socket(trx_context, libbitcoin::protocol::zmq::socket::role::subscriber) {
@ -590,7 +592,7 @@ zmq_listener_libbitcoin::~zmq_listener_libbitcoin() {
}
void zmq_listener_libbitcoin::start() {
std::string endpoint_address = "tcp://" + ip;
const std::string endpoint_address = "tcp://" + ip;
libbitcoin::config::endpoint block_address(endpoint_address, block_zmq_port);
libbitcoin::config::endpoint trx_address(endpoint_address, trx_zmq_port);
@ -662,18 +664,20 @@ void zmq_listener_libbitcoin::handle_block() {
// =============================================================================
sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
sidechain_net_handler(sidechain_type::bitcoin, _plugin, options) {
sidechain_net_handler(sidechain_type::bitcoin, _plugin, options),
work_guard_block(io_context_block.get_executor()),
work_guard_trx(io_context_trx.get_executor()) {
if (options.count("debug-rpc-calls")) {
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
}
bool simulate_connection_reselection = options.at("simulate-rpc-connection-reselection").as<bool>();
const bool simulate_connection_reselection = options.at("simulate-rpc-connection-reselection").as<bool>();
std::vector<std::string> ips = options.at("bitcoin-node-ip").as<std::vector<std::string>>();
const std::vector<std::string> ips = options.at("bitcoin-node-ip").as<std::vector<std::string>>();
bitcoin_node_zmq_port = options.at("bitcoin-node-zmq-port").as<uint32_t>();
uint32_t rpc_port = options.at("bitcoin-node-rpc-port").as<uint32_t>();
std::string rpc_user = options.at("bitcoin-node-rpc-user").as<std::string>();
std::string rpc_password = options.at("bitcoin-node-rpc-password").as<std::string>();
const uint32_t rpc_port = options.at("bitcoin-node-rpc-port").as<uint32_t>();
const std::string rpc_user = options.at("bitcoin-node-rpc-user").as<std::string>();
const std::string rpc_password = options.at("bitcoin-node-rpc-password").as<std::string>();
if (options.count("use-bitcoind-client")) {
use_bitcoind_client = options.at("use-bitcoind-client").as<bool>();
@ -732,7 +736,7 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain
listener = std::unique_ptr<zmq_listener_libbitcoin>(new zmq_listener_libbitcoin(libbitcoin_server_ip, libbitcoin_block_zmq_port, libbitcoin_trx_zmq_port));
}
std::string chain_info = bitcoin_client->getblockchaininfo();
const std::string chain_info = bitcoin_client->getblockchaininfo();
using namespace bitcoin;
network_type = bitcoin_address::network::mainnet;
@ -745,12 +749,15 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain
bitcoin_client->getnetworkinfo();
init_thread_pool(io_context_block, thread_pool_block, MAX_THREADS);
init_thread_pool(io_context_trx, thread_pool_trx, MAX_THREADS);
listener->block_event_received.connect([this](const block_data &block_event_data) {
std::thread(&sidechain_net_handler_bitcoin::block_handle_event, this, block_event_data).detach();
io_context_block.post(boost::bind(&sidechain_net_handler_bitcoin::block_handle_event, this, block_event_data));
});
listener->trx_event_received.connect([this](const libbitcoin::chain::transaction &trx_event_data) {
std::thread(&sidechain_net_handler_bitcoin::trx_handle_event, this, trx_event_data).detach();
io_context_trx.post(boost::bind(&sidechain_net_handler_bitcoin::trx_handle_event, this, trx_event_data));
});
listener->start();
@ -761,6 +768,11 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain
}
sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
work_guard_block.reset();
work_guard_trx.reset();
thread_pool_block.join_all();
thread_pool_trx.join_all();
try {
if (on_changed_objects_task.valid()) {
on_changed_objects_task.cancel_and_wait(__FUNCTION__);
@ -1212,7 +1224,7 @@ bool sidechain_net_handler_bitcoin::process_deposit(const son_wallet_deposit_obj
return false;
}
std::string tx_str = create_deposit_transaction(swdo);
const std::string tx_str = create_deposit_transaction(swdo);
if (!tx_str.empty()) {
const chain::global_property_object &gpo = database.get_global_properties();
@ -1263,7 +1275,7 @@ bool sidechain_net_handler_bitcoin::process_withdrawal(const son_wallet_withdraw
return false;
}
std::string tx_str = create_withdrawal_transaction(swwo);
const std::string tx_str = create_withdrawal_transaction(swwo);
if (!tx_str.empty()) {
const chain::global_property_object &gpo = database.get_global_properties();
@ -1327,7 +1339,7 @@ bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain
return false;
}
btc_tx tx = bitcoin_client->getrawtransaction(sto.sidechain_transaction, true);
const btc_tx tx = bitcoin_client->getrawtransaction(sto.sidechain_transaction, true);
if (tx.tx_in_list.empty()) {
// This case will result with segmentation fault.
@ -1349,11 +1361,11 @@ bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain
payment_type_address = payment_type::P2WSH;
}
btc_weighted_multisig_address addr(pubkey_weights, network_type, payment_type_address);
const btc_weighted_multisig_address addr(pubkey_weights, network_type, payment_type_address);
std::string tx_txid = tx.tx_txid;
uint32_t tx_confirmations = tx.tx_confirmations;
std::string tx_address = addr.get_address();
const std::string tx_txid = tx.tx_txid;
const uint32_t tx_confirmations = tx.tx_confirmations;
const std::string tx_address = addr.get_address();
int64_t tx_amount = -1;
if (tx_confirmations >= gpo.parameters.son_bitcoin_min_tx_confirmations()) {
@ -1397,14 +1409,14 @@ std::string sidechain_net_handler_bitcoin::create_primary_wallet_address(const s
if (use_bitcoind_client) {
payment_type_address = payment_type::P2WSH;
}
btc_weighted_multisig_address addr(pubkey_weights, network_type, payment_type_address);
const btc_weighted_multisig_address addr(pubkey_weights, network_type, payment_type_address);
std::stringstream ss;
ss << "{\"result\": {\"address\": \"" << addr.get_address() << "\", \"redeemScript\": \"" << fc::to_hex(addr.get_redeem_script()) << "\""
<< "}, \"error\":null}";
std::string res = ss.str();
const std::string res = ss.str();
return res;
}
@ -1423,8 +1435,8 @@ std::string sidechain_net_handler_bitcoin::create_primary_wallet_transaction(con
std::stringstream prev_sw_ss(s);
boost::property_tree::ptree prev_sw_pt;
boost::property_tree::read_json(prev_sw_ss, prev_sw_pt);
std::string prev_pw_address = prev_sw_pt.get<std::string>("address");
std::string prev_redeem_script = prev_sw_pt.get<std::string>("redeemScript");
const std::string prev_pw_address = prev_sw_pt.get<std::string>("address");
const std::string prev_redeem_script = prev_sw_pt.get<std::string>("redeemScript");
if (prev_pw_address == new_sw_address) {
wlog("BTC previous and new primary wallet addresses are same. No funds moving needed [from ${prev_sw} to ${new_sw_address}]", ("prev_swo", prev_swo.id)("active_sw", new_sw_address));
@ -1465,18 +1477,18 @@ std::string sidechain_net_handler_bitcoin::create_deposit_transaction(const son_
return "";
}
// Get redeem script for deposit address
std::string redeem_script = get_redeemscript_for_userdeposit(swdo.sidechain_from);
std::string pw_address_json = obj->addresses.find(sidechain)->second;
const std::string redeem_script = get_redeemscript_for_userdeposit(swdo.sidechain_from);
const std::string pw_address_json = obj->addresses.find(sidechain)->second;
std::stringstream ss(pw_address_json);
boost::property_tree::ptree json;
boost::property_tree::read_json(ss, json);
std::string pw_address = json.get<std::string>("address");
const std::string pw_address = json.get<std::string>("address");
std::string txid = swdo.sidechain_transaction_id;
std::string suid = swdo.sidechain_uid;
std::string nvout = suid.substr(suid.find_last_of("-") + 1);
const std::string txid = swdo.sidechain_transaction_id;
const std::string suid = swdo.sidechain_uid;
const std::string nvout = suid.substr(suid.find_last_of("-") + 1);
uint64_t deposit_amount = swdo.sidechain_amount.value;
uint64_t fee_rate = bitcoin_client->estimatesmartfee();
const uint64_t min_fee_rate = 1000;
@ -1488,7 +1500,7 @@ std::string sidechain_net_handler_bitcoin::create_deposit_transaction(const son_
}
deposit_amount -= fee_rate; // Deduct minimum relay fee
double transfer_amount = (double)deposit_amount / 100000000.0;
const double transfer_amount = (double)deposit_amount / 100000000.0;
std::vector<btc_txout> inputs;
fc::flat_map<std::string, double> outputs;
@ -1512,14 +1524,14 @@ std::string sidechain_net_handler_bitcoin::create_withdrawal_transaction(const s
return "";
}
std::string pw_address_json = obj->addresses.find(sidechain)->second;
const std::string pw_address_json = obj->addresses.find(sidechain)->second;
std::stringstream ss(pw_address_json);
boost::property_tree::ptree json;
boost::property_tree::read_json(ss, json);
std::string pw_address = json.get<std::string>("address");
std::string redeem_script = json.get<std::string>("redeemScript");
const std::string pw_address = json.get<std::string>("address");
const std::string redeem_script = json.get<std::string>("redeemScript");
int64_t fee_rate = bitcoin_client->estimatesmartfee();
const int64_t min_fee_rate = 1000;
@ -1551,7 +1563,7 @@ std::string sidechain_net_handler_bitcoin::create_withdrawal_transaction(const s
return create_transaction(inputs, outputs, redeem_script);
}
std::string sidechain_net_handler_bitcoin::create_transaction(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs, std::string &redeem_script) {
std::string sidechain_net_handler_bitcoin::create_transaction(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs, const std::string &redeem_script) {
using namespace bitcoin;
bitcoin_transaction_builder tb;
@ -1570,15 +1582,15 @@ std::string sidechain_net_handler_bitcoin::create_transaction(const std::vector<
}
const auto tx = tb.get_transaction();
std::string hex_tx = fc::to_hex(pack(tx));
std::string tx_raw = write_transaction_data(hex_tx, in_amounts, redeem_script);
const std::string hex_tx = fc::to_hex(pack(tx));
const std::string tx_raw = write_transaction_data(hex_tx, in_amounts, redeem_script);
return tx_raw;
}
std::string sidechain_net_handler_bitcoin::sign_transaction(const sidechain_transaction_object &sto) {
using namespace bitcoin;
std::string pubkey = plugin.get_current_son_object(sidechain).sidechain_public_keys.at(sidechain);
std::string prvkey = get_private_key(pubkey);
const std::string pubkey = plugin.get_current_son_object(sidechain).sidechain_public_keys.at(sidechain);
const std::string prvkey = get_private_key(pubkey);
std::vector<uint64_t> in_amounts;
std::string tx_hex;
std::string redeem_script;
@ -1589,14 +1601,14 @@ std::string sidechain_net_handler_bitcoin::sign_transaction(const sidechain_tran
return "";
}
const auto secret = btc_private_key->get_secret();
bitcoin::bytes privkey_signing(secret.data(), secret.data() + secret.data_size());
const bitcoin::bytes privkey_signing(secret.data(), secret.data() + secret.data_size());
read_transaction_data(sto.transaction, tx_hex, in_amounts, redeem_script);
bitcoin_transaction tx = unpack(parse_hex(tx_hex));
std::vector<bitcoin::bytes> redeem_scripts(tx.vin.size(), parse_hex(redeem_script));
const bitcoin_transaction tx = unpack(parse_hex(tx_hex));
const std::vector<bitcoin::bytes> redeem_scripts(tx.vin.size(), parse_hex(redeem_script));
auto sigs = sign_witness_transaction_part(tx, redeem_scripts, in_amounts, privkey_signing, btc_context(), 1);
std::string tx_signature = write_transaction_signatures(sigs);
const std::string tx_signature = write_transaction_signatures(sigs);
return tx_signature;
}
@ -1613,7 +1625,7 @@ std::string sidechain_net_handler_bitcoin::send_transaction(const sidechain_tran
std::vector<bitcoin::bytes> redeem_scripts(tx.vin.size(), parse_hex(redeem_script));
uint32_t inputs_number = in_amounts.size();
const uint32_t inputs_number = in_amounts.size();
vector<bitcoin::bytes> dummy;
dummy.resize(inputs_number);
// Organise weighted address signatures
@ -1645,8 +1657,8 @@ std::string sidechain_net_handler_bitcoin::send_transaction(const sidechain_tran
}
}
std::string final_tx_hex = fc::to_hex(pack(tx));
std::string res = bitcoin_client->sendrawtransaction(final_tx_hex);
const std::string final_tx_hex = fc::to_hex(pack(tx));
const std::string res = bitcoin_client->sendrawtransaction(final_tx_hex);
if (res.empty()) {
return res;
@ -1657,7 +1669,7 @@ std::string sidechain_net_handler_bitcoin::send_transaction(const sidechain_tran
void sidechain_net_handler_bitcoin::block_handle_event(const block_data &event_data) {
auto vins = bitcoin_client->getblock(event_data);
const auto vins = bitcoin_client->getblock(event_data);
add_to_son_listener_log("BLOCK : " + event_data.block_hash);
@ -1698,6 +1710,7 @@ void sidechain_net_handler_bitcoin::block_handle_event(const block_data &event_d
}
void sidechain_net_handler_bitcoin::trx_handle_event(const libbitcoin::chain::transaction &trx_data) {
bitcoin_client->import_trx_to_memory_pool(trx_data);
}
@ -1720,20 +1733,20 @@ std::string sidechain_net_handler_bitcoin::get_redeemscript_for_userdeposit(cons
auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(son.public_key)));
pubkey_weights.push_back(std::make_pair(pub_key, son.weight));
}
auto user_pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(addr_itr->deposit_public_key)));
const auto user_pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(addr_itr->deposit_public_key)));
payment_type payment_type_address = payment_type::P2SH_WSH;
if (use_bitcoind_client) {
payment_type_address = payment_type::P2WSH;
}
btc_one_or_weighted_multisig_address deposit_addr(user_pub_key, pubkey_weights, network_type, payment_type_address);
const btc_one_or_weighted_multisig_address deposit_addr(user_pub_key, pubkey_weights, network_type, payment_type_address);
return fc::to_hex(deposit_addr.get_redeem_script());
}
void sidechain_net_handler_bitcoin::on_changed_objects(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) {
fc::time_point now = fc::time_point::now();
int64_t time_to_next_changed_objects_processing = 5000;
const fc::time_point now = fc::time_point::now();
const int64_t time_to_next_changed_objects_processing = 5000;
fc::time_point next_wakeup(now + fc::microseconds(time_to_next_changed_objects_processing));
@ -1784,6 +1797,12 @@ void sidechain_net_handler_bitcoin::on_changed_objects_cb(const vector<object_id
}
}
void sidechain_net_handler_bitcoin::init_thread_pool(boost::asio::io_context &io_context, boost::thread_group &thread_pool, int num_threads) {
for (int i = 0; i < num_threads; ++i) {
thread_pool.create_thread(boost::bind(&boost::asio::io_context::run, &io_context));
}
}
// =============================================================================
}
} // namespace graphene::peerplays_sidechain

View file

@ -934,6 +934,31 @@ class wallet_api
string memo,
bool broadcast = false);
/** Transfer an amount from one account to another,
* even without the authority of the from account. This function
* is an "issuer override." To use it, you must be the issuer of
* the asset and the override permission must be retained and enabled
* on the asset.
* @param from the name or id of the account sending the funds
* @param to the name or id of the account receiving the funds
* @param issuer the name or id of the asset issuer
* @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5)
* @param asset_symbol the symbol or id of the asset to send
* @param memo a memo to attach to the transaction. The memo will be encrypted in the
* transaction and readable for the receiver. There is no length limit
* other than the limit imposed by maximum transaction size, but transaction
* increase with transaction size
* @param broadcast true to broadcast the transaction on the network
* @returns the signed transaction transferring funds
*/
signed_transaction override_transfer(string from,
string to,
string issuer,
string amount,
string asset_symbol,
string memo,
bool broadcast = false);
/**
* This method works just like transfer, except it always broadcasts and
* returns the transaction ID (hash) along with the signed transaction.
@ -1965,6 +1990,7 @@ class wallet_api
std::vector<std::string> witnesses_to_reject,
uint16_t desired_number_of_witnesses,
bool broadcast = false);
/** Set the voting proxy for an account.
*
* If a user does not wish to take an active part in voting, they can choose
@ -2012,6 +2038,18 @@ class wallet_api
uint16_t desired_number_of_committee_members,
bool broadcast = false);
/** Vote recharge gpos.
*
* Explicit voting recharge function that is used solely when the user wishes to recharge their GPOS voting power
* without changing their voting slate
*
* @param voting_account the name or id of the account who is voting with their shares
* @param broadcast true if you wish to broadcast the transaction
* @return the signed transaction changing your vote for the given SON
*/
signed_transaction vote_recharge_gpos(string voting_account,
bool broadcast = false);
/** Signs a transaction.
*
* Given a fully-formed transaction that is only lacking signatures, this signs
@ -2804,6 +2842,7 @@ FC_API( graphene::wallet::wallet_api,
(borrow_asset)
(cancel_order)
(transfer)
(override_transfer)
(transfer2)
(get_transaction_id)
(create_asset)
@ -2870,6 +2909,7 @@ FC_API( graphene::wallet::wallet_api,
(update_witness_votes)
(set_voting_proxy)
(set_desired_witness_and_committee_member_count)
(vote_recharge_gpos)
(get_account)
(get_account_id)
(get_block)

View file

@ -3101,6 +3101,31 @@ public:
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (account_to_modify)(desired_number_of_witnesses)(desired_number_of_committee_members)(broadcast) ) }
signed_transaction vote_recharge_gpos(string voting_account,
bool broadcast /* = false */)
{ try {
const std::vector<vesting_balance_object_with_info> vbo_info = get_vesting_balances(voting_account);
std::vector<vesting_balance_object_with_info>::const_iterator vbo_iter;
vbo_iter = std::find_if(vbo_info.begin(), vbo_info.end(), [](vesting_balance_object_with_info const& obj){return obj.balance_type == vesting_balance_type::gpos;});
if( vbo_info.size() == 0 || vbo_iter == vbo_info.end())
FC_THROW("Account ${account} has no core Token ${TOKEN} vested and will not be allowed to recharge the votes", ("account", voting_account)("TOKEN", GRAPHENE_SYMBOL));
const account_object voting_account_object = get_account(voting_account);
account_update_operation account_update_op;
account_update_op.account = voting_account_object.id;
account_update_op.new_options = voting_account_object.options;
account_update_op.extensions.value.update_last_voting_time = true; //Allow user to vote in each sub-period (Update voting time, which is reference in calculating VF)
signed_transaction tx;
tx.operations.push_back( account_update_op );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (voting_account)(broadcast) ) }
signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false)
{
set<public_key_type> pks = _remote_db->get_potential_signatures(tx);
@ -3373,6 +3398,59 @@ public:
return sign_transaction(tx, broadcast);
} FC_CAPTURE_AND_RETHROW( (from)(to)(amount)(asset_symbol)(memo)(broadcast) ) }
signed_transaction override_transfer(string from, string to, string issuer, string amount,
string asset_symbol, string memo, bool broadcast = false) {
try {
FC_ASSERT(!self.is_locked());
fc::optional<asset_object> asset_obj = get_asset(asset_symbol);
FC_ASSERT(asset_obj, "Could not find asset matching ${asset}", ("asset", asset_symbol));
account_object from_account = get_account(from);
account_object to_account = get_account(to);
account_object issuer_account = get_account(issuer);
account_id_type from_id = from_account.id;
account_id_type to_id = get_account_id(to);
account_id_type issuer_id = get_account_id(issuer);
override_transfer_operation xfer_op;
xfer_op.issuer = issuer_id;
xfer_op.from = from_id;
xfer_op.to = to_id;
xfer_op.amount = asset_obj->amount_from_string(amount);
if (memo.size()) {
xfer_op.memo = memo_data();
xfer_op.memo->from = from_account.options.memo_key;
xfer_op.memo->to = to_account.options.memo_key;
xfer_op.memo->set_message(get_private_key(from_account.options.memo_key),
to_account.options.memo_key, memo);
}
signed_transaction tx;
tx.operations.push_back(xfer_op);
set_operation_fees(tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
//! For sidechain withdrawal check if amount is greater than fee
if (to_id == _remote_db->get_global_properties().parameters.son_account()) {
const auto sidechain = get_sidechain_type_from_asset(asset_obj->id);
const auto transaction_fee = estimate_withdrawal_transaction_fee(sidechain);
if (transaction_fee) {
if (*transaction_fee >= xfer_op.amount) {
FC_THROW("Transaction fee: ${sidechain_fee}, is greater than or equal to the transferred amount ${amount}",
("sidechain_fee", get_asset(transaction_fee->asset_id).amount_to_pretty_string(transaction_fee->amount))("amount", get_asset(xfer_op.amount.asset_id).amount_to_pretty_string(xfer_op.amount.amount)));
}
}
}
return sign_transaction(tx, broadcast);
}
FC_CAPTURE_AND_RETHROW((from)(to)(issuer)(amount)(asset_symbol)(memo)(broadcast))
}
signed_transaction issue_asset(string to_account, string amount, string symbol,
string memo, bool broadcast = false)
{
@ -5072,6 +5150,12 @@ signed_transaction wallet_api::transfer(string from, string to, string amount,
{
return my->transfer(from, to, amount, asset_symbol, memo, broadcast);
}
signed_transaction wallet_api::override_transfer(string from, string to, string issuer, string amount,
string asset_symbol, string memo, bool broadcast /* = false */) {
return my->override_transfer(from, to, issuer, amount, asset_symbol, memo, broadcast);
}
signed_transaction wallet_api::create_asset(string issuer,
string symbol,
uint8_t precision,
@ -5551,6 +5635,12 @@ signed_transaction wallet_api::set_desired_witness_and_committee_member_count(st
desired_number_of_committee_members, broadcast);
}
signed_transaction wallet_api::vote_recharge_gpos(string voting_account,
bool broadcast /* = false */)
{
return my->vote_recharge_gpos(voting_account, broadcast);
}
void wallet_api::set_wallet_filename(string wallet_filename)
{
my->_wallet_filename = wallet_filename;