Skip to content

Commit

Permalink
dapi: TransactionHistory: using different vectors for different tx types
Browse files Browse the repository at this point in the history
  • Loading branch information
mbg033 committed Oct 28, 2019
1 parent b17567c commit e284048
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
29 changes: 20 additions & 9 deletions src/supernode/baseclientproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ bool supernode::BaseClientProxy::GetWalletTransactions(const supernode::rpc_comm
{
MINFO("BaseClientProxy::GetWalletTransactions: " << in.Account);
std::unique_ptr<tools::GraftWallet> wallet = initWallet(base64_decode(in.Account), in.Password, false);
MINFO("BaseClientProxy::GetWalletTransactions: initWallet done");
if (!wallet)
{
out.Result = ERROR_OPEN_WALLET_FAILED;
Expand All @@ -203,47 +204,56 @@ bool supernode::BaseClientProxy::GetWalletTransactions(const supernode::rpc_comm
{
// copy-pasted from wallet_rpc_server.cpp
// TODO: refactor to avoid code duplication or use wallet2_api.h interfaces
MINFO("BaseClientProxy::GetWalletTransactions: about to call 'refresh()'");
wallet->refresh(wallet->is_trusted_daemon());
MINFO("BaseClientProxy::GetWalletTransactions: 'refresh()' done");
// incoming

{
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
wallet->get_payments(payments, in.MinHeight, in.MaxHeight, in.AccountIndex, in.SubaddrIndices);
for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
out.Transfers.push_back(tools::wallet_rpc::transfer_entry());
fill_transfer_entry(wallet.get(), out.Transfers.back(), i->second.m_tx_hash, i->first, i->second);
out.TransfersIn.push_back(tools::wallet_rpc::transfer_entry());
fill_transfer_entry(wallet.get(), out.TransfersIn.back(), i->second.m_tx_hash, i->first, i->second);
}
}
MINFO("BaseClientProxy::GetWalletTransactions: 'incoming payments' done");

// outgoing
{
std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> payments;
wallet->get_payments_out(payments, in.MinHeight, in.MaxHeight, in.AccountIndex, in.SubaddrIndices);
for (std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
out.Transfers.push_back(tools::wallet_rpc::transfer_entry());
fill_transfer_entry(wallet.get(), out.Transfers.back(), i->first, i->second);
out.TransfersOut.push_back(tools::wallet_rpc::transfer_entry());
fill_transfer_entry(wallet.get(), out.TransfersOut.back(), i->first, i->second);
}
}
MINFO("BaseClientProxy::GetWalletTransactions: 'outgoing payments' done");
// pending or failed
{
std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>> upayments;
wallet->get_unconfirmed_payments_out(upayments, in.AccountIndex, in.SubaddrIndices);
for (std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) {
const tools::wallet2::unconfirmed_transfer_details &pd = i->second;
out.Transfers.push_back(tools::wallet_rpc::transfer_entry());
fill_transfer_entry(wallet.get(), out.Transfers.back(), i->first, i->second);
bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed;
std::list<tools::wallet_rpc::transfer_entry> &entries = is_failed ? out.TransfersFailed : out.TransfersPending;
entries.push_back(tools::wallet_rpc::transfer_entry());
fill_transfer_entry(wallet.get(), entries.back(), i->first, i->second);
}
}
MINFO("BaseClientProxy::GetWalletTransactions: 'unconfirmed payments' done");
// pool
{
wallet->update_pool_state();

std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>> payments;
wallet->get_unconfirmed_payments(payments, in.AccountIndex, in.SubaddrIndices);
for (std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
out.Transfers.push_back(tools::wallet_rpc::transfer_entry());
fill_transfer_entry(wallet.get(), out.Transfers.back(), i->first, i->second);
out.TransfersPool.push_back(tools::wallet_rpc::transfer_entry());
fill_transfer_entry(wallet.get(), out.TransfersPool.back(), i->first, i->second);
}
}
MINFO("BaseClientProxy::GetWalletTransactions: 'pool payments' done");

storeWalletState(wallet.get());
}
Expand All @@ -253,7 +263,8 @@ bool supernode::BaseClientProxy::GetWalletTransactions(const supernode::rpc_comm
out.Result = ERROR_TX_HISTORY_NOT_AVAILABLE;
return false;
}
MINFO("Returning transactions: " << out.Transfers.size());
MINFO("Returning transactions: " << out.TransfersIn.size() + out.TransfersOut.size() + out.TransfersFailed.size()
+ out.TransfersPending.size());
out.Result = STATUS_OK;
return true;
}
Expand Down
13 changes: 11 additions & 2 deletions src/supernode/supernode_rpc_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,19 @@ namespace supernode {
};
struct response {
int64_t Result;
std::list<tools::wallet_rpc::transfer_entry> Transfers;
std::list<tools::wallet_rpc::transfer_entry> TransfersIn;
std::list<tools::wallet_rpc::transfer_entry> TransfersOut;
std::list<tools::wallet_rpc::transfer_entry> TransfersPending;
std::list<tools::wallet_rpc::transfer_entry> TransfersFailed;
std::list<tools::wallet_rpc::transfer_entry> TransfersPool;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(Result)
KV_SERIALIZE(Transfers)
KV_SERIALIZE(TransfersIn)
KV_SERIALIZE(TransfersOut)
KV_SERIALIZE(TransfersPending)
KV_SERIALIZE(TransfersFailed)
KV_SERIALIZE(TransfersPool)
END_KV_SERIALIZE_MAP()
};
};
Expand Down

0 comments on commit e284048

Please sign in to comment.