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

i1768 - transactions and wallet api to return Bad Request on invalid tx #1779

Merged
merged 5 commits into from Jul 29, 2022

Conversation

pragmaxim
Copy link
Collaborator

@pragmaxim pragmaxim commented Jul 22, 2022

Closes #1768

P.S. I did the same for wallet API as there was a similar case

@pragmaxim pragmaxim requested review from kushti, MrStahlfelge and greenhat and removed request for MrStahlfelge July 22, 2022 14:21
Base automatically changed from v4.0.35 to master July 25, 2022 10:38
}
}

def checkTransactionR: Route = (path("check") & post & entity(as[ErgoTransaction])) { tx =>
validateTransactionAndProcess(tx) { tx => tx }
validateTransactionAndProcess(tx) { tx => Future.successful(()) }
Copy link
Member

Choose a reason for hiding this comment

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

tx is not used in a closure

nodeViewActorRef ! LocallyGeneratedTransaction(tx)
(nodeViewActorRef ? LocallyGeneratedTransaction(tx))
.mapTo[ProcessingOutcome]
.flatMap {
Copy link
Member

Choose a reason for hiding this comment

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

This code is also duplicated in WalletApiRoute, can be unified somehow?

memoryPool().process(tx, minimalState()) match {
case (newPool, ProcessingOutcome.Accepted) =>
log.debug(s"Unconfirmed transaction $tx added to the memory pool")
val newVault = vault().scanOffchain(tx)
updateNodeView(updatedVault = Some(newVault), updatedMempool = Some(newPool))
context.system.eventStream.publish(SuccessfulTransaction(tx))
ProcessingOutcome.Accepted
Copy link
Member

Choose a reason for hiding this comment

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

You can memoize processing result and thus eliminate 2 LoC

@pragmaxim
Copy link
Collaborator Author

Nice comments, shared logic extracted to ErgoBaseApiRoute, Route functions cleaned and processingOutcome memoized.

@kushti kushti changed the base branch from master to v4.0.36 July 29, 2022 09:32
@kushti kushti merged commit 9cb3b6d into v4.0.36 Jul 29, 2022
@kushti kushti deleted the i1768-return-bad-request-on-invalid-transactions branch July 29, 2022 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

POST /transactions API request return 200 OK on declined tx due to insufficient tx fee
3 participants