Skip to content

Commit

Permalink
Merge pull request #257 from safex/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
VanGrx authored Jul 12, 2021
2 parents 3b9b23a + e7ef8c1 commit 48cb13c
Show file tree
Hide file tree
Showing 13 changed files with 586 additions and 533 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ubuntu-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/rpc_command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
58 changes: 55 additions & 3 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<COMMAND_RPC_GET_SAFEX_OFFERS_JSON>(invoke_http_mode::JON, "/get_safex_offers_json", req, res, r))
return r;

std::vector<safex::safex_offer> 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)
{
Expand Down Expand Up @@ -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<cryptonote::tx_out_type>(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))
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<cryptonote::tx_out_type>(req.out_type_as_int);
}
else {
output_type = req.out_type;
}


for (uint64_t amount: req.amounts)
{
static struct D
Expand All @@ -2369,7 +2421,7 @@ namespace cryptonote

std::vector<uint64_t> 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";
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions src/rpc/core_rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
74 changes: 71 additions & 3 deletions src/rpc/core_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,66 @@ namespace cryptonote
typedef epee::misc_utils::struct_init<response_t> 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_t> request;

struct entry
{
std::string title;
uint64_t quantity;
uint64_t price;
uint64_t min_sfx_price;
std::vector<uint8_t> description;
bool active;
bool price_peg_used;
std::vector<uint8_t> 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<entry> 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_t> response;
};

struct COMMAND_RPC_GET_SAFEX_PRICE_PEGS
{
struct request_t
Expand Down Expand Up @@ -1095,9 +1155,13 @@ namespace cryptonote
struct request_t
{
std::vector<get_outputs_out> 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_t> request;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
};
Expand Down Expand Up @@ -2834,6 +2900,7 @@ namespace cryptonote
uint64_t end;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(interval)
KV_SERIALIZE(end)
END_KV_SERIALIZE_MAP()
};

Expand Down Expand Up @@ -2867,6 +2934,7 @@ namespace cryptonote
uint64_t end;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(interval)
KV_SERIALIZE(end)
END_KV_SERIALIZE_MAP()
};

Expand Down
12 changes: 7 additions & 5 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8828,12 +8828,14 @@ std::vector<wallet::pending_tx> 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;
}
}
};
Expand Down
Loading

0 comments on commit 48cb13c

Please sign in to comment.