Skip to content

Commit

Permalink
server: Add Block.HasTransactions persisted model
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Feb 23, 2019
1 parent 485faea commit 8b9f1c0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion server/app/com/xsn/explorer/models/persisted/Block.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,24 @@ case class Block(
bits: String,
chainwork: String,
difficulty: BigDecimal,
extractionMethod: BlockExtractionMethod)
extractionMethod: BlockExtractionMethod) {

def withTransactions(transactions: List[Transaction.HasIO]): Block.HasTransactions = {
Block.HasTransactions(this, transactions)
}
}

object Block {

case class HasTransactions(block: Block, transactions: List[Transaction.HasIO]) {
require(
transactions.forall(_.blockhash == block.hash),
s"The transaction = ${transactions.find(_.blockhash != block.hash).get.id} doesn't belong to the block = ${block.hash}"
)

def hash: Blockhash = block.hash
def height: Height = block.height
def previousBlockhash: Option[Blockhash] = block.previousBlockhash
def asTip: HasTransactions = HasTransactions(block.copy(nextBlockhash = None), transactions)
}
}

0 comments on commit 8b9f1c0

Please sign in to comment.