defined implementation of get/create accounts/subaddresses

This commit is contained in:
woodser
2019-05-31 10:22:22 -04:00
parent a8b1dedd81
commit 88d86f61be
2 changed files with 84 additions and 71 deletions
+37 -11
View File
@@ -274,17 +274,7 @@ namespace monero {
MoneroAccount account;
account.index = accountIdx;
account.primaryAddress = MoneroWallet::getAddress(0, 0);
// build subaddresses
if (includeSubaddresses) {
for (uint32_t subaddressIdx = 0; subaddressIdx < wallet2->get_num_subaddresses(accountIdx); subaddressIdx++) {
MoneroSubaddress subaddress;
subaddress.accountIndex = accountIdx;
subaddress.index = subaddressIdx;
subaddress.address = MoneroWallet::getAddress(accountIdx, subaddressIdx);
account.subaddresses.push_back(subaddress);
}
}
if (includeSubaddresses) account.subaddresses = getSubaddresses(accountIdx);
accounts.push_back(account);
}
@@ -303,10 +293,46 @@ namespace monero {
throw runtime_error("Not implemented");
}
MoneroAccount MoneroWallet::createAccount(const string label) {
throw runtime_error("Not implemented");
}
vector<MoneroSubaddress> MoneroWallet::getSubaddresses(const uint32_t accountIdx) const {
vector<MoneroSubaddress> subaddresses;
for (uint32_t subaddressIdx = 0; subaddressIdx < wallet2->get_num_subaddresses(accountIdx); subaddressIdx++) {
MoneroSubaddress subaddress;
subaddress.accountIndex = accountIdx;
subaddress.index = subaddressIdx;
subaddress.address = getAddress(accountIdx, subaddressIdx);
subaddresses.push_back(subaddress);
}
return subaddresses;
}
vector<MoneroSubaddress> MoneroWallet::getSubaddresses(const uint32_t accountIdx, const vector<uint32_t> subaddressIndices) const {
throw runtime_error("Not implemented");
}
MoneroSubaddress MoneroWallet::getSubaddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const {
throw runtime_error("Not implemented");
}
MoneroSubaddress MoneroWallet::createSubaddress(const uint32_t accountIdx, const string label) {
throw runtime_error("Not implemented");
}
// create account
// getSubaddresses
// 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();
}
+47 -60
View File
@@ -403,64 +403,49 @@ namespace monero {
* @return the retrieved account
*/
MoneroAccount getAccount(const uint32_t accountIdx, const bool includeSubaddresses) const;
//
// /**
// * Create a new account without a label.
// *
// * @return the created account
// */
// public MoneroAccount createAccount();
//
// /**
// * Create a new account.
// *
// * @param label specifies the label for the account (optional)
// * @return the created account
// */
// public MoneroAccount createAccount(String label);
//
// /**
// * Get all subaddresses in an account.
// *
// * @param accountIdx specifies the account to get subaddresses within
// * @return List<MoneroSubaddress> are the retrieved subaddresses
// */
// public List<MoneroSubaddress> getSubaddresses(int accountIdx);
//
// /**
// * Get subaddresses in an account.
// *
// * @param accountIdx specifies the account to get subaddresses within
// * @param subaddressIndices are specific subaddresses to get (optional)
// * @return the retrieved subaddresses
// */
// public List<MoneroSubaddress> getSubaddresses(int accountIdx, List<Integer> subaddressIndices);
//
// /**
// * Get a subaddress.
// *
// * @param accountIdx specifies the index of the subaddress's account
// * @param subaddressIdx specifies index of the subaddress within the account
// * @return the retrieved subaddress
// */
// public MoneroSubaddress getSubaddress(int accountIdx, int subaddressIdx);
//
// /**
// * Create a subaddress within an account and without a label.
// *
// * @param accountIdx specifies the index of the account to create the subaddress within
// * @return the created subaddress
// */
// public MoneroSubaddress createSubaddress(int accountIdx);
//
// /**
// * Create a subaddress within an account.
// *
// * @param accountIdx specifies the index of the account to create the subaddress within
// * @param label specifies the the label for the subaddress (optional)
// * @return the created subaddress
// */
// public MoneroSubaddress createSubaddress(int accountIdx, String label);
/**
* Create a new account.
*
* @param label specifies the label for the account (optional)
* @return the created account
*/
MoneroAccount createAccount(const string label = "");
/**
* Get all subaddresses in an account.
*
* @param accountIdx specifies the account to get subaddresses within
* @return List<MoneroSubaddress> are the retrieved subaddresses
*/
vector<MoneroSubaddress> getSubaddresses(const uint32_t accountIdx) const;
/**
* Get subaddresses in an account.
*
* @param accountIdx specifies the account to get subaddresses within
* @param subaddressIndices are specific subaddresses to get (optional)
* @return the retrieved subaddresses
*/
vector<MoneroSubaddress> getSubaddresses(const uint32_t accountIdx, const vector<uint32_t> subaddressIndices) const;
/**
* Get a subaddress.
*
* @param accountIdx specifies the index of the subaddress's account
* @param subaddressIdx specifies index of the subaddress within the account
* @return the retrieved subaddress
*/
MoneroSubaddress getSubaddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const;
/**
* Create a subaddress within an account.
*
* @param accountIdx specifies the index of the account to create the subaddress within
* @param label specifies the the label for the subaddress (optional)
* @return the created subaddress
*/
MoneroSubaddress createSubaddress(uint32_t accountIdx, const string label = "");
/**
* Get the address of a specific subaddress.
@@ -469,7 +454,9 @@ namespace monero {
* @param subaddressIdx specifies the subaddress index within the account
* @return the receive address of the specified subaddress
*/
string getAddress(uint32_t accountIdx, uint32_t subaddressIdx) const;
string getAddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const;
// get address index
// /**
// * Get the account and subaddress index of the given address.
@@ -493,7 +480,7 @@ namespace monero {
* @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;
uint64_t getBalance(uint32_t accountIdx) const; // TODO: this param should be const and others
/**
* Get a subaddress's balance.