Skip to content

Commit

Permalink
Convenience ScriptBuilder.addChunk() method can add arbitrary script …
Browse files Browse the repository at this point in the history
…chunks.
  • Loading branch information
schildbach committed May 28, 2014
1 parent 8ff52f5 commit 8ca8075
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions core/src/main/java/com/google/bitcoin/script/ScriptBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ public ScriptBuilder() {
chunks = Lists.newLinkedList();
}

public ScriptBuilder addChunk(ScriptChunk chunk) {
chunks.add(chunk);
return this;
}

public ScriptBuilder op(int opcode) {
checkArgument(opcode > OP_PUSHDATA4);
chunks.add(new ScriptChunk(opcode, null));
return this;
return addChunk(new ScriptChunk(opcode, null));
}

public ScriptBuilder data(byte[] data) {
Expand All @@ -68,15 +72,13 @@ public ScriptBuilder data(byte[] data) {
} else {
throw new RuntimeException("Unimplemented");
}
chunks.add(new ScriptChunk(opcode, copy));
return this;
return addChunk(new ScriptChunk(opcode, copy));
}

public ScriptBuilder smallNum(int num) {
checkArgument(num >= 0, "Cannot encode negative numbers with smallNum");
checkArgument(num <= 16, "Cannot encode numbers larger than 16 with smallNum");
chunks.add(new ScriptChunk(Script.encodeToOpN(num), null));
return this;
return addChunk(new ScriptChunk(Script.encodeToOpN(num), null));
}

public Script build() {
Expand Down

0 comments on commit 8ca8075

Please sign in to comment.