mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 12:09:54 +00:00
Merge pull request #1564
1d317981
Wallet API: add key image import/export functions (Jaquee)
This commit is contained in:
commit
865f5bef34
3 changed files with 67 additions and 6 deletions
|
@ -83,7 +83,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
|||
|
||||
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
|
||||
{
|
||||
LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
|
||||
//LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
|
||||
|
||||
if (m_listener) {
|
||||
m_listener->newBlock(height);
|
||||
|
@ -662,25 +662,68 @@ UnsignedTransaction *WalletImpl::loadUnsignedTx(const std::string &unsigned_file
|
|||
|
||||
bool WalletImpl::submitTransaction(const string &fileName) {
|
||||
clearStatus();
|
||||
PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);
|
||||
std::unique_ptr<PendingTransactionImpl> transaction(new PendingTransactionImpl(*this));
|
||||
|
||||
// bool r = m_wallet->load_tx(fileName, transaction->m_pending_tx, [&](const tools::wallet2::signed_tx_set &tx){ return accept_loaded_tx(tx); });
|
||||
bool r = m_wallet->load_tx(fileName, transaction->m_pending_tx);
|
||||
if (!r) {
|
||||
m_errorString = tr("Failed to load transaction from file");
|
||||
m_status = Status_Ok;
|
||||
delete transaction;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!transaction->commit()) {
|
||||
m_errorString = transaction->m_errorString;
|
||||
m_status = Status_Error;
|
||||
delete transaction;
|
||||
return false;
|
||||
}
|
||||
|
||||
delete transaction;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WalletImpl::exportKeyImages(const string &filename)
|
||||
{
|
||||
if (m_wallet->watch_only())
|
||||
{
|
||||
m_errorString = tr("Wallet is view only");
|
||||
m_status = Status_Error;
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!m_wallet->export_key_images(filename))
|
||||
{
|
||||
m_errorString = tr("failed to save file ") + filename;
|
||||
m_status = Status_Error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
LOG_ERROR("Error exporting key images: " << e.what());
|
||||
m_errorString = e.what();
|
||||
m_status = Status_Error;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WalletImpl::importKeyImages(const string &filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
uint64_t spent = 0, unspent = 0;
|
||||
uint64_t height = m_wallet->import_key_images(filename, spent, unspent);
|
||||
LOG_PRINT_L2("Signed key images imported to height " << height << ", "
|
||||
<< print_money(spent) << " spent, " << print_money(unspent) << " unspent");
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_ERROR("Error exporting key images: " << e.what());
|
||||
m_errorString = string(tr("Failed to import key images: ")) + e.what();
|
||||
m_status = Status_Error;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -102,6 +102,8 @@ public:
|
|||
virtual PendingTransaction * createSweepUnmixableTransaction();
|
||||
bool submitTransaction(const std::string &fileName);
|
||||
virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename);
|
||||
bool exportKeyImages(const std::string &filename);
|
||||
bool importKeyImages(const std::string &filename);
|
||||
|
||||
virtual void disposeTransaction(PendingTransaction * t);
|
||||
virtual TransactionHistory * history() const;
|
||||
|
@ -127,6 +129,7 @@ private:
|
|||
bool isNewWallet() const;
|
||||
void doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
|
||||
|
||||
|
||||
private:
|
||||
friend class PendingTransactionImpl;
|
||||
friend class UnsignedTransactionImpl;
|
||||
|
|
|
@ -513,6 +513,21 @@ struct Wallet
|
|||
*/
|
||||
virtual void disposeTransaction(PendingTransaction * t) = 0;
|
||||
|
||||
/*!
|
||||
* \brief exportKeyImages - exports key images to file
|
||||
* \param filename
|
||||
* \return - true on success
|
||||
*/
|
||||
virtual bool exportKeyImages(const std::string &filename) = 0;
|
||||
|
||||
/*!
|
||||
* \brief importKeyImages - imports key images from file
|
||||
* \param filename
|
||||
* \return - true on success
|
||||
*/
|
||||
virtual bool importKeyImages(const std::string &filename) = 0;
|
||||
|
||||
|
||||
virtual TransactionHistory * history() const = 0;
|
||||
virtual AddressBook * addressBook() const = 0;
|
||||
virtual void setListener(WalletListener *) = 0;
|
||||
|
|
Loading…
Reference in a new issue