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

extend API route for get transaction with query parameter withEvents #104

Merged
merged 5 commits into from
Nov 24, 2020

Conversation

miiu96
Copy link
Contributor

@miiu96 miiu96 commented Nov 4, 2020

Extend API route /transaction/:txHash with a query parameter ?withResults=true.
Now when someone wants to get a transaction from proxy has the option to receive also the results of transaction.

  • A transaction can have as results a receipt or a list of smart contract results

@miiu96 miiu96 self-assigned this Nov 4, 2020
api/mock/facade.go Outdated Show resolved Hide resolved
go.sum Show resolved Hide resolved
process/transactionProcessor.go Outdated Show resolved Hide resolved
process/transactionProcessor.go Outdated Show resolved Hide resolved
process/transactionProcessor.go Outdated Show resolved Hide resolved
if err != nil {
return UnknownStatusTx, errors.ErrTransactionNotFound
}

return string(tx.Status), nil
}

func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType requestType) (*data.FullTransaction, error) {
func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType requestType, withEvents bool) (*data.FullTransaction, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please split the logic in this function into two functions, such as one of them does not call alterTxWithScResultsFromSourceIfNeeded or mergeScResultsFromSourceAndDestIfNeeded. This way, it would be trivial to prove (more obvious) that the implementation does never lead to a stackoverflow.

Currently, alterTxWithScResultsFromSourceIfNeeded or mergeScResultsFromSourceAndDestIfNeeded contain some risky recursive calls to getTxFromObserver.

EDIT: sorry, only now I realize that we have getTxFromObserver vs. getTxFromObservers. I will think of some possible refactoring. If you have any ideas, go on :)

process/transactionProcessor.go Outdated Show resolved Hide resolved
process/transactionProcessor.go Outdated Show resolved Hide resolved
@@ -239,13 +240,19 @@ func GetTransaction(c *gin.Context) {
return
}

withEvents, err := getQueryParamWithEvents(c)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

please insert the error or a more specific one that tells about the parameter

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.

process/transactionProcessor.go Outdated Show resolved Hide resolved
@@ -455,19 +469,46 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques
return nil, errors.ErrTransactionNotFound
}

func (tp *TransactionProcessor) getTxWithSenderAddr(txHash, sender string) (*data.FullTransaction, error) {
func (tp *TransactionProcessor) alterTxWithScResultsFromSourceIfNeeded(txHash string, tx *data.FullTransaction, withEvents bool) *data.FullTransaction {
if !withEvents && len(tx.ScResults) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe change to || instead of && ? I think that if any of the 2 options are false, the tx wouldn't be altered

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 right. done.

bogdan-rosianu
bogdan-rosianu previously approved these changes Nov 12, 2020
andreibancioiu
andreibancioiu previously approved these changes Nov 13, 2020
@LucianMincu LucianMincu merged commit cdc818c into development Nov 24, 2020
@andreibancioiu andreibancioiu deleted the extend-api-route-get-tx-with-events branch November 21, 2022 13:51
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.

4 participants