Consistently use standard acronyms: P2PKH, P2PK, P2SH

This commit is contained in:
Andreas Schildbach 2018-03-05 16:07:57 +01:00
parent 4722b48628
commit b9a31104af
14 changed files with 28 additions and 28 deletions

View File

@ -47,11 +47,11 @@ import static java.lang.Math.*;
*/
public class BloomFilter extends Message {
/** The BLOOM_UPDATE_* constants control when the bloom filter is auto-updated by the peer using
it as a filter, either never, for all outputs or only for pay-2-pubkey outputs (default) */
it as a filter, either never, for all outputs or only for P2PK outputs (default) */
public enum BloomUpdate {
UPDATE_NONE, // 0
UPDATE_ALL, // 1
/** Only adds outpoints to the filter if the output is a pay-to-pubkey/pay-to-multisig script */
/** Only adds outpoints to the filter if the output is a P2PK/pay-to-multisig script */
UPDATE_P2PUBKEY_ONLY //2
}
@ -74,7 +74,7 @@ public class BloomFilter extends Message {
}
/**
* Constructs a filter with the given parameters which is updated on pay2pubkey outputs only.
* Constructs a filter with the given parameters which is updated on P2PK outputs only.
*/
public BloomFilter(int elements, double falsePositiveRate, long randomNonce) {
this(elements, falsePositiveRate, randomNonce, BloomUpdate.UPDATE_P2PUBKEY_ONLY);

View File

@ -394,7 +394,7 @@ public abstract class NetworkParameters {
public abstract Coin getMaxMoney();
/**
* Any standard (ie pay-to-address) output smaller than this value will
* Any standard (ie P2PKH) output smaller than this value will
* most likely be rejected by the network.
*/
public abstract Coin getMinNonDustOutput();

View File

@ -178,11 +178,11 @@ public class PeerGroup implements TransactionBroadcaster {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
// We received a relevant transaction. We MAY need to recalculate and resend the Bloom filter, but only
// if we have received a transaction that includes a relevant pay-to-pubkey output.
// if we have received a transaction that includes a relevant P2PK output.
//
// The reason is that pay-to-pubkey outputs, when spent, will not repeat any data we can predict in their
// The reason is that P2PK outputs, when spent, will not repeat any data we can predict in their
// inputs. So a remote peer will update the Bloom filter for us when such an output is seen matching the
// existing filter, so that it includes the tx hash in which the pay-to-pubkey output was observed. Thus
// existing filter, so that it includes the tx hash in which the P2PK output was observed. Thus
// the spending transaction will always match (due to the outpoint structure).
//
// Unfortunately, whilst this is required for correct sync of the chain in blocks, there are two edge cases.

View File

@ -115,7 +115,7 @@ public class Transaction extends ChildMessage {
public static final Coin DEFAULT_TX_FEE = Coin.valueOf(100000); // 1 mBTC
/**
* Any standard (ie pay-to-address) output smaller than this value (in satoshis) will most likely be rejected by the network.
* Any standard (ie P2PKH) output smaller than this value (in satoshis) will most likely be rejected by the network.
* This is calculated by assuming a standard output will be 34 bytes, and then using the formula used in
* {@link TransactionOutput#getMinNonDustValue(Coin)}.
*/

View File

@ -129,7 +129,7 @@ public class TransactionOutPoint extends ChildMessage {
}
/**
* Returns the ECKey identified in the connected output, for either pay-to-address scripts or pay-to-key scripts.
* Returns the ECKey identified in the connected output, for either P2PKH scripts or P2PK scripts.
* For P2SH scripts you can use {@link #getConnectedRedeemData(org.bitcoinj.wallet.KeyBag)} and then get the
* key from RedeemData.
* If the script form cannot be understood, throws ScriptException.
@ -153,7 +153,7 @@ public class TransactionOutPoint extends ChildMessage {
}
/**
* Returns the RedeemData identified in the connected output, for either pay-to-address scripts, pay-to-key
* Returns the RedeemData identified in the connected output, for either P2PKH scripts, P2PK
* or P2SH scripts.
* If the script forms cannot be understood, throws ScriptException.
*

View File

@ -212,7 +212,7 @@ public class TransactionOutput extends ChildMessage {
public Coin getMinNonDustValue(Coin feePerKb) {
// A typical output is 33 bytes (pubkey hash + opcodes) and requires an input of 148 bytes to spend so we add
// that together to find out the total amount of data used to transfer this amount of value. Note that this
// formula is wrong for anything that's not a pay-to-address output, unfortunately, we must follow Bitcoin Core's
// formula is wrong for anything that's not a P2PKH output, unfortunately, we must follow Bitcoin Core's
// wrongness in order to ensure we're considered standard. A better formula would either estimate the
// size of data needed to satisfy all different script types, or just hard code 33 below.
final long size = this.unsafeBitcoinSerialize().length + 148;

View File

@ -299,7 +299,7 @@ public class Script {
else if (ScriptPattern.isPayToWitnessHash(this))
return SegwitAddress.fromHash(params, ScriptPattern.extractHashFromPayToWitnessHash(this));
else
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Cannot cast this script to a pay-to-address type");
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Cannot cast this script to an address");
}
////////////////////// Interface for writing scripts from scratch ////////////////////////////////
@ -378,7 +378,7 @@ public class Script {
*/
public Script createEmptyInputScript(@Nullable ECKey key, @Nullable Script redeemScript) {
if (ScriptPattern.isPayToPubKeyHash(this)) {
checkArgument(key != null, "Key required to create pay-to-address input script");
checkArgument(key != null, "Key required to create P2PKH input script");
return ScriptBuilder.createInputScript(null, key);
} else if (ScriptPattern.isPayToPubKey(this)) {
return ScriptBuilder.createInputScript(null);
@ -568,7 +568,7 @@ public class Script {
ScriptChunk nChunk = chunks.get(0);
return Script.decodeFromOpN(nChunk.opcode);
} else if (ScriptPattern.isPayToPubKeyHash(this) || ScriptPattern.isPayToPubKey(this)) {
// pay-to-address and pay-to-pubkey require single sig
// P2PKH and P2PK require single sig
return 1;
} else if (ScriptPattern.isPayToScriptHash(this)) {
throw new IllegalStateException("For P2SH number of signatures depends on redeem script");

View File

@ -288,7 +288,7 @@ public class ScriptBuilder {
}
/**
* Creates a scriptSig that can redeem a pay-to-address output.
* 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
*/
public static Script createInputScript(@Nullable TransactionSignature signature, ECKey pubKey) {
@ -298,7 +298,7 @@ public class ScriptBuilder {
}
/**
* Creates a scriptSig that can redeem a pay-to-pubkey output.
* Creates a scriptSig that can redeem a P2PK output.
* If given signature is null, incomplete scriptSig will be created with OP_0 instead of signature
*/
public static Script createInputScript(@Nullable TransactionSignature signature) {
@ -342,7 +342,7 @@ public class ScriptBuilder {
}
/**
* Create a program that satisfies a pay-to-script hashed OP_CHECKMULTISIG program.
* Create a program that satisfies a P2SH OP_CHECKMULTISIG program.
* If given signature list is null, incomplete scriptSig will be created with OP_0 instead of signatures
*/
public static Script createP2SHMultiSigInputScript(@Nullable List<TransactionSignature> signatures,

View File

@ -66,7 +66,7 @@ public class ScriptPattern {
/**
* <p>
* Whether or not this is a scriptPubKey representing a pay-to-script-hash output. In such outputs, the logic that
* Whether or not this is a scriptPubKey representing a P2SH output. In such outputs, the logic that
* controls reclamation is not actually in the output at all. Instead there's just a hash, and it's up to the
* spending input to provide a program matching that hash.
* </p>

View File

@ -91,7 +91,7 @@ public class LocalTransactionSigner extends StatelessTransactionSigner {
propTx.keyPaths.put(scriptPubKey, (((DeterministicKey) pubKey).getPath()));
ECKey key;
// locate private key in redeem data. For pay-to-address and pay-to-key inputs RedeemData will always contain
// locate private key in redeem data. For P2PKH and P2PK inputs RedeemData will always contain
// only one key (with private bytes). For P2SH inputs RedeemData will contain multiple keys, one of which MAY
// have private bytes
if ((key = redeemData.getFullKey()) == null) {
@ -100,7 +100,7 @@ public class LocalTransactionSigner extends StatelessTransactionSigner {
}
Script inputScript = txIn.getScriptSig();
// script here would be either a standard CHECKSIG program for pay-to-address or pay-to-pubkey inputs or
// script here would be either a standard CHECKSIG program for P2PKH or P2PK inputs or
// a CHECKMULTISIG program for P2SH inputs
byte[] script = redeemData.redeemScript.getProgram();
try {
@ -108,7 +108,7 @@ public class LocalTransactionSigner extends StatelessTransactionSigner {
// at this point we have incomplete inputScript with OP_0 in place of one or more signatures. We already
// have calculated the signature using the local key and now need to insert it in the correct place
// within inputScript. For pay-to-address and pay-to-key script there is only one signature and it always
// within inputScript. For P2PKH and P2PK script there is only one signature and it always
// goes first in an inputScript (sigIndex = 0). In P2SH input scripts we need to figure out our relative
// position relative to other signers. Since we don't have that information at this point, and since
// we always run first, we have to depend on the other signers rearranging the signatures as needed.

View File

@ -58,7 +58,7 @@ public class KeyTimeCoinSelector implements CoinSelector {
for (TransactionOutput output : candidates) {
if (ignorePending && !isConfirmed(output))
continue;
// Find the key that controls output, assuming it's a regular pay-to-pubkey or pay-to-address output.
// Find the key that controls output, assuming it's a regular P2PK or P2PKH output.
// We ignore any other kind of exotic output on the assumption we can't spend it ourselves.
final Script scriptPubKey = output.getScriptPubKey();
ECKey controllingKey;

View File

@ -29,7 +29,7 @@ import static com.google.common.base.Preconditions.checkArgument;
/**
* This class aggregates data required to spend transaction output.
*
* For pay-to-address and pay-to-pubkey transactions it will have only a single key and CHECKSIG program as redeemScript.
* For P2PKH and P2PK transactions it will have only a single key and CHECKSIG program as redeemScript.
* For multisignature transactions there will be multiple keys one of which will be a full key and the rest are watch only,
* redeem script will be a CHECKMULTISIG program. Keys will be sorted in the same order they appear in
* a program (lexicographical order).
@ -50,7 +50,7 @@ public class RedeemData {
}
/**
* Creates RedeemData for pay-to-address or pay-to-pubkey input. Provided key is a single private key needed
* Creates RedeemData for P2PKH or P2PK input. Provided key is a single private key needed
* to spend such inputs and provided program should be a proper CHECKSIG program.
*/
public static RedeemData of(ECKey key, Script program) {

View File

@ -83,7 +83,7 @@ public class BloomFilterTest {
Wallet wallet = new Wallet(MAINNET, group);
wallet.commitTx(new Transaction(MAINNET, HEX.decode("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0d038754030114062f503253482fffffffff01c05e559500000000232103cb219f69f1b49468bd563239a86667e74a06fcba69ac50a08a5cbc42a5808e99ac00000000")));
// We should have 2 per pubkey, and one for the pay-2-pubkey output we have
// We should have 2 per pubkey, and one for the P2PK output we have
assertEquals(5, wallet.getBloomFilterElementCount());
BloomFilter filter = wallet.getBloomFilter(wallet.getBloomFilterElementCount(), 0.001, 0);

View File

@ -172,20 +172,20 @@ public class ScriptTest {
TransactionSignature dummySig = TransactionSignature.dummy();
ECKey key = new ECKey();
// pay-to-pubkey
// P2PK
Script inputScript = ScriptBuilder.createInputScript(dummySig);
assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin()));
inputScript = ScriptBuilder.createInputScript(null);
assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0));
// pay-to-address
// P2PKH
inputScript = ScriptBuilder.createInputScript(dummySig, key);
assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin()));
inputScript = ScriptBuilder.createInputScript(null, key);
assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0));
assertThat(inputScript.getChunks().get(1).data, equalTo(key.getPubKey()));
// pay-to-script-hash
// P2SH
ECKey key2 = new ECKey();
Script multisigScript = ScriptBuilder.createMultiSigOutputScript(2, Arrays.asList(key, key2));
inputScript = ScriptBuilder.createP2SHMultiSigInputScript(Arrays.asList(dummySig, dummySig), multisigScript);