aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet2.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-11-27 20:09:16 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-12-17 16:12:35 +0000
commit2fa707d1a54c2e2c00c542edb3757ae553b5b84a (patch)
tree09837cc890b05196ea80f8f6a88a85cac1ca77bc /src/wallet/wallet2.cpp
parentMatch surae's recommendation to derive multisig keys (diff)
downloadmonero-2fa707d1a54c2e2c00c542edb3757ae553b5b84a.tar.xz
wallet: add multisig sign/submit RPC
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r--src/wallet/wallet2.cpp62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 29ca3dd2f..07f986e02 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -4477,25 +4477,12 @@ bool wallet2::save_multisig_tx(const std::vector<pending_tx>& ptx_vector, const
return epee::file_io_utils::save_string_to_file(filename, ciphertext);
}
//----------------------------------------------------------------------------------------------------
-bool wallet2::load_multisig_tx_from_file(const std::string &filename, multisig_tx_set &exported_txs, std::function<bool(const multisig_tx_set&)> accept_func)
+bool wallet2::load_multisig_tx(cryptonote::blobdata s, multisig_tx_set &exported_txs, std::function<bool(const multisig_tx_set&)> accept_func)
{
- std::string s;
- boost::system::error_code errcode;
-
- if (!boost::filesystem::exists(filename, errcode))
- {
- LOG_PRINT_L0("File " << filename << " does not exist: " << errcode);
- return false;
- }
- if (!epee::file_io_utils::load_file_to_string(filename.c_str(), s))
- {
- LOG_PRINT_L0("Failed to load from " << filename);
- return false;
- }
const size_t magiclen = strlen(MULTISIG_UNSIGNED_TX_PREFIX);
if (strncmp(s.c_str(), MULTISIG_UNSIGNED_TX_PREFIX, magiclen))
{
- LOG_PRINT_L0("Bad magic from " << filename);
+ LOG_PRINT_L0("Bad magic from multisig tx data");
return false;
}
try
@@ -4504,8 +4491,8 @@ bool wallet2::load_multisig_tx_from_file(const std::string &filename, multisig_t
}
catch (const std::exception &e)
{
- LOG_PRINT_L0("Failed to decrypt " << filename << ": " << e.what());
- return 0;
+ LOG_PRINT_L0("Failed to decrypt multisig tx data: " << e.what());
+ return false;
}
try
{
@@ -4515,7 +4502,7 @@ bool wallet2::load_multisig_tx_from_file(const std::string &filename, multisig_t
}
catch (...)
{
- LOG_PRINT_L0("Failed to parse data from " << filename);
+ LOG_PRINT_L0("Failed to parse multisig tx data");
return false;
}
@@ -4557,12 +4544,43 @@ bool wallet2::load_multisig_tx_from_file(const std::string &filename, multisig_t
return true;
}
//----------------------------------------------------------------------------------------------------
+bool wallet2::load_multisig_tx_from_file(const std::string &filename, multisig_tx_set &exported_txs, std::function<bool(const multisig_tx_set&)> accept_func)
+{
+ std::string s;
+ boost::system::error_code errcode;
+
+ if (!boost::filesystem::exists(filename, errcode))
+ {
+ LOG_PRINT_L0("File " << filename << " does not exist: " << errcode);
+ return false;
+ }
+ if (!epee::file_io_utils::load_file_to_string(filename.c_str(), s))
+ {
+ LOG_PRINT_L0("Failed to load from " << filename);
+ return false;
+ }
+
+ if (!load_multisig_tx(s, exported_txs, accept_func))
+ {
+ LOG_PRINT_L0("Failed to parse multisig tx data from " << filename);
+ return false;
+ }
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs, std::vector<crypto::hash> &txids)
{
THROW_WALLET_EXCEPTION_IF(exported_txs.m_ptx.empty(), error::wallet_internal_error, "No tx found");
const crypto::public_key local_signer = get_multisig_signer_public_key();
+ THROW_WALLET_EXCEPTION_IF(exported_txs.m_signers.find(local_signer) != exported_txs.m_signers.end(),
+ error::wallet_internal_error, "Transaction already signed by this private key");
+ THROW_WALLET_EXCEPTION_IF(exported_txs.m_signers.size() > m_multisig_threshold,
+ error::wallet_internal_error, "Transaction was signed by too many signers");
+ THROW_WALLET_EXCEPTION_IF(exported_txs.m_signers.size() == m_multisig_threshold,
+ error::wallet_internal_error, "Transaction is already fully signed");
+
txids.clear();
// sign the transactions
@@ -4667,14 +4685,6 @@ bool wallet2::sign_multisig_tx_from_file(const std::string &filename, std::vecto
if(!load_multisig_tx_from_file(filename, exported_txs))
return false;
- const crypto::public_key signer = get_multisig_signer_public_key();
- THROW_WALLET_EXCEPTION_IF(exported_txs.m_signers.find(signer) != exported_txs.m_signers.end(),
- error::wallet_internal_error, "Transaction already signed by this private key");
- THROW_WALLET_EXCEPTION_IF(exported_txs.m_signers.size() > m_multisig_threshold,
- error::wallet_internal_error, "Transaction was signed by too many signers");
- THROW_WALLET_EXCEPTION_IF(exported_txs.m_signers.size() == m_multisig_threshold,
- error::wallet_internal_error, "Transaction is already fully signed");
-
if (accept_func && !accept_func(exported_txs))
{
LOG_PRINT_L1("Transactions rejected by callback");