diff --git a/.github/workflows/macos-release.yml b/.github/workflows/macos-release.yml index 5164fe6e..ddb6fa5c 100644 --- a/.github/workflows/macos-release.yml +++ b/.github/workflows/macos-release.yml @@ -19,7 +19,7 @@ jobs: run: brew install autogen autoconf automake binutils coreutils cmake ldns expat xz doxygen hidapi graphviz libpgm libunwind-headers unbound zmq czmq jmuncaster/header-only/cppzmq zeromq libsodium miniupnpc openssl pkg-config protobuf readline - name: install boost run: | - curl -OL https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz + curl -L -o boost_1_72_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.gz/download tar -xf boost_1_72_0.tar.gz cd boost_1_72_0 ./bootstrap.sh diff --git a/.github/workflows/macos-test.yml b/.github/workflows/macos-test.yml index 3bbdbef2..d7d32141 100644 --- a/.github/workflows/macos-test.yml +++ b/.github/workflows/macos-test.yml @@ -19,7 +19,7 @@ jobs: run: brew install autogen autoconf automake binutils coreutils cmake ldns expat xz doxygen hidapi graphviz libpgm libunwind-headers unbound zmq czmq jmuncaster/header-only/cppzmq zeromq libsodium miniupnpc openssl pkg-config protobuf readline - name: install boost run: | - curl -OL https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz + curl -L -o boost_1_72_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.gz/download tar -xf boost_1_72_0.tar.gz cd boost_1_72_0 ./bootstrap.sh diff --git a/.github/workflows/ubuntu-release.yml b/.github/workflows/ubuntu-release.yml index c0bf6e7b..31637f2f 100644 --- a/.github/workflows/ubuntu-release.yml +++ b/.github/workflows/ubuntu-release.yml @@ -25,9 +25,7 @@ jobs: run: sudo apt-get install build-essential=12.4ubuntu1 cmake=3.10.2-1ubuntu2.18.04.1 pkg-config=0.29.1-0ubuntu2 libboost-all-dev=1.65.1.0ubuntu1 libssl-dev libsodium23=1.0.16-2 libsodium-dev=1.0.16-2 libpgm-dev=5.2.122~dfsg-2 libzmq3-dev=4.2.5-1ubuntu0.2 libunbound-dev libminiupnpc-dev libunwind8-dev liblzma-dev libreadline6-dev libldns-dev libexpat1-dev libgtest-dev doxygen graphviz libpcsclite-dev libnorm-dev=1.5r6+dfsg1-6 libpcsclite1 - name: Build protobuf library run: | - git clone https://github.com/protocolbuffers/protobuf.git - cd protobuf - git submodule update --init --recursive + cd external/protobuf ./autogen.sh ./configure make diff --git a/Makefile b/Makefile index 4c503456..e9cc5aca 100644 --- a/Makefile +++ b/Makefile @@ -42,8 +42,8 @@ libwallet-build: -DSTATIC=ON \ -DProtobuf_USE_STATIC_LIBS=OFF \ -DBUILD_SAFEX_PROTOBUF_RPC=OFF \ - -DARCH="x86-64" -D \ - -DBUILD_64=ON -D \ + -DARCH="x86-64" \ + -DBUILD_64=ON \ -DCMAKE_BUILD_TYPE=release \ -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true \ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${PWD}/deps \ @@ -57,8 +57,8 @@ libwallet-build-windows: -DSTATIC=ON \ -DProtobuf_USE_STATIC_LIBS=OFF \ -DBUILD_SAFEX_PROTOBUF_RPC=OFF \ - -DARCH="x86-64" -D \ - -DBUILD_64=ON -D \ + -DARCH="x86-64" \ + -DBUILD_64=ON \ -DCMAKE_BUILD_TYPE=release \ -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true \ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${PWD}/deps \ diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 7b96dfb7..f34a08b9 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -2025,7 +2025,7 @@ bool t_rpc_command_executor::token_locked_on_interval(const uint64_t& start, con } else { - if (!m_rpc_server->on_get_locked_tokens(req, res)) + if (!m_rpc_server->on_get_staked_tokens(req, res)) { tools::fail_msg_writer() << "Failed!"; return true; diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index ec78fa12..7cd523cb 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -202,6 +202,38 @@ namespace cryptonote res.status = CORE_RPC_STATUS_OK; return true; } + //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_get_safex_offers_json(const COMMAND_RPC_GET_SAFEX_OFFERS_JSON::request& req, COMMAND_RPC_GET_SAFEX_OFFERS_JSON::response& res) + { + PERF_TIMER(on_get_safex_offers); + bool r; + if (use_bootstrap_daemon_if_necessary(invoke_http_mode::JON, "/get_safex_offers_json", req, res, r)) + return r; + + std::vector offers; + bool result = m_core.get_safex_offers(offers); + + for(auto offer: offers) { + if(offer.seller != req.seller && req.seller != "") + continue; + uint64_t offer_height; + result = m_core.get_safex_offer_height(offer.offer_id, offer_height); + if(!result) + continue; + std::string offer_id_str = epee::string_tools::pod_to_hex(offer.offer_id); + std::string price_peg_id_str = epee::string_tools::pod_to_hex(offer.price_peg_id); + + std::string seller_address = cryptonote::get_account_address_as_str(m_nettype, false, offer.seller_address); + + COMMAND_RPC_GET_SAFEX_OFFERS_JSON::entry ent{offer.title, offer.quantity, offer.price, offer.min_sfx_price, offer.description, + offer.active, offer.price_peg_used, offer.shipping, offer_id_str, price_peg_id_str, offer.seller, + seller_address, offer_height}; + res.offers.push_back(ent); + } + res.status = CORE_RPC_STATUS_OK; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_safex_price_pegs(const COMMAND_RPC_GET_SAFEX_PRICE_PEGS::request& req, COMMAND_RPC_GET_SAFEX_PRICE_PEGS::response& res) { @@ -559,8 +591,18 @@ namespace cryptonote } } + cryptonote::tx_out_type output_type = cryptonote::tx_out_type::out_invalid; + + if(req.out_type == cryptonote::tx_out_type::out_invalid) { + output_type = static_cast(req.out_type_as_int); + } + else { + output_type = req.out_type; + } + cryptonote::COMMAND_RPC_GET_OUTPUTS_BIN::request req_bin; req_bin.outputs = req.outputs; + req_bin.out_type = output_type; cryptonote::COMMAND_RPC_GET_OUTPUTS_BIN::response res_bin; if(!m_core.get_outs(req_bin, res_bin)) { @@ -1965,7 +2007,7 @@ namespace cryptonote for (const auto &i: histogram) { if (std::get<0>(i.second) >= req.min_count && (std::get<0>(i.second) <= req.max_count || req.max_count == 0)) - res.histogram.push_back(COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry(i.first, std::get<0>(i.second), std::get<1>(i.second), std::get<2>(i.second), req.out_type)); + res.histogram.push_back(COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry(i.first, std::get<0>(i.second), std::get<1>(i.second), std::get<2>(i.second), output_type)); } res.status = CORE_RPC_STATUS_OK; @@ -2349,6 +2391,16 @@ namespace cryptonote PERF_TIMER(on_get_output_distribution); try { + cryptonote::tx_out_type output_type = cryptonote::tx_out_type::out_invalid; + + if(req.out_type == cryptonote::tx_out_type::out_invalid) { + output_type = static_cast(req.out_type_as_int); + } + else { + output_type = req.out_type; + } + + for (uint64_t amount: req.amounts) { static struct D @@ -2369,7 +2421,7 @@ namespace cryptonote std::vector distribution; uint64_t start_height, base; - if (!m_core.get_output_distribution(amount, req.out_type, req.from_height, start_height, distribution, base)) + if (!m_core.get_output_distribution(amount, output_type, req.from_height, start_height, distribution, base)) { error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR; error_resp.message = "Failed to get rct distribution"; @@ -2724,7 +2776,7 @@ namespace cryptonote return true; } - bool core_rpc_server::on_get_locked_tokens(const COMMAND_RPC_TOKEN_STAKED::request& req, COMMAND_RPC_TOKEN_STAKED::response& res) + bool core_rpc_server::on_get_staked_tokens(const COMMAND_RPC_TOKEN_STAKED::request& req, COMMAND_RPC_TOKEN_STAKED::response& res) { if (req.interval == 0) { // @todo: Implement here to return last interval value. diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index c4ff5b96..c87cd1cb 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -91,8 +91,8 @@ namespace cryptonote MAP_URI_AUTO_BIN2("/get_random_outs.bin", on_get_random_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS) MAP_URI_AUTO_BIN2("/getrandom_outs.bin", on_get_random_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS) MAP_URI_AUTO_BIN2("/get_outs.bin", on_get_outs_bin, COMMAND_RPC_GET_OUTPUTS_BIN) - MAP_URI_AUTO_BIN2("/get_random_rctouts.bin", on_get_random_rct_outs, COMMAND_RPC_GET_RANDOM_RCT_OUTPUTS) - MAP_URI_AUTO_BIN2("/getrandom_rctouts.bin", on_get_random_rct_outs, COMMAND_RPC_GET_RANDOM_RCT_OUTPUTS) +// MAP_URI_AUTO_BIN2("/get_random_rctouts.bin", on_get_random_rct_outs, COMMAND_RPC_GET_RANDOM_RCT_OUTPUTS) +// MAP_URI_AUTO_BIN2("/getrandom_rctouts.bin", on_get_random_rct_outs, COMMAND_RPC_GET_RANDOM_RCT_OUTPUTS) MAP_URI_AUTO_JON2("/get_transactions", on_get_transactions, COMMAND_RPC_GET_TRANSACTIONS) MAP_URI_AUTO_PROTOBUF_RES("/proto/get_transactions", on_get_transactions_protobuf, COMMAND_RPC_GET_TRANSACTIONS_PROTOBUF) MAP_URI_AUTO_PROTOBUF_RES("/proto/get_blocks", on_get_blocks_protobuf, COMMAND_RPC_GET_BLOCKS_PROTOBUF) @@ -118,12 +118,13 @@ namespace cryptonote MAP_URI_AUTO_JON2_IF("/stop_daemon", on_stop_daemon, COMMAND_RPC_STOP_DAEMON, !m_restricted) MAP_URI_AUTO_JON2("/get_info", on_get_info, COMMAND_RPC_GET_INFO) MAP_URI_AUTO_JON2("/getinfo", on_get_info, COMMAND_RPC_GET_INFO) - MAP_URI_AUTO_JON2("/get_staked_tokens", on_get_locked_tokens, COMMAND_RPC_TOKEN_STAKED) + MAP_URI_AUTO_JON2("/get_staked_tokens", on_get_staked_tokens, COMMAND_RPC_TOKEN_STAKED) MAP_URI_AUTO_JON2("/get_interest_map", on_get_interest_map, COMMAND_RPC_GET_INTEREST_MAP) MAP_URI_AUTO_JON2("/get_network_fee", on_get_network_fee, COMMAND_RPC_NETWORK_FEE) MAP_URI_AUTO_JON2("/get_safex_account_info", on_get_safex_account_info, COMMAND_RPC_SAFEX_ACCOUNT_INFO) MAP_URI_AUTO_JON2("/get_safex_accounts", on_get_safex_accounts, COMMAND_RPC_GET_SAFEX_ACCOUNTS) MAP_URI_AUTO_JON2("/get_safex_offers", on_get_safex_offers, COMMAND_RPC_GET_SAFEX_OFFERS) + MAP_URI_AUTO_JON2("/get_safex_offers_json", on_get_safex_offers_json, COMMAND_RPC_GET_SAFEX_OFFERS_JSON) MAP_URI_AUTO_JON2("/get_safex_ratings", on_get_safex_ratings, COMMAND_RPC_GET_SAFEX_RATINGS) MAP_URI_AUTO_JON2("/get_safex_price_pegs", on_get_safex_price_pegs, COMMAND_RPC_GET_SAFEX_PRICE_PEGS) MAP_URI_AUTO_JON2("/get_limit", on_get_limit, COMMAND_RPC_GET_LIMIT) @@ -175,13 +176,15 @@ namespace cryptonote bool on_get_safex_account_info(const COMMAND_RPC_SAFEX_ACCOUNT_INFO::request &req, COMMAND_RPC_SAFEX_ACCOUNT_INFO::response &res); bool on_get_interest_map(const COMMAND_RPC_GET_INTEREST_MAP::request& req, COMMAND_RPC_GET_INTEREST_MAP::response& res); - bool on_get_locked_tokens(const COMMAND_RPC_TOKEN_STAKED::request& req, COMMAND_RPC_TOKEN_STAKED::response& res); + bool on_get_staked_tokens(const COMMAND_RPC_TOKEN_STAKED::request& req, COMMAND_RPC_TOKEN_STAKED::response& res); bool on_get_network_fee(const COMMAND_RPC_NETWORK_FEE::request& req, COMMAND_RPC_NETWORK_FEE::response& res); bool on_get_safex_accounts(const COMMAND_RPC_GET_SAFEX_ACCOUNTS::request& req, COMMAND_RPC_GET_SAFEX_ACCOUNTS::response& res); bool on_get_safex_offers(const COMMAND_RPC_GET_SAFEX_OFFERS::request& req, COMMAND_RPC_GET_SAFEX_OFFERS::response& res); bool on_get_safex_ratings(const COMMAND_RPC_GET_SAFEX_RATINGS::request& req, COMMAND_RPC_GET_SAFEX_RATINGS::response& res); bool on_get_safex_price_pegs(const COMMAND_RPC_GET_SAFEX_PRICE_PEGS::request& req, COMMAND_RPC_GET_SAFEX_PRICE_PEGS::response& res); + bool on_get_safex_offers_json(const COMMAND_RPC_GET_SAFEX_OFFERS_JSON::request& req, COMMAND_RPC_GET_SAFEX_OFFERS_JSON::response& res); + bool on_get_output_histogram_protobuf(const COMMAND_RPC_GET_OUTPUT_HISTOGRAM_PROTOBUF::request& req, COMMAND_RPC_GET_OUTPUT_HISTOGRAM_PROTOBUF::response& res); bool on_send_proto_raw_tx(const COMMAND_RPC_PROTO_SEND_RAW_TX::request& req, COMMAND_RPC_PROTO_SEND_RAW_TX::response& res); diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index c41e30c7..42b7745a 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -175,6 +175,66 @@ namespace cryptonote typedef epee::misc_utils::struct_init response; }; + + struct COMMAND_RPC_GET_SAFEX_OFFERS_JSON + { + struct request_t + { + std::string seller = ""; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(seller); + END_KV_SERIALIZE_MAP() + }; + typedef epee::misc_utils::struct_init request; + + struct entry + { + std::string title; + uint64_t quantity; + uint64_t price; + uint64_t min_sfx_price; + std::vector description; + bool active; + bool price_peg_used; + std::vector shipping; + std::string offer_id; + std::string price_peg_id; + std::string seller; + std::string seller_address; + uint64_t height; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(title) + KV_SERIALIZE(quantity) + KV_SERIALIZE(price) + KV_SERIALIZE(min_sfx_price) + KV_SERIALIZE(description) + KV_SERIALIZE(active) + KV_SERIALIZE(price_peg_used) + KV_SERIALIZE(shipping) + KV_SERIALIZE(offer_id) + KV_SERIALIZE(price_peg_id) + KV_SERIALIZE(seller) + KV_SERIALIZE(seller_address) + KV_SERIALIZE(height) + END_KV_SERIALIZE_MAP() + }; + + struct response_t + { + std::vector offers; + std::string status; + bool untrusted; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(offers) + KV_SERIALIZE(status) + KV_SERIALIZE(untrusted); + END_KV_SERIALIZE_MAP() + }; + typedef epee::misc_utils::struct_init response; + }; + struct COMMAND_RPC_GET_SAFEX_PRICE_PEGS { struct request_t @@ -1095,9 +1155,13 @@ namespace cryptonote struct request_t { std::vector outputs; + uint64_t out_type_as_int; + tx_out_type out_type = cryptonote::tx_out_type::out_invalid; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(outputs) + KV_SERIALIZE_OPT(out_type_as_int, (uint64_t)0) + KV_SERIALIZE_VAL_POD_AS_BLOB(out_type) END_KV_SERIALIZE_MAP() }; typedef epee::misc_utils::struct_init request; @@ -2353,7 +2417,7 @@ namespace cryptonote bool unlocked; uint64_t recent_cutoff; uint64_t out_type_as_int; - tx_out_type out_type; + tx_out_type out_type = cryptonote::tx_out_type::out_invalid; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(amounts); @@ -2673,13 +2737,15 @@ namespace cryptonote uint64_t from_height; uint64_t to_height; bool cumulative; - tx_out_type out_type; - + uint64_t out_type_as_int; + tx_out_type out_type = cryptonote::tx_out_type::out_invalid; + BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(amounts) KV_SERIALIZE_OPT(from_height, (uint64_t)0) KV_SERIALIZE_OPT(to_height, (uint64_t)0) KV_SERIALIZE_OPT(cumulative, false) + KV_SERIALIZE_OPT(out_type_as_int, (uint64_t)0) KV_SERIALIZE_VAL_POD_AS_BLOB(out_type) END_KV_SERIALIZE_MAP() }; @@ -2834,6 +2900,7 @@ namespace cryptonote uint64_t end; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(interval) + KV_SERIALIZE(end) END_KV_SERIALIZE_MAP() }; @@ -2867,6 +2934,7 @@ namespace cryptonote uint64_t end; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(interval) + KV_SERIALIZE(end) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b2cd2e50..94b93cd6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -8828,12 +8828,14 @@ std::vector wallet::create_transactions_advanced(safex::comm THROW_WALLET_EXCEPTION_IF(original_output_index > dsts.size(), error::wallet_internal_error, std::string("original_output_index too large: ") + std::to_string(original_output_index) + " > " + std::to_string(dsts.size())); if (original_output_index == dsts.size()) + { dsts.emplace_back(0, addr, is_subaddress, output_type, output_data); - THROW_WALLET_EXCEPTION_IF(memcmp(&dsts[original_output_index].addr, &addr, sizeof(addr)), error::wallet_internal_error, "Mismatched destination address"); - THROW_WALLET_EXCEPTION_IF((output_type == cryptonote::tx_out_type::out_token) && !tools::is_whole_token_amount(amount), error::wallet_internal_error, - "Token amount must be whole number."); - dsts[original_output_index].token_amount += token_amount; - dsts[original_output_index].amount += amount; + } + THROW_WALLET_EXCEPTION_IF(memcmp(&dsts[original_output_index].addr, &addr, sizeof(addr)), error::wallet_internal_error, "Mismatched destination address"); + THROW_WALLET_EXCEPTION_IF((output_type == cryptonote::tx_out_type::out_token) && !tools::is_whole_token_amount(amount), error::wallet_internal_error, + "Token amount must be whole number."); + dsts[original_output_index].token_amount += token_amount; + dsts[original_output_index].amount += amount; } } }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index ceb6d5a5..f49546a7 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -2878,250 +2878,252 @@ bool wallet_rpc_server::on_is_multisig(const wallet_rpc::COMMAND_RPC_IS_MULTISIG return true; } //------------------------------------------------------------------------------------------------------------------------------ -bool wallet_rpc_server::on_migrate_view_only( - const tools::wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY::request &req, - tools::wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY::response &res, - epee::json_rpc::error &er) -{ - if (!m_wallet) return not_open(er); - - if (!m_wallet->watch_only()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "Command unavailable in regular mode. Only view mode."; - return false; - } - - if (m_wallet->restricted()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "Command unavailable in restricted mode."; - return false; - } - - cryptonote::address_parse_info info = AUTO_VAL_INIT(info); - cryptonote::tx_destination_entry token_destination = AUTO_VAL_INIT(token_destination); - if (!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), req.address)) { - er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; - er.message = "Invalid address: " + req.address; - return false; - } - token_destination.addr = info.address; - token_destination.is_subaddress = info.is_subaddress; - token_destination.token_transaction = true; - token_destination.token_amount = req.amount * SAFEX_CASH_COIN; - token_destination.output_type = cryptonote::tx_out_type::out_token; - - //parse bitcoin transaction hash - cryptonote::blobdata expected_bitcoin_hash_data; - if (!epee::string_tools::parse_hexstr_to_binbuff(req.bitcoin_hash, expected_bitcoin_hash_data) || - expected_bitcoin_hash_data.size() != sizeof(crypto::hash)) { - er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; - er.message = "Invalid address: " + req.address; - return false; - } - const crypto::hash bitcoin_burn_transaction = *reinterpret_cast(expected_bitcoin_hash_data.data()); - - //airdrop reward calculation - cryptonote::tx_destination_entry airdrop_destination = AUTO_VAL_INIT(airdrop_destination); - airdrop_destination.addr = info.address; - airdrop_destination.is_subaddress = info.is_subaddress; - airdrop_destination.token_transaction = false; - airdrop_destination.amount = cryptonote::get_airdrop_cash(token_destination.token_amount); - airdrop_destination.output_type = cryptonote::tx_out_type::out_cash; - - std::vector dsts; - dsts.push_back(token_destination); - dsts.push_back(airdrop_destination); - - - //for migration transaction, extra nonce is so far not used - std::vector extra; - - cryptonote::add_bitcoin_hash_to_extra(extra, bitcoin_burn_transaction); - - try { - // figure out what tx will be necessary - std::vector ptx_vector; - std::string err; - - ptx_vector = m_wallet->create_transactions_migration( - dsts, bitcoin_burn_transaction, 0 /* unlock_time */, 0 /* priority, 0 == default */, - extra, m_trusted_daemon, true); - - if (ptx_vector.empty()) { - er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE; - er.message = "No outputs found, or daemon is not ready"; - return false; - } - - // ugly hack... used bitcoin_hash noy saved in sources - for (auto &ptx : ptx_vector) { - cryptonote::add_bitcoin_hash_to_extra(ptx.construction_data.extra, bitcoin_burn_transaction); - } - - std::string path = req.filename; - bool is_saved = m_wallet->save_tx(ptx_vector, path); - - if (!is_saved) { - er.code = WALLET_RPC_ERROR_CODE_COULD_NOT_SAVE_FILE; - er.message = "Could not save to file"; - return false; - } else { - res.filename = req.filename; - } - } - catch (...) { - er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; - } - return true; -} - -bool wallet_rpc_server::on_sign_migration( - const tools::wallet_rpc::COMMAND_RPC_SIGN_MIGRATION::request &req, - tools::wallet_rpc::COMMAND_RPC_SIGN_MIGRATION::response &res, - epee::json_rpc::error &er) -{ - if (!m_wallet) return not_open(er); - - if (m_wallet->watch_only()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "Command unavailable in view only mode. Must be able to sign transactions."; - return false; - } - - if (m_wallet->restricted()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "Command unavailable in restricted mode."; - return false; - } - - if (m_wallet->key_on_device()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "Command unavailable in restricted mode."; - return false; - } - if (m_wallet->multisig()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "This is a multisig wallet, it can only sign with sign_multisig"; - return false; - } - - std::vector ptx; - try { - bool success = m_wallet->sign_tx( - req.unsigned_filename, req.signed_filename, - ptx, [&](const tools::wallet::unsigned_tx_set &tx) { - return true; - }, false); - - if (!success) { - er.code = WALLET_RPC_ERROR_CODE_COULD_NOT_SAVE_FILE; - er.message = "Failed to sign transaction"; - return false; - } - } - catch (const std::exception &e) { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = std::string("Failed to sign transaction: ") + e.what(); - return false; - } - res.signed_filename = req.signed_filename; - return true; -} - -bool wallet_rpc_server::on_submit_migration( - const tools::wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION::request &req, - tools::wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION::response &res, - epee::json_rpc::error &er) -{ - if (m_wallet->key_on_device()) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = "Command not supported by HW wallet"; - return false; - } - - try - { - std::vector pending_transactions; - bool is_loading_successful = m_wallet->load_tx(req.signed_filename, pending_transactions, - [&](const tools::wallet::signed_tx_set &tx) { - return true; - }); - if (!is_loading_successful) - { - er.code = WALLET_RPC_ERROR_CODE_COULD_NOT_LOAD_SIGNED_TX; - er.message = "Could not load signed transaction"; - return false; - } - - m_wallet->commit_tx(pending_transactions); - res.signed_filename = req.signed_filename; - } - catch (const std::exception& e) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = std::string("Could not submit transaction: ") + e.what(); - return false; - } - - return true; -} - -bool wallet_rpc_server::on_stake_token(const wallet_rpc::COMMAND_RPC_STAKE_TOKEN::request& req, wallet_rpc::COMMAND_RPC_STAKE_TOKEN::response& res, epee::json_rpc::error& er) -{ - std::vector dsts; - std::vector extra; - - LOG_PRINT_L3("on_transfer starts"); - if (!m_wallet) return not_open(er); - if (m_wallet->restricted()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "Command unavailable in restricted mode."; - return false; - } - - // validate the transfer requested and populate dsts & extra - if (!validate_transfer_advanced(req.destinations, req.payment_id, dsts, extra, true, er, safex::command_t::token_stake)) { - return false; - } - - try { - uint64_t mixin; - if (req.ring_size != 0) { - mixin = m_wallet->adjust_mixin(req.ring_size - 1); - } else { - mixin = m_wallet->adjust_mixin(req.mixin); - - } - - uint32_t priority = m_wallet->adjust_priority(req.priority); - std::vector ptx_vector = m_wallet->create_transactions_advanced(safex::command_t::token_stake, - dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, m_trusted_daemon); - - if (ptx_vector.empty()) { - er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE; - er.message = "No transaction created"; - return false; - } - - // reject proposed transactions if there are more than one. see on_transfer_split below. - if (ptx_vector.size() != 1) { - er.code = WALLET_RPC_ERROR_CODE_TX_TOO_LARGE; - er.message = "Transaction would be too large. try /transfer_split."; - return false; - } - - return fill_response(ptx_vector, req.get_tx_key, res.tx_key, res.token_amount, res.fee, res.multisig_txset, - req.do_not_relay, res.tx_hash, req.get_tx_hex, res.tx_blob, req.get_tx_metadata, - res.tx_metadata, er, true); - } - catch (const std::exception &e) { - handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR); - return false; - } - return true; -} - + +// bool wallet_rpc_server::on_migrate_view_only( +// const tools::wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY::request &req, +// tools::wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY::response &res, +// epee::json_rpc::error &er) +// { +// if (!m_wallet) return not_open(er); + +// if (!m_wallet->watch_only()) { +// er.code = WALLET_RPC_ERROR_CODE_DENIED; +// er.message = "Command unavailable in regular mode. Only view mode."; +// return false; +// } + +// if (m_wallet->restricted()) { +// er.code = WALLET_RPC_ERROR_CODE_DENIED; +// er.message = "Command unavailable in restricted mode."; +// return false; +// } + +// cryptonote::address_parse_info info = AUTO_VAL_INIT(info); +// cryptonote::tx_destination_entry token_destination = AUTO_VAL_INIT(token_destination); +// if (!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), req.address)) { +// er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; +// er.message = "Invalid address: " + req.address; +// return false; +// } +// token_destination.addr = info.address; +// token_destination.is_subaddress = info.is_subaddress; +// token_destination.token_transaction = true; +// token_destination.token_amount = req.amount * SAFEX_CASH_COIN; +// token_destination.output_type = cryptonote::tx_out_type::out_token; + +// //parse bitcoin transaction hash +// cryptonote::blobdata expected_bitcoin_hash_data; +// if (!epee::string_tools::parse_hexstr_to_binbuff(req.bitcoin_hash, expected_bitcoin_hash_data) || +// expected_bitcoin_hash_data.size() != sizeof(crypto::hash)) { +// er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; +// er.message = "Invalid address: " + req.address; +// return false; +// } +// const crypto::hash bitcoin_burn_transaction = *reinterpret_cast(expected_bitcoin_hash_data.data()); + +// //airdrop reward calculation +// cryptonote::tx_destination_entry airdrop_destination = AUTO_VAL_INIT(airdrop_destination); +// airdrop_destination.addr = info.address; +// airdrop_destination.is_subaddress = info.is_subaddress; +// airdrop_destination.token_transaction = false; +// airdrop_destination.amount = cryptonote::get_airdrop_cash(token_destination.token_amount); +// airdrop_destination.output_type = cryptonote::tx_out_type::out_cash; + +// std::vector dsts; +// dsts.push_back(token_destination); +// dsts.push_back(airdrop_destination); + + +// //for migration transaction, extra nonce is so far not used +// std::vector extra; + +// cryptonote::add_bitcoin_hash_to_extra(extra, bitcoin_burn_transaction); + +// try { +// // figure out what tx will be necessary +// std::vector ptx_vector; +// std::string err; + +// ptx_vector = m_wallet->create_transactions_migration( +// dsts, bitcoin_burn_transaction, 0 /* unlock_time */, 0 /* priority, 0 == default */, +// extra, m_trusted_daemon, true); + +// if (ptx_vector.empty()) { +// er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE; +// er.message = "No outputs found, or daemon is not ready"; +// return false; +// } + +// // ugly hack... used bitcoin_hash noy saved in sources +// for (auto &ptx : ptx_vector) { +// cryptonote::add_bitcoin_hash_to_extra(ptx.construction_data.extra, bitcoin_burn_transaction); +// } + +// std::string path = req.filename; +// bool is_saved = m_wallet->save_tx(ptx_vector, path); + +// if (!is_saved) { +// er.code = WALLET_RPC_ERROR_CODE_COULD_NOT_SAVE_FILE; +// er.message = "Could not save to file"; +// return false; +// } else { +// res.filename = req.filename; +// } +// } +// catch (...) { +// er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; +// } +// return true; +// } + +// bool wallet_rpc_server::on_sign_migration( +// const tools::wallet_rpc::COMMAND_RPC_SIGN_MIGRATION::request &req, +// tools::wallet_rpc::COMMAND_RPC_SIGN_MIGRATION::response &res, +// epee::json_rpc::error &er) +// { +// if (!m_wallet) return not_open(er); + +// if (m_wallet->watch_only()) { +// er.code = WALLET_RPC_ERROR_CODE_DENIED; +// er.message = "Command unavailable in view only mode. Must be able to sign transactions."; +// return false; +// } + +// if (m_wallet->restricted()) { +// er.code = WALLET_RPC_ERROR_CODE_DENIED; +// er.message = "Command unavailable in restricted mode."; +// return false; +// } + +// if (m_wallet->key_on_device()) { +// er.code = WALLET_RPC_ERROR_CODE_DENIED; +// er.message = "Command unavailable in restricted mode."; +// return false; +// } +// if (m_wallet->multisig()) { +// er.code = WALLET_RPC_ERROR_CODE_DENIED; +// er.message = "This is a multisig wallet, it can only sign with sign_multisig"; +// return false; +// } + +// std::vector ptx; +// try { +// bool success = m_wallet->sign_tx( +// req.unsigned_filename, req.signed_filename, +// ptx, [&](const tools::wallet::unsigned_tx_set &tx) { +// return true; +// }, false); + +// if (!success) { +// er.code = WALLET_RPC_ERROR_CODE_COULD_NOT_SAVE_FILE; +// er.message = "Failed to sign transaction"; +// return false; +// } +// } +// catch (const std::exception &e) { +// er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; +// er.message = std::string("Failed to sign transaction: ") + e.what(); +// return false; +// } +// res.signed_filename = req.signed_filename; +// return true; +// } + +// bool wallet_rpc_server::on_submit_migration( +// const tools::wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION::request &req, +// tools::wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION::response &res, +// epee::json_rpc::error &er) +// { +// if (m_wallet->key_on_device()) +// { +// er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; +// er.message = "Command not supported by HW wallet"; +// return false; +// } + +// try +// { +// std::vector pending_transactions; +// bool is_loading_successful = m_wallet->load_tx(req.signed_filename, pending_transactions, +// [&](const tools::wallet::signed_tx_set &tx) { +// return true; +// }); +// if (!is_loading_successful) +// { +// er.code = WALLET_RPC_ERROR_CODE_COULD_NOT_LOAD_SIGNED_TX; +// er.message = "Could not load signed transaction"; +// return false; +// } + +// m_wallet->commit_tx(pending_transactions); +// res.signed_filename = req.signed_filename; +// } +// catch (const std::exception& e) +// { +// er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; +// er.message = std::string("Could not submit transaction: ") + e.what(); +// return false; +// } + +// return true; +// } + + +// bool wallet_rpc_server::on_stake_token(const wallet_rpc::COMMAND_RPC_STAKE_TOKEN::request& req, wallet_rpc::COMMAND_RPC_STAKE_TOKEN::response& res, epee::json_rpc::error& er) +// { +// std::vector dsts; +// std::vector extra; +// +// LOG_PRINT_L3("on_transfer starts"); +// if (!m_wallet) return not_open(er); +// if (m_wallet->restricted()) { +// er.code = WALLET_RPC_ERROR_CODE_DENIED; +// er.message = "Command unavailable in restricted mode."; +// return false; +// } +// +// validate the transfer requested and populate dsts & extra +// if (!validate_transfer_advanced(req.destinations, req.payment_id, dsts, extra, true, er, safex::command_t::token_stake)) { +// return false; +// } +// +// try { +// uint64_t mixin; +// if (req.ring_size != 0) { +// mixin = m_wallet->adjust_mixin(req.ring_size - 1); +// } else { +// mixin = m_wallet->adjust_mixin(req.mixin); +// +// } +// +// uint32_t priority = m_wallet->adjust_priority(req.priority); +// std::vector ptx_vector = m_wallet->create_transactions_advanced(safex::command_t::token_stake, +// dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, m_trusted_daemon); +// +// if (ptx_vector.empty()) { +// er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE; +// er.message = "No transaction created"; +// return false; +// } +// +// reject proposed transactions if there are more than one. see on_transfer_split below. +// if (ptx_vector.size() != 1) { +// er.code = WALLET_RPC_ERROR_CODE_TX_TOO_LARGE; +// er.message = "Transaction would be too large. try /transfer_split."; +// return false; +// } +// +// return fill_response(ptx_vector, req.get_tx_key, res.tx_key, res.token_amount, res.fee, res.multisig_txset, +// req.do_not_relay, res.tx_hash, req.get_tx_hex, res.tx_blob, req.get_tx_metadata, +// res.tx_metadata, er, true); +// } +// catch (const std::exception &e) { +// handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR); +// return false; +// } +// return true; +// } +/* bool wallet_rpc_server::on_donate_safex_fee(const wallet_rpc::COMMAND_RPC_DONATE_SAFEX_FEE::request& req, wallet_rpc::COMMAND_RPC_DONATE_SAFEX_FEE::response& res, epee::json_rpc::error& er) { std::vector dsts; @@ -3176,124 +3178,62 @@ bool wallet_rpc_server::on_donate_safex_fee(const wallet_rpc::COMMAND_RPC_DONATE } return true; } - -bool wallet_rpc_server::on_unstake_token(const wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN::request& req, wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN::response& res, epee::json_rpc::error& er) -{ - std::vector dsts; - std::vector extra; - - LOG_PRINT_L3("on_transfer starts"); - if (!m_wallet) return not_open(er); - if (m_wallet->restricted()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "Command unavailable in restricted mode."; - return false; - } - - // validate the transfer requested and populate dsts & extra - if (!validate_transfer_advanced(req.destinations, req.payment_id, dsts, extra, true, er, safex::command_t::token_unstake)) { - return false; - } - - try { - uint64_t mixin; - if (req.ring_size != 0) { - mixin = m_wallet->adjust_mixin(req.ring_size - 1); - } else { - mixin = m_wallet->adjust_mixin(req.mixin); - - } - - uint32_t priority = m_wallet->adjust_priority(req.priority); - std::vector ptx_vector = m_wallet->create_transactions_advanced(safex::command_t::token_unstake, - dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, m_trusted_daemon); - - if (ptx_vector.empty()) { - er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE; - er.message = "No transaction created"; - return false; - } - - // reject proposed transactions if there are more than one. see on_transfer_split below. - if (ptx_vector.size() != 1) { - er.code = WALLET_RPC_ERROR_CODE_TX_TOO_LARGE; - er.message = "Transaction would be too large. try /transfer_split."; - return false; - } - - return fill_response(ptx_vector, req.get_tx_key, res.tx_key, res.token_amount, res.fee, res.multisig_txset, - req.do_not_relay, res.tx_hash, req.get_tx_hex, res.tx_blob, req.get_tx_metadata, - res.tx_metadata, er, true); - } - catch (const std::exception &e) { - handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR); - return false; - } - return true; -} - -bool wallet_rpc_server::on_make_demo_purchase(const wallet_rpc::COMMAND_RPC_DEMO_PURCHASE::request& req, wallet_rpc::COMMAND_RPC_DEMO_PURCHASE::response& res, epee::json_rpc::error& er) -{ - std::vector dsts; - std::vector extra; - - LOG_PRINT_L3("on_transfer starts"); - if (!m_wallet) return not_open(er); - if (m_wallet->restricted()) { - er.code = WALLET_RPC_ERROR_CODE_DENIED; - er.message = "Command unavailable in restricted mode."; - return false; - } - - // validate the transfer requested and populate dsts & extra - if (!validate_transfer_advanced(req.destinations, req.payment_id, dsts, extra, true, er, safex::command_t::simple_purchase)) { - return false; - } - - if(simple_trade_ids.find(req.offer_id) == simple_trade_ids.end()){ - er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE; - er.message = "There is no offer with given offer id!!!"; - return false; - } else { - res.purchased_offer_id = req.offer_id; - } - - try { - uint64_t mixin; - if (req.ring_size != 0) { - mixin = m_wallet->adjust_mixin(req.ring_size - 1); - } else { - mixin = m_wallet->adjust_mixin(req.mixin); - - } - - uint32_t priority = m_wallet->adjust_priority(req.priority); - std::vector ptx_vector = m_wallet->create_transactions_advanced(safex::command_t::simple_purchase, - dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, m_trusted_daemon); - - if (ptx_vector.empty()) { - er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE; - er.message = "No transaction created"; - return false; - } - - // reject proposed transactions if there are more than one. see on_transfer_split below. - if (ptx_vector.size() != 1) { - er.code = WALLET_RPC_ERROR_CODE_TX_TOO_LARGE; - er.message = "Transaction would be too large. try /transfer_split."; - return false; - } - - return fill_response(ptx_vector, req.get_tx_key, res.tx_key, res.token_amount, res.fee, res.multisig_txset, - req.do_not_relay, res.tx_hash, req.get_tx_hex, res.tx_blob, req.get_tx_metadata, - res.tx_metadata, er, true); - } - catch (const std::exception &e) { - handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR); - return false; - } - return true; -} +*/ + +// bool wallet_rpc_server::on_unstake_token(const wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN::request& req, wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN::response& res, epee::json_rpc::error& er) +// { +// std::vector dsts; +// std::vector extra; +// +// LOG_PRINT_L3("on_transfer starts"); +// if (!m_wallet) return not_open(er); +// if (m_wallet->restricted()) { +// er.code = WALLET_RPC_ERROR_CODE_DENIED; +// er.message = "Command unavailable in restricted mode."; +// return false; +// } +// +// validate the transfer requested and populate dsts & extra +// if (!validate_transfer_advanced(req.destinations, req.payment_id, dsts, extra, true, er, safex::command_t::token_unstake)) { +// return false; +// } +// +// try { +// uint64_t mixin; +// if (req.ring_size != 0) { +// mixin = m_wallet->adjust_mixin(req.ring_size - 1); +// } else { +// mixin = m_wallet->adjust_mixin(req.mixin); +// +// } +// +// uint32_t priority = m_wallet->adjust_priority(req.priority); +// std::vector ptx_vector = m_wallet->create_transactions_advanced(safex::command_t::token_unstake, +// dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, m_trusted_daemon); +// +// if (ptx_vector.empty()) { +// er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE; +// er.message = "No transaction created"; +// return false; +// } +// +// reject proposed transactions if there are more than one. see on_transfer_split below. +// if (ptx_vector.size() != 1) { +// er.code = WALLET_RPC_ERROR_CODE_TX_TOO_LARGE; +// er.message = "Transaction would be too large. try /transfer_split."; +// return false; +// } +// +// return fill_response(ptx_vector, req.get_tx_key, res.tx_key, res.token_amount, res.fee, res.multisig_txset, +// req.do_not_relay, res.tx_hash, req.get_tx_hex, res.tx_blob, req.get_tx_metadata, +// res.tx_metadata, er, true); +// } +// catch (const std::exception &e) { +// handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR); +// return false; +// } +// return true; +// } bool wallet_rpc_server::on_available_interest(const wallet_rpc::COMMAND_RPC_GET_AVAILABLE_INTEREST::request& req, wallet_rpc::COMMAND_RPC_GET_AVAILABLE_INTEREST::response& res, diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index dc905c25..2f4e9537 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -131,26 +131,21 @@ namespace tools MAP_JON_RPC_WE("get_languages", on_get_languages, wallet_rpc::COMMAND_RPC_GET_LANGUAGES) MAP_JON_RPC_WE("create_wallet", on_create_wallet, wallet_rpc::COMMAND_RPC_CREATE_WALLET) MAP_JON_RPC_WE("open_wallet", on_open_wallet, wallet_rpc::COMMAND_RPC_OPEN_WALLET) - MAP_JON_RPC_WE("migrate_view_only", on_migrate_view_only, wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY) - MAP_JON_RPC_WE("sign_migration", on_sign_migration, wallet_rpc::COMMAND_RPC_SIGN_MIGRATION) - MAP_JON_RPC_WE("submit_migration", on_submit_migration, wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION) MAP_JON_RPC_WE("is_multisig", on_is_multisig, wallet_rpc::COMMAND_RPC_IS_MULTISIG) MAP_JON_RPC_WE("get_available_interest", on_available_interest, wallet_rpc::COMMAND_RPC_GET_AVAILABLE_INTEREST) - MAP_JON_RPC_WE("stake_token", on_stake_token, wallet_rpc::COMMAND_RPC_STAKE_TOKEN) - MAP_JON_RPC_WE("unstake_token", on_unstake_token, wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN) - MAP_JON_RPC_WE("donate_safex_fee", on_donate_safex_fee, wallet_rpc::COMMAND_RPC_DONATE_SAFEX_FEE) - MAP_JON_RPC_WE("make_demo_purchase", on_make_demo_purchase, wallet_rpc::COMMAND_RPC_DEMO_PURCHASE) +// MAP_JON_RPC_WE("stake_token", on_stake_token, wallet_rpc::COMMAND_RPC_STAKE_TOKEN) +// MAP_JON_RPC_WE("unstake_token", on_unstake_token, wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN) +// MAP_JON_RPC_WE("donate_safex_fee", on_donate_safex_fee, wallet_rpc::COMMAND_RPC_DONATE_SAFEX_FEE) END_JSON_RPC_MAP() END_URI_MAP2() //json_rpc bool on_available_interest(const wallet_rpc::COMMAND_RPC_GET_AVAILABLE_INTEREST::request& req, wallet_rpc::COMMAND_RPC_GET_AVAILABLE_INTEREST::response& res, epee::json_rpc::error& er); - bool on_stake_token(const wallet_rpc::COMMAND_RPC_STAKE_TOKEN::request& req, wallet_rpc::COMMAND_RPC_STAKE_TOKEN::response& res, epee::json_rpc::error& er); - bool on_unstake_token(const wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN::request& req, wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN::response& res, epee::json_rpc::error& er); - bool on_donate_safex_fee(const wallet_rpc::COMMAND_RPC_DONATE_SAFEX_FEE::request& req, wallet_rpc::COMMAND_RPC_DONATE_SAFEX_FEE::response& res, epee::json_rpc::error& er); - bool on_make_demo_purchase(const wallet_rpc::COMMAND_RPC_DEMO_PURCHASE::request& req, wallet_rpc::COMMAND_RPC_DEMO_PURCHASE::response& res, epee::json_rpc::error& er); +// bool on_stake_token(const wallet_rpc::COMMAND_RPC_STAKE_TOKEN::request& req, wallet_rpc::COMMAND_RPC_STAKE_TOKEN::response& res, epee::json_rpc::error& er); +// bool on_unstake_token(const wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN::request& req, wallet_rpc::COMMAND_RPC_UNSTAKE_TOKEN::response& res, epee::json_rpc::error& er); +// bool on_donate_safex_fee(const wallet_rpc::COMMAND_RPC_DONATE_SAFEX_FEE::request& req, wallet_rpc::COMMAND_RPC_DONATE_SAFEX_FEE::response& res, epee::json_rpc::error& er); bool on_refresh(const wallet_rpc::COMMAND_RPC_REFRESH::request& req, wallet_rpc::COMMAND_RPC_REFRESH::response& res, epee::json_rpc::error& er); bool on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE::request& req, wallet_rpc::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er); @@ -214,10 +209,10 @@ namespace tools bool on_open_wallet(const wallet_rpc::COMMAND_RPC_OPEN_WALLET::request& req, wallet_rpc::COMMAND_RPC_OPEN_WALLET::response& res, epee::json_rpc::error& er); bool on_is_multisig(const wallet_rpc::COMMAND_RPC_IS_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_IS_MULTISIG::response& res, epee::json_rpc::error& er); - // migration rpc - bool on_migrate_view_only(const wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY::request& req, wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY::response& res, epee::json_rpc::error& er); - bool on_sign_migration(const tools::wallet_rpc::COMMAND_RPC_SIGN_MIGRATION::request &req, tools::wallet_rpc::COMMAND_RPC_SIGN_MIGRATION::response &res, epee::json_rpc::error &er); - bool on_submit_migration(const tools::wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION::request &req, tools::wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION::response &res, epee::json_rpc::error &er); + // migration rpc. Not needed anymore +// bool on_migrate_view_only(const wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY::request& req, wallet_rpc::COMMAND_RPC_MIGRATE_VIEW_ONLY::response& res, epee::json_rpc::error& er); +// bool on_sign_migration(const tools::wallet_rpc::COMMAND_RPC_SIGN_MIGRATION::request &req, tools::wallet_rpc::COMMAND_RPC_SIGN_MIGRATION::response &res, epee::json_rpc::error &er); +// bool on_submit_migration(const tools::wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION::request &req, tools::wallet_rpc::COMMAND_RPC_SUBMIT_MIGRATION::response &res, epee::json_rpc::error &er); //json rpc v2 bool on_query_key(const wallet_rpc::COMMAND_RPC_QUERY_KEY::request& req, wallet_rpc::COMMAND_RPC_QUERY_KEY::response& res, epee::json_rpc::error& er); @@ -241,6 +236,5 @@ namespace tools bool m_trusted_daemon; const boost::program_options::variables_map *m_vm; - std::map simple_trade_ids; }; } diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index dcda07ca..f56f5492 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -2165,72 +2165,72 @@ namespace wallet_rpc typedef epee::misc_utils::struct_init response; }; -struct COMMAND_RPC_MIGRATE_VIEW_ONLY -{ - struct request_t { - uint64_t amount; - std::string address; - std::string bitcoin_hash; - std::string unsigned_transaction_filename; - std::string filename; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(amount) - KV_SERIALIZE(address) - KV_SERIALIZE(bitcoin_hash) - KV_SERIALIZE(unsigned_transaction_filename) - KV_SERIALIZE(filename) - END_KV_SERIALIZE_MAP() - }; - typedef epee::misc_utils::struct_init request; - - struct response_t { - std::string filename; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(filename) - END_KV_SERIALIZE_MAP() - }; - typedef epee::misc_utils::struct_init response; -}; - -struct COMMAND_RPC_SIGN_MIGRATION -{ - struct request_t { - std::string unsigned_filename; - std::string signed_filename; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(unsigned_filename) - KV_SERIALIZE(signed_filename) - END_KV_SERIALIZE_MAP() - }; - typedef epee::misc_utils::struct_init request; - - struct response_t { - std::string signed_filename; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(signed_filename) - END_KV_SERIALIZE_MAP() - }; - typedef epee::misc_utils::struct_init response; -}; - -struct COMMAND_RPC_SUBMIT_MIGRATION -{ - struct request_t { - std::string signed_filename; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(signed_filename) - END_KV_SERIALIZE_MAP() - }; - typedef epee::misc_utils::struct_init request; - - struct response_t { - std::string signed_filename; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(signed_filename) - END_KV_SERIALIZE_MAP() - }; - typedef epee::misc_utils::struct_init response; -}; +// struct COMMAND_RPC_MIGRATE_VIEW_ONLY +// { +// struct request_t { +// uint64_t amount; +// std::string address; +// std::string bitcoin_hash; +// std::string unsigned_transaction_filename; +// std::string filename; +// BEGIN_KV_SERIALIZE_MAP() +// KV_SERIALIZE(amount) +// KV_SERIALIZE(address) +// KV_SERIALIZE(bitcoin_hash) +// KV_SERIALIZE(unsigned_transaction_filename) +// KV_SERIALIZE(filename) +// END_KV_SERIALIZE_MAP() +// }; +// typedef epee::misc_utils::struct_init request; +// +// struct response_t { +// std::string filename; +// BEGIN_KV_SERIALIZE_MAP() +// KV_SERIALIZE(filename) +// END_KV_SERIALIZE_MAP() +// }; +// typedef epee::misc_utils::struct_init response; +// }; +// +// struct COMMAND_RPC_SIGN_MIGRATION +// { +// struct request_t { +// std::string unsigned_filename; +// std::string signed_filename; +// BEGIN_KV_SERIALIZE_MAP() +// KV_SERIALIZE(unsigned_filename) +// KV_SERIALIZE(signed_filename) +// END_KV_SERIALIZE_MAP() +// }; +// typedef epee::misc_utils::struct_init request; +// +// struct response_t { +// std::string signed_filename; +// BEGIN_KV_SERIALIZE_MAP() +// KV_SERIALIZE(signed_filename) +// END_KV_SERIALIZE_MAP() +// }; +// typedef epee::misc_utils::struct_init response; +// }; +// +// struct COMMAND_RPC_SUBMIT_MIGRATION +// { +// struct request_t { +// std::string signed_filename; +// BEGIN_KV_SERIALIZE_MAP() +// KV_SERIALIZE(signed_filename) +// END_KV_SERIALIZE_MAP() +// }; +// typedef epee::misc_utils::struct_init request; +// +// struct response_t { +// std::string signed_filename; +// BEGIN_KV_SERIALIZE_MAP() +// KV_SERIALIZE(signed_filename) +// END_KV_SERIALIZE_MAP() +// }; +// typedef epee::misc_utils::struct_init response; +// }; struct COMMAND_RPC_REFRESH { @@ -2429,67 +2429,6 @@ struct COMMAND_RPC_DONATE_SAFEX_FEE }; }; -struct COMMAND_RPC_DEMO_PURCHASE -{ - struct request - { - std::list destinations; - uint32_t account_index; - std::string offer_id; - std::set subaddr_indices; - uint32_t priority; - uint64_t mixin; - uint64_t ring_size; - uint64_t unlock_time; - std::string payment_id; - bool get_tx_key; - bool do_not_relay; - bool get_tx_hex; - bool get_tx_metadata; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(destinations) - KV_SERIALIZE(account_index) - KV_SERIALIZE(offer_id) - KV_SERIALIZE(subaddr_indices) - KV_SERIALIZE(priority) - KV_SERIALIZE_OPT(mixin, (uint64_t)0) - KV_SERIALIZE_OPT(ring_size, (uint64_t)0) - KV_SERIALIZE(unlock_time) - KV_SERIALIZE(payment_id) - KV_SERIALIZE(get_tx_key) - KV_SERIALIZE_OPT(do_not_relay, false) - KV_SERIALIZE_OPT(get_tx_hex, false) - KV_SERIALIZE_OPT(get_tx_metadata, false) - END_KV_SERIALIZE_MAP() - }; - - struct response - { - std::string tx_hash; - std::string tx_key; - std::string purchased_offer_id; - std::list amount_keys; - uint64_t token_amount; - uint64_t fee; - std::string tx_blob; - std::string tx_metadata; - std::string multisig_txset; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(tx_hash) - KV_SERIALIZE(tx_key) - KV_SERIALIZE(purchased_offer_id) - KV_SERIALIZE(amount_keys) - KV_SERIALIZE(token_amount) - KV_SERIALIZE(fee) - KV_SERIALIZE(tx_blob) - KV_SERIALIZE(tx_metadata) - KV_SERIALIZE(multisig_txset) - END_KV_SERIALIZE_MAP() - }; -}; - struct COMMAND_RPC_GET_AVAILABLE_INTEREST { struct request diff --git a/src/wallet/wallet_safex.cpp b/src/wallet/wallet_safex.cpp index db6e843e..a438047d 100644 --- a/src/wallet/wallet_safex.cpp +++ b/src/wallet/wallet_safex.cpp @@ -348,7 +348,17 @@ namespace tools std::vector wallet::get_safex_accounts() { - return std::vector(m_safex_accounts.begin(), m_safex_accounts.end()); + + for (const auto& td: m_transfers) + { + if(td.m_output_type == tx_out_type::out_safex_account || td.m_output_type == tx_out_type::out_safex_account_update) + { + const txout_to_script &txout = boost::get(td.m_tx.vout[td.m_internal_output_index].target); + process_advanced_output(txout, td.m_output_type); + } + } + + return m_safex_accounts; } //----------------------------------------------------------------------------------------------------------------- uint8_t wallet::get_safex_account_status(const safex::safex_account& sfx_account) const { @@ -624,21 +634,68 @@ namespace tools std::vector wallet::get_my_safex_offers() { + m_safex_offers.clear(); + + for (const auto& td: m_transfers) + { + if(td.m_output_type == tx_out_type::out_safex_offer || td.m_output_type == tx_out_type::out_safex_offer_update + || td.m_output_type == tx_out_type::out_safex_purchase) + { + const txout_to_script &txout = boost::get(td.m_tx.vout[td.m_internal_output_index].target); + process_advanced_output(txout, td.m_output_type); + } + } + return m_safex_offers; } std::vector wallet::get_my_safex_price_pegs() { - return m_safex_price_pegs; + m_safex_price_pegs.clear(); + + for (const auto& td: m_transfers) + { + if(td.m_output_type == tx_out_type::out_safex_price_peg || td.m_output_type == tx_out_type::out_safex_price_peg_update) + { + const txout_to_script &txout = boost::get(td.m_tx.vout[td.m_internal_output_index].target); + process_advanced_output(txout, td.m_output_type); + } + } + + return m_safex_price_pegs; } std::vector wallet::get_my_safex_feedbacks_to_give() { - return m_safex_feedback_tokens; + m_safex_feedback_tokens.clear(); + m_safex_given_feedbacks.clear(); + + for (const auto& td: m_transfers) + { + if(td.m_output_type == tx_out_type::out_safex_feedback_token || td.m_output_type == tx_out_type::out_safex_feedback) + { + const txout_to_script &txout = boost::get(td.m_tx.vout[td.m_internal_output_index].target); + process_advanced_output(txout, td.m_output_type); + } + } + + return m_safex_feedback_tokens; } std::vector wallet::get_my_safex_feedbacks_given() { + m_safex_feedback_tokens.clear(); + m_safex_given_feedbacks.clear(); + + for (const auto& td: m_transfers) + { + if(td.m_output_type == tx_out_type::out_safex_feedback_token || td.m_output_type == tx_out_type::out_safex_feedback) + { + const txout_to_script &txout = boost::get(td.m_tx.vout[td.m_internal_output_index].target); + process_advanced_output(txout, td.m_output_type); + } + } + return m_safex_given_feedbacks; }