mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-12-23 21:57:46 +00:00
Transaction API continued
This commit is contained in:
parent
079fbd3d42
commit
d97e9ef8a5
3 changed files with 23 additions and 4 deletions
|
@ -81,6 +81,7 @@ public:
|
||||||
int status() const;
|
int status() const;
|
||||||
std::string errorString() const;
|
std::string errorString() const;
|
||||||
bool commit();
|
bool commit();
|
||||||
|
uint64_t amount() const;
|
||||||
uint64_t dust() const;
|
uint64_t dust() const;
|
||||||
uint64_t fee() const;
|
uint64_t fee() const;
|
||||||
// TODO: continue with interface;
|
// TODO: continue with interface;
|
||||||
|
@ -365,11 +366,13 @@ Transaction *WalletImpl::createTransaction(const string &dst_addr, uint64_t amou
|
||||||
bool has_payment_id;
|
bool has_payment_id;
|
||||||
bool payment_id_seen = false;
|
bool payment_id_seen = false;
|
||||||
crypto::hash8 new_payment_id;
|
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();
|
size_t fake_outs_count = m_wallet->default_mixin();
|
||||||
if (fake_outs_count == 0)
|
if (fake_outs_count == 0)
|
||||||
fake_outs_count = DEFAULT_MIX;
|
fake_outs_count = DEFAULT_MIX;
|
||||||
|
|
||||||
TransactionImpl * transaction = new TransactionImpl(this);
|
TransactionImpl * transaction = new TransactionImpl(this);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
if(!cryptonote::get_account_integrated_address_from_str(de.addr, has_payment_id, new_payment_id, m_wallet->testnet(), dst_addr)) {
|
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_status = Status_Error;
|
||||||
m_errorString = "Invalid destination address";
|
m_errorString = "Invalid destination address";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
de.amount = amount;
|
de.amount = amount;
|
||||||
|
@ -510,6 +512,9 @@ string TransactionImpl::errorString() const
|
||||||
|
|
||||||
bool TransactionImpl::commit()
|
bool TransactionImpl::commit()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
LOG_PRINT_L0("m_pending_tx size: " << m_pending_tx.size());
|
||||||
|
assert(m_pending_tx.size() == 1);
|
||||||
try {
|
try {
|
||||||
while (!m_pending_tx.empty()) {
|
while (!m_pending_tx.empty()) {
|
||||||
auto & ptx = m_pending_tx.back();
|
auto & ptx = m_pending_tx.back();
|
||||||
|
@ -541,10 +546,21 @@ bool TransactionImpl::commit()
|
||||||
return m_status == Status_Ok;
|
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
|
uint64_t TransactionImpl::dust() const
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
for (auto ptx : m_pending_tx) {
|
for (const auto & ptx : m_pending_tx) {
|
||||||
result += ptx.dust;
|
result += ptx.dust;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -553,7 +569,7 @@ uint64_t TransactionImpl::dust() const
|
||||||
uint64_t TransactionImpl::fee() const
|
uint64_t TransactionImpl::fee() const
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
for (auto ptx : m_pending_tx) {
|
for (const auto ptx : m_pending_tx) {
|
||||||
result += ptx.fee;
|
result += ptx.fee;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -638,7 +654,7 @@ WalletManager *WalletManagerFactory::getWalletManager()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!g_walletManager) {
|
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();
|
g_walletManager = new WalletManagerImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ struct Transaction
|
||||||
virtual int status() const = 0;
|
virtual int status() const = 0;
|
||||||
virtual std::string errorString() const = 0;
|
virtual std::string errorString() const = 0;
|
||||||
virtual bool commit() = 0;
|
virtual bool commit() = 0;
|
||||||
|
virtual uint64_t amount() const = 0;
|
||||||
virtual uint64_t dust() const = 0;
|
virtual uint64_t dust() const = 0;
|
||||||
virtual uint64_t fee() 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->init(TESTNET_DAEMON_ADDRESS, 0));
|
||||||
ASSERT_TRUE(wallet1->refresh());
|
ASSERT_TRUE(wallet1->refresh());
|
||||||
uint64_t balance = wallet1->balance();
|
uint64_t balance = wallet1->balance();
|
||||||
|
ASSERT_TRUE(wallet1->status() == Bitmonero::Transaction::Status_Ok);
|
||||||
|
|
||||||
Bitmonero::Transaction * transaction = wallet1->createTransaction(
|
Bitmonero::Transaction * transaction = wallet1->createTransaction(
|
||||||
RECIPIENT_WALLET_ADDRESS, AMOUNT_10XMR);
|
RECIPIENT_WALLET_ADDRESS, AMOUNT_10XMR);
|
||||||
ASSERT_TRUE(transaction->status() == Bitmonero::Transaction::Status_Ok);
|
ASSERT_TRUE(transaction->status() == Bitmonero::Transaction::Status_Ok);
|
||||||
|
|
||||||
ASSERT_TRUE(wallet1->balance() == balance);
|
ASSERT_TRUE(wallet1->balance() == balance);
|
||||||
|
ASSERT_TRUE(transaction->amount() == AMOUNT_10XMR);
|
||||||
ASSERT_TRUE(transaction->commit());
|
ASSERT_TRUE(transaction->commit());
|
||||||
ASSERT_FALSE(wallet1->balance() == balance);
|
ASSERT_FALSE(wallet1->balance() == balance);
|
||||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||||
|
|
Loading…
Reference in a new issue