Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API organize functions #9368

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions src/wallet/api/address_book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ AddressBook::~AddressBook() {}
AddressBookImpl::AddressBookImpl(WalletImpl *wallet)
: m_wallet(wallet), m_errorCode(Status_Ok) {}

AddressBookImpl::~AddressBookImpl()
{
clearRows();
}

std::vector<AddressBookRow*> AddressBookImpl::getAll() const
{
return m_rows;
}

bool AddressBookImpl::addRow(const std::string &dst_addr , const std::string &payment_id_str, const std::string &description)
{
clearStatus();
Expand All @@ -70,6 +80,15 @@ bool AddressBookImpl::addRow(const std::string &dst_addr , const std::string &pa
return r;
}

bool AddressBookImpl::deleteRow(std::size_t rowId)
{
LOG_PRINT_L2("Deleting address book row " << rowId);
bool r = m_wallet->m_wallet->delete_address_book_row(rowId);
if (r)
refresh();
return r;
}

bool AddressBookImpl::setDescription(std::size_t index, const std::string &description)
{
clearStatus();
Expand Down Expand Up @@ -111,15 +130,6 @@ void AddressBookImpl::refresh()

}

bool AddressBookImpl::deleteRow(std::size_t rowId)
{
LOG_PRINT_L2("Deleting address book row " << rowId);
bool r = m_wallet->m_wallet->delete_address_book_row(rowId);
if (r)
refresh();
return r;
}

int AddressBookImpl::lookupPaymentID(const std::string &payment_id) const
{
// turn short ones into long ones for comparison
Expand Down Expand Up @@ -154,15 +164,4 @@ void AddressBookImpl::clearStatus(){
m_errorCode = 0;
}

std::vector<AddressBookRow*> AddressBookImpl::getAll() const
{
return m_rows;
}


AddressBookImpl::~AddressBookImpl()
{
clearRows();
}

} // namespace
5 changes: 2 additions & 3 deletions src/wallet/api/address_book.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ class AddressBookImpl : public AddressBook
AddressBookImpl(WalletImpl * wallet);
~AddressBookImpl();

// Fetches addresses from Wallet2
void refresh() override;
std::vector<AddressBookRow*> getAll() const override;
bool addRow(const std::string &dst_addr , const std::string &payment_id, const std::string &description) override;
bool setDescription(std::size_t index, const std::string &description) override;
bool deleteRow(std::size_t rowId) override;
bool setDescription(std::size_t index, const std::string &description) override;
void refresh() override;

// Error codes. See AddressBook:ErrorCode enum in wallet2_api.h
std::string errorString() const override {return m_errorString;}
Expand Down
16 changes: 8 additions & 8 deletions src/wallet/api/pending_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ string PendingTransactionImpl::errorString() const
return m_errorString;
}

std::vector<std::string> PendingTransactionImpl::txid() const
{
std::vector<std::string> txid;
for (const auto &pt: m_pending_tx)
txid.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(pt.tx)));
return txid;
}

bool PendingTransactionImpl::commit(const std::string &filename, bool overwrite)
{

Expand Down Expand Up @@ -191,6 +183,14 @@ uint64_t PendingTransactionImpl::fee() const
return result;
}

std::vector<std::string> PendingTransactionImpl::txid() const
{
std::vector<std::string> txid;
for (const auto &pt: m_pending_tx)
txid.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(pt.tx)));
return txid;
}

uint64_t PendingTransactionImpl::txCount() const
{
return m_pending_tx.size();
Expand Down
20 changes: 10 additions & 10 deletions src/wallet/api/subaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ Subaddress::~Subaddress() {}
SubaddressImpl::SubaddressImpl(WalletImpl *wallet)
: m_wallet(wallet) {}

SubaddressImpl::~SubaddressImpl()
{
clearRows();
}

std::vector<SubaddressRow*> SubaddressImpl::getAll() const
{
return m_rows;
}

void SubaddressImpl::addRow(uint32_t accountIndex, const std::string &label)
{
m_wallet->m_wallet->add_subaddress(accountIndex, label);
Expand Down Expand Up @@ -78,14 +88,4 @@ void SubaddressImpl::clearRows() {
m_rows.clear();
}

std::vector<SubaddressRow*> SubaddressImpl::getAll() const
{
return m_rows;
}

SubaddressImpl::~SubaddressImpl()
{
clearRows();
}

} // namespace
3 changes: 1 addition & 2 deletions src/wallet/api/subaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ class SubaddressImpl : public Subaddress
SubaddressImpl(WalletImpl * wallet);
~SubaddressImpl();

// Fetches addresses from Wallet2
void refresh(uint32_t accountIndex) override;
std::vector<SubaddressRow*> getAll() const override;
void addRow(uint32_t accountIndex, const std::string &label) override;
void setLabel(uint32_t accountIndex, uint32_t addressIndex, const std::string &label) override;
void refresh(uint32_t accountIndex) override;

private:
void clearRows();
Expand Down
20 changes: 10 additions & 10 deletions src/wallet/api/subaddress_account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ SubaddressAccount::~SubaddressAccount() {}
SubaddressAccountImpl::SubaddressAccountImpl(WalletImpl *wallet)
: m_wallet(wallet) {}

SubaddressAccountImpl::~SubaddressAccountImpl()
{
clearRows();
}

std::vector<SubaddressAccountRow*> SubaddressAccountImpl::getAll() const
{
return m_rows;
}

void SubaddressAccountImpl::addRow(const std::string &label)
{
m_wallet->m_wallet->add_subaddress_account(label);
Expand Down Expand Up @@ -77,14 +87,4 @@ void SubaddressAccountImpl::clearRows() {
m_rows.clear();
}

std::vector<SubaddressAccountRow*> SubaddressAccountImpl::getAll() const
{
return m_rows;
}

SubaddressAccountImpl::~SubaddressAccountImpl()
{
clearRows();
}

} // namespace
3 changes: 1 addition & 2 deletions src/wallet/api/subaddress_account.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ class SubaddressAccountImpl : public SubaddressAccount
SubaddressAccountImpl(WalletImpl * wallet);
~SubaddressAccountImpl();

// Fetches addresses from Wallet2
void refresh();
std::vector<SubaddressAccountRow*> getAll() const;
void addRow(const std::string &label);
void setLabel(uint32_t accountIndex, const std::string &label);
void refresh();

private:
void clearRows();
Expand Down
22 changes: 11 additions & 11 deletions src/wallet/api/transaction_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ std::vector<TransactionInfo *> TransactionHistoryImpl::getAll() const
return m_history;
}

void TransactionHistoryImpl::setTxNote(const std::string &txid, const std::string &note)
{
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(txid, txid_data) || txid_data.size() != sizeof(crypto::hash))
return;
const crypto::hash htxid = *reinterpret_cast<const crypto::hash*>(txid_data.data());

m_wallet->m_wallet->set_tx_note(htxid, note);
refresh();
}

void TransactionHistoryImpl::refresh()
{
// multithreaded access:
Expand Down Expand Up @@ -265,4 +254,15 @@ void TransactionHistoryImpl::refresh()

}

void TransactionHistoryImpl::setTxNote(const std::string &txid, const std::string &note)
{
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(txid, txid_data) || txid_data.size() != sizeof(crypto::hash))
return;
const crypto::hash htxid = *reinterpret_cast<const crypto::hash*>(txid_data.data());

m_wallet->m_wallet->set_tx_note(htxid, note);
refresh();
}

} // namespace
19 changes: 9 additions & 10 deletions src/wallet/api/transaction_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ string TransactionInfoImpl::label() const
return m_label;
}

uint64_t TransactionInfoImpl::confirmations() const
{
return m_confirmations;
}

uint64_t TransactionInfoImpl::unlockTime() const
{
return m_unlock_time;
}

string TransactionInfoImpl::hash() const
{
Expand All @@ -139,14 +148,4 @@ const std::vector<TransactionInfo::Transfer> &TransactionInfoImpl::transfers() c
return m_transfers;
}

uint64_t TransactionInfoImpl::confirmations() const
{
return m_confirmations;
}

uint64_t TransactionInfoImpl::unlockTime() const
{
return m_unlock_time;
}

} // namespace
5 changes: 2 additions & 3 deletions src/wallet/api/transaction_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ class TransactionInfoImpl : public TransactionInfo
virtual std::set<uint32_t> subaddrIndex() const override;
virtual uint32_t subaddrAccount() const override;
virtual std::string label() const override;

virtual uint64_t confirmations() const override;
virtual uint64_t unlockTime() const override;
virtual std::string hash() const override;
virtual std::time_t timestamp() const override;
virtual std::string paymentId() const override;
virtual const std::vector<Transfer> &transfers() const override;
virtual uint64_t confirmations() const override;
virtual uint64_t unlockTime() const override;

private:
int m_direction;
Expand Down
Loading
Loading