mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 02:09:29 +01:00
Script: migrate a native constructor that wraps chunks to of()
static constructor
This commit is contained in:
parent
28af827c0e
commit
2444fad85b
@ -229,6 +229,29 @@ public class Script {
|
||||
// Creation time of the associated keys, or null if unknown.
|
||||
@Nullable private Instant creationTime;
|
||||
|
||||
/**
|
||||
* Wraps given script chunks.
|
||||
*
|
||||
* @param chunks chunks to wrap
|
||||
* @return script that wraps the chunks
|
||||
*/
|
||||
public static Script of(List<ScriptChunk> chunks) {
|
||||
return of(chunks, TimeUtils.currentTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps given script chunks.
|
||||
*
|
||||
* @param chunks chunks to wrap
|
||||
* @param creationTime creation time of the script
|
||||
* @return script that wraps the chunks
|
||||
*/
|
||||
public static Script of(List<ScriptChunk> chunks, Instant creationTime) {
|
||||
chunks = Collections.unmodifiableList(new ArrayList<>(chunks)); // defensive copy
|
||||
Objects.requireNonNull(creationTime);
|
||||
return new Script(null, chunks, creationTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a script that copies and wraps a given program. The array is parsed and checked for syntactic
|
||||
* validity. Programs like this are e.g. used in {@link TransactionInput} and {@link TransactionOutput}.
|
||||
@ -310,12 +333,6 @@ public class Script {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
// Used from ScriptBuilder.
|
||||
Script(List<ScriptChunk> chunks, Instant creationTime) {
|
||||
this.chunks = Collections.unmodifiableList(new ArrayList<>(chunks));
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the creation time of this script, or empty if unknown.
|
||||
* @return creation time of this script, or empty if unknown
|
||||
|
@ -277,7 +277,7 @@ public class ScriptBuilder {
|
||||
|
||||
/** Creates a new immutable Script based on the state of the builder. */
|
||||
public Script build() {
|
||||
return new Script(chunks, creationTime);
|
||||
return Script.of(chunks, creationTime);
|
||||
}
|
||||
|
||||
/** Creates an empty script. */
|
||||
|
Loading…
Reference in New Issue
Block a user