From b55fb192d3d2d4c98da69aad5bb3b97a837b9fbc Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 30 May 2019 10:26:39 -0400 Subject: [PATCH] implemented getBalances() and getUnlockedBalances() --- src/wallet/MoneroWallet.cpp | 24 +++++++++ src/wallet/MoneroWallet.h | 98 ++++++++++++++++++------------------- 2 files changed, 73 insertions(+), 49 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index ee2dcec..ce2a18f 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -247,6 +247,30 @@ namespace monero { return wallet2->get_subaddress_as_str({accountIdx, subaddressIdx}); } + uint64_t MoneroWallet::getBalance() const { + return wallet2->balance_all(); + } + + uint64_t MoneroWallet::getBalance(uint32_t accountIdx) const { + return wallet2->balance(accountIdx); + } + + uint64_t MoneroWallet::getBalance(uint32_t accountIdx, uint32_t subaddressIdx) const { + return wallet2->balance_per_subaddress(accountIdx).at(subaddressIdx); + } + + uint64_t MoneroWallet::getUnlockedBalance() const { + return wallet2->unlocked_balance_all(); + } + + uint64_t MoneroWallet::getUnlockedBalance(uint32_t accountIdx) const { + return wallet2->unlocked_balance(accountIdx); + } + + uint64_t MoneroWallet::getUnlockedBalance(uint32_t accountIdx, uint32_t subaddressIdx) const { + return wallet2->unlocked_balance_per_subaddress(accountIdx).at(subaddressIdx).first; + } + // ------------------------------- PRIVATE HELPERS ---------------------------- MoneroSyncResult MoneroWallet::syncAux(uint64_t* startHeight, uint64_t* endHeight, MoneroSyncListener* listener) { diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index e630110..4ec974f 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -249,7 +249,7 @@ namespace monero { /** * Get the blockchain's height. * - * @return the block chain's height + * @return the blockchain's height */ uint64_t getChainHeight() const; @@ -429,54 +429,54 @@ namespace monero { // * @throws exception if address is not a wallet address // */ // public MoneroSubaddress getAddressIndex(String address); -// -// /** -// * Get the wallet's balance. -// * -// * @return the wallet's balance -// */ -// public BigInteger getBalance(); -// -// /** -// * Get an account's balance. -// * -// * @param accountIdx is the index of the account to get the balance of -// * @return the account's balance -// */ -// public BigInteger getBalance(int accountIdx); -// -// /** -// * Get a subaddress's balance. -// * -// * @param accountIdx is the index of the subaddress's account to get the balance of -// * @param subaddressIdx is the index of the subaddress to get the balance of -// * @return the subaddress's balance -// */ -// public BigInteger getBalance(int accountIdx, int subaddressIdx); -// -// /** -// * Get the wallet's unlocked balance. -// * -// * @return the wallet's unlocked balance -// */ -// public BigInteger getUnlockedBalance(); -// -// /** -// * Get an account's unlocked balance. -// * -// * @param accountIdx is the index of the account to get the unlocked balance of -// * @return the account's unlocked balance -// */ -// public BigInteger getUnlockedBalance(int accountIdx); -// -// /** -// * Get a subaddress's unlocked balance. -// * -// * @param accountIdx is the index of the subaddress's account to get the unlocked balance of -// * @param subaddressIdx is the index of the subaddress to get the unlocked balance of -// * @return the subaddress's balance -// */ -// public BigInteger getUnlockedBalance(int accountIdx, int subaddressIdx); + + /** + * Get the wallet's balance. + * + * @return the wallet's balance + */ + uint64_t getBalance() const; + + /** + * Get an account's balance. + * + * @param accountIdx is the index of the account to get the balance of + * @return the account's balance + */ + uint64_t getBalance(uint32_t accountIdx) const; + + /** + * Get a subaddress's balance. + * + * @param accountIdx is the index of the subaddress's account to get the balance of + * @param subaddressIdx is the index of the subaddress to get the balance of + * @return the subaddress's balance + */ + uint64_t getBalance(uint32_t accountIdx, uint32_t subaddressIdx) const; + + /** + * Get the wallet's unlocked balance. + * + * @return the wallet's unlocked balance + */ + uint64_t getUnlockedBalance() const; + + /** + * Get an account's unlocked balance. + * + * @param accountIdx is the index of the account to get the unlocked balance of + * @return the account's unlocked balance + */ + uint64_t getUnlockedBalance(uint32_t accountIdx) const; + + /** + * Get a subaddress's unlocked balance. + * + * @param accountIdx is the index of the subaddress's account to get the unlocked balance of + * @param subaddressIdx is the index of the subaddress to get the unlocked balance of + * @return the subaddress's balance + */ + uint64_t getUnlockedBalance(uint32_t accountIdx, uint32_t subaddressIdx) const; // // /** // * Get a wallet transaction by id.