Skip to content

Fix: Get account by index instead of name#1135

Open
manavdesai27 wants to merge 8 commits into
bcoin-org:masterfrom
manavdesai27:account_by_index
Open

Fix: Get account by index instead of name#1135
manavdesai27 wants to merge 8 commits into
bcoin-org:masterfrom
manavdesai27:account_by_index

Conversation

@manavdesai27
Copy link
Copy Markdown
Contributor

Fixes #968

Applied a temporary fix regarding the issue.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 29, 2023

Codecov Report

❌ Patch coverage is 4.00000% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.41%. Comparing base (57f5956) to head (01e3b0c).
⚠️ Report is 33 commits behind head on master.

Files with missing lines Patch % Lines
lib/wallet/rpc.js 4.34% 22 Missing ⚠️
lib/wallet/wallet.js 0.00% 13 Missing ⚠️
lib/wallet/http.js 8.33% 11 Missing ⚠️
lib/client/wallet.js 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1135      +/-   ##
==========================================
- Coverage   69.53%   69.41%   -0.13%     
==========================================
  Files         158      158              
  Lines       26598    26643      +45     
==========================================
- Hits        18494    18493       -1     
- Misses       8104     8150      +46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@haxwell
Copy link
Copy Markdown

haxwell commented Jan 29, 2023

I think this PR should include tests.

@manavdesai27
Copy link
Copy Markdown
Contributor Author

manavdesai27 commented Jan 30, 2023

I think this PR should include tests.

Could you point me in the right direction as to which files I should look into regarding the same.
Edit: Don't we already have the test for getting account info, in wallet-http-test.js at line 86?

@manavdesai27
Copy link
Copy Markdown
Contributor Author

manavdesai27 commented Jan 31, 2023

I have created separate cli options to get account information via name and index, bot for rpc and http.

  • If there is an account name, with name being an integer, and we use get accountbyname, it would get the account whose name is 7, not index.
  • But if I use get accountbyindex, it would provide the account with accountIndex as 7

Screenshot from 2023-01-31 12-06-18
Screenshot from 2023-01-31 12-06-03
Screenshot from 2023-01-31 12-05-19

@manavdesai27
Copy link
Copy Markdown
Contributor Author

@pinheadmz could you please review this pull request?

Comment thread bin/bwallet-cli
@@ -608,6 +618,7 @@ class CLI {
this.log(' $ abandon [hash]: Abandon a transaction.');
this.log(' $ account create [account-name]: Create account.');
this.log(' $ account get [account-name]: Get account details.');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please specify that this method gets account by name.

Comment thread lib/client/wallet.js
/**
* Get wallet account.
* @param {Number} id
* @param {Number|String} accountIndex
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The account index is supposed to be a Number, not a String.

Comment thread lib/client/wallet.js
return this.client.getAccount(this.id, account);
}

getAccountIndex(account) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need JSDocs here.

Comment thread lib/wallet/http.js
acct = num;
}

const account = await req.wallet.getAccount(acct);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to create a new method in the wallet/wallet.js file and name it getAccountByAccountIndex as there is already a method named getAccountIndex. I also ask you to name all the references of getAccountIndex to getAccountByAccountIndex.

Comment thread lib/wallet/rpc.js

if (name === '')
name = 'default';
let acct = valid.get(0, 'default');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right @pinheadmz could you please take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get accounts by index instead of name

4 participants