Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fluency03 committed Apr 28, 2018
2 parents 4dfacec + 2e3883b commit 4b52536
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/scala/com/fluency03/blockchain/core/Block.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ object Block {
transactions: Seq[Transaction]): Block =
mineNextBlock(currentBlock.index + 1, currentBlock.hash, newBlockData, timestamp, difficulty, transactions)

def mineNextBlock(
currentBlock: Block,
newBlockData: String,
timestamp: Long,
difficulty: Int,
transactions: Seq[Transaction],
miner: String): Block =
mineNextBlock(currentBlock.index + 1, currentBlock.hash, newBlockData, timestamp, difficulty,
transactions :+ createCoinbaseTx(currentBlock.index + 1, miner, timestamp))

/**
* Check whether transactions of a Block are valid:
* 1. Coinbase transaction is valid
Expand Down
4 changes: 3 additions & 1 deletion src/test/scala/com/fluency03/blockchain/core/BlockTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core

import java.security.KeyPair

import com.fluency03.blockchain.core.Block.allTransValidOf
import com.fluency03.blockchain.core.BlockHeader.hashOfBlockHeader
import com.fluency03.blockchain.core.Transaction.{COINBASE_AMOUNT, createCoinbaseTx, signTxIn, updateUTxOs}
import org.json4s.JValue
Expand Down Expand Up @@ -151,6 +152,7 @@ class BlockTest extends FlatSpec with Matchers {
"allTransAreValid" should "check whether all transactions of a Block are valid." in {
val uTxOs: mutable.Map[Outpoint, TxOut] = mutable.Map.empty[Outpoint, TxOut]
genesis.allTransAreValid(uTxOs) shouldEqual true
allTransValidOf(Nil, 0, uTxOs) shouldEqual false

val pair1 = Crypto.generateKeyPair()
val address1 = pair1.getPublic.toHex
Expand All @@ -175,7 +177,7 @@ class BlockTest extends FlatSpec with Matchers {
val signedTx = Transaction(signedTxIns, Seq(TxOut(address1, COINBASE_AMOUNT)), ts)

val validNewBlock = Block.mineNextBlock(genesis, "This is next Block!", ts, genesis.difficulty,
Seq(signedTx, createCoinbaseTx(1, address1, ts)))
Seq(signedTx), address1)
validNewBlock.allTransAreValid(uTxOs) shouldEqual true
}

Expand Down

0 comments on commit 4b52536

Please sign in to comment.