1
0
Fork 0
forked from lthn/blockchain

adaptation of zarcanum era codebase to pre_zarcanum api(for backward compatibility with exchanges)

This commit is contained in:
cryptozoidberg 2024-02-15 06:13:54 +04:00
parent dcdffce051
commit c4be6e120a
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
5 changed files with 71 additions and 25 deletions

View file

@ -273,18 +273,28 @@ namespace wallet_public
}
};
struct wallet_transfer_info_old : public wallet_transfer_info
{
uint64_t amount = 0;
bool is_income = false;
//uint64_t amount = 0;
//bool is_income = false;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(is_income)
KV_SERIALIZE(amount)
KV_SERIALIZE_EPHEMERAL_N(uint64_t, wallet_transfer_info_to_amount, "amount")
KV_SERIALIZE_EPHEMERAL_N(bool, wallet_transfer_info_to_is_income, "is_income")
//KV_SERIALIZE(amount)
KV_CHAIN_BASE(wallet_transfer_info)
END_KV_SERIALIZE_MAP()
static uint64_t wallet_transfer_info_to_amount(const wallet_transfer_info_old& wtio)
{
return wtio.get_native_amount();
}
static bool wallet_transfer_info_to_is_income(const wallet_transfer_info_old& wtio)
{
return wtio.get_native_is_income();
}
};
@ -1226,6 +1236,29 @@ namespace wallet_public
};
};
struct COMMAND_RPC_SEARCH_FOR_TRANSACTIONS_LEGACY
{
typedef COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request request;
struct response
{
std::list<wallet_transfer_info_old> in;
std::list<wallet_transfer_info_old> out;
//std::list<wallet_transfer_info> pending;
//std::list<wallet_transfer_info> failed;
std::list<wallet_transfer_info_old> pool;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(in)
KV_SERIALIZE(out)
//KV_SERIALIZE(pending)
//KV_SERIALIZE(failed)
KV_SERIALIZE(pool)
END_KV_SERIALIZE_MAP()
};
};
struct htlc_entry_info
{
currency::account_public_address counterparty_address;

View file

@ -276,6 +276,16 @@ namespace tools
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
template<typename t_from, typename t_to>
void copy_wallet_transfer_info_old_container(const t_from& from_c, t_to& to_c)
{
for (const auto& item : from_c)
{
to_c.push_back(wallet_public::wallet_transfer_info_old());
*static_cast<wallet_public::wallet_transfer_info*>(&to_c.back()) = item;
}
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_get_recent_txs_and_info(const wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request& req, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
//this is legacy api, should be removed after successful transition to HF4
@ -286,20 +296,7 @@ namespace tools
res.pi = rsp2.pi;
res.total_transfers = rsp2.total_transfers;
res.last_item_index = rsp2.last_item_index;
for (const auto& item : rsp2.transfers)
{
res.transfers.push_back(wallet_public::wallet_transfer_info_old());
*static_cast<wallet_public::wallet_transfer_info*>(&res.transfers.back()) = item;
for (const auto& subitem : item.subtransfers)
{
if (subitem.asset_id == currency::native_coin_asset_id)
{
res.transfers.back().amount = subitem.amount;
res.transfers.back().is_income = subitem.is_income;
}
}
}
copy_wallet_transfer_info_old_container(rsp2.transfers, res.transfers);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
@ -699,8 +696,19 @@ namespace tools
return true;
}
bool wallet_rpc_server::on_search_for_transactions(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS_LEGACY::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS_LEGACY::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response res_origin;
bool r = this->on_search_for_transactions2(req, res_origin, er, cntx);
copy_wallet_transfer_info_old_container(res_origin.in, res.in);
copy_wallet_transfer_info_old_container(res_origin.out, res.out);
copy_wallet_transfer_info_old_container(res_origin.pool, res.pool);
return r;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_search_for_transactions(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_search_for_transactions2(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
bool tx_id_specified = req.tx_id != currency::null_hash;
@ -753,6 +761,7 @@ namespace tools
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_get_mining_history(const wallet_public::COMMAND_RPC_GET_MINING_HISTORY::request& req, wallet_public::COMMAND_RPC_GET_MINING_HISTORY::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();

View file

@ -105,7 +105,8 @@ namespace tools
MAP_JON_RPC_WE("sweep_below", on_sweep_below, wallet_public::COMMAND_SWEEP_BELOW)
MAP_JON_RPC_WE("sign_transfer", on_sign_transfer, wallet_public::COMMAND_SIGN_TRANSFER)
MAP_JON_RPC_WE("submit_transfer", on_submit_transfer, wallet_public::COMMAND_SUBMIT_TRANSFER)
MAP_JON_RPC_WE("search_for_transactions", on_search_for_transactions, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS)
MAP_JON_RPC_WE("search_for_transactions", on_search_for_transactions, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS_LEGACY)
MAP_JON_RPC_WE("search_for_transactions2", on_search_for_transactions2, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS)
MAP_JON_RPC_WE("get_restore_info", on_getwallet_restore_info, wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO)
MAP_JON_RPC_WE("get_seed_phrase_info", on_get_seed_phrase_info, wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO)
MAP_JON_RPC_WE("get_mining_history", on_get_mining_history, wallet_public::COMMAND_RPC_GET_MINING_HISTORY)
@ -161,7 +162,8 @@ namespace tools
bool on_sweep_below(const wallet_public::COMMAND_SWEEP_BELOW::request& req, wallet_public::COMMAND_SWEEP_BELOW::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_sign_transfer(const wallet_public::COMMAND_SIGN_TRANSFER::request& req, wallet_public::COMMAND_SIGN_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_submit_transfer(const wallet_public::COMMAND_SUBMIT_TRANSFER::request& req, wallet_public::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_search_for_transactions(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_search_for_transactions(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS_LEGACY::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS_LEGACY::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_search_for_transactions2(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_get_mining_history(const wallet_public::COMMAND_RPC_GET_MINING_HISTORY::request& req, wallet_public::COMMAND_RPC_GET_MINING_HISTORY::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_register_alias(const wallet_public::COMMAND_RPC_REGISTER_ALIAS::request& req, wallet_public::COMMAND_RPC_REGISTER_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx);

View file

@ -1085,7 +1085,7 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(wallet_rpc_integrated_address);
GENERATE_AND_PLAY(wallet_rpc_integrated_address_transfer);
GENERATE_AND_PLAY(wallet_rpc_transfer);
GENERATE_AND_PLAY(wallet_rpc_exchange_suite);
GENERATE_AND_PLAY_HF(wallet_rpc_exchange_suite, "3,4");
GENERATE_AND_PLAY(wallet_chain_switch_with_spending_the_same_ki);
GENERATE_AND_PLAY(wallet_sending_to_integrated_address);

View file

@ -314,6 +314,8 @@ bool wallet_rpc_exchange_suite::generate(std::vector<test_event_entry>& events)
account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate();
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time());
DO_CALLBACK(events, "configure_core"); // default callback will initialize core runtime config with m_hardforks
DO_CALLBACK(events, "c1");
return true;
@ -379,7 +381,7 @@ std::string get_integr_addr(tools::wallet_rpc_server& custody_wlt_rpc, const std
#define TRANSFER_COMMENT "SSDVSf"
std::string transfer_(std::shared_ptr<tools::wallet2> wlt, const std::string& address, uint64_t amount)
{
tools::wallet_rpc_server custody_wlt_rpc(*wlt);
tools::wallet_rpc_server custody_wlt_rpc(wlt);
pre_hf4_api::COMMAND_RPC_TRANSFER::request tr_req = AUTO_VAL_INIT(tr_req);
tr_req.comment = TRANSFER_COMMENT;
tr_req.destinations.resize(1);
@ -447,7 +449,7 @@ bool wallet_rpc_exchange_suite::c1(currency::core& c, size_t ev_index, const std
// wallet RPC server
tools::wallet_rpc_server custody_wlt_rpc(*custody_wlt);
tools::wallet_rpc_server custody_wlt_rpc(custody_wlt);
r = test_payment_ids_generation(custody_wlt_rpc);
CHECK_AND_ASSERT_MES(r, false, "test_payment_ids_generation() failed ");