Skip to content

Conversation

dmitry-timofeev
Copy link
Contributor

Overview

Use TransactionContext in transaction-like methods:

  • Service#initialize, #resume, #before- and #afterTransactions
  • Configurable

That enables easier re-use of @transaction methods, as they
already accept TransactionContext; and makes the API a little
easier to learn because there are fewer immediate abstractions
(though you will have to use TransactionContext#getBlockchainData
to access the data anyway).


See:

Definition of Done

  • There are no TODOs left in the code
  • Change is covered by automated tests
  • The coding guidelines are followed
  • Public API has Javadoc
  • Method preconditions are checked and documented in the Javadoc of the method
  • Changelog is updated if needed (in case of notable or breaking changes)
  • The continuous integration build passes

Comment on lines 105 to 107
<!-- TODO: Shall we rename it into `ExecutionContext` (as
TransactionExecutionException has become ExecutionException)?
-->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

⚠️

Copy link

Choose a reason for hiding this comment

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

I think renaming the type to ExecutionContext makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like renaming to ExecutionContext. For example, TransactionContext at initialize leads to a question "what kind of transaction do I have here?".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, thanks, will do here.

Use `TransactionContext` in transaction-like methods:
- Service#initialize, #resume, #before- and #afterTransactions
- Configurable

That enables easier re-use of @transaction methods, as they
already accept TransactionContext; and makes the API a little
easier to learn because there are fewer immediate abstractions
(though you will have to use TransactionContext#getBlockchainData
to access the data anyway).
@dmitry-timofeev dmitry-timofeev force-pushed the unify-contexts-ECR-4303 branch from 812641d to 7d39fd1 Compare March 4, 2020 16:29
Copy link

@slowli slowli left a comment

Choose a reason for hiding this comment

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

Couple of comments as of 7d39fd1.

Comment on lines 105 to 107
<!-- TODO: Shall we rename it into `ExecutionContext` (as
TransactionExecutionException has become ExecutionException)?
-->
Copy link

Choose a reason for hiding this comment

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

I think renaming the type to ExecutionContext makes sense.

* Returns SHA-256 hash of the {@linkplain TransactionMessage transaction message} that
* carried the payload of the transaction.
* Each transaction message is uniquely identified by its hash; the messages are persisted
* carried the payload of the transaction; or a zero hash if no message corresponds to this
Copy link

Choose a reason for hiding this comment

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

Question as a non-Java person: would it make sense to return Optional.empty() rather than a zero hash? IMO, this would be more semantically sound.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it would make sense, since we are on Java 11, it has acquired some methods that make it easier to use than previously, where it added some friction.

private String serviceName;
private Integer serviceId;

// todo: Init hash and author to zeroes? Or always leave to the client (as now)?
Copy link
Contributor

Choose a reason for hiding this comment

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

Now is ok because the context is created on the framework site.

Copy link
Contributor

@bullet-tooth bullet-tooth left a comment

Choose a reason for hiding this comment

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

👍

@dmitry-timofeev dmitry-timofeev merged commit 4e00cd8 into exonum:master Mar 13, 2020
@dmitry-timofeev dmitry-timofeev deleted the unify-contexts-ECR-4303 branch March 13, 2020 11:31
dmitry-timofeev added a commit that referenced this pull request Mar 13, 2020
Redefine the TransactionContext:
  - Rename it to ExecutionContext and move to service package.
  - Return Optional for optional context properties.

Use `ExecutionContext` in transaction-like methods:
  - Service#initialize, #resume, #before- and #afterTransactions
  - Configurable

That enables easier re-use of @transaction methods, as they
already accept ExecutionContext; and makes the API a little
easier to learn because there are fewer immediate abstractions
(though you will have to use ExecutionContext#getBlockchainData
to access the data anyway).

Also, move ex-transaction classes to service package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants