1
0
Fork 0
forked from lthn/blockchain

wallet RPC: search_for_transactions added

This commit is contained in:
sowle 2020-04-07 14:30:38 +03:00
parent c12f8487fb
commit cacd5206ef
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 99 additions and 0 deletions

View file

@ -871,6 +871,52 @@ namespace wallet_public
};
};
struct COMMAND_RPC_SEARCH_FOR_TRANSACTIONS
{
struct request
{
crypto::hash tx_id;
bool in;
bool out;
//bool pending;
//bool failed;
bool pool;
bool filter_by_height;
uint64_t min_height;
uint64_t max_height;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id)
KV_SERIALIZE(in)
KV_SERIALIZE(out)
//KV_SERIALIZE(pending)
//KV_SERIALIZE(failed)
KV_SERIALIZE(pool)
KV_SERIALIZE(filter_by_height)
KV_SERIALIZE(min_height)
KV_SERIALIZE(max_height)
END_KV_SERIALIZE_MAP()
};
struct response
{
std::list<wallet_transfer_info> in;
std::list<wallet_transfer_info> out;
//std::list<wallet_transfer_info> pending;
//std::list<wallet_transfer_info> failed;
std::list<wallet_transfer_info> pool;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(in)
KV_SERIALIZE(out)
//KV_SERIALIZE(pending)
//KV_SERIALIZE(failed)
KV_SERIALIZE(pool)
END_KV_SERIALIZE_MAP()
};
};
inline std::string get_escrow_contract_state_name(uint32_t state)
{

View file

@ -578,6 +578,57 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
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 tx_id_specified = req.tx_id != currency::null_hash;
//
m_wallet.enumerate_transfers_history([&](const wallet_public::wallet_transfer_info& wti) -> bool {
if (tx_id_specified)
{
if (wti.tx_hash != req.tx_id)
return true; // continue
}
if (req.filter_by_height)
{
if (!wti.height) // unconfirmed
return true; // continue
if (wti.height < req.min_height)
{
// no need to scan more
return false; // stop
}
if (wti.height > req.max_height)
{
return true; // continue
}
}
if (wti.is_income && req.in)
res.in.push_back(wti);
if (!wti.is_income && req.out)
res.out.push_back(wti);
return true; // continue
}, false /* enumerate_forward */);
if (req.pool)
{
m_wallet.enumerate_unconfirmed_transfers([&](const wallet_public::wallet_transfer_info& wti) -> bool {
if ((wti.is_income && req.in) || (!wti.is_income && req.out))
res.pool.push_back(wti);
return true; // continue
});
}
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();

View file

@ -50,6 +50,7 @@ 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)
//contracts API Skipped block by timestamp, height: 94766, block time 1563035089
MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL)
MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL)
@ -79,6 +80,7 @@ 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_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_contracts_accept_proposal(const wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx);