-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get accounts by index instead of name #968
Labels
wallet
Wallet related
Comments
I have a temporary patch to enable this functionality: diff --git a/lib/wallet/http.js b/lib/wallet/http.js
index c2b492d2..ded535b4 100644
--- a/lib/wallet/http.js
+++ b/lib/wallet/http.js
@@ -298,7 +298,13 @@ class HTTP extends Server {
// Get account
this.get('/wallet/:id/account/:account', async (req, res) => {
const valid = Validator.fromRequest(req);
- const acct = valid.str('account');
+ let acct = valid.str('account');
+
+ const num = parseInt(acct);
+
+ if (!Number.isNaN(num))
+ acct = num;
+
const account = await req.wallet.getAccount(acct);
if (!account) {
diff --git a/lib/wallet/rpc.js b/lib/wallet/rpc.js
index 8bd68627..5242f758 100644
--- a/lib/wallet/rpc.js
+++ b/lib/wallet/rpc.js
@@ -419,15 +419,23 @@ class RPC extends RPCBase {
const wallet = this.wallet;
const valid = new Validator(args);
- let name = valid.str(0, '');
- const addrs = [];
+ let acct = valid.get(0, 'default');
- if (name === '')
- name = 'default';
+ if (typeof acct !== 'number' && typeof acct !== 'string') {
+ throw new RPCError(errs.MISC_ERROR,
+ 'Param #0 must be string or number.');
+ }
+
+ const num = parseInt(acct);
+
+ if (!Number.isNaN(num))
+ acct = num;
+
+ const addrs = [];
let paths;
try {
- paths = await wallet.getPaths(name);
+ paths = await wallet.getPaths(acct);
} catch (e) {
if (e.message === 'Account not found.')
return [];
diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js
index a3e770e6..770edfed 100644
--- a/lib/wallet/wallet.js
+++ b/lib/wallet/wallet.js
@@ -934,7 +934,8 @@ class Wallet extends EventEmitter {
const hashes = await this.getAccountHashes(index);
const name = await this.getAccountName(acct);
- assert(name);
+ if (name == null)
+ throw new Error('Account not found.');
const result = [];
|
I think we should add an option like |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently the internal API can get an account by index (number) instead of the name, however when these are available over HTTP and RPC the value is assumed to be a string and the name of the account instead of the index.
As the account index can be restored from the seed, and the name cannot, I think this value should be preferred, if not the only option. The account name I think is informational only, rather than a reference point.
Handling both cases could potentially cause an issue if an account name was actually a number, so if both were an option it should be possible to specify which is being used.
The text was updated successfully, but these errors were encountered: