-
Notifications
You must be signed in to change notification settings - Fork 0
EC-781 #14
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
Open
CapDev12
wants to merge
30
commits into
master
Choose a base branch
from
EC-781
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
EC-781 #14
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
660d590
fix log name
ba9b71f
akka remote
a25eff1
Uncommited transactions - dao, web
fbe95c0
rename Transaction
08c7cab
remove commited transactions logic
1089118
rename module
3c741cd
separate main and content html
5ab1100
add cache actor
e3b1ce9
switch to FullFilledTransaction
9b2f059
open FullTransaction by link
85b3169
get transaction from cache/db
3d9186b
add expired interval for unconfirmed transactions
10868e5
sort transaction
455de9e
transactions pagination web
d3d533b
move dao to package
afd07dc
transactions pagination
7551293
remove input.contract.contract becouse removed in explorer
3361535
fix Output
ea63595
rename Output
35f4ec3
fix layouts
e5ab0a4
github link open in new window
2bdf264
main -> walletInfo
e150378
refactoring
ed3ee44
actor create logs
d67c9f7
settings
797c9cb
settings
60ee817
refactoring
cfc5785
PR fixes
CapDev12 8ee17bf
optimized for fast reading in TransactionsQ(from, to)
CapDev12 5369037
use Map with preserve order
CapDev12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package actors | ||
|
|
||
| import actors.TransStorage.RemoveConfirmedTransactions | ||
| import akka.actor.{Actor, ActorRef, Props} | ||
| import javax.inject.{Inject, Named} | ||
| import org.encryfoundation.common.modifiers.mempool.transaction.Transaction | ||
| import play.api.Logger | ||
|
|
||
| class Receiver @Inject()(@Named("transStorage") transStorage: ActorRef) extends Actor { | ||
|
|
||
| def receive: Receive = { | ||
| case transaction: Transaction => | ||
| transStorage ! transaction | ||
|
|
||
| case confirmedTransactionIds: List[String] => | ||
| transStorage ! RemoveConfirmedTransactions(confirmedTransactionIds) | ||
| } | ||
| } | ||
|
|
||
| object Receiver { | ||
| def props(transStorage: ActorRef): Props = Props(new Receiver(transStorage)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package actors | ||
|
|
||
| import actors.TransStorage._ | ||
| import akka.actor.{Actor, Timers} | ||
| import javax.inject.Inject | ||
| import models.FullFilledTransaction | ||
| import org.encryfoundation.common.modifiers.mempool.transaction.Transaction | ||
| import settings.Settings | ||
|
|
||
| import scala.collection.mutable | ||
| import scala.concurrent.duration._ | ||
|
|
||
| class TransStorage @Inject()(settings: Settings) extends Actor with Timers { | ||
|
|
||
| val transactions: mutable.LinkedHashMap[String, FullFilledTransaction] = mutable.LinkedHashMap.empty[String, FullFilledTransaction] | ||
|
|
||
| object Timer | ||
|
|
||
| timers.startPeriodicTimer(Timer, Tick, 10 seconds) | ||
|
|
||
| def receive: Receive = { | ||
| case tx: Transaction => | ||
| transactions += tx.encodedId -> FullFilledTransaction(tx) | ||
|
|
||
| case TransactionsQ(from, to) => | ||
|
CapDev12 marked this conversation as resolved.
|
||
| val fromBound = if (from >= 0) from else 0 | ||
| val toBound = if (to <= transactions.size) to else transactions.size | ||
| val fromBoundR = transactions.size - toBound | ||
| val toBoundR = transactions.size - (if (fromBound <= toBound) fromBound else toBound) | ||
| val txs = transactions.values.slice(fromBoundR, toBoundR).toList.reverse | ||
| sender ! TransactionsA(txs) | ||
|
CapDev12 marked this conversation as resolved.
|
||
|
|
||
| case TransactionByIdQ(id) => | ||
| sender ! TransactionByIdA(transactions.get(id)) | ||
|
|
||
| case RemoveConfirmedTransactions(txIds) => | ||
| txIds.foreach(id => transactions.remove(id)) | ||
|
|
||
| case Tick => | ||
| val timestamp = System.currentTimeMillis() | ||
|
|
||
| transactions.takeWhile { case (_, tx) => | ||
| timestamp - tx.transaction.timestamp > settings.trans.unconfirmedTransactionExpiredInterval.toMillis | ||
| }.foreach { case (_, tx) => | ||
| transactions.remove(tx.transaction.id) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object TransStorage { | ||
| case object Tick | ||
|
|
||
| case class TransactionsQ(from: Int, to: Int) | ||
| case class TransactionsA(txs: List[FullFilledTransaction]) | ||
|
|
||
| case class TransactionByIdQ(id: String) | ||
| case class TransactionByIdA(tx: Option[FullFilledTransaction]) | ||
|
|
||
| case class RemoveConfirmedTransactions(txIds: List[String]) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,31 @@ | ||
| package controllers | ||
|
|
||
| import models.{Contract, FullFilledTransaction, Input, Output, TransactionsDao} | ||
| import javax.inject.{Inject, Singleton} | ||
| import models.dao.TransactionsDao | ||
| import play.api.libs.circe.Circe | ||
| import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents} | ||
|
|
||
| import scala.concurrent.{ExecutionContext, Future} | ||
| import scala.concurrent.ExecutionContext | ||
|
|
||
| @Singleton | ||
| class TransactionsController @Inject()(cc: ControllerComponents, | ||
| transactionsDao: TransactionsDao) | ||
| (implicit ex: ExecutionContext) extends AbstractController(cc) with Circe { | ||
| class TransactionsController @Inject()(cc: ControllerComponents, transactionsDao: TransactionsDao)(implicit ex: ExecutionContext) | ||
| extends AbstractController(cc) with Circe { | ||
|
|
||
| def getFullTransaction(id: String): Future[Option[FullFilledTransaction]] = | ||
| transactionsDao.transactionById(id).flatMap { | ||
| case Some(tx) => | ||
| val outputsF: Future[List[Output]] = transactionsDao.outputsByTransaction(tx.id) | ||
| val inputsF: Future[List[Input]] = transactionsDao.inputsByTransaction(tx.id) | ||
| val contractF: Future[List[Contract]] = transactionsDao.contractByTransaction(tx.id) | ||
| for { | ||
| outputs <- outputsF | ||
| inputs <- inputsF | ||
| contract <- contractF | ||
| } yield Some(FullFilledTransaction(tx, inputs, outputs, contract)) | ||
|
|
||
| case _ => Future(Option.empty[FullFilledTransaction]) | ||
| } | ||
| val TRANSACTIONS_PER_PAGE = 50 | ||
|
|
||
| def getTransaction(txId: String): Action[AnyContent] = Action.async { | ||
| getFullTransaction(txId).map { | ||
| transactionsDao.fullTransactionById(txId).map { | ||
| case Some(tx) => Ok(views.html.transactionInfo(tx)) | ||
| case None => NotFound | ||
| case None => NotFound | ||
| } | ||
| } | ||
|
|
||
| def getUnconfirmedTransactions(page: Int): Action[AnyContent] = Action.async { | ||
| val from = page * TRANSACTIONS_PER_PAGE | ||
| val to = (page + 1) * TRANSACTIONS_PER_PAGE | ||
| transactionsDao.unconfirmedTransactions(from, to).map { txs => | ||
| Ok(views.html.transactions(txs, page)) | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/loggingSystem/LoggingFilter.scala → app/logging/LoggingFilter.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package loggingSystem | ||
| package logging | ||
|
|
||
| import akka.stream.Materializer | ||
| import javax.inject.Inject | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| package models | ||
|
|
||
| case class Block(header: Header, payload: List[Transaction]) | ||
| case class Block(header: Header, payload: List[DBTransaction]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| package models | ||
|
|
||
| case class Contract (hash: String, | ||
| contract: String) | ||
| case class Contract(hash: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package models | ||
|
|
||
| import org.encryfoundation.common.modifiers.mempool.transaction.Input | ||
| import org.encryfoundation.common.utils.Algos | ||
|
|
||
| case class DBInput(bxId: String, txId: String, contractHash: String, proofs: String) | ||
|
|
||
| object DBInput { | ||
| def apply(input: Input, txId: String): DBInput = | ||
| new DBInput( | ||
| Algos.encode(input.boxId), | ||
| txId, | ||
| input.contract.fold(c => Algos.encode(c.hash), c => Algos.encode(c.contract.hash)), | ||
| input.proofs.map(_.toString).mkString(",") | ||
| ) | ||
|
|
||
| def apply(bxId: String, txId: String, contractHash: String, proofs: String): DBInput = new DBInput(bxId, txId, contractHash, proofs) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package models | ||
|
|
||
| import models.DBOutput.Proposition | ||
| import org.encryfoundation.common.modifiers.mempool.directive.TransferDirective | ||
| import org.encryfoundation.common.modifiers.mempool.transaction.EncryAddress.Address | ||
| import org.encryfoundation.common.modifiers.mempool.transaction.Transaction | ||
| import org.encryfoundation.common.modifiers.state.box.{AssetBox, DataBox} | ||
| import org.encryfoundation.common.utils.Algos | ||
| import settings.Utils | ||
|
|
||
| case class DBOutput(idx: Int, | ||
| id: String, | ||
| `type`: Long, | ||
| txId: String, | ||
| value: Long, | ||
| nonce: Long, | ||
| tokenId: String, | ||
| proposition: Proposition, | ||
| data: String, | ||
| isActive: Boolean, | ||
| minerAddress: String) | ||
|
|
||
| object DBOutput { | ||
|
|
||
| case class Proposition(contractHash: String) | ||
|
|
||
| def apply(idx: Int, | ||
| id: String, | ||
| `type`: Long, | ||
| txId: String, | ||
| value: Long, | ||
| nonce: Long, | ||
| tokenId: String, | ||
| proposition: String, | ||
| data: String, | ||
| isActive: Boolean, | ||
| minerAddress: String): DBOutput = new DBOutput(idx, id, `type`, txId, value, nonce, tokenId, Proposition(proposition), data, isActive, minerAddress) | ||
|
|
||
| def apply(tx: Transaction): List[DBOutput] = { | ||
| tx.directives.toList.collect { | ||
| case TransferDirective(address, amount, tokenIdOpt) => address | ||
| } | ||
|
|
||
| tx.newBoxes.toList.zipWithIndex.map { case(box, idx) => | ||
| val (amount, tokenId, data) = box match { | ||
| case box: AssetBox => | ||
| (box.amount, Algos.encode(box.tokenIdOpt.getOrElse(Utils.IntrinsicTokenId)), "") | ||
| case box: DataBox => | ||
| (0L, "", Algos.encode(box.data)) | ||
| case _ => (0L, "", "") | ||
| } | ||
| val address: Option[Address] = tx.directives(idx) match { | ||
| case d: TransferDirective => Some(d.address) | ||
| case _ => None | ||
| } | ||
|
|
||
| new DBOutput(idx, Algos.encode(box.id), box.typeId, tx.encodedId, amount, box.nonce, tokenId, | ||
| Proposition(Algos.encode(box.proposition.contractHash)), data, true, address.getOrElse("")) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.