Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private val logger = createLogger {}
private const val NOT_FOUND_ERROR_CODE = -5

@PluginSpec(name = "BitcoinFamily", key = "btc")
class BitcoinFamilyChain(
open class BitcoinFamilyChain(
override val key: String,
configuration: PluginConfig
) : HttpSecurityInheritingChain {
Expand Down Expand Up @@ -287,7 +287,7 @@ class BitcoinFamilyChain(
val witnessProgram = ByteArray(addressData.size - 2)
addressData.copyInto(witnessProgram, 0,2, addressData.size)
try {
segwitToBech32(config.addressPrefix,0, witnessProgram)
segwitToBech32(config.addressPrefix!!,0, witnessProgram)
} catch (exception: Exception) {
throw IllegalArgumentException("Can't extract the Bech32 address from the address data: ${addressData.toHex()}", exception)
}
Expand Down Expand Up @@ -387,12 +387,12 @@ class BitcoinFamilyChain(
checkNotNull(config.payoutAddress) {
"$name's payoutAddress ($key.payoutAddress) must be configured!"
}
if (config.payoutAddress.isEmpty() || config.payoutAddress == "INSERT PAYOUT ADDRESS") {
if (config.payoutAddress?.isEmpty() == true || config.payoutAddress == "INSERT PAYOUT ADDRESS") {
error(
"'${config.payoutAddress}' is not a valid value for the $name's payoutAddress configuration ($key.payoutAddress). Please set up a valid payout address"
)
}
payoutAddress = config.payoutAddress
payoutAddress = config.payoutAddress!!
}

private suspend fun validateAddress(address: String): ByteArray {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// VeriBlock Blockchain Project
// Copyright 2017-2018 VeriBlock, Inc
// Copyright 2018-2021 Xenios SEZC
// All rights reserved.
// https://www.veriblock.org
// Distributed under the MIT software license, see the accompanying
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.

package org.veriblock.alt.plugins.bitcoin

import org.veriblock.core.altchain.AltchainPoPEndorsement
import org.veriblock.core.contracts.BlockEvidence
import org.veriblock.core.crypto.*
import org.veriblock.core.utilities.SerializerUtility
import org.veriblock.core.utilities.extensions.flip
import org.veriblock.sdk.alt.plugin.PluginConfig
import org.veriblock.sdk.alt.plugin.PluginSpec
import java.nio.ByteBuffer

@PluginSpec(name = "PexaFamily", key = "phx")
class PexaFamilyChain(
override val key: String,
configuration: PluginConfig
) : BitcoinFamilyChain(key, configuration) {

private val crypto = Crypto()

override fun extractBlockEvidence(altchainPopEndorsement: AltchainPoPEndorsement): BlockEvidence {
val hash = crypto.SHA256D(altchainPopEndorsement.getHeader()).flip()
val previousHash = altchainPopEndorsement.getHeader().copyOfRange(4, 36).flip()
val contextBuffer = ByteBuffer.wrap(altchainPopEndorsement.getContextInfo())
val height = contextBuffer.getInt()
val previousKeystone = SerializerUtility.readSingleByteLenValue(contextBuffer, 8, 64).flip()
val secondPreviousKeystone = SerializerUtility.readSingleByteLenValue(contextBuffer, 8, 64).flip()

return BlockEvidence(height, hash, previousHash, previousKeystone, secondPreviousKeystone)
}
}