Skip to content

Commit

Permalink
Simple fixes (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstone authored Aug 2, 2023
1 parent bc2c032 commit 86c20e9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
val currentOs = org.gradle.internal.os.OperatingSystem.current()

group = "fr.acinq.bitcoin"
version = "0.14.0-SNASPHOT"
version = "0.14.0-SNAPSHOT"

repositories {
google()
Expand Down
20 changes: 10 additions & 10 deletions src/commonMain/kotlin/fr/acinq/bitcoin/Bitcoin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public sealed class AddressToPublicKeyScriptResult {

public abstract val result: List<ScriptElt>?

public val isSuccess: Boolean = result != null
public fun isSuccess(): Boolean = result != null

public val isFailure: Boolean = !isSuccess
public fun isFailure(): Boolean = !isSuccess()

public data class Success(val script: List<ScriptElt>) : AddressToPublicKeyScriptResult() {
override val result: List<ScriptElt>? = script
override val result: List<ScriptElt> = script
}

public sealed class Failure : AddressToPublicKeyScriptResult() {
Expand All @@ -61,11 +61,11 @@ public sealed class AddressToPublicKeyScriptResult {

public sealed class AddressFromPublicKeyScriptResult {
public abstract val result: String?
public val isSuccess: Boolean = result != null
public val isFailure: Boolean = !isSuccess
public fun isSuccess(): Boolean = result != null
public fun isFailure(): Boolean = !isSuccess()

public data class Success(val address: String) : AddressFromPublicKeyScriptResult() {
override val result: String? = address
override val result: String = address
}

public sealed class Failure : AddressFromPublicKeyScriptResult() {
Expand Down Expand Up @@ -95,7 +95,7 @@ public object Bitcoin {
/**
* @param pub public key
* @param chainHash chain hash (i.e. hash of the genesic block of the chain we're on)
* @return the p2swh-of-p2pkh address for this key). It is a Base58 address that is compatible with most bitcoin wallets
* @return the p2swh-of-p2pkh address for this key. It is a Base58 address that is compatible with most bitcoin wallets
*/
@JvmStatic
public fun computeP2ShOfP2WpkhAddress(pub: PublicKey, chainHash: ByteVector32): String = pub.p2shOfP2wpkhAddress(chainHash)
Expand All @@ -105,9 +105,9 @@ public object Bitcoin {

/**
* @param pub public key
* @param chainHash chain hash (i.e. hash of the genesic block of the chain we're on)
* @param chainHash chain hash (i.e. hash of the genesis block of the chain we're on)
* @return the BIP84 address for this key (i.e. the p2wpkh address for this key). It is a Bech32 address that will be
* understood only by native sewgit wallets
* understood only by native segwit wallets
*/
@JvmStatic
public fun computeP2WpkhAddress(pub: PublicKey, chainHash: ByteVector32): String = pub.p2wpkhAddress(chainHash)
Expand All @@ -117,7 +117,7 @@ public object Bitcoin {

/**
* Compute an address from a public key script
* @param chainHash chain hash (i.e. hash of the genesic block of the chain we're on)
* @param chainHash chain hash (i.e. hash of the genesis block of the chain we're on)
* @param pubkeyScript public key script
*/
@JvmStatic
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/fr/acinq/bitcoin/ScriptElt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public data class OP_PUSHDATA(@JvmField val data: ByteVector, @JvmField val opCo
@JvmStatic
public fun isMinimal(data: ByteArray, code: Int): Boolean {
return when {
data.size == 0 -> code == OP_0.code
data.isEmpty() -> code == OP_0.code
data.size == 1 && data[0] >= 1 && data[0] <= 16 -> code == (OP_1.code).plus(data[0] - 1)
data.size == 1 && data[0] == 0x81.toByte() -> code == OP_1NEGATE.code
data.size <= 75 -> code == data.size
Expand Down
6 changes: 3 additions & 3 deletions src/commonTest/kotlin/fr/acinq/bitcoin/BitcoinTestsCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class BitcoinTestsCommon {
assertEquals(address(Script.pay2wpkh(pub), it).result, computeP2WpkhAddress(pub, it))
assertEquals(address(Script.pay2sh(Script.pay2wpkh(pub)), it).result, computeP2ShOfP2WpkhAddress(pub, it))
// all these chain hashes are invalid
assertTrue(address(Script.pay2pkh(pub), it.reversed()).isFailure)
assertTrue(address(Script.pay2wpkh(pub), it.reversed()).isFailure)
assertTrue(address(Script.pay2sh(Script.pay2wpkh(pub)), it.reversed()).isFailure)
assertTrue(address(Script.pay2pkh(pub), it.reversed()).isFailure())
assertTrue(address(Script.pay2wpkh(pub), it.reversed()).isFailure())
assertTrue(address(Script.pay2sh(Script.pay2wpkh(pub)), it.reversed()).isFailure())
}

listOf(
Expand Down

0 comments on commit 86c20e9

Please sign in to comment.