Skip to content
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

feat: new cli commands accounts:notes and accounts:transactions #1086

Merged
merged 15 commits into from Jun 15, 2022

Conversation

wd021
Copy link
Contributor

@wd021 wd021 commented Feb 28, 2022

Proposing to add an accounts:transactions command to display transaction notes for an account. I've been debugging some account balance issues lately and found this to be quite helpful. Here's what it looks like

Screen Shot 2022-02-28 at 2 04 16 PM

If we add this, I'll open a PR to update docs on the website repo.

Is this a breaking change? If yes, add notes below on why this is breaking and
what additional work is required, if any.

[ ] Yes
[x] No

new cli command - accounts:transactions
@wd021 wd021 requested a review from a team as a code owner February 28, 2022 14:07
@wd021 wd021 mentioned this pull request Mar 5, 2022
@dguenther
Copy link
Member

Going to assign this to @NullSoldier because I think he wanted to give it a review next week before it merges. This looks useful!

@QustomQure
Copy link

QustomQure commented Mar 30, 2022

I think that this command must be able to work with both accountName and account address whichever type was written for better usability.

@wd021
Copy link
Contributor Author

wd021 commented Mar 30, 2022

for consistency, I'm using the same format as accounts:balance, which is accountName. We can update to take both, although it is one quick step to get names from accounts:list

@Allmaaz
Copy link

Allmaaz commented Apr 12, 2022

Very good project

@wd021
Copy link
Contributor Author

wd021 commented May 19, 2022

@dguenther @NullSoldier still interested in merging this?

If so, i can update the code for latest version.. lmk!

@dguenther
Copy link
Member

I'd still like to merge this, I think it's definitely useful especially in the latest testnet phase. Nobody on our side has been directly involved in reviewing + merging it, so sorry for the delay! I'd like to get one other person than myself to take a look at it, then it should be good to go, if you don't mind updating the code to fix conflicts.

memo: decryptedNote.memo().replace(/\x00/g, ''),
})

continue
Copy link
Member

Choose a reason for hiding this comment

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

Is this continue needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, removed.

* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { expect as expectCli, test } from '@oclif/test'
import { GetTransactionsResponse } from 'ironfish'
Copy link

Choose a reason for hiding this comment

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

This import didn't work for me, I had to change the path to ../../../../ironfish/src/rpc/routes/transactions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, this needs updating for the latest version. I just pushed an update.

@wd021
Copy link
Contributor Author

wd021 commented May 23, 2022

@dguenther updated for the latest version, can review now.

@mat-if
Copy link
Contributor

mat-if commented May 26, 2022

Hey @wd021, I'm starting to dig into this PR, sorry for the delay. I wanted to clarify which direction to look at this from.

What's the intended goal of this CLI command? I think there's a few different things technically happening here so I wanted to make sure we're on the same page on expectations of what questions this command should answer.

For example, are you expecting this to show a complete list of all transactions this account has participated in? A complete list of notes, spent and unspent? A list of transactions containing unspent notes? etc.

Looking at this right now, it feels a little bit awkward in that it is kind of a view into transactions, and also kind of a view into notes, and I think we can improve that together

@wd021
Copy link
Contributor Author

wd021 commented May 27, 2022

@mat-if no worries.

The motivation for adding this command was to help debug account balances & faucet errors during phase 1. I wanted an easy way to output the spent notes associated with a given account.

I agree that the wording is probably unclear. Would also be interested in expanding the scope of this into filtering by txs/notes/unspent notes.

@mat-if mat-if assigned mat-if and unassigned NullSoldier Jun 2, 2022
@mat-if
Copy link
Contributor

mat-if commented Jun 2, 2022

Ok, so I've thought about this a bit now. As I've mentioned, this feels a little bit like a view into both transactions and notes and feels a little confusing because of that.

I think this could go a couple different directions, let me know what you think.

  1. This focuses on transactions, and stays as accounts:transactions.
    This would summarize things like the value of notes, so instead of showing individual notes, you could just show the net value of the transactions (-10 $IRON, 5 $IRON), etc. Maybe show the number of spends and outputs as well. Jason suggested possibly showing the status of the transaction but that might be a lot more work, I haven't looked, so feel free to not do it here 😂. That can easily be a future improvement.

  2. This focuses on notes, and becomes accounts:notes
    This would instead show similar to how it is now, but without things like tx fee, since that's a transaction level concept and is unclear looking at the current table. If I didn't know better, I might think that each note is accruing a separate transaction fee. I would expect this to be mostly for debugging, whereas the other 2 also have use outside of debugging by providing better visibility that we currently lack.

  3. Another interesting idea that I think could be useful alongside accounts:transactions would be like accounts:transaction <hash> to show the note-level breakdown of a specific transaction.

I think all 3 are very useful on their own, but to be clear, I don't expect you to implement all 3 in this PR. I think one is sufficient, and we can iterate from there. Let me know what you think!

If you want to continue on one of these, great! If not, let me know and I can take over the PR if you prefer.

@wd021
Copy link
Contributor Author

wd021 commented Jun 2, 2022

yea, 1 and 2 were exactly where my mind was at. let's have 2 separate methods, accounts:transactions and accounts:notes. And also agree that 3 could be useful too!

i don't mind taking a crack at all 3 in this PR, will have some time later in the week 👨‍💻

@wd021
Copy link
Contributor Author

wd021 commented Jun 6, 2022

@mat-if PR updated. here's the latest👇

accounts:notes - note level breakdown for given account (optional -a flag)

Screenshot 2022-06-06 at 11 08 36

accounts:transactions - transaction breakdown for given account or txhash (optional -a / -t flags)

Screenshot 2022-06-06 at 11 08 56

Screenshot 2022-06-06 at 11 09 33

@wd021 wd021 changed the title feat: new cli command accounts:transactions feat: new cli commands accounts:notes and accounts:transactions Jun 6, 2022
Copy link
Contributor

@mat-if mat-if left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! A few comments, but overall this looks pretty good.

let transactionInfo = null
const transactionNotes = []

for (const transactionMapValue of this.transactionMap.values()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this function is for a specific transaction, instead of looping over this.transactionMap.values(), you can lookup on the hash directly: const transactionMapValue = this.transactionMap.get(Buffer.from(hash, 'hex'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh right, good catch.

@@ -603,6 +603,46 @@ export class Accounts {
this.scan = null
}

getNotesFor(account: Account): {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about renaming this to getNotes to be more inline with the other function names in here?

Suggested change
getNotesFor(account: Account): {
getNotes(account: Account): {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense 👌

@@ -921,6 +961,125 @@ export class Accounts {
await this.scanTransactions()
}

getTransactionsFor(account: Account): {
Copy link
Contributor

Choose a reason for hiding this comment

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

Like above, what do you think about getTransactions

Suggested change
getTransactionsFor(account: Account): {
getTransactions(account: Account): {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense 👌

}
}

if (transactionCreator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding this correctly, this check makes it so we only add transactions if we were a spender of a note. I would expect to also see transactions in which I only received IRON as well. Or more specifically, I would expect to see a transaction in which I have any decryptable notes.

To show what I mean, I set up a test where this account has exactly 1 note, which was IRON I sent from a different account. You'll see the note, and it references a transaction, but when I do accounts:transactions it doesn't show anything

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right. I updated this method to include notes where one is the receiver of iron in a transaction. but i also think its valuable to be able to detect the transactions created by the account, so there's now an extra creator column for the table.


if (transactionInfo !== null) {
this.log(
`Transaction: ${transactionHash}, Status: ${transactionInfo.status}, Miner Fee: ${
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about making each of these on a new line? I think it makes it a little easier to parse the info.

Transaction: fdaf29274587c8f58ac6214f42642fd610a222cea8e5e39ff4e11d58d379c194
Status: completed
Miner Fee: x
Fee ($ORE): 1
Spends: 1

Copy link
Contributor Author

@wd021 wd021 Jun 10, 2022

Choose a reason for hiding this comment

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

updated to this

}
}

if (transactionCreator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here about the transactionCreator thing, not able to look up a transaction that a note references if I only received in that transaction

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, removed this.

@wd021
Copy link
Contributor Author

wd021 commented Jun 10, 2022

@mat-if

  • went through review changes and updated
  • added extra creator column for account:transactions
  • merge latest staging to resolve conflicts

Copy link
Contributor

@mat-if mat-if left a comment

Choose a reason for hiding this comment

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

Thanks!

@mat-if mat-if merged commit 7441c21 into iron-fish:staging Jun 15, 2022
mumu714 pushed a commit to 6block/ironfish that referenced this pull request Jun 30, 2022
…ron-fish#1086)

* new cli command - accounts:transactions

new cli command - accounts:transactions

* fix linting

* add assertHasAccount() in getTransactionNotes

* use variable 'account' instead of 'accountName'

* update code to latest version

* fix linting

* refactor: convert accounts:transactions -> accounts:notes

* refactor: getNotes type change

* feat: new accounts:transactions command

* fix: linting on test files

* make review changes

* fix test fail

* fix lint
vchs1v pushed a commit to vchs1v/ironfish that referenced this pull request Jun 30, 2022
…ron-fish#1086)

* new cli command - accounts:transactions

new cli command - accounts:transactions

* fix linting

* add assertHasAccount() in getTransactionNotes

* use variable 'account' instead of 'accountName'

* update code to latest version

* fix linting

* refactor: convert accounts:transactions -> accounts:notes

* refactor: getNotes type change

* feat: new accounts:transactions command

* fix: linting on test files

* make review changes

* fix test fail

* fix lint
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.

None yet

8 participants