Skip to content

Commit

Permalink
Script, ScriptBuilder: clarify concept of creation time in the JavaDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
schildbach committed Nov 5, 2024
1 parent d606d7f commit 97b8acc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
24 changes: 15 additions & 9 deletions core/src/main/java/org/bitcoinj/script/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,12 @@ public enum VerifyFlag {
// must preserve the exact bytes that we read off the wire, along with the parsed form.
@Nullable private final byte[] program;

// Creation time of the associated keys, or null if unknown.
@Nullable private final Instant creationTime;
/**
* If this is set, the script is associated with a creation time. This is currently used in the context of
* watching wallets only, where the scriptPubKeys being watched actually represent public keys and their addresses.
*/
@Nullable
private final Instant creationTime;

/**
* Wraps given script chunks.
Expand All @@ -243,7 +247,7 @@ public static Script of(List<ScriptChunk> chunks) {
* Wraps given script chunks.
*
* @param chunks chunks to wrap
* @param creationTime creation time of the script
* @param creationTime creation time to associate the script with
* @return script that wraps the chunks
*/
public static Script of(List<ScriptChunk> chunks, Instant creationTime) {
Expand All @@ -263,12 +267,11 @@ public static Script parse(byte[] program) throws ScriptException {
}

/**
* Construct a script that copies and wraps a given program, and a creation time. The array is parsed and checked
* for syntactic validity. Programs like this are e.g. used in {@link TransactionInput} and
* {@link TransactionOutput}.
* 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}.
*
* @param program Array of program bytes from a transaction.
* @param creationTime creation time of the script
* @param creationTime creation time to associate the script with
* @return parsed program
* @throws ScriptException if the program could not be parsed
*/
Expand Down Expand Up @@ -410,8 +413,11 @@ public List<ScriptChunk> getChunks() {
}

/**
* Gets the creation time of this script, or empty if unknown.
* @return creation time of this script, or empty if unknown
* Gets the associated creation time of this script, or empty if undefined. This is currently used in the context of
* watching wallets only, where the scriptPubKeys being watched actually represent public keys and their
* addresses.
*
* @return associated creation time of this script, or empty if undefined
*/
public Optional<Instant> creationTime() {
return Optional.ofNullable(creationTime);
Expand Down
13 changes: 11 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,6 +61,12 @@
*/
public class ScriptBuilder {
private final List<ScriptChunk> chunks;
/**
* If this is set, the script to be built is associated with a creation time. This is currently used in the
* context of watching wallets only, where the scriptPubKeys being watched actually represent public keys and
* their addresses.
*/
@Nullable
private Instant creationTime = TimeUtils.currentTime();

/** Creates a fresh ScriptBuilder with an empty program. */
Expand All @@ -74,9 +80,12 @@ public ScriptBuilder(Script template) {
}

/**
* Sets the creation time to build the script with. If this is not set, the current time is used by the builder.
* Associates this script to be built with a given creation time. This is currently used in the context of
* watching wallets only, where the scriptPubKeys being watched actually represent public keys and their addresses.
* <p>
* If this is not set, the current time is used by the builder.
*
* @param creationTime creation time to build the script with
* @param creationTime creation time to associate the script with
* @return this builder
*/
public ScriptBuilder creationTime(Instant creationTime) {
Expand Down

0 comments on commit 97b8acc

Please sign in to comment.