mirror of
https://github.com/monero-project/monero.git
synced 2024-12-13 20:06:32 +02:00
Transaction API continued
This commit is contained in:
parent
079fbd3d42
commit
d97e9ef8a5
@ -81,6 +81,7 @@ public:
|
||||
int status() const;
|
||||
std::string errorString() const;
|
||||
bool commit();
|
||||
uint64_t amount() const;
|
||||
uint64_t dust() const;
|
||||
uint64_t fee() const;
|
||||
// TODO: continue with interface;
|
||||
@ -365,11 +366,13 @@ Transaction *WalletImpl::createTransaction(const string &dst_addr, uint64_t amou
|
||||
bool has_payment_id;
|
||||
bool payment_id_seen = false;
|
||||
crypto::hash8 new_payment_id;
|
||||
// TODO: how this number affects (https://bitcointalk.org/index.php?topic=753252.msg9985441#msg9985441)
|
||||
size_t fake_outs_count = m_wallet->default_mixin();
|
||||
if (fake_outs_count == 0)
|
||||
fake_outs_count = DEFAULT_MIX;
|
||||
|
||||
TransactionImpl * transaction = new TransactionImpl(this);
|
||||
|
||||
do {
|
||||
|
||||
if(!cryptonote::get_account_integrated_address_from_str(de.addr, has_payment_id, new_payment_id, m_wallet->testnet(), dst_addr)) {
|
||||
@ -377,7 +380,6 @@ Transaction *WalletImpl::createTransaction(const string &dst_addr, uint64_t amou
|
||||
m_status = Status_Error;
|
||||
m_errorString = "Invalid destination address";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
de.amount = amount;
|
||||
@ -510,6 +512,9 @@ string TransactionImpl::errorString() const
|
||||
|
||||
bool TransactionImpl::commit()
|
||||
{
|
||||
|
||||
LOG_PRINT_L0("m_pending_tx size: " << m_pending_tx.size());
|
||||
assert(m_pending_tx.size() == 1);
|
||||
try {
|
||||
while (!m_pending_tx.empty()) {
|
||||
auto & ptx = m_pending_tx.back();
|
||||
@ -541,10 +546,21 @@ bool TransactionImpl::commit()
|
||||
return m_status == Status_Ok;
|
||||
}
|
||||
|
||||
uint64_t TransactionImpl::amount() const
|
||||
{
|
||||
uint64_t result = 0;
|
||||
for (const auto &ptx : m_pending_tx) {
|
||||
for (const auto &dest : ptx.dests) {
|
||||
result += dest.amount;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t TransactionImpl::dust() const
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for (auto ptx : m_pending_tx) {
|
||||
for (const auto & ptx : m_pending_tx) {
|
||||
result += ptx.dust;
|
||||
}
|
||||
return result;
|
||||
@ -553,7 +569,7 @@ uint64_t TransactionImpl::dust() const
|
||||
uint64_t TransactionImpl::fee() const
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for (auto ptx : m_pending_tx) {
|
||||
for (const auto ptx : m_pending_tx) {
|
||||
result += ptx.fee;
|
||||
}
|
||||
return result;
|
||||
@ -638,7 +654,7 @@ WalletManager *WalletManagerFactory::getWalletManager()
|
||||
{
|
||||
|
||||
if (!g_walletManager) {
|
||||
epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_0);
|
||||
epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_MAX);
|
||||
g_walletManager = new WalletManagerImpl();
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ struct Transaction
|
||||
virtual int status() const = 0;
|
||||
virtual std::string errorString() const = 0;
|
||||
virtual bool commit() = 0;
|
||||
virtual uint64_t amount() const = 0;
|
||||
virtual uint64_t dust() const = 0;
|
||||
virtual uint64_t fee() const = 0;
|
||||
};
|
||||
|
@ -271,12 +271,14 @@ TEST_F(WalletManagerTest, WalletTransaction)
|
||||
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
|
||||
ASSERT_TRUE(wallet1->refresh());
|
||||
uint64_t balance = wallet1->balance();
|
||||
ASSERT_TRUE(wallet1->status() == Bitmonero::Transaction::Status_Ok);
|
||||
|
||||
Bitmonero::Transaction * transaction = wallet1->createTransaction(
|
||||
RECIPIENT_WALLET_ADDRESS, AMOUNT_10XMR);
|
||||
ASSERT_TRUE(transaction->status() == Bitmonero::Transaction::Status_Ok);
|
||||
|
||||
ASSERT_TRUE(wallet1->balance() == balance);
|
||||
ASSERT_TRUE(transaction->amount() == AMOUNT_10XMR);
|
||||
ASSERT_TRUE(transaction->commit());
|
||||
ASSERT_FALSE(wallet1->balance() == balance);
|
||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||
|
Loading…
Reference in New Issue
Block a user