@@ -116,7 +116,7 @@ public object Bitcoin {
116
116
Script .isPay2pkh(pubkeyScript) -> {
117
117
val prefix = when (chainHash) {
118
118
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
120
120
else -> return Either .Left (BitcoinError .InvalidChainHash )
121
121
}
122
122
Either .Right (Base58Check .encode(prefix, (pubkeyScript[2 ] as OP_PUSHDATA ).data))
@@ -125,7 +125,7 @@ public object Bitcoin {
125
125
Script .isPay2sh(pubkeyScript) -> {
126
126
val prefix = when (chainHash) {
127
127
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
129
129
else -> return Either .Left (BitcoinError .InvalidChainHash )
130
130
}
131
131
Either .Right (Base58Check .encode(prefix, (pubkeyScript[1 ] as OP_PUSHDATA ).data))
@@ -204,13 +204,13 @@ public object Bitcoin {
204
204
return runCatching { Base58Check .decode(address) }.fold(
205
205
onSuccess = {
206
206
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) ->
208
208
Either .Right (Script .pay2pkh(it.second))
209
209
210
210
it.first == Base58 .Prefix .PubkeyAddress && chainHash == Block .LivenetGenesisBlock .hash ->
211
211
Either .Right (Script .pay2pkh(it.second))
212
212
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) ->
214
214
Either .Right (listOf (OP_HASH160 , OP_PUSHDATA (it.second), OP_EQUAL ))
215
215
216
216
it.first == Base58 .Prefix .ScriptAddress && chainHash == Block .LivenetGenesisBlock .hash ->
@@ -227,7 +227,8 @@ public object Bitcoin {
227
227
witnessVersion == null -> Either .Left (BitcoinError .InvalidWitnessVersion (it.second.toInt()))
228
228
it.third.size != 20 && it.third.size != 32 -> Either .Left (BitcoinError .InvalidBech32Address )
229
229
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)))
231
232
it.first == " tb" && chainHash == Block .SignetGenesisBlock .hash -> Either .Right (listOf (witnessVersion, OP_PUSHDATA (it.third)))
232
233
it.first == " bcrt" && chainHash == Block .RegtestGenesisBlock .hash -> Either .Right (listOf (witnessVersion, OP_PUSHDATA (it.third)))
233
234
else -> Either .Left (BitcoinError .ChainHashMismatch )
@@ -244,12 +245,14 @@ public object Bitcoin {
244
245
245
246
public sealed class Chain (public val name : String , private val genesis : Block ) {
246
247
public object Regtest : Chain(" Regtest" , Block .RegtestGenesisBlock )
247
- public object Testnet : Chain(" Testnet" , Block .TestnetGenesisBlock )
248
+ public object Testnet : Chain(" Testnet" , Block .Testnet3GenesisBlock )
249
+ public object Testnet4 : Chain(" Testnet4" , Block .Testnet4GenesisBlock )
248
250
public object Signet : Chain(" Signet" , Block .SignetGenesisBlock )
249
251
public object Mainnet : Chain(" Mainnet" , Block .LivenetGenesisBlock )
250
252
251
253
public fun isMainnet (): Boolean = this is Mainnet
252
- public fun isTestnet (): Boolean = this is Testnet
254
+ public fun isTestnet (): Boolean = this is Testnet || this is Testnet4
255
+ public fun isTestnet4 (): Boolean = this is Testnet4
253
256
254
257
public val chainHash: BlockHash get() = genesis.hash
255
258
0 commit comments