Skip to content

Commit

Permalink
Change totalDifficulty to BigInteger
Browse files Browse the repository at this point in the history
  • Loading branch information
omurovch committed Mar 13, 2019
1 parent 88ba0e9 commit 0e77e2b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.content.Context
import io.horizontalsystems.ethereumkit.models.EthereumTransaction
import io.horizontalsystems.ethereumkit.spv.models.BlockHeader

@Database(entities = [BlockHeader::class, EthereumTransaction::class], version = 2, exportSchema = true)
@Database(entities = [BlockHeader::class, EthereumTransaction::class], version = 3, exportSchema = true)
abstract class SPVDatabase : RoomDatabase() {

abstract fun blockHeaderDao(): BlockHeaderDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BlockHeader {

@PrimaryKey
val hashHex: ByteArray
var totalDifficulty: ByteArray = byteArrayOf() // Scalar value corresponding to the sum of difficulty values of all previous blocks
var totalDifficulty: BigInteger = BigInteger.ZERO // Scalar value corresponding to the sum of difficulty values of all previous blocks
val parentHash: ByteArray // 256-bit Keccak-256 hash of parent block
val unclesHash: ByteArray // 256-bit Keccak-256 hash of uncles portion of this block
val coinbase: ByteArray // 160-bit address for fees collected from successful mining
Expand All @@ -48,7 +48,7 @@ class BlockHeader {

constructor(
hashHex: ByteArray,
totalDifficulty: ByteArray, // Scalar value corresponding to the sum of difficulty values of all previous blocks
totalDifficulty: BigInteger, // Scalar value corresponding to the sum of difficulty values of all previous blocks
parentHash: ByteArray, // 256-bit Keccak-256 hash of parent block
unclesHash: ByteArray, // 256-bit Keccak-256 hash of uncles portion of this block
coinbase: ByteArray, // 160-bit address for fees collected from successful mining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Ropsten : INetwork {

override val checkpointBlock =
BlockHeader(hashHex = "8e979e196f08a06ecd3e7bbbf83b387a5e429b43a6694df7b01b9402a272eec6".hexStringToByteArray(),
totalDifficulty = "18284610994619994".hexStringToByteArray(),
totalDifficulty = BigInteger("18284610994619994"),
parentHash = "91690d0990e80aa73341926434746bb532194204d81b0736cc5f147a60c0824f".hexStringToByteArray(),
unclesHash = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".hexStringToByteArray(),
coinbase = "b17fc44dd79d21cd7f4d8c9686c98ae9039b3909".hexStringToByteArray(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class StatusMessage : IMessage {
val protocolVersion: Byte
val networkId: Int
val genesisHash: ByteArray
val bestBlockTotalDifficulty: ByteArray
val bestBlockTotalDifficulty: BigInteger
val bestBlockHash: ByteArray
val bestBlockHeight: BigInteger

constructor(protocolVersion: Byte, networkId: Int,
genesisHash: ByteArray, bestBlockTotalDifficulty: ByteArray,
genesisHash: ByteArray, bestBlockTotalDifficulty: BigInteger,
bestBlockHash: ByteArray, bestBlockHeight: BigInteger) {
this.protocolVersion = protocolVersion
this.networkId = networkId
Expand All @@ -35,9 +35,8 @@ class StatusMessage : IMessage {
val networkIdBytes = (paramsList[1] as RLPList)[1].rlpData

networkId = networkIdBytes.toInt()
val difficultyBytes = (paramsList[2] as RLPList)[1].rlpData

bestBlockTotalDifficulty = difficultyBytes ?: byteArrayOf()
bestBlockTotalDifficulty = (paramsList[2] as RLPList)[1].rlpData.toBigInteger()
bestBlockHash = (paramsList[3] as RLPList)[1].rlpData ?: byteArrayOf()
bestBlockHeight = (paramsList[4] as RLPList)[1].rlpData.toBigInteger()
genesisHash = (paramsList[5] as RLPList)[1].rlpData ?: byteArrayOf()
Expand All @@ -46,7 +45,7 @@ class StatusMessage : IMessage {
override fun encoded(): ByteArray {
val protocolVersion = RLP.encodeList(RLP.encodeString("protocolVersion"), RLP.encodeByte(this.protocolVersion))
val networkId = RLP.encodeList(RLP.encodeString("networkId"), RLP.encodeInt(this.networkId))
val totalDifficulty = RLP.encodeList(RLP.encodeString("headTd"), RLP.encodeElement(this.bestBlockTotalDifficulty))
val totalDifficulty = RLP.encodeList(RLP.encodeString("headTd"), RLP.encodeBigInteger(this.bestBlockTotalDifficulty))
val bestHash = RLP.encodeList(RLP.encodeString("headHash"), RLP.encodeElement(this.bestBlockHash))
val bestNum = RLP.encodeList(RLP.encodeString("headNum"), RLP.encodeBigInteger(this.bestBlockHeight))
val genesisHash = RLP.encodeList(RLP.encodeString("genesisHash"), RLP.encodeElement(this.genesisHash))
Expand All @@ -57,7 +56,7 @@ class StatusMessage : IMessage {

override fun toString(): String {
return "Status [protocolVersion: $protocolVersion; networkId: $networkId; " +
"totalDifficulty: ${bestBlockTotalDifficulty.toHexString()}; " +
"totalDifficulty: $bestBlockTotalDifficulty; " +
"bestHash: ${bestBlockHash.toHexString()}; bestNum: $bestBlockHeight; " +
"genesisHash: ${genesisHash.toHexString()}]"
}
Expand Down

0 comments on commit 0e77e2b

Please sign in to comment.