@@ -116,7 +116,7 @@ public object Bitcoin {
116116 Script .isPay2pkh(pubkeyScript) -> {
117117 val prefix = when (chainHash) {
118118 Block .LivenetGenesisBlock .hash -> Base58 .Prefix .PubkeyAddress
119- Block .TestnetGenesisBlock .hash, Block .RegtestGenesisBlock .hash, Block .SignetGenesisBlock .hash -> Base58 .Prefix .PubkeyAddressTestnet
119+ Block .Testnet4GenesisBlock .hash, Block . Testnet3GenesisBlock .hash, Block .RegtestGenesisBlock .hash, Block .SignetGenesisBlock .hash -> Base58 .Prefix .PubkeyAddressTestnet
120120 else -> return Either .Left (BitcoinError .InvalidChainHash )
121121 }
122122 Either .Right (Base58Check .encode(prefix, (pubkeyScript[2 ] as OP_PUSHDATA ).data))
@@ -125,7 +125,7 @@ public object Bitcoin {
125125 Script .isPay2sh(pubkeyScript) -> {
126126 val prefix = when (chainHash) {
127127 Block .LivenetGenesisBlock .hash -> Base58 .Prefix .ScriptAddress
128- Block .TestnetGenesisBlock .hash, Block .RegtestGenesisBlock .hash, Block .SignetGenesisBlock .hash -> Base58 .Prefix .ScriptAddressTestnet
128+ Block .Testnet4GenesisBlock .hash, Block . Testnet3GenesisBlock .hash, Block .RegtestGenesisBlock .hash, Block .SignetGenesisBlock .hash -> Base58 .Prefix .ScriptAddressTestnet
129129 else -> return Either .Left (BitcoinError .InvalidChainHash )
130130 }
131131 Either .Right (Base58Check .encode(prefix, (pubkeyScript[1 ] as OP_PUSHDATA ).data))
@@ -204,13 +204,13 @@ public object Bitcoin {
204204 return runCatching { Base58Check .decode(address) }.fold(
205205 onSuccess = {
206206 when {
207- it.first == Base58 .Prefix .PubkeyAddressTestnet && (chainHash == Block .TestnetGenesisBlock .hash || chainHash == Block .RegtestGenesisBlock .hash || chainHash == Block .SignetGenesisBlock .hash) ->
207+ it.first == Base58 .Prefix .PubkeyAddressTestnet && (chainHash == Block .Testnet4GenesisBlock .hash || chainHash == Block . Testnet3GenesisBlock .hash || chainHash == Block .RegtestGenesisBlock .hash || chainHash == Block .SignetGenesisBlock .hash) ->
208208 Either .Right (Script .pay2pkh(it.second))
209209
210210 it.first == Base58 .Prefix .PubkeyAddress && chainHash == Block .LivenetGenesisBlock .hash ->
211211 Either .Right (Script .pay2pkh(it.second))
212212
213- it.first == Base58 .Prefix .ScriptAddressTestnet && (chainHash == Block .TestnetGenesisBlock .hash || chainHash == Block .RegtestGenesisBlock .hash || chainHash == Block .SignetGenesisBlock .hash) ->
213+ it.first == Base58 .Prefix .ScriptAddressTestnet && (chainHash == Block .Testnet4GenesisBlock .hash || chainHash == Block . Testnet3GenesisBlock .hash || chainHash == Block .RegtestGenesisBlock .hash || chainHash == Block .SignetGenesisBlock .hash) ->
214214 Either .Right (listOf (OP_HASH160 , OP_PUSHDATA (it.second), OP_EQUAL ))
215215
216216 it.first == Base58 .Prefix .ScriptAddress && chainHash == Block .LivenetGenesisBlock .hash ->
@@ -227,7 +227,8 @@ public object Bitcoin {
227227 witnessVersion == null -> Either .Left (BitcoinError .InvalidWitnessVersion (it.second.toInt()))
228228 it.third.size != 20 && it.third.size != 32 -> Either .Left (BitcoinError .InvalidBech32Address )
229229 it.first == " bc" && chainHash == Block .LivenetGenesisBlock .hash -> Either .Right (listOf (witnessVersion, OP_PUSHDATA (it.third)))
230- it.first == " tb" && chainHash == Block .TestnetGenesisBlock .hash -> Either .Right (listOf (witnessVersion, OP_PUSHDATA (it.third)))
230+ it.first == " tb" && chainHash == Block .Testnet4GenesisBlock .hash -> Either .Right (listOf (witnessVersion, OP_PUSHDATA (it.third)))
231+ it.first == " tb" && chainHash == Block .Testnet3GenesisBlock .hash -> Either .Right (listOf (witnessVersion, OP_PUSHDATA (it.third)))
231232 it.first == " tb" && chainHash == Block .SignetGenesisBlock .hash -> Either .Right (listOf (witnessVersion, OP_PUSHDATA (it.third)))
232233 it.first == " bcrt" && chainHash == Block .RegtestGenesisBlock .hash -> Either .Right (listOf (witnessVersion, OP_PUSHDATA (it.third)))
233234 else -> Either .Left (BitcoinError .ChainHashMismatch )
@@ -244,12 +245,14 @@ public object Bitcoin {
244245
245246public sealed class Chain (public val name : String , private val genesis : Block ) {
246247 public object Regtest : Chain(" Regtest" , Block .RegtestGenesisBlock )
247- public object Testnet : Chain(" Testnet" , Block .TestnetGenesisBlock )
248+ public object Testnet3 : Chain(" Testnet3" , Block .Testnet3GenesisBlock )
249+ public object Testnet4 : Chain(" Testnet4" , Block .Testnet4GenesisBlock )
248250 public object Signet : Chain(" Signet" , Block .SignetGenesisBlock )
249251 public object Mainnet : Chain(" Mainnet" , Block .LivenetGenesisBlock )
250252
251253 public fun isMainnet (): Boolean = this is Mainnet
252- public fun isTestnet (): Boolean = this is Testnet
254+ public fun isTestnet3 (): Boolean = this is Testnet3
255+ public fun isTestnet4 (): Boolean = this is Testnet4
253256
254257 public val chainHash: BlockHash get() = genesis.hash
255258
0 commit comments