re-order wallet api

This commit is contained in:
woodser
2019-06-02 13:59:01 -04:00
parent 45b900f66e
commit bea2eb9a8c
2 changed files with 149 additions and 148 deletions
+51 -49
View File
@@ -202,27 +202,20 @@ namespace monero {
return wallet2->get_seed_language();
}
// get primary address (default impl?)
string MoneroWallet::getAddress(uint32_t accountIdx, uint32_t subaddressIdx) const {
return wallet2->get_subaddress_as_str({accountIdx, subaddressIdx});
}
// get address index
string MoneroWallet::getMnemonic() const {
epee::wipeable_string wipeablePassword;
wallet2->get_seed(wipeablePassword);
return string(wipeablePassword.data(), wipeablePassword.size());
}
uint64_t MoneroWallet::getHeight() const {
return wallet2->get_blockchain_current_height();
}
uint64_t MoneroWallet::getChainHeight() const {
string err;
uint64_t chainHeight = wallet2->get_daemon_blockchain_height(err);
if (!err.empty()) throw runtime_error(err); // TODO: proper monero error
return chainHeight;
}
uint64_t MoneroWallet::getRestoreHeight() const {
return wallet2->get_refresh_from_block_height();
}
void MoneroWallet::setListener(MoneroWalletListener* listener) {
cout << "setListener()" << endl;
wallet2Listener->setWalletListener(listener);
@@ -252,6 +245,49 @@ namespace monero {
// isMultisigImportNeeded
uint64_t MoneroWallet::getHeight() const {
return wallet2->get_blockchain_current_height();
}
uint64_t MoneroWallet::getChainHeight() const {
string err;
uint64_t chainHeight = wallet2->get_daemon_blockchain_height(err);
if (!err.empty()) throw runtime_error(err); // TODO: proper monero error
return chainHeight;
}
uint64_t MoneroWallet::getRestoreHeight() const {
return wallet2->get_refresh_from_block_height();
}
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 {
map<uint32_t, uint64_t> balancePerSubaddress = wallet2->balance_per_subaddress(accountIdx);
auto iter = balancePerSubaddress.find(subaddressIdx);
return iter == balancePerSubaddress.end() ? 0 : iter->second;
}
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 {
map<uint32_t, std::pair<uint64_t, uint64_t>> unlockedBalancePerSubaddress = wallet2->unlocked_balance_per_subaddress(accountIdx);
auto iter = unlockedBalancePerSubaddress.find(subaddressIdx);
return iter == unlockedBalancePerSubaddress.end() ? 0 : iter->second.first;
}
vector<MoneroAccount> MoneroWallet::getAccounts() const {
cout << "getAccounts()" << endl;
return getAccounts(false, string(""));
@@ -369,40 +405,6 @@ namespace monero {
// createSubaddress
string MoneroWallet::getAddress(uint32_t accountIdx, uint32_t subaddressIdx) const {
return wallet2->get_subaddress_as_str({accountIdx, subaddressIdx});
}
// get address index
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 {
map<uint32_t, uint64_t> balancePerSubaddress = wallet2->balance_per_subaddress(accountIdx);
auto iter = balancePerSubaddress.find(subaddressIdx);
return iter == balancePerSubaddress.end() ? 0 : iter->second;
}
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 {
map<uint32_t, std::pair<uint64_t, uint64_t>> unlockedBalancePerSubaddress = wallet2->unlocked_balance_per_subaddress(accountIdx);
auto iter = unlockedBalancePerSubaddress.find(subaddressIdx);
return iter == unlockedBalancePerSubaddress.end() ? 0 : iter->second.first;
}
void MoneroWallet::save() {
cout << "save()" << endl;
save("", "");
+98 -99
View File
@@ -286,28 +286,12 @@ namespace monero {
*/
string getLanguage() const;
// /**
// * Get a list of available languages for the wallet's seed.
// *
// * @return the available languages for the wallet's seed
// */
// virtual string[] getLanguages() const;
/**
* Get the height of the last block processed by the wallet (its index + 1).
*
* @return the height of the last block processed by the wallet
*/
uint64_t getHeight() const;
/**
* Get the blockchain's height.
*
* @return the blockchain's height
*/
uint64_t getChainHeight() const;
uint64_t getRestoreHeight() const;
// /**
// * Get a list of available languages for the wallet's seed.
// *
// * @return the available languages for the wallet's seed
// */
// virtual string[] getLanguages() const;
/**
* Get the wallet's primary address.
@@ -316,6 +300,24 @@ namespace monero {
*/
string getPrimaryAddress() const;
/**
* Get the address of a specific subaddress.
*
* @param accountIdx specifies the account index of the address's subaddress
* @param subaddressIdx specifies the subaddress index within the account
* @return the receive address of the specified subaddress
*/
string getAddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const;
// /**
// * Get the account and subaddress index of the given address.
// *
// * @param address is the address to get the account and subaddress index from
// * @return the account and subaddress indices
// * @throws exception if address is not a wallet address
// */
// public MoneroSubaddress getAddressIndex(String address);
// /**
// * Get an integrated address based on this wallet's primary address and the
// * given payment ID. Generates a random payment ID if none is given.
@@ -343,15 +345,32 @@ namespace monero {
MoneroSyncResult sync(uint64_t startHeight, MoneroSyncListener& listener);
// /**
// * Rescan the blockchain from scratch, losing any information which cannot be recovered from
// * the blockchain itself.
// *
// * WARNING: This method discards local wallet data like destination addresses, tx secret keys,
// * tx notes, etc.
// */
// public void rescanBlockchain();
//
// /**
// * Rescan the blockchain from scratch, losing any information which cannot be recovered from
// * the blockchain itself.
// *
// * WARNING: This method discards local wallet data like destination addresses, tx secret keys,
// * tx notes, etc.
// */
// public void rescanBlockchain();
/**
* Get the height of the last block processed by the wallet (its index + 1).
*
* @return the height of the last block processed by the wallet
*/
uint64_t getHeight() const;
/**
* Get the blockchain's height.
*
* @return the blockchain's height
*/
uint64_t getChainHeight() const;
uint64_t getRestoreHeight() const;
//
// /**
// * Indicates if importing multisig data is needed for returning a correct balance.
// *
@@ -359,6 +378,54 @@ namespace monero {
// */
// public boolean isMultisigImportNeeded();
/**
* 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; // TODO: this param should be const and others
/**
* 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 all accounts.
*
@@ -451,74 +518,6 @@ namespace monero {
*/
MoneroSubaddress createSubaddress(uint32_t accountIdx, const string label = "");
/**
* Get the address of a specific subaddress.
*
* @param accountIdx specifies the account index of the address's subaddress
* @param subaddressIdx specifies the subaddress index within the account
* @return the receive address of the specified subaddress
*/
string getAddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const;
// get address index
// /**
// * Get the account and subaddress index of the given address.
// *
// * @param address is the address to get the account and subaddress index from
// * @return the account and subaddress indices
// * @throws exception if address is not a wallet address
// */
// public MoneroSubaddress getAddressIndex(String address);
/**
* 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; // TODO: this param should be const and others
/**
* 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.
// *