mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-08-01 12:31:23 +00:00
ScriptBuilder: Rename createOutputScript(ECKey) to createP2PKOutputScript and add a byte[] variant.
This commit is contained in:
@@ -882,7 +882,7 @@ public class Block extends Message {
|
||||
coinbase.addInput(new TransactionInput(params, coinbase,
|
||||
inputBuilder.build().getProgram()));
|
||||
coinbase.addOutput(new TransactionOutput(params, coinbase, value,
|
||||
ScriptBuilder.createOutputScript(ECKey.fromPublicOnly(pubKeyTo)).getProgram()));
|
||||
ScriptBuilder.createP2PKOutputScript(ECKey.fromPublicOnly(pubKeyTo)).getProgram()));
|
||||
transactions.add(coinbase);
|
||||
coinbase.setParent(this);
|
||||
coinbase.length = coinbase.unsafeBitcoinSerialize().length;
|
||||
|
@@ -96,7 +96,7 @@ public class TransactionOutput extends ChildMessage {
|
||||
* {@link Transaction#addOutput(Coin, ECKey)} instead of creating an output directly.
|
||||
*/
|
||||
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, ECKey to) {
|
||||
this(params, parent, value, ScriptBuilder.createOutputScript(to).getProgram());
|
||||
this(params, parent, value, ScriptBuilder.createP2PKOutputScript(to).getProgram());
|
||||
}
|
||||
|
||||
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes) {
|
||||
|
@@ -275,11 +275,6 @@ public class ScriptBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a scriptPubKey that encodes payment to the given raw public key. */
|
||||
public static Script createOutputScript(ECKey key) {
|
||||
return new ScriptBuilder().data(key.getPubKey()).op(OP_CHECKSIG).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a scriptSig that can redeem a P2PKH output.
|
||||
* If given signature is null, incomplete scriptSig will be created with OP_0 instead of signature
|
||||
@@ -430,6 +425,16 @@ public class ScriptBuilder {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/** Creates a scriptPubKey that encodes payment to the given raw public key. */
|
||||
public static Script createP2PKOutputScript(byte[] pubKey) {
|
||||
return new ScriptBuilder().data(pubKey).op(OP_CHECKSIG).build();
|
||||
}
|
||||
|
||||
/** Creates a scriptPubKey that encodes payment to the given raw public key. */
|
||||
public static Script createP2PKOutputScript(ECKey pubKey) {
|
||||
return createP2PKOutputScript(pubKey.getPubKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a scriptPubKey that sends to the given public key hash.
|
||||
*/
|
||||
|
@@ -907,7 +907,7 @@ public class FullBlockTestGenerator {
|
||||
|
||||
// A valid block created exactly like b44 to make sure the creation itself works
|
||||
Block b44 = new Block(params, Block.BLOCK_VERSION_GENESIS);
|
||||
byte[] outScriptBytes = ScriptBuilder.createOutputScript(ECKey.fromPublicOnly(coinbaseOutKeyPubKey)).getProgram();
|
||||
byte[] outScriptBytes = ScriptBuilder.createP2PKOutputScript(ECKey.fromPublicOnly(coinbaseOutKeyPubKey)).getProgram();
|
||||
{
|
||||
b44.setDifficultyTarget(b43.block.getDifficultyTarget());
|
||||
b44.addCoinbaseTransaction(coinbaseOutKeyPubKey, ZERO, chainHeadHeight + 15);
|
||||
|
@@ -326,14 +326,14 @@ public class TransactionTest {
|
||||
ECKey key0 = ECKey.fromPrivate(
|
||||
HEX.decode("bbc27228ddcb9209d7fd6f36b02f7dfa6252af40bb2f1cbc7a557da8027ff866"));
|
||||
assertEquals("2103c9f4836b9a4f77fc0d81f7bcb01b7f1b35916864b9476c241ce9fc198bd25432ac",
|
||||
HEX.encode(ScriptBuilder.createOutputScript(key0).getProgram()));
|
||||
HEX.encode(ScriptBuilder.createP2PKOutputScript(key0).getProgram()));
|
||||
ECKey key1 = ECKey.fromPrivate(
|
||||
HEX.decode("619c335025c7f4012e556c2a58b2506e30b8511b53ade95ea316fd8c3286feb9"));
|
||||
assertEquals("025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357",
|
||||
key1.getPublicKeyAsHex());
|
||||
|
||||
TransactionSignature txSig0 = tx.calculateSignature(0, key0,
|
||||
ScriptBuilder.createOutputScript(key0).getProgram(),
|
||||
ScriptBuilder.createP2PKOutputScript(key0).getProgram(),
|
||||
Transaction.SigHash.ALL, false);
|
||||
assertEquals("30450221008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be022040529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed01",
|
||||
HEX.encode(txSig0.encodeToBitcoin()));
|
||||
|
@@ -32,7 +32,7 @@ public class UTXOTest {
|
||||
@Test
|
||||
public void testJavaSerialization() throws Exception {
|
||||
ECKey key = new ECKey();
|
||||
UTXO utxo = new UTXO(Sha256Hash.of(new byte[]{1,2,3}), 1, Coin.COIN, 10, true, ScriptBuilder.createOutputScript(key));
|
||||
UTXO utxo = new UTXO(Sha256Hash.of(new byte[]{1,2,3}), 1, Coin.COIN, 10, true, ScriptBuilder.createP2PKOutputScript(key));
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
new ObjectOutputStream(os).writeObject(utxo);
|
||||
UTXO utxoCopy = (UTXO) new ObjectInputStream(
|
||||
|
@@ -39,7 +39,7 @@ public class ScriptPatternTest {
|
||||
ScriptBuilder.createP2SHOutputScript(2, keys)
|
||||
));
|
||||
assertTrue(ScriptPattern.isPayToPubKey(
|
||||
ScriptBuilder.createOutputScript(keys.get(0))
|
||||
ScriptBuilder.createP2PKOutputScript(keys.get(0))
|
||||
));
|
||||
assertTrue(ScriptPattern.isPayToWitnessPubKeyHash(
|
||||
ScriptBuilder.createP2WPKHOutputScript(keys.get(0))
|
||||
|
@@ -93,7 +93,7 @@ public class ScriptTest {
|
||||
List<ECKey> pubkeys = new ArrayList<>(3);
|
||||
for (ECKey key : keys) pubkeys.add(ECKey.fromPublicOnly(key.getPubKeyPoint()));
|
||||
assertEquals(script.getPubKeys(), pubkeys);
|
||||
assertFalse(ScriptPattern.isSentToMultisig(ScriptBuilder.createOutputScript(new ECKey())));
|
||||
assertFalse(ScriptPattern.isSentToMultisig(ScriptBuilder.createP2PKOutputScript(new ECKey())));
|
||||
try {
|
||||
// Fail if we ask for more signatures than keys.
|
||||
Script.createMultiSigOutputScript(4, keys);
|
||||
@@ -440,7 +440,7 @@ public class ScriptTest {
|
||||
// pay to pubkey
|
||||
ECKey toKey = new ECKey();
|
||||
Address toAddress = LegacyAddress.fromKey(TESTNET, toKey);
|
||||
assertEquals(toAddress, ScriptBuilder.createOutputScript(toKey).getToAddress(TESTNET, true));
|
||||
assertEquals(toAddress, ScriptBuilder.createP2PKOutputScript(toKey).getToAddress(TESTNET, true));
|
||||
// pay to pubkey hash
|
||||
assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(TESTNET, true));
|
||||
// pay to script hash
|
||||
@@ -452,6 +452,6 @@ public class ScriptTest {
|
||||
|
||||
@Test(expected = ScriptException.class)
|
||||
public void getToAddressNoPubKey() throws Exception {
|
||||
ScriptBuilder.createOutputScript(new ECKey()).getToAddress(TESTNET, false);
|
||||
ScriptBuilder.createP2PKOutputScript(new ECKey()).getToAddress(TESTNET, false);
|
||||
}
|
||||
}
|
||||
|
@@ -210,8 +210,8 @@ public class DefaultRiskAnalysisTest {
|
||||
// A pay to address output
|
||||
tx.addOutput(Coin.CENT, ScriptBuilder.createP2PKHOutputScript(key1));
|
||||
// A pay to pubkey output
|
||||
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1));
|
||||
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1));
|
||||
tx.addOutput(Coin.CENT, ScriptBuilder.createP2PKOutputScript(key1));
|
||||
tx.addOutput(Coin.CENT, ScriptBuilder.createP2PKOutputScript(key1));
|
||||
// 1-of-2 multisig output.
|
||||
ImmutableList<ECKey> keys = ImmutableList.of(key1, new ECKey());
|
||||
tx.addOutput(Coin.CENT, ScriptBuilder.createMultiSigOutputScript(1, keys));
|
||||
|
Reference in New Issue
Block a user