Commit 47950f3b authored by Pierre Kim's avatar Pierre Kim

Add search by paymentID RPC command.

parent 70188f14
......@@ -894,13 +894,14 @@ bool core::getTransactionsByPaymentId(const Crypto::Hash& paymentId, std::vector
if (!m_blockchain.getTransactionIdsByPaymentId(paymentId, blockchainTransactionHashes)) {
return false;
}
/*
std::vector<Crypto::Hash> poolTransactionHashes;
if (!m_mempool.getTransactionIdsByPaymentId(paymentId, poolTransactionHashes)) {
return false;
}
}*/
std::list<Transaction> txs;
std::list<Crypto::Hash> missed_txs;
blockchainTransactionHashes.insert(blockchainTransactionHashes.end(), poolTransactionHashes.begin(), poolTransactionHashes.end());
//blockchainTransactionHashes.insert(blockchainTransactionHashes.end(), poolTransactionHashes.begin(), poolTransactionHashes.end());
getTransactions(blockchainTransactionHashes, txs, missed_txs, true);
if (missed_txs.size() > 0) {
......
......@@ -165,6 +165,26 @@ struct F_COMMAND_RPC_GET_TRANSACTIONS_POOL {
};
};
struct M_COMMAND_RPC_GET_TRANSACTIONS_BY_PAYMENTID {
struct request {
std::string payment_id;
void serialize(ISerializer &s) {
KV_MEMBER(payment_id)
}
};
struct response {
std::vector<f_transaction_short_response> transactions;
std::string status;
void serialize(ISerializer &s) {
KV_MEMBER(transactions)
KV_MEMBER(status)
}
};
};
struct F_COMMAND_RPC_GET_POOL {
typedef std::vector<std::string> request;
......
......@@ -139,6 +139,7 @@ bool RpcServer::processJsonRpcRequest(const HttpRequest& request, HttpResponse&
{ "f_transaction_json",{ makeMemberMethod(&RpcServer::f_on_transaction_json), false } },
{ "f_pool_json",{ makeMemberMethod(&RpcServer::f_on_pool_json), false } },
{ "f_transactions_pool_json",{ makeMemberMethod(&RpcServer::f_on_transactions_pool_json), false } },
{ "m_transactions_by_payment_id",{ makeMemberMethod(&RpcServer::m_on_transactions_by_payment_id), false } },
{ "getblockcount", { makeMemberMethod(&RpcServer::on_getblockcount), true } },
{ "on_getblockhash", { makeMemberMethod(&RpcServer::on_getblockhash), false } },
{ "getblocktemplate", { makeMemberMethod(&RpcServer::on_getblocktemplate), false } },
......@@ -905,6 +906,38 @@ bool RpcServer::f_on_pool_json(const F_COMMAND_RPC_GET_POOL::request& req, F_COM
return true;
}
bool RpcServer::m_on_transactions_by_payment_id(const M_COMMAND_RPC_GET_TRANSACTIONS_BY_PAYMENTID::request& req, M_COMMAND_RPC_GET_TRANSACTIONS_BY_PAYMENTID::response& res) {
Hash paymentId;
std::vector<CryptoNote::Transaction> txs;
Block blk;
if (!parse_hash256(req.payment_id, paymentId)) {
throw JsonRpc::JsonRpcError{
CORE_RPC_ERROR_CODE_WRONG_PARAM,
"Failed to parse hex representation of PaymentID. Hex = " + req.payment_id + '.' };
}
if (!m_core.getTransactionsByPaymentId(paymentId, txs)) {
throw JsonRpc::JsonRpcError{
CORE_RPC_ERROR_CODE_INTERNAL_ERROR,
"Internal error: can't get transactions by PaymentID. PaymentID = " + Common::podToHex(paymentId) + '.' };
}
for (const Transaction tx : txs) {
f_transaction_short_response transaction_short;
uint64_t amount_in = getInputAmount(tx);
uint64_t amount_out = getOutputAmount(tx);
transaction_short.hash = Common::podToHex(getObjectHash(tx));
transaction_short.fee = amount_in - amount_out;
transaction_short.amount_out = amount_out;
transaction_short.size = getObjectBinarySize(tx);
res.transactions.push_back(transaction_short);
}
res.status = CORE_RPC_STATUS_OK;
return true;
}
bool RpcServer::enableCors(const std::vector<std::string> domains) {
m_cors_domains = domains;
......
......@@ -71,6 +71,7 @@ private:
bool f_on_transaction_json(const F_COMMAND_RPC_GET_TRANSACTION_DETAILS::request& req, F_COMMAND_RPC_GET_TRANSACTION_DETAILS::response& res);
bool f_on_transactions_pool_json(const F_COMMAND_RPC_GET_TRANSACTIONS_POOL::request& req, F_COMMAND_RPC_GET_TRANSACTIONS_POOL::response& res);
bool f_on_pool_json(const F_COMMAND_RPC_GET_POOL::request& req, F_COMMAND_RPC_GET_POOL::response& res);
bool m_on_transactions_by_payment_id(const M_COMMAND_RPC_GET_TRANSACTIONS_BY_PAYMENTID::request& req, M_COMMAND_RPC_GET_TRANSACTIONS_BY_PAYMENTID::response& res);
void fill_block_header_response(const Block& blk, bool orphan_status, uint64_t height, const Crypto::Hash& hash, block_header_response& responce);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment