Script, ScriptBuilder: clarify concept of creation time in the JavaDocs

This commit is contained in:
Andreas Schildbach 2024-10-18 00:19:40 +02:00
parent e0c20f2bb0
commit 24fb83c2fe
2 changed files with 26 additions and 11 deletions

View File

@ -225,8 +225,12 @@ public class Script {
// must preserve the exact bytes that we read off the wire, along with the parsed form. // must preserve the exact bytes that we read off the wire, along with the parsed form.
@Nullable private final byte[] program; @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. * Wraps given script chunks.
@ -242,7 +246,7 @@ public class Script {
* Wraps given script chunks. * Wraps given script chunks.
* *
* @param chunks chunks to wrap * @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 * @return script that wraps the chunks
*/ */
public static Script of(List<ScriptChunk> chunks, Instant creationTime) { public static Script of(List<ScriptChunk> chunks, Instant creationTime) {
@ -262,12 +266,11 @@ public class Script {
} }
/** /**
* Construct a script that copies and wraps a given program, and a creation time. The array is parsed and checked * Construct a script that copies and wraps a given program. The array is parsed and checked for syntactic
* for syntactic validity. Programs like this are e.g. used in {@link TransactionInput} and * validity. Programs like this are e.g. used in {@link TransactionInput} and {@link TransactionOutput}.
* {@link TransactionOutput}.
* *
* @param program Array of program bytes from a transaction. * @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 * @return parsed program
* @throws ScriptException if the program could not be parsed * @throws ScriptException if the program could not be parsed
*/ */
@ -394,8 +397,11 @@ public class Script {
} }
/** /**
* Gets the 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
* @return creation time of this script, or empty if unknown * 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() { public Optional<Instant> creationTime() {
return Optional.ofNullable(creationTime); return Optional.ofNullable(creationTime);

View File

@ -61,6 +61,12 @@ import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN;
*/ */
public class ScriptBuilder { public class ScriptBuilder {
private final List<ScriptChunk> chunks; 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(); private Instant creationTime = TimeUtils.currentTime();
/** Creates a fresh ScriptBuilder with an empty program. */ /** Creates a fresh ScriptBuilder with an empty program. */
@ -74,9 +80,12 @@ public class ScriptBuilder {
} }
/** /**
* 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 * @return this builder
*/ */
public ScriptBuilder creationTime(Instant creationTime) { public ScriptBuilder creationTime(Instant creationTime) {