From aa06b37024fcb1a37af1e4e575f861ef1966c798 Mon Sep 17 00:00:00 2001 From: Igor Grkavac Date: Wed, 22 Jan 2020 16:21:32 +0100 Subject: [PATCH] Update of Safe purchase logic * Wallet now needs OfferID and quantity of product as input * Offer creation takes private view key and public address * With this, we can verify if funds are sent to the seller * Updated tests --- src/blockchain_db/lmdb/db_lmdb.cpp | 2 + src/cryptonote_core/blockchain.cpp | 13 +++- src/cryptonote_core/cryptonote_core.cpp | 2 +- src/rpc/core_rpc_server.cpp | 2 +- src/rpc/core_rpc_server_commands_defs.h | 2 + src/safex/command.h | 18 ++++- src/safex/safex_offer.h | 16 +++- src/simplewallet/simplewallet.cpp | 2 +- src/simplewallet/simplewallet_safex.cpp | 97 ++++++++++++++----------- src/wallet/wallet_safex.cpp | 2 +- tests/core_tests/safex_offer.cpp | 10 ++- tests/core_tests/safex_offer.h | 2 + tests/core_tests/safex_purchase.cpp | 27 ++----- tests/core_tests/safex_purchase.h | 3 + tests/unit_tests/safex_offer.cpp | 6 +- tests/unit_tests/simple_purchase.cpp | 4 +- 16 files changed, 120 insertions(+), 88 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 0c0212b00..995adb049 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -5505,6 +5505,8 @@ bool BlockchainLMDB::is_valid_transaction_output_type(const txout_target_v &txou offer.offer_id = offer_result.offer_id; offer.active = offer_result.active; offer.title = std::string{offer_result.title.begin(),offer_result.title.end()}; + offer.seller_private_view_key = offer_result.seller_private_view_key; + offer.seller_address = offer_result.seller_address; } else if (get_result == MDB_NOTFOUND) { diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 3ca6d74a9..abc6f98b6 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3320,11 +3320,11 @@ bool Blockchain::check_safex_tx(const transaction &tx, tx_verification_context & total_payment = purchase.price; get_safex_offer(purchase.offer_id, offer_to_purchase); - std::string desc_secret_key{offer_to_purchase.description.begin(), offer_to_purchase.description.begin()+64}; - epee::string_tools::hex_to_pod(desc_secret_key, secret_seller_view_key); + secret_seller_view_key = offer_to_purchase.seller_private_view_key; + cryptonote::account_public_address seller_address = offer_to_purchase.seller_address; - std::string desc_public_key{offer_to_purchase.description.begin()+65, offer_to_purchase.description.end()}; - epee::string_tools::hex_to_pod(desc_public_key, public_seller_spend_key); + public_seller_spend_key = seller_address.m_spend_public_key; + std::string seller_key_str = epee::string_tools::pod_to_hex(public_seller_spend_key); } } @@ -6053,6 +6053,11 @@ bool Blockchain::get_safex_offers( std::vector &safex_offers std::vector Blockchain::is_safex_purchase_right_address(crypto::secret_key seller_secret_view_key, crypto::public_key public_seller_spend_key, const cryptonote::transaction& tx) { + crypto::public_key pkey; + if (!crypto::secret_key_to_public_key(seller_secret_view_key, pkey)) { + return {}; + } + hw::device &hwdev = hw::get_device("default"); boost::unique_lock hwdev_lock (hwdev); diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index adc41b0cd..e0ad421ff 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1167,7 +1167,7 @@ namespace cryptonote //todo Atana optimize somehow key image validation, so many conversions const crypto::key_image &k_image = *boost::apply_visitor(key_image_visitor(), in); std::unique_ptr cmd = safex::safex_command_serializer::parse_safex_command(txin.script); - safex::create_offer_data offer(cmd->get_offerid(),cmd->get_seller(),cmd->get_title(),cmd->get_quantity(),cmd->get_price(),cmd->get_description(),cmd->get_active()); + safex::create_offer_data offer(cmd->get_offerid(),cmd->get_seller(),cmd->get_title(),cmd->get_quantity(),cmd->get_price(),cmd->get_description(),cmd->get_active(),cmd->get_seller_address(),cmd->get_seller_private_view_key()); crypto::hash cmd_hash{}; get_object_hash(offer, cmd_hash); if (memcmp(cmd_hash.data, k_image.data, sizeof(k_image.data)) != 0) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 81107845f..f304a23d4 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -184,7 +184,7 @@ namespace cryptonote for(auto offer: offers) { std::string offer_id_str = epee::string_tools::pod_to_hex(offer.offer_id); - COMMAND_RPC_GET_SAFEX_OFFERS::entry ent{offer.title,offer.quantity,offer.price,offer.description,offer.active,offer.shipping,offer_id_str,offer.seller}; + COMMAND_RPC_GET_SAFEX_OFFERS::entry ent{offer.title,offer.quantity,offer.price,offer.description,offer.active,offer.shipping,offer_id_str,offer.seller,offer.seller_address}; res.offers.push_back(ent); } res.status = CORE_RPC_STATUS_OK; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 9d0adc020..a9c36631e 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -131,6 +131,7 @@ namespace cryptonote std::vector shipping; std::string offer_id; std::string seller; + cryptonote::account_public_address seller_address; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(title) @@ -141,6 +142,7 @@ namespace cryptonote KV_SERIALIZE(shipping) KV_SERIALIZE(offer_id) KV_SERIALIZE(seller) + KV_SERIALIZE(seller_address) END_KV_SERIALIZE_MAP() }; diff --git a/src/safex/command.h b/src/safex/command.h index 02ba1c7fd..8b8135f0e 100644 --- a/src/safex/command.h +++ b/src/safex/command.h @@ -276,13 +276,15 @@ struct edit_offer_result : public execution_result uint64_t price; std::vector description{}; bool active{false}; + crypto::secret_key seller_private_view_key; + cryptonote::account_public_address seller_address; create_offer_data() {} - create_offer_data(const safex::safex_offer& offer): offer_id{offer.offer_id}, description{offer.description},quantity{offer.quantity},price{offer.price},seller(offer.seller.begin(),offer.seller.end()),active{offer.active},title{offer.title.begin(),offer.title.end()} + create_offer_data(const safex::safex_offer& offer): offer_id{offer.offer_id}, description{offer.description},quantity{offer.quantity},price{offer.price},seller(offer.seller.begin(),offer.seller.end()),active{offer.active},title{offer.title.begin(),offer.title.end()},seller_address{offer.seller_address},seller_private_view_key{offer.seller_private_view_key} { } - create_offer_data(const crypto::hash &_offer_id, const std::vector &_seller, const std::vector &_title, const uint64_t &_quantity, const uint64_t &_price, const std::vector &_offer_data,const bool &_active): - offer_id{_offer_id},seller{_seller},title{_title},quantity{_quantity},price{_price},description{_offer_data},active{_active}{} + create_offer_data(const crypto::hash &_offer_id, const std::vector &_seller, const std::vector &_title, const uint64_t &_quantity, const uint64_t &_price, const std::vector &_offer_data,const bool &_active, const cryptonote::account_public_address& _seller_address, const crypto::secret_key& _seller_private_view_key): + offer_id{_offer_id},seller{_seller},title{_title},quantity{_quantity},price{_price},description{_offer_data},active{_active},seller_address{_seller_address},seller_private_view_key{_seller_private_view_key}{} BEGIN_SERIALIZE_OBJECT() FIELD(offer_id) @@ -292,6 +294,8 @@ struct edit_offer_result : public execution_result FIELD(quantity) FIELD(active) FIELD(description) + FIELD(seller_private_view_key) + FIELD(seller_address) END_SERIALIZE() }; @@ -698,7 +702,7 @@ class create_offer : public command * */ create_offer(const uint32_t _version, const safex::create_offer_data &offer) : command(_version, command_t::create_offer), offer_id(offer.offer_id), description{offer.description}, - seller{offer.seller},title{offer.title},price{offer.price},quantity{offer.quantity},active{offer.active}{ + seller{offer.seller},title{offer.title},price{offer.price},quantity{offer.quantity},active{offer.active},seller_address{offer.seller_address},seller_private_view_key{offer.seller_private_view_key}{ } create_offer() : command(0, command_t::create_offer), offer_id{}, description{} {} @@ -710,6 +714,8 @@ class create_offer : public command uint64_t get_quantity() const { return quantity; } bool get_active() const { return active; } std::vector get_description() const { return description; } + cryptonote::account_public_address get_seller_address() const { return seller_address; } + crypto::secret_key get_seller_private_view_key() const { return seller_private_view_key; } virtual create_offer_result* execute(const cryptonote::BlockchainDB &blokchain, const cryptonote::txin_to_script &txin) override; virtual execution_status validate(const cryptonote::BlockchainDB &blokchain, const cryptonote::txin_to_script &txin) override; @@ -724,6 +730,8 @@ class create_offer : public command FIELD(quantity) FIELD(active) FIELD(description) + FIELD(seller_private_view_key) + FIELD(seller_address) END_SERIALIZE() private: @@ -734,6 +742,8 @@ class create_offer : public command uint64_t price; std::vector description{}; bool active{}; + crypto::secret_key seller_private_view_key; + cryptonote::account_public_address seller_address; }; class edit_offer : public command diff --git a/src/safex/safex_offer.h b/src/safex/safex_offer.h index 022f23b3a..7ba3615cb 100644 --- a/src/safex/safex_offer.h +++ b/src/safex/safex_offer.h @@ -32,15 +32,15 @@ namespace safex } safex_offer(const std::string &_title, const uint64_t _quantity, const uint64_t _price, const std::vector &_description, - crypto::hash _id, std::string seller_username, bool _active = true):title{_title},quantity{_quantity},price{_price}, - description{_description},offer_id{_id},seller{seller_username},active{_active} + crypto::hash _id, std::string seller_username, bool _active = true , const cryptonote::account_public_address& _seller_address = {}, const crypto::secret_key& view_key = {}):title{_title},quantity{_quantity},price{_price}, + description{_description},offer_id{_id},seller{seller_username},active{_active},seller_private_view_key{view_key},seller_address{_seller_address} { } safex_offer(const std::string &_title, const uint64_t _quantity, const uint64_t _price, const std::string& _description, - std::string seller_username): - title{_title}, quantity{_quantity}, price{_price}, active{true}, shipping{}, seller{seller_username} { + std::string seller_username, const crypto::secret_key& view_key, const cryptonote::account_public_address& _seller_address = {}): + title{_title}, quantity{_quantity}, price{_price}, active{true}, shipping{}, seller{seller_username},seller_private_view_key{view_key},seller_address{_seller_address} { description = std::vector(_description.begin(),_description.end()); offer_id = create_offer_id(seller_username); @@ -56,6 +56,8 @@ namespace safex KV_SERIALIZE(shipping) KV_SERIALIZE(offer_id) KV_SERIALIZE(seller) + KV_SERIALIZE(seller_private_view_key) + KV_SERIALIZE(seller_address) END_KV_SERIALIZE_MAP() BEGIN_SERIALIZE_OBJECT() @@ -67,6 +69,8 @@ namespace safex FIELD(shipping) FIELD(offer_id) FIELD(seller) + FIELD(seller_private_view_key) + FIELD(seller_address) END_SERIALIZE() template @@ -80,6 +84,8 @@ namespace safex a & shipping; a & offer_id; a & seller; + a & seller_private_view_key; + a & seller_address; } @@ -91,6 +97,8 @@ namespace safex std::vector shipping; crypto::hash offer_id; //unique id of the offer std::string seller; // username of the seller + crypto::secret_key seller_private_view_key; + cryptonote::account_public_address seller_address; private: crypto::hash create_offer_id(std::string& username); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index d5cc5f76a..e668bf5a6 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1220,7 +1220,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("safex_purchase", boost::bind(&simple_wallet::safex_purchase, this, _1), - tr("safex_purchase [index=[,,...]] [] []
[] \"),"), + tr("safex_purchase [index=[,,...]] [] [] \"),"), tr("Safex purchase. 95% of cash sent is given to the seller, 5% is taken as fee")); m_cmd_binder.set_handler("donate_safex_fee", diff --git a/src/simplewallet/simplewallet_safex.cpp b/src/simplewallet/simplewallet_safex.cpp index e96733a3e..30ceb20cc 100644 --- a/src/simplewallet/simplewallet_safex.cpp +++ b/src/simplewallet/simplewallet_safex.cpp @@ -98,26 +98,7 @@ namespace cryptonote std::vector local_args = args_; - crypto::hash purchase_offer_id{}; - std::vector offers = m_wallet->get_safex_offers(); - std::vector::iterator offer_to_purchase; - uint64_t quantity_to_purchase; - if(command_type == CommandType::TransferPurchase) { - if(!epee::string_tools::hex_to_pod(local_args.back(), purchase_offer_id)){ - fail_msg_writer() << tr("Bad offer ID given!!!"); - return true; - } - - offer_to_purchase = std::find_if(offers.begin(), offers.end(), [purchase_offer_id](safex::safex_offer offer){ - return offer.offer_id == purchase_offer_id;}); - if(offer_to_purchase!=offers.end()) - local_args.pop_back(); - else { - fail_msg_writer() << tr("There is no offer with given id!!"); - return true; - } - } std::set subaddr_indices; if (!local_args.empty() && local_args[0].substr(0, 6) == "index=") @@ -306,7 +287,7 @@ namespace cryptonote std::copy(local_args.begin() + 4, local_args.end(), ostream_iterator(offerdata_ostr, " ")); std::string description = offerdata_ostr.str(); - safex::safex_offer sfx_offer{offer_title, quantity, price, description, my_safex_account.username}; + safex::safex_offer sfx_offer{offer_title, quantity, price, description, my_safex_account.username,m_wallet->get_account().get_keys().m_view_secret_key,m_wallet->get_account().get_keys().m_account_address}; cryptonote::tx_destination_entry de_offer = create_safex_offer_destination(info.address, sfx_offer); dsts.push_back(de_offer); @@ -335,14 +316,64 @@ namespace cryptonote std::string description = offerdata_ostr.str(); safex::safex_offer sfx_offer{offer_title, quantity, price, std::vector{description.begin(),description.end()}, - offer_id_hash, my_safex_account.username}; - sfx_offer.active = active; + offer_id_hash, my_safex_account.username, active, m_wallet->get_account().get_keys().m_account_address, m_wallet->get_account().get_keys().m_view_secret_key}; cryptonote::tx_destination_entry de_offer_update = edit_safex_offer_destination(info.address, sfx_offer); dsts.push_back(de_offer_update); } } + else if (command_type == CommandType::TransferPurchase) + { + crypto::hash purchase_offer_id{}; + std::vector offers = m_wallet->get_safex_offers(); + std::vector::iterator offer_to_purchase; + uint64_t quantity_to_purchase; + + if (!epee::string_tools::get_xtype_from_string(quantity_to_purchase, local_args.back())){ + fail_msg_writer() << tr("Bad quantity to purchase given!!!"); + return true; + } + local_args.pop_back(); + if(!epee::string_tools::hex_to_pod(local_args.back(), purchase_offer_id)){ + fail_msg_writer() << tr("Bad offer ID given!!!"); + return true; + } + + offer_to_purchase = std::find_if(offers.begin(), offers.end(), [purchase_offer_id](safex::safex_offer offer){ + return offer.offer_id == purchase_offer_id;}); + + if(offer_to_purchase!=offers.end()) + local_args.pop_back(); + else { + fail_msg_writer() << tr("There is no offer with given id!!"); + return true; + } + + cryptonote::tx_destination_entry de = AUTO_VAL_INIT(de); + + de.amount = quantity_to_purchase*offer_to_purchase->price * 95 / 100; + de.output_type = tx_out_type::out_cash; + safex_network_fee += quantity_to_purchase*offer_to_purchase->price * 5 / 100; + + cryptonote::address_parse_info info = AUTO_VAL_INIT(info); + cryptonote::tx_destination_entry de_purchase = AUTO_VAL_INIT(de_purchase); + std::string destination_addr = m_wallet->get_subaddress_as_str({m_current_subaddress_account, 0}); + if (!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), destination_addr)) + { + fail_msg_writer() << tr("failed to parse address"); + return true; + } + + safex::create_purchase_data safex_purchase_output_data{purchase_offer_id,quantity_to_purchase,offer_to_purchase->price}; + blobdata blobdata = cryptonote::t_serializable_object_to_blob(safex_purchase_output_data); + de_purchase = tx_destination_entry{0, info.address, false, tx_out_type::out_safex_purchase, blobdata}; + dsts.push_back(de_purchase); + + de.addr = offer_to_purchase->seller_address; + + dsts.push_back(de); + } else { @@ -423,26 +454,6 @@ namespace cryptonote de.output_type = tx_out_type::out_network_fee; } // Allow to collect outputs for regular SFX transaction. - else if (command_type == CommandType::TransferPurchase) - { - quantity_to_purchase = stoi(local_args[i + 1]); - de.amount = quantity_to_purchase*offer_to_purchase->price * 95 / 100; - de.output_type = tx_out_type::out_cash; - safex_network_fee += quantity_to_purchase*offer_to_purchase->price * 5 / 100; - - cryptonote::tx_destination_entry de_purchase = AUTO_VAL_INIT(de_purchase); - std::string destination_addr = m_wallet->get_subaddress_as_str({m_current_subaddress_account, 0}); - - cryptonote::address_parse_info info_dest = AUTO_VAL_INIT(info_dest); - if (!cryptonote::get_account_address_from_str(info_dest, m_wallet->nettype(), destination_addr)){ - fail_msg_writer() << tr("failed to parse address"); - return true; - } - safex::create_purchase_data safex_purchase_output_data{purchase_offer_id,quantity_to_purchase,offer_to_purchase->price}; - blobdata blobdata = cryptonote::t_serializable_object_to_blob(safex_purchase_output_data); - de_purchase = tx_destination_entry{0, info_dest.address, false, tx_out_type::out_safex_purchase, blobdata}; - dsts.push_back(de_purchase); - } dsts.push_back(de); } @@ -771,7 +782,7 @@ namespace cryptonote if (args.empty()) { success_msg_writer() << tr("usage:\n" - " safex_purchase [index=[,,...]] [] []
[] \n"); + " safex_purchase [index=[,,...]] [] [] \n"); return true; } return create_command(CommandType::TransferPurchase, args); diff --git a/src/wallet/wallet_safex.cpp b/src/wallet/wallet_safex.cpp index 0092bcd16..8a70a7add 100644 --- a/src/wallet/wallet_safex.cpp +++ b/src/wallet/wallet_safex.cpp @@ -381,7 +381,7 @@ namespace tools for (auto &item : res.offers) { crypto::hash hash; epee::string_tools::hex_to_pod(item.offer_id, hash); - offers.emplace_back(item.title, item.quantity, item.price, item.description, hash, item.seller, item.active); + offers.emplace_back(item.title, item.quantity, item.price, item.description, hash, item.seller, item.active,item.seller_address); } return offers; diff --git a/tests/core_tests/safex_offer.cpp b/tests/core_tests/safex_offer.cpp index 1aac9b782..8f6289536 100644 --- a/tests/core_tests/safex_offer.cpp +++ b/tests/core_tests/safex_offer.cpp @@ -109,11 +109,13 @@ gen_safex_offer_001::gen_safex_offer_001() std::string data4 = "Тхис ис соме Едвардс дата фор тест"; safex_account_edward.account_data = std::vector(data4.begin(), data4.end()); - safex_offer_alice = safex::safex_offer("Black Sabbath T-shirt",100,1999,"Quality 100% cotton t-shirt with the heaviest band in the universe", - safex_account_alice.username); + alice.generate(); + bob.generate(); - safex_offer_bob = safex::safex_offer("Metallica T-shirt",1000,3999,"Quality 100% cotton t-shirt with the loudest band in the universe", - safex_account_bob.username); + safex_offer_alice = safex::safex_offer("Black Sabbath T-shirt",100,MK_COINS(10),"Quality 100% cotton t-shirt with the heaviest band in the universe", + safex_account_alice.username,alice.get_keys().m_view_secret_key,alice.get_keys().m_account_address); + safex_offer_bob = safex::safex_offer("Metallica T-shirt",1000,MK_COINS(10),"Quality 100% cotton t-shirt with the loudest band in the universe", + safex_account_bob.username,bob.get_keys().m_view_secret_key,bob.get_keys().m_account_address); if (!expected_data_fields_intialized) { diff --git a/tests/core_tests/safex_offer.h b/tests/core_tests/safex_offer.h index 2762d374a..b3e0fe13f 100644 --- a/tests/core_tests/safex_offer.h +++ b/tests/core_tests/safex_offer.h @@ -70,6 +70,8 @@ class gen_safex_offer_001: public test_chain_unit_base safex::safex_offer safex_offer_alice; safex::safex_offer safex_offer_bob; + cryptonote::account_base alice; + cryptonote::account_base bob; static const std::string data2_alternative; static const std::string data2_alternative_2; diff --git a/tests/core_tests/safex_purchase.cpp b/tests/core_tests/safex_purchase.cpp index 1cfa17ea0..8470f8677 100644 --- a/tests/core_tests/safex_purchase.cpp +++ b/tests/core_tests/safex_purchase.cpp @@ -96,10 +96,13 @@ gen_safex_purchase_001::gen_safex_purchase_001() std::string data4 = "Тхис ис соме Едвардс дата фор тест"; safex_account_edward.account_data = std::vector(data4.begin(), data4.end()); + alice.generate(); + bob.generate(); + safex_offer_alice = safex::safex_offer("Black Sabbath T-shirt",100,MK_COINS(10),"Quality 100% cotton t-shirt with the heaviest band in the universe", - safex_account_alice.username); + safex_account_alice.username,alice.get_keys().m_view_secret_key,alice.get_keys().m_account_address); safex_offer_bob = safex::safex_offer("Metallica T-shirt",1000,MK_COINS(10),"Quality 100% cotton t-shirt with the loudest band in the universe", - safex_account_bob.username); + safex_account_bob.username,bob.get_keys().m_view_secret_key,bob.get_keys().m_account_address); safex_alice_purchase_from_bob = safex::safex_purchase{1, safex_offer_bob.price, safex_offer_bob.offer_id, false}; @@ -147,8 +150,8 @@ bool gen_safex_purchase_001::generate(std::vector &events) MAKE_GENESIS_BLOCK(events, blk_0, miner, ts_start); - MAKE_ACCOUNT(events, alice); - MAKE_ACCOUNT(events, bob); + events.push_back(alice); + events.push_back(bob); MAKE_ACCOUNT(events, daniel); MAKE_ACCOUNT(events, edward); @@ -182,22 +185,6 @@ bool gen_safex_purchase_001::generate(std::vector &events) MAKE_NEXT_BLOCK_TX_LIST(events, blk_9, blk_8, miner, txlist_4); REWIND_BLOCKS(events, blk_10, blk_9, miner); - safex_offer_bob.description.clear(); - - std::string desc_key = string_tools::pod_to_hex(bob.get_keys().m_view_secret_key); - safex_offer_bob.description = {desc_key.begin(),desc_key.end()}; - safex_offer_bob.description.push_back('|'); - std::string pub_desc_key = string_tools::pod_to_hex(bob.get_keys().m_account_address.m_spend_public_key); - std::copy(pub_desc_key.begin(), pub_desc_key.end(), std::back_inserter(safex_offer_bob.description)); - - safex_offer_alice.description.clear(); - desc_key = string_tools::pod_to_hex(alice.get_keys().m_view_secret_key); - safex_offer_alice.description = {desc_key.begin(),desc_key.end()}; - safex_offer_alice.description.push_back('|'); - pub_desc_key = string_tools::pod_to_hex(alice.get_keys().m_account_address.m_spend_public_key); - std::copy(pub_desc_key.begin(), pub_desc_key.end(), std::back_inserter(safex_offer_alice.description)); - - //create test offer MAKE_TX_CREATE_SAFEX_OFFER_LIST_START(events, txlist_5, alice, safex_account_alice.pkey, safex_offer_alice, m_safex_account1_keys.get_keys(), blk_10); MAKE_CREATE_SAFEX_OFFER_TX_LIST(events, txlist_5, bob, safex_account_bob.pkey, safex_offer_bob, m_safex_account2_keys.get_keys(), blk_10); diff --git a/tests/core_tests/safex_purchase.h b/tests/core_tests/safex_purchase.h index f4bd6543b..9db685191 100644 --- a/tests/core_tests/safex_purchase.h +++ b/tests/core_tests/safex_purchase.h @@ -68,6 +68,9 @@ class gen_safex_purchase_001: public test_chain_unit_base safex::safex_account safex_account_daniel; safex::safex_account safex_account_edward; + cryptonote::account_base alice; + cryptonote::account_base bob; + safex::safex_offer safex_offer_alice; safex::safex_offer safex_offer_bob; diff --git a/tests/unit_tests/safex_offer.cpp b/tests/unit_tests/safex_offer.cpp index 14e99d9b7..3b31704f2 100644 --- a/tests/unit_tests/safex_offer.cpp +++ b/tests/unit_tests/safex_offer.cpp @@ -99,9 +99,9 @@ namespace data1_new = std::vector(data1_new_str.begin(), data1_new_str.end()); - m_safex_offer[0] = safex::safex_offer("Apple",10,100,"This is an apple", m_safex_account1.username); - m_safex_offer[1] = safex::safex_offer("Barbie",30,500,"This is a Barbie", m_safex_account2.username); - m_safex_offer[2] = safex::safex_offer("Car",1,1000,"This is a car", m_safex_account1.username); + m_safex_offer[0] = safex::safex_offer("Apple",10,100,"This is an apple", m_safex_account1.username,m_users_acc[0].get_keys().m_view_secret_key,m_users_acc[0].get_keys().m_account_address); + m_safex_offer[1] = safex::safex_offer("Barbie",30,500,"This is a Barbie", m_safex_account2.username,m_users_acc[1].get_keys().m_view_secret_key,m_users_acc[1].get_keys().m_account_address); + m_safex_offer[2] = safex::safex_offer("Car",1,1000,"This is a car", m_safex_account1.username,m_users_acc[0].get_keys().m_view_secret_key,m_users_acc[0].get_keys().m_account_address); std::string new_str_desc{"Now without worms!!"}; std::vector new_desc{new_str_desc.begin(),new_str_desc.end()}; diff --git a/tests/unit_tests/simple_purchase.cpp b/tests/unit_tests/simple_purchase.cpp index ac257dcaf..103ac81aa 100644 --- a/tests/unit_tests/simple_purchase.cpp +++ b/tests/unit_tests/simple_purchase.cpp @@ -101,8 +101,8 @@ namespace data1_new = std::vector(data1_new_str.begin(), data1_new_str.end()); - m_safex_offer[0] = safex::safex_offer("Apple", 10, 10*SAFEX_CASH_COIN,"This is an apple", m_safex_account1.username); - m_safex_offer[1] = safex::safex_offer("Barbie", 30, 50*SAFEX_CASH_COIN,"This is a Barbie", m_safex_account2.username); + m_safex_offer[0] = safex::safex_offer("Apple", 10, 10*SAFEX_CASH_COIN,"This is an apple", m_safex_account1.username,m_users_acc[0].get_keys().m_view_secret_key,m_users_acc[0].get_keys().m_account_address); + m_safex_offer[1] = safex::safex_offer("Barbie", 30, 50*SAFEX_CASH_COIN,"This is a Barbie", m_safex_account2.username,m_users_acc[0].get_keys().m_view_secret_key,m_users_acc[0].get_keys().m_account_address); m_safex_purchase = safex::safex_purchase{1, m_safex_offer[0].price, m_safex_offer[0].offer_id, true};