diff --git a/core/src/main/java/com/google/bitcoin/core/Transaction.java b/core/src/main/java/com/google/bitcoin/core/Transaction.java index 2caf1af1..8813014c 100644 --- a/core/src/main/java/com/google/bitcoin/core/Transaction.java +++ b/core/src/main/java/com/google/bitcoin/core/Transaction.java @@ -636,6 +636,20 @@ public class Transaction extends ChildMessage implements Serializable { return s.toString(); } + /** + * Removes all the inputs from this transaction. + * Note that this also invalidates the length attribute + */ + public void clearInputs() { + unCache(); + for (TransactionInput input : inputs) { + input.setParent(null); + } + inputs.clear(); + // You wanted to reserialize, right? + this.length = this.bitcoinSerialize().length; + } + /** * Adds an input to this transaction that imports value from the given output. Note that this input is NOT * complete and after every input is added with addInput() and every output is added with addOutput(), @@ -656,6 +670,20 @@ public class Transaction extends ChildMessage implements Serializable { adjustLength(inputs.size(), input.length); } + /** + * Removes all the inputs from this transaction. + * Note that this also invalidates the length attribute + */ + public void clearOutputs() { + unCache(); + for (TransactionOutput output : outputs) { + output.setParent(null); + } + outputs.clear(); + // You wanted to reserialize, right? + this.length = this.bitcoinSerialize().length; + } + /** * Adds the given output to this transaction. The output must be completely initialized. */ @@ -964,16 +992,16 @@ public class Transaction extends ChildMessage implements Serializable { return version; } - /** Returns a modifiable list of all inputs. */ + /** Returns an unmodifiable view of all inputs. */ public List getInputs() { maybeParse(); - return inputs; + return Collections.unmodifiableList(inputs); } - /** Returns a modifiable list of all outputs. */ + /** Returns an unmodifiable view of all outputs. */ public List getOutputs() { maybeParse(); - return outputs; + return Collections.unmodifiableList(outputs); } /** @return the given transaction: same as getInputs().get(index). */