42 #include <boost/format.hpp> 48 UnsignedTransaction::~UnsignedTransaction() {}
51 UnsignedTransactionImpl::UnsignedTransactionImpl(
WalletImpl &wallet)
76 m_errorString =
tr(
"This is a watch only wallet");
80 std::vector<tools::wallet2::pending_tx> ptx;
83 bool r = m_wallet.m_wallet->sign_tx(m_unsigned_tx_set, signedFileName, ptx);
86 m_errorString =
tr(
"Failed to sign transaction");
91 catch (
const std::exception &e)
93 m_errorString =
string(
tr(
"Failed to sign transaction")) + e.what();
105 size_t min_ring_size = ~0;
106 std::unordered_map<cryptonote::account_public_address, std::pair<std::string, uint64_t>> dests;
107 int first_known_non_zero_change_index = -1;
109 for (
size_t n = 0; n < get_num_txes(); ++n)
113 std::vector<cryptonote::tx_extra_field> tx_extra_fields;
114 bool has_encrypted_payment_id =
false;
124 if (!payment_id_string.empty())
125 payment_id_string +=
", ";
128 memcpy(payment_id.data, payment_id8.data, 8);
129 memset(payment_id.data + 8, 0, 24);
135 if (!payment_id_string.empty())
136 payment_id_string +=
", ";
142 for (
size_t s = 0; s < cd.
sources.size(); ++s)
145 size_t ring_size = cd.
sources[s].outputs.size();
146 if (ring_size < min_ring_size)
147 min_ring_size = ring_size;
160 auto i = dests.find(entry.
addr);
161 if (i == dests.end())
164 i->second.second += entry.
amount;
165 amount_to_dests += entry.
amount;
170 if (it == dests.end())
173 m_errorString =
tr(
"Claimed change does not go to a paid address");
179 m_errorString =
tr(
"Claimed change is larger than payment to the change address");
184 if (first_known_non_zero_change_index == -1)
185 first_known_non_zero_change_index = n;
189 m_errorString =
tr(
"Change goes to more than one address");
195 if (it->second.second == 0)
200 for (
auto i = dests.begin(); i != dests.end(); )
202 dest_string += (boost::format(
tr(
"sending %s to %s")) %
cryptonote::print_etn(i->second.second) % i->second.first).str();
204 if (i != dests.end())
207 if (dest_string.empty())
208 dest_string =
tr(
"with no destinations");
217 change_string +=
tr(
"no change");
219 m_confirmationMessage = (boost::format(
tr(
"Loaded %lu transactions, for %s, fee %s, %s, %s, with min ring size %lu. %s")) % (
unsigned long)get_num_txes() %
cryptonote::print_etn(
amount) %
cryptonote::print_etn(
fee) % dest_string % change_string % (
unsigned long)min_ring_size % extra_message).str();
225 std::vector<uint64_t> result;
226 for (
const auto &utx : m_unsigned_tx_set.
txes) {
227 for (
const auto &unsigned_dest : utx.dests) {
228 result.push_back(unsigned_dest.amount);
236 std::vector<uint64_t> result;
237 for (
const auto &utx : m_unsigned_tx_set.
txes) {
239 for (
const auto &i: utx.sources)
fee += i.amount;
240 for (
const auto &i: utx.splitted_dsts)
fee -= i.amount;
241 result.push_back(
fee);
248 std::vector<uint64_t> result;
249 for (
const auto &utx: m_unsigned_tx_set.
txes) {
250 size_t min_mixin = ~0;
252 for (
size_t s = 0; s < utx.sources.size(); ++s) {
253 size_t mixin = utx.sources[s].outputs.size() - 1;
254 if (
mixin < min_mixin)
257 result.push_back(min_mixin);
264 return m_unsigned_tx_set.
txes.size();
269 std::vector<string> result;
270 for (
const auto &utx: m_unsigned_tx_set.
txes) {
273 std::vector<cryptonote::tx_extra_field> tx_extra_fields;
281 memcpy(payment_id.data, payment_id8.data, 8);
285 payment_id = crypto::null_hash;
288 if(payment_id != crypto::null_hash)
291 result.push_back(
"");
299 std::vector<string> result;
300 for (
const auto &utx: m_unsigned_tx_set.
txes) {
301 if (utx.dests.empty()) {
302 MERROR(
"empty destinations, skipped");
313 for (
const auto &utx: m_unsigned_tx_set.
txes) {
314 for (
size_t s = 0; s < utx.sources.size(); ++s) {
315 size_t mixin = utx.sources[s].outputs.size() - 1;
316 if (
mixin < min_mixin)
bool parse_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
std::vector< uint64_t > fee() const override
std::vector< std::string > recipientAddress() const override
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
bool sign(const std::string &signedFileName) override
sign - Sign txs and saves to file
std::string print_etn(uint64_t amount, unsigned int decimal_point)
std::vector< uint64_t > mixin() const override
bool find_tx_extra_field_by_type(const std::vector< tx_extra_field > &tx_extra_fields, T &field, size_t index=0)
std::string get_account_integrated_address_as_str(network_type nettype, account_public_address const &adr, crypto::hash8 const &payment_id)
unsigned __int64 uint64_t
bool get_payment_id_from_tx_extra_nonce(const blobdata &extra_nonce, crypto::hash &payment_id)
bool get_encrypted_payment_id_from_tx_extra_nonce(const blobdata &extra_nonce, crypto::hash8 &payment_id)
uint64_t minMixinCount() const override
account_public_address addr
std::string errorString() const override
bool watchOnly() const override
watchOnly - checks if wallet is watch only
void * memcpy(void *a, const void *b, size_t c)
std::vector< uint64_t > amount() const override
int status() const override
std::vector< std::string > paymentId() const override
uint64_t txCount() const override
txCount - number of transactions current transaction will be splitted to
~UnsignedTransactionImpl()