mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-12-22 18:38:52 +00:00
Transaction fee multiplier aka priority integraged
This commit is contained in:
parent
00ed12bd6c
commit
083380cb8f
@ -402,7 +402,9 @@ bool WalletImpl::refresh()
|
||||
// - unconfirmed_transfer_details;
|
||||
// - confirmed_transfer_details)
|
||||
|
||||
PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, const string &payment_id, uint64_t amount, uint32_t mixin_count)
|
||||
PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, const string &payment_id, uint64_t amount, uint32_t mixin_count,
|
||||
PendingTransaction::Priority priority)
|
||||
|
||||
{
|
||||
clearStatus();
|
||||
vector<cryptonote::tx_destination_entry> dsts;
|
||||
@ -464,8 +466,10 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, const
|
||||
//std::vector<tools::wallet2::pending_tx> ptx_vector;
|
||||
|
||||
try {
|
||||
// priority called "fee_multiplied in terms of underlying wallet interface
|
||||
transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */,
|
||||
0 /* unused fee arg*/, extra, m_trustedDaemon);
|
||||
static_cast<uint64_t>(priority),
|
||||
extra, m_trustedDaemon);
|
||||
|
||||
} catch (const tools::error::daemon_busy&) {
|
||||
// TODO: make it translatable with "tr"?
|
||||
|
@ -71,8 +71,11 @@ public:
|
||||
uint64_t balance() const;
|
||||
uint64_t unlockedBalance() const;
|
||||
bool refresh();
|
||||
|
||||
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
|
||||
uint64_t amount, uint32_t mixin_count);
|
||||
uint64_t amount, uint32_t mixin_count,
|
||||
PendingTransaction::Priority priority = PendingTransaction::Priority_Low);
|
||||
|
||||
virtual void disposeTransaction(PendingTransaction * t);
|
||||
virtual TransactionHistory * history() const;
|
||||
virtual void setListener(WalletListener * l);
|
||||
|
@ -50,6 +50,14 @@ struct PendingTransaction
|
||||
Status_Ok,
|
||||
Status_Error
|
||||
};
|
||||
|
||||
enum Priority {
|
||||
Priority_Low = 1,
|
||||
Priority_Medium = 2,
|
||||
Priority_High = 3,
|
||||
Priority_Last
|
||||
};
|
||||
|
||||
virtual ~PendingTransaction() = 0;
|
||||
virtual int status() const = 0;
|
||||
virtual std::string errorString() const = 0;
|
||||
@ -186,13 +194,19 @@ struct Wallet
|
||||
* \param payment_id optional payment_id, can be empty string
|
||||
* \param amount amount
|
||||
* \param mixin_count mixin count. if 0 passed, wallet will use default value
|
||||
* \param priority
|
||||
* \return PendingTransaction object. caller is responsible to check PendingTransaction::status()
|
||||
* after object returned
|
||||
*/
|
||||
|
||||
virtual PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
|
||||
uint64_t amount, uint32_t mixin_count) = 0;
|
||||
uint64_t amount, uint32_t mixin_count,
|
||||
PendingTransaction::Priority = PendingTransaction::Priority_Low) = 0;
|
||||
|
||||
/*!
|
||||
* \brief disposeTransaction - destroys transaction object
|
||||
* \param t - pointer to the "PendingTransaction" object. Pointer is not valid after function returned;
|
||||
*/
|
||||
virtual void disposeTransaction(PendingTransaction * t) = 0;
|
||||
virtual TransactionHistory * history() const = 0;
|
||||
virtual void setListener(WalletListener *) = 0;
|
||||
|
@ -482,6 +482,48 @@ TEST_F(WalletTest1, WalletTransactionWithMixin)
|
||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||
}
|
||||
|
||||
TEST_F(WalletTest1, WalletTransactionWithPriority)
|
||||
{
|
||||
|
||||
std::string payment_id = "";
|
||||
|
||||
Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
||||
|
||||
// make sure testnet daemon is running
|
||||
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
|
||||
ASSERT_TRUE(wallet1->refresh());
|
||||
uint64_t balance = wallet1->balance();
|
||||
ASSERT_TRUE(wallet1->status() == Bitmonero::PendingTransaction::Status_Ok);
|
||||
|
||||
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
|
||||
uint32_t mixin = 2;
|
||||
uint64_t fee = 0;
|
||||
|
||||
std::vector<Bitmonero::PendingTransaction::Priority> priorities = {
|
||||
Bitmonero::PendingTransaction::Priority_Low,
|
||||
Bitmonero::PendingTransaction::Priority_Medium,
|
||||
Bitmonero::PendingTransaction::Priority_High
|
||||
};
|
||||
|
||||
for (auto it = priorities.begin(); it != priorities.end(); ++it) {
|
||||
std::cerr << "Transaction priority: " << *it << std::endl;
|
||||
Bitmonero::PendingTransaction * transaction = wallet1->createTransaction(
|
||||
recepient_address, payment_id, AMOUNT_5XMR, mixin, *it);
|
||||
std::cerr << "Transaction status: " << transaction->status() << std::endl;
|
||||
std::cerr << "Transaction fee: " << Bitmonero::Wallet::displayAmount(transaction->fee()) << std::endl;
|
||||
std::cerr << "Transaction error: " << transaction->errorString() << std::endl;
|
||||
ASSERT_TRUE(transaction->fee() > fee);
|
||||
ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok);
|
||||
fee = transaction->fee();
|
||||
wallet1->disposeTransaction(transaction);
|
||||
}
|
||||
wallet1->refresh();
|
||||
ASSERT_TRUE(wallet1->balance() == balance);
|
||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_F(WalletTest1, WalletHistory)
|
||||
{
|
||||
Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
||||
|
Loading…
Reference in New Issue
Block a user