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

validate added #1956

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

validate added #1956

wants to merge 29 commits into from

Conversation

n13
Copy link
Member

@n13 n13 commented Jun 12, 2024

🗃 Github Issue Or Explanation for this PR. (What is it supposed to do and Why is needed)

replace naked try/catch with transfer action parser

chuck-h and others added 26 commits April 30, 2024 16:03
@n13 n13 mentioned this pull request Jun 12, 2024
Base automatically changed from update/from_rainbo to master June 12, 2024 06:42
timestamp: parseTimestamp(json['@timestamp']),
transactionId: json['trx_id'],
);
static bool validateTokenTransferAction(Map<String, dynamic> json) {
Copy link
Collaborator

@chuck-h chuck-h Jun 12, 2024

Choose a reason for hiding this comment

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

I don't see that this is an improvement.
The only thing we know about the blockchain tx we are handling here is that the action name is transfer. Anyone can write a contract with a transfer action, and we should handle whatever gets thrown at us.
This validator code only tests for a specific type of mismatch: absent fields. However the json we're parsing could have different data types, return structures where we expect a scalar, etc. Lots of ways to fail, and try/catch deals with them all. @n13

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree - we don't want to "deal with them all" - we only want to deal with the one transfer action that our code can actually handle, which is the one that has all the fields we need.

The try / catch also removes all that don't have the required fields since the fields are non-nullable, and would throw null pointer exceptions in the constructor, it's just implicit.

So to compare try/catch (A) with validate (B):
A:

  • dismisses all transfer actions that don't have the required parameters (non-nullable fields set to null causes crash)
  • also dismisses any actions that cause unknown errors to happen

B:

  • dismisses all transfer actions that don't have the required parameters
  • surfaces any other errors we don't know about as crashes

Copy link
Collaborator

@chuck-h chuck-h Jun 22, 2024

Choose a reason for hiding this comment

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

We are talking about what shows up on the history list, which is a convenience for the user.
image

Fundamentally we want the history to show ordinary Telos token transfers and nothing else. (We could also, say, show issue events, like https://wallet.telos.net/?network=telos does, but we choose not to.) I think "transfer" actions from any other type of contract (e.g. NFTs) should be silently ignored. Such blockchain actions are not "errors to be surfaced", they are just a record of the user interacting with other contracts that are beyond our interest.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah ok but we never have a naked try/catch with no error printed.

That's kind of the point, not the functionality

Catch is for error conditions

Not for expected conditions. like transfer actions that are other actions than the transfer actions we're interested in.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about we try/catch around the validation, log a catch as an "error" event, and continue (i.e. return null)? That way if, in the future, some new type of unexpected action shows up on the blockchain, we "surface any other errors we don't know about" as logged errors but not as crashes that block the app from displaying the transaction list (disrupt the UX).

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.

2 participants