mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
Script.ScriptType: Remove the NO_TYPE value and use null instead.
This commit is contained in:
parent
d231bade1f
commit
8e395e2b31
@ -24,6 +24,8 @@ import org.bitcoinj.params.Networks;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.Script.ScriptType;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Implementation of native segwit addresses. They are composed of two parts:
|
||||
@ -139,15 +141,13 @@ public class SegwitAddress extends Address {
|
||||
@Override
|
||||
public ScriptType getOutputScriptType() {
|
||||
int version = getWitnessVersion();
|
||||
if (version != 0)
|
||||
return ScriptType.NO_TYPE;
|
||||
checkState(version == 0);
|
||||
int programLength = getWitnessProgram().length;
|
||||
if (programLength == WITNESS_PROGRAM_LENGTH_PKH)
|
||||
return ScriptType.P2WPKH;
|
||||
else if (programLength == WITNESS_PROGRAM_LENGTH_SH)
|
||||
if (programLength == WITNESS_PROGRAM_LENGTH_SH)
|
||||
return ScriptType.P2WSH;
|
||||
else
|
||||
return ScriptType.NO_TYPE;
|
||||
throw new IllegalStateException("Cannot happen.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,6 @@ public class Script {
|
||||
|
||||
/** Enumeration to encapsulate the type of this script. */
|
||||
public enum ScriptType {
|
||||
NO_TYPE(0),
|
||||
P2PKH(1), // pay to pubkey hash (aka pay to address)
|
||||
P2PK(2), // pay to pubkey
|
||||
P2SH(3), // pay to script hash
|
||||
@ -1606,18 +1605,16 @@ public class Script {
|
||||
|
||||
/**
|
||||
* Get the {@link org.bitcoinj.script.Script.ScriptType}.
|
||||
* @return The script type.
|
||||
* @return The script type, or null if the script is of unknown type
|
||||
*/
|
||||
public ScriptType getScriptType() {
|
||||
ScriptType type = ScriptType.NO_TYPE;
|
||||
if (ScriptPattern.isPayToPubKeyHash(this)) {
|
||||
type = ScriptType.P2PKH;
|
||||
} else if (ScriptPattern.isPayToPubKey(this)) {
|
||||
type = ScriptType.P2PK;
|
||||
} else if (ScriptPattern.isPayToScriptHash(this)) {
|
||||
type = ScriptType.P2SH;
|
||||
}
|
||||
return type;
|
||||
public @Nullable ScriptType getScriptType() {
|
||||
if (ScriptPattern.isPayToPubKeyHash(this))
|
||||
return ScriptType.P2PKH;
|
||||
if (ScriptPattern.isPayToPubKey(this))
|
||||
return ScriptType.P2PK;
|
||||
if (ScriptPattern.isPayToScriptHash(this))
|
||||
return ScriptType.P2SH;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ package org.bitcoinj.store;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -959,7 +960,8 @@ public abstract class DatabaseFullPrunedBlockStore implements FullPrunedBlockSto
|
||||
s.setLong(4, out.getValue().value);
|
||||
s.setBytes(5, out.getScript().getProgram());
|
||||
s.setString(6, out.getAddress());
|
||||
s.setInt(7, out.getScript().getScriptType().id);
|
||||
ScriptType scriptType = out.getScript().getScriptType();
|
||||
s.setInt(7, scriptType != null ? scriptType.id : 0);
|
||||
s.setBoolean(8, out.isCoinbase());
|
||||
s.executeUpdate();
|
||||
s.close();
|
||||
|
Loading…
Reference in New Issue
Block a user