ForwardingService, PrivateKeys: also parse segwit addresses from arguments

This commit is contained in:
Andreas Schildbach 2022-05-01 00:12:22 +02:00
parent eb71e0b0c6
commit 837b614906
2 changed files with 4 additions and 4 deletions

View File

@ -74,7 +74,7 @@ public class ForwardingService {
filePrefix = "forwarding-service";
}
// Parse the address given as the first parameter.
forwardingAddress = LegacyAddress.fromBase58(params, args[0]);
forwardingAddress = Address.fromString(params, args[0]);
System.out.println("Network: " + params.getId());
System.out.println("Forwarding address: " + forwardingAddress);

View File

@ -22,10 +22,10 @@ import org.bitcoinj.core.Base58;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.PeerAddress;
import org.bitcoinj.core.PeerGroup;
import org.bitcoinj.core.SegwitAddress;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.script.Script;
import org.bitcoinj.store.MemoryBlockStore;
@ -59,9 +59,9 @@ public class PrivateKeys {
BigInteger privKey = Base58.decodeToBigInteger(args[0]);
key = ECKey.fromPrivate(privKey);
}
System.out.println("Address from private key is: " + LegacyAddress.fromKey(params, key).toString());
System.out.println("Address from private key is: " + SegwitAddress.fromKey(params, key).toString());
// And the address ...
Address destination = LegacyAddress.fromBase58(params, args[1]);
Address destination = Address.fromString(params, args[1]);
// Import the private key to a fresh wallet.
Wallet wallet = Wallet.createDeterministic(params, Script.ScriptType.P2PKH);