Skip to content

Commit

Permalink
Merge pull request #355 from horizontalsystems/release-v040
Browse files Browse the repository at this point in the history
Release version 0.4.0
  • Loading branch information
abdrasulov authored Jun 6, 2019
2 parents e80fdaa + 1db185d commit f54ed84
Show file tree
Hide file tree
Showing 152 changed files with 6,989 additions and 2,007 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "dashkit/cpp/dashj-bls/bls-signatures"]
path = dashkit/cpp/dashj-bls/bls-signatures
url = https://github.com/Chia-Network/bls-signatures
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
pickFirst("META-INF/atomicfu.kotlin_module")
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<application
android:name=".App"
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Expand Down
2 changes: 1 addition & 1 deletion bitcoincashkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "0.3.0"
versionName "0.4.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import io.horizontalsystems.bitcoincore.AbstractKit
import io.horizontalsystems.bitcoincore.BitcoinCore
import io.horizontalsystems.bitcoincore.BitcoinCoreBuilder
import io.horizontalsystems.bitcoincore.blocks.validators.LegacyDifficultyAdjustmentValidator
import io.horizontalsystems.bitcoincore.managers.BCoinApi
import io.horizontalsystems.bitcoincore.managers.BitcoinCashAddressSelector
import io.horizontalsystems.bitcoincore.managers.InsightApi
import io.horizontalsystems.bitcoincore.models.TransactionInfo
import io.horizontalsystems.bitcoincore.network.Network
import io.horizontalsystems.bitcoincore.storage.CoreDatabase
Expand All @@ -37,28 +37,28 @@ class BitcoinCashKit : AbstractKit {
bitcoinCore.listener = value
}

constructor(context: Context, words: List<String>, walletId: String, networkType: NetworkType = NetworkType.MainNet, peerSize: Int = 10, newWallet: Boolean = false, confirmationsThreshold: Int = 6) :
this(context, Mnemonic().toSeed(words), walletId, networkType, peerSize, newWallet, confirmationsThreshold)
constructor(context: Context, words: List<String>, walletId: String, networkType: NetworkType = NetworkType.MainNet, peerSize: Int = 10, syncMode: BitcoinCore.SyncMode = BitcoinCore.SyncMode.Api(), confirmationsThreshold: Int = 6) :
this(context, Mnemonic().toSeed(words), walletId, networkType, peerSize, syncMode, confirmationsThreshold)

constructor(context: Context, seed: ByteArray, walletId: String, networkType: NetworkType = NetworkType.MainNet, peerSize: Int = 10, newWallet: Boolean = false, confirmationsThreshold: Int = 6) {
constructor(context: Context, seed: ByteArray, walletId: String, networkType: NetworkType = NetworkType.MainNet, peerSize: Int = 10, syncMode: BitcoinCore.SyncMode = BitcoinCore.SyncMode.Api(), confirmationsThreshold: Int = 6) {
val database = CoreDatabase.getInstance(context, getDatabaseName(networkType, walletId))
val storage = Storage(database)
val initialSyncUrl: String

network = when (networkType) {
NetworkType.MainNet -> {
initialSyncUrl = "https://bch.horizontalsystems.xyz/apg"
initialSyncUrl = "https://blockdozer.com/api"
MainNetBitcoinCash()
}
NetworkType.TestNet -> {
initialSyncUrl = "http://bch-testnet.horizontalsystems.xyz/apg"
initialSyncUrl = "https://tbch.blockdozer.com/api"
TestNetBitcoinCash()
}
}

val paymentAddressParser = PaymentAddressParser("bitcoincash", removeScheme = false)
val addressSelector = BitcoinCashAddressSelector()
val initialSyncApi = BCoinApi(initialSyncUrl)
val initialSyncApi = InsightApi(initialSyncUrl)

bitcoinCore = BitcoinCoreBuilder()
.setContext(context)
Expand All @@ -67,7 +67,7 @@ class BitcoinCashKit : AbstractKit {
.setPaymentAddressParser(paymentAddressParser)
.setAddressSelector(addressSelector)
.setPeerSize(peerSize)
.setNewWallet(newWallet)
.setSyncMode(syncMode)
.setConfirmationThreshold(confirmationsThreshold)
.setStorage(storage)
.setInitialSyncApi(initialSyncApi)
Expand All @@ -83,7 +83,7 @@ class BitcoinCashKit : AbstractKit {

bitcoinCore.addBlockValidator(DAAValidator(targetSpacing, blockHelper))
bitcoinCore.addBlockValidator(LegacyDifficultyAdjustmentValidator(blockHelper, heightInterval, targetTimespan, maxTargetBits))
bitcoinCore.addBlockValidator(EDAValidator(maxTargetBits, blockHelper))
bitcoinCore.addBlockValidator(EDAValidator(maxTargetBits, blockHelper, network.bip44CheckpointBlock.height))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MainNetBitcoinCash : Network() {
override val sigHashForked = true
override val sigHashValue = Sighash.FORKID or Sighash.ALL

override var dnsSeeds: Array<String> = arrayOf(
override var dnsSeeds = listOf(
"seed.bitcoinabc.org", // Bitcoin ABC seeder
"seed-abc.bitcoinforks.org", // bitcoinforks seeders
"btccash-seeder.bitcoinunlimited.info", // BU backed seeder
Expand All @@ -32,15 +32,23 @@ class MainNetBitcoinCash : Network() {
"seeder.criptolayer.net" // criptolayer.net
)

private val blockHeader = BlockHeader(
version = 805289984,
previousBlockHeaderHash = HashUtils.toBytesAsLE("000000000000000000e1f8ea917f17c378fdfd8d13f23160c6cb522d406c37ab"),
merkleRoot = HashUtils.toBytesAsLE("923fb5f581b3dfe4bc6103891c63e5789abbaac7d8fcd2ba4b25ac2abccdba9c"),
timestamp = 1557394860,
bits = 402883015,
nonce = 3963128149,
hash = HashUtils.toBytesAsLE("0000000000000000030e41502adfbcb20fdca66b15cc9e157449585c6c85da6e")
)

override val checkpointBlock = Block(blockHeader, 581790)
override val bip44CheckpointBlock = Block(BlockHeader(
version = 2,
previousBlockHeaderHash = HashUtils.toBytesAsLE("00000000000000006bcf448b771c8f4db4e2ca653474e3b29504ec08422b3fba"),
merkleRoot = HashUtils.toBytesAsLE("4ea18e999a57fc55fb390558dbb88a7b9c55c71c7de4cec160c045802ee587d2"),
timestamp = 1397755646,
bits = 419470732,
nonce = 2160181286,
hash = HashUtils.toBytesAsLE("00000000000000003decdbb5f3811eab3148fbc29d3610528eb3b50d9ee5723f")
), 296352)

override val lastCheckpointBlock = Block(BlockHeader(
version = 0x2000e000,
previousBlockHeaderHash = HashUtils.toBytesAsLE("000000000000000002a1f5acfab47e5e1afcac9f50eb9b7c875e6c736d099763"),
merkleRoot = HashUtils.toBytesAsLE("e6a8e517f708d294f426895c255cfd0a443d7f55a768b04398eadde0c516027c"),
timestamp = 1559650598,
bits = 0x1803769a,
nonce = 0xed7bb8ff,
hash = HashUtils.toBytesAsLE("00000000000000000040f26002e04126dc84700d6f82c0785efab2293080fe68")
), 585504)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,32 @@ class TestNetBitcoinCash : Network() {
override val sigHashForked = true
override val sigHashValue = Sighash.FORKID or Sighash.ALL

override var dnsSeeds: Array<String> = arrayOf(
override var dnsSeeds = listOf(
"testnet-seed.bitcoinabc.org", // Bitcoin ABC seeder
"testnet-seed-abc.bitcoinforks.org", // bitcoinforks seeders
"testnet-seed.bitprim.org", // Bitprim
"testnet-seed.deadalnix.me", // Amaury SÉCHET
"testnet-seeder.criptolayer.net" // criptolayer.net
)

override val checkpointBlock = Block(BlockHeader(
version = 536870912,
previousBlockHeaderHash = HashUtils.toBytesAsLE("000000000dea8d3a526bc2d7b3a26588935992a1a412a6c5c449ffaa41b070b0"),
merkleRoot = HashUtils.toBytesAsLE("dfa42c8fc3d8bac6d6fb51007128092f41d590ace1b3522af7062b8a848ebde7"),
timestamp = 1551085591,
bits = 486604799,
nonce = 1684221831,
hash = HashUtils.toBytesAsLE("000000002d867bde415b82a4a276e802d1536c632d9138d599dba930cf45e2c3")
), 1287761)
override val bip44CheckpointBlock = Block(BlockHeader(
version = 2,
previousBlockHeaderHash = HashUtils.toBytesAsLE("0000000003dc49f7472f960eedb4fb2d1ccc8b0530ca6c75ed2bba9718b6f297"),
merkleRoot = HashUtils.toBytesAsLE("a60fdbc889976c573450e9f78f1c330e374968a54f294e427180da1e9a07806b"),
timestamp = 1393645018,
bits = 0x1c0180ab,
nonce = 634051227,
hash = HashUtils.toBytesAsLE("000000000000bbde3a83bd29bc5cacd73f039f345318e7a4088914342c9d259a")
), 199584)

override val lastCheckpointBlock = Block(BlockHeader(
version = 0x20000000,
previousBlockHeaderHash = HashUtils.toBytesAsLE("000000000000041abedc84c2ab85f72febbee655ed9d1dfdc9497126026e1bba"),
merkleRoot = HashUtils.toBytesAsLE("cccf617e3ab704923dd45399649e7a5be11aa71ce344b7099b580c9d85445948"),
timestamp = 1559627940,
bits = 0x1a065b0f,
nonce = 1911921100,
hash = HashUtils.toBytesAsLE("000000000000058417bfcbfaa5bd7c0449743d9a386331db58e4453bc77ae536")
), 1307081)

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import io.horizontalsystems.bitcoincore.crypto.CompactBits
import io.horizontalsystems.bitcoincore.models.Block

// Emergency Difficulty Adjustment
class EDAValidator(private val maxTargetBits: Long, private val blockValidatorHelper: BitcoinCashBlockValidatorHelper) : IBlockValidator {
class EDAValidator(private val maxTargetBits: Long, private val blockValidatorHelper: BitcoinCashBlockValidatorHelper, val firstCheckpointHeight: Int) : IBlockValidator {

override fun isBlockValidatable(block: Block, previousBlock: Block): Boolean {
return true
}

override fun validate(block: Block, previousBlock: Block) {
// we must trust first 6 blocks from checkpoint, because can't calculate it's bits
if (previousBlock.height < firstCheckpointHeight + 6) return

if (previousBlock.bits == maxTargetBits) {
if (block.bits != maxTargetBits) {
throw BlockValidatorException.NotEqualBits()
Expand All @@ -28,7 +31,8 @@ class EDAValidator(private val maxTargetBits: Long, private val blockValidatorHe

val mpt6blocks = blockValidatorHelper.medianTimePast(previousBlock) - blockValidatorHelper.medianTimePast(cursorBlock)
if (mpt6blocks >= 12 * 3600) {
val pow = CompactBits.decode(previousBlock.bits) shr 2
val decodedBits = CompactBits.decode(previousBlock.bits)
val pow = decodedBits + (decodedBits shr 2)
var powBits = CompactBits.encode(pow)
if (powBits > maxTargetBits)
powBits = maxTargetBits
Expand Down
3 changes: 2 additions & 1 deletion bitcoincore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "0.3.0"
versionName "0.4.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -40,6 +40,7 @@ dependencies {

// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.0'

// Room
implementation "android.arch.persistence.room:runtime:1.1.1"
Expand Down
7 changes: 5 additions & 2 deletions bitcoincore/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
<manifest package="io.horizontalsystems.bitcoincore"
xmlns:android="http://schemas.android.com/apk/res/android"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.horizontalsystems.bitcoincore">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.horizontalsystems.bitcoincore

import io.horizontalsystems.bitcoincore.models.BitcoinPaymentData
import io.horizontalsystems.bitcoincore.network.Network
import io.horizontalsystems.bitcoincore.transactions.scripts.ScriptType

abstract class AbstractKit {

Expand Down Expand Up @@ -37,8 +38,8 @@ abstract class AbstractKit {
bitcoinCore.send(address, value, senderPay, feeRate)
}

fun receiveAddress(): String {
return bitcoinCore.receiveAddress()
fun receiveAddress(type: Int = ScriptType.P2PKH): String {
return bitcoinCore.receiveAddress(type)
}

fun validateAddress(address: String) {
Expand Down
Loading

0 comments on commit f54ed84

Please sign in to comment.