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: add /accounts/:id/activities endpoint #906

Merged
merged 8 commits into from
Sep 21, 2022
Merged

feat: add /accounts/:id/activities endpoint #906

merged 8 commits into from
Sep 21, 2022

Conversation

sborrazas
Copy link
Contributor

Initial approach for dealing with account activities.

This endpoint contains exclusively events generated by direct transactions (no internal transactions generated by contract calls).

The next steps are:

  • Including contract call events.
  • Including key-block and micro-block events (e.g. block_mined, dev_reward).
  • Including AEx9 and AEx141 events.
  • Refactor AeMdw.Txs so that it uses the Field module as well.

refs #725

Initial approach for dealing with account activities.

This endpoint contains exclusively events generated by direct
transactions (no internal transactions generated by contract calls).

The next steps are:
  * Including contract call events.
  * Including key-block and micro-block events (e.g. block_mined, dev_reward).
  * Including AEx9 and AEx141 events.
  * Refactor AeMdw.Txs so that it uses the Field module as well.
@sborrazas sborrazas self-assigned this Sep 15, 2022
README.md Outdated Show resolved Hide resolved

## Activities

Inteded for being able to display all events in which a specific account is related to in any way.
Copy link
Member

Choose a reason for hiding this comment

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

As events are mostly related to logs on blockchain taxonomy, for disambiguation purpose, a description of the concept of event would be helpful.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe action instead of event? Even when the account is passive (like a receiver on SpendTx) there would be an action happening from somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think event makes more than action since, since it's related to something that sometimes happens independently of the account given

Copy link
Member

Choose a reason for hiding this comment

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

Would you mind giving some description about the events, that they are not only log events?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what kind of description you would want, can you send me the description you're referring to so I can include it on the PR?

Copy link
Member

Choose a reason for hiding this comment

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

Any description or examples clarifying that events are not log events would be fine. "For example when an account receives an AE transfer from a SpendTx ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

README.md Outdated Show resolved Hide resolved
@typep range() :: {:gen, Range.t()} | nil
@typep cursor() :: Txs.tx() | nil

@create_tx_types ~w(contract_create_tx channel_create_tx oracle_register_tx name_claim_tx ga_attach_tx)a
Copy link
Member

Choose a reason for hiding this comment

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

Following the same logic as :contract_create_tx, the child contracts are indexed likewise with :contract_call_tx and nil pos.

The Field with nil pos the name_claim_tx would be the name hash (not an account). Would it make sense for a use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for clarifying, I removed name_claim_tx from the list, since I think that these (together with contract_create_tx) should be handled differently. The account ID given in the URL does not appear in the tx object being return for these types of events. A new type of event would make more sense (next PR)

Copy link
Member

Choose a reason for hiding this comment

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

:contract_create_tx may be kept for the contract account (would only add the :contract_call_tx for child contracts)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The contract_create_tx is already included. I wanted contracts created through transaction calls to be a separate type of event so we are able to transmit to the user that this isn't a contract call made TO the contract, but to a different contract that creates the account given

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for clarifying, I removed name_claim_tx from the list, since I think that these (together with contract_create_tx) should be handled differently. The account ID given in the URL does not appear in the tx object being return for these types of events. A new type of event would make more sense (next PR)

I was referring to "the account ID given in the URL does not appear, ... A new type of event would make more sense" to say that :contract_create_tx works "for the contract account".

Likewise the :contract_create_tx, the child contract account might appear on the contract call but I also think that it would be better leave it for another kind of event. The only request here is that it should be uniform, if a contract creation will be handled for contract account in a different event, the same would need to be done for child contracts and generalized accounts (or if kept :contract_call_tx would be added).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I hadn't realized that child contracts were also included in the Field model. I've now removed these to then add them as a separate event later. Thank you!

{tx_type, tx_field_pos, account_pk, Util.max_256bit_int()}}
end

cursor = if cursor, do: {tx_type, tx_field_pos, account_pk, cursor}
Copy link
Member

Choose a reason for hiding this comment

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

Would rename the latter cursor to make it clear it's a different kind from the one being assigned to.

@@ -0,0 +1,76 @@
defmodule Integration.AeMdwWeb.ActivityControllerTest do
Copy link
Member

Choose a reason for hiding this comment

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

BlockchainSim was a nice module tool created to easily allow adding new transactions to a blockchain from scratch. It could be used here to be able to have automated unit/controller tests. Even only with :spend_txs, could help validating the activities pagination (if continuation is correct) and if all are returned (later could be used for validating the filters).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Validating all of these future use cases can be done using integration tests, so I would avoid too much mocking that would make the tests lose their value

Copy link
Member

Choose a reason for hiding this comment

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

The reason for the proposal is because there were many data that I needed to test manually. It could be automated somehow to avoid manual regression tests before releases. Besides that we can't have proper integration tests with backward direction. This is what the current tests would be missing for both directions:

  • if all activities are from the account (on directions)
  • if the activities pages are complete in a way that the key boundary doesn't exclude some entry (for both directions)
  • if the next continues from the last of previous page without repetition
  • if the endpoint renders all fields and if these fields have proper value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added some unit tests now

Copy link
Member

@jyeshe jyeshe left a comment

Choose a reason for hiding this comment

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

Besides adding the :contract_call_tx for child contracts, some improvement on automated tests is needed (if not on CI with integration ones).


## Activities

Inteded for being able to display all events in which a specific account is related to in any way.
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind giving some description about the events, that they are not only log events?

@@ -0,0 +1,76 @@
defmodule Integration.AeMdwWeb.ActivityControllerTest do
Copy link
Member

Choose a reason for hiding this comment

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

The reason for the proposal is because there were many data that I needed to test manually. It could be automated somehow to avoid manual regression tests before releases. Besides that we can't have proper integration tests with backward direction. This is what the current tests would be missing for both directions:

  • if all activities are from the account (on directions)
  • if the activities pages are complete in a way that the key boundary doesn't exclude some entry (for both directions)
  • if the next continues from the last of previous page without repetition
  • if the endpoint renders all fields and if these fields have proper value

Copy link
Member

@jyeshe jyeshe left a comment

Choose a reason for hiding this comment

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

I would also add unit tests for validating

  • if the activities pages are complete in a way that the key boundary doesn't exclude some entry (for both directions)
  • if the next continues from the last of previous page without repetition

but there will be opportunity for that on next PRs

Copy link
Collaborator

@thepiwo thepiwo left a comment

Choose a reason for hiding this comment

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

really cool first step! lets tackle AEX-9 next

@sborrazas sborrazas merged commit 950f738 into master Sep 21, 2022
@sborrazas sborrazas deleted the activities branch September 21, 2022 21:48
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.

3 participants