Skip to content

Commit

Permalink
Prevent massive log output. Support 20 bytes scripts. Prevent 32 byte…
Browse files Browse the repository at this point in the history
…s scripts.
  • Loading branch information
bernardladenthin committed Mar 22, 2024
1 parent 0811c20 commit c51c0dc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ public AddressToCoin fromLine(String line, KeyUtility keyUtility) {
return null;
} else if (address.startsWith("bc1")) {
// bitcoin Bech32 (P2WSH or P2WPKH) or P2TR
// supported (20 bytes): https://privatekeys.pw/address/bitcoin/bc1qazcm763858nkj2dj986etajv6wquslv8uxwczt
SegwitAddress segwitAddress = SegwitAddress.fromBech32(keyUtility.networkParameters, address);
byte[] hash = segwitAddress.getHash();
ByteBuffer hash160 = keyUtility.byteBufferUtility.byteArrayToByteBuffer(hash);
if (hash160.limit() != PublicKeyBytes.HASH160_SIZE) {
// unsupported (32 bytes): https://privatekeys.pw/bitcoin/address/bc1qp762gmkychywl4elnuyuwph68hqw0uc2jkzu3ax48zfjkskslpsq8p66gf
return null;
}
return new AddressToCoin(hash160, amount);
} else if (address.startsWith("fc1")) {
// feathercoin Bech32 (P2WSH or P2WPKH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public void shutdownAndAwaitTermination_producersSetAndInitialized_shutdownCalle
// Attention: Change the duration.
Finder.AWAIT_DURATION_TERMINATE = AwaitTimeTests.AWAIT_DURATION;

// Attention: During the long duration, this test produce a lot of debug and warn output, prevent it by set the log details
new LogLevelChange().turnOff();

// arrange
CFinder cFinder = new CFinder();
final CProducerJava cProducerJava = new CProducerJava();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @formatter:off
/**
* Copyright 2024 Bernard Ladenthin [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// @formatter:on
package net.ladenthin.bitcoinaddressfinder;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;

public class LogLevelChange {
public void turnOff() {
final Logger logger = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
logger.setLevel(Level.OFF);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ public enum StaticP2SHAddress implements PublicAddress {
* https://privatekeys.pw/bitcoin/address/3MSvaVbVFFLML86rt5eqgA9SvW23upaXdY
*/
BitcoinAndLitecoinDeprecated("3MSvaVbVFFLML86rt5eqgA9SvW23upaXdY", "d8b83ad7bf8795b9ff61464fcf06f156c28e3e1f"),

// bitcoin Bech32 (P2WSH) (Pay to Witness Script Hash) with 20 bytes
/**
* P2TR (Pay-to-Taproot)
* https://bitcoin.stackexchange.com/questions/110995/how-can-i-find-samples-for-p2tr-transactions-on-mainnet
* https://privatekeys.pw/address/bitcoin/bc1qazcm763858nkj2dj986etajv6wquslv8uxwczt
*/
BitcoinP2TR("bc1p5d7rjq7g6rdk2yhzks9smlaqtedr4dekq08ge8ztwac72sfr9rusxg3297", "a37c3903c8d0db6512e2b40b0dffa05e5a3ab73603ce8c9c4b7771e5412328f9"),
//
/**
* P2SH (Pay to Witness Script Hash)
* https://privatekeys.pw/bitcoin/address/bc1qp762gmkychywl4elnuyuwph68hqw0uc2jkzu3ax48zfjkskslpsq8p66gf
*/
BitcoinP2WSH("bc1qp762gmkychywl4elnuyuwph68hqw0uc2jkzu3ax48zfjkskslpsq8p66gf", "0fb4a46ec4c5c8efd73f9f09c706fa3dc0e7f30a9585c8f4d538932b42d0f860"),
BitcoinP2WSH_20_BYTES("bc1qazcm763858nkj2dj986etajv6wquslv8uxwczt", "e8b1bf6a27a1e76929b229f595f64cd381c87d87"),
/**
* https://privatekeys.pw/dogecoin/address/A8c3xNz2mqsDLFwv5KL5fpH12QEwDaoTXo
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ public enum StaticUnsupportedAddress implements PublicAddress {
* https://privatekeys.pw/bitcoin-cash/address/d-414f1537e051163a5a558d5e9ee37439
*/
BitcoinP2MS("d-414f1537e051163a5a558d5e9ee37439"),

// Scripts with 32 bytes
/**
* bitcoin Bech32 (P2WSH) (Pay to Witness Script Hash) with 32 bytes
* https://privatekeys.pw/bitcoin/address/bc1qp762gmkychywl4elnuyuwph68hqw0uc2jkzu3ax48zfjkskslpsq8p66gf
* The hash of this script has 32 bytes: 0fb4a46ec4c5c8efd73f9f09c706fa3dc0e7f30a9585c8f4d538932b42d0f860
*/
BitcoinP2WSH_32_BYTES("bc1qp762gmkychywl4elnuyuwph68hqw0uc2jkzu3ax48zfjkskslpsq8p66gf"),
// P2TR
/**
* P2TR (Pay-to-Taproot) with 32 bytes
* https://bitcoin.stackexchange.com/questions/110995/how-can-i-find-samples-for-p2tr-transactions-on-mainnet
* The hash of this script has 32 bytes: a37c3903c8d0db6512e2b40b0dffa05e5a3ab73603ce8c9c4b7771e5412328f9
*/
BitcoinP2TR("bc1p5d7rjq7g6rdk2yhzks9smlaqtedr4dekq08ge8ztwac72sfr9rusxg3297"),

// feathercoin Bech32 (P2WSH or P2WPKH)
/**
Expand Down

0 comments on commit c51c0dc

Please sign in to comment.