Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
schildbach committed Oct 17, 2024
1 parent aa04abc commit 85faeef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 6 additions & 8 deletions core/src/main/java/org/bitcoinj/script/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public enum VerifyFlag {
* @return script that wraps the chunks
*/
public static Script of(List<ScriptChunk> chunks) {
return of(chunks, TimeUtils.currentTime());
return of(chunks, null);
}

/**
Expand All @@ -259,7 +259,7 @@ public static Script of(List<ScriptChunk> chunks, Instant creationTime) {
* @throws ScriptException if the program could not be parsed
*/
public static Script parse(byte[] program) throws ScriptException {
return parse(program, TimeUtils.currentTime());
return parse(program, null);
}

/**
Expand Down Expand Up @@ -340,30 +340,28 @@ private static void parseIntoChunksPartial(byte[] program, List<ScriptChunk> chu
*/
@Deprecated
public Script(byte[] program) {
this(program, TimeUtils.currentTime());
this(program, null);
}

/**
* @deprecated Use {@link Script#parse(byte[], Instant)}
*/
@Deprecated
public Script(byte[] program, long creationTimeInSeconds) {
this(program, Instant.ofEpochSecond(creationTimeInSeconds));
this(program, creationTimeInSeconds != 0 ? Instant.ofEpochSecond(creationTimeInSeconds) : null);
}

// When constructing from a program, we store both program and chunks
private Script(byte[] program, Instant creationTime) {
private Script(byte[] program, @Nullable Instant creationTime) {
Objects.requireNonNull(program);
Objects.requireNonNull(creationTime);
this.program = Arrays.copyOf(program, program.length); // defensive copy;
this.chunks = parseIntoChunks(this.program);
this.creationTime = creationTime;
}

// When constructing from chunks, we store only chunks, and generate program when getter is called
private Script(List<ScriptChunk> chunks, Instant creationTime) {
private Script(List<ScriptChunk> chunks, @Nullable Instant creationTime) {
Objects.requireNonNull(chunks);
Objects.requireNonNull(creationTime);
this.program = null;
this.chunks = Collections.unmodifiableList(new ArrayList<>(chunks)); // defensive copy
this.creationTime = creationTime;
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/org/bitcoinj/script/ScriptBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
*/
public class ScriptBuilder {
private final List<ScriptChunk> chunks;
private Instant creationTime = TimeUtils.currentTime();
private Instant creationTime = null;

/** Creates a fresh ScriptBuilder with an empty program. */
public ScriptBuilder() {
Expand Down Expand Up @@ -277,7 +277,10 @@ public ScriptBuilder opFalse(int index) {

/** Creates a new immutable Script based on the state of the builder. */
public Script build() {
return Script.of(chunks, creationTime);
if (creationTime != null)
return Script.of(chunks, creationTime);
else
return Script.of(chunks);
}

/** Creates an empty script. */
Expand Down

0 comments on commit 85faeef

Please sign in to comment.