Skip to content

Instantly share code, notes, and snippets.

@kushti
Created August 25, 2016 14:31
Show Gist options
  • Save kushti/ec7d4f8d781cc3cc6f29d3ea6cb7f77e to your computer and use it in GitHub Desktop.
Save kushti/ec7d4f8d781cc3cc6f29d3ea6cb7f77e to your computer and use it in GitHub Desktop.
package scorex.newstate
import akka.actor.{Actor, ActorRef}
import scorex.api.http.ApiRoute
import scorex.serialization.BytesSerializable
import scorex.transaction.box.proposition.Proposition
import shapeless.HList
import scala.util.Try
trait NodeStateModifier
trait Transaction[P <: Proposition] extends NodeStateModifier with BytesSerializable {
self =>
type TX >: self.type <: Transaction[P]
def companion: TransactionCompanion[P, TX]
}
trait TransactionCompanion[P <: Proposition, TX <: Transaction[P]] {
trait NewOffchainTransaction
trait DropOffchainTransaction
}
trait Block[P <: Proposition, TX <: Transaction[P]] extends BytesSerializable {
self =>
type B >: self.type <: Block[P, TX]
type BlockFields <: HList
def blockFields: BlockFields
def companion: BlockCompanion[P, TX, B]
}
trait BlockCompanion[P <: Proposition, TX <: Transaction[P], B <: Block[P, TX]] {
self =>
def parse(bytes: Array[Byte]): Try[B]
def genesis: B
def isValid(block: B): Boolean
def build(blockFields: B#BlockFields): B
def transactions(block: B): Seq[TX]
trait AppendBlock
trait RollbackTo
}
trait NodeStateComponent {
self =>
type NS >: self.type <: NodeStateComponent
def companion: NodeStateComponentCompanion
}
trait NodeStateComponentCompanion {
def api: ApiRoute
//network functions to call
}
trait Synchronizable {
val invId: Byte
}
trait MinimalState[P <: Proposition, TX <: Transaction[P]] extends NodeStateComponent
trait History[P <: Proposition, TX <: Transaction[P]] extends NodeStateComponent with Synchronizable
trait MemPool[TX <: Transaction[_]] extends NodeStateComponent with Synchronizable
trait Wallet[P <: Proposition, TX <: Transaction[P]] extends NodeStateComponent
trait NodeStateHolder[P <: Proposition, TX <: Transaction[P]] {
self =>
type NSF >: self.type <: NodeStateHolder[P, TX]
type MS <: MinimalState[P, TX]
type HIS <: History[P, TX]
type MP <: MemPool[TX]
type WL <: Wallet[P, TX]
type NodeState = (MS, HIS, MP, WL)
def currentState: NodeState
protected def componentsSeq: Seq[NodeStateComponent] = Seq(
currentState._1,
currentState._2,
currentState._3,
currentState._4
)
def apis: Seq[ApiRoute] = componentsSeq.map(_.companion.api)
import shapeless.syntax.typeable._
def synchronizeables: Seq[Synchronizable] = componentsSeq.flatMap(_.cast[Synchronizable])
}
trait Source
object Local extends Source
case class Remote(listener: ActorRef) extends Source
trait Peer extends Actor {
}
trait IngoingObjectsController extends Actor {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment