From dd541a019b1a1d9e15cde57e076691411918f44c Mon Sep 17 00:00:00 2001 From: magmahindenburg Date: Wed, 1 Feb 2017 14:30:49 +0900 Subject: [PATCH 1/3] Added method for replacing all transactions in a block --- .../main/java/org/bitcoinj/core/Block.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/core/src/main/java/org/bitcoinj/core/Block.java b/core/src/main/java/org/bitcoinj/core/Block.java index 7f3d4cf3e..2328fbea0 100644 --- a/core/src/main/java/org/bitcoinj/core/Block.java +++ b/core/src/main/java/org/bitcoinj/core/Block.java @@ -774,6 +774,32 @@ public class Block extends Message { hash = null; } + /** + * Replace the list of transactions in the block. This method is only useful when building thin + * blocks and using different compression techniques to make blocks smaller. This will not recalculate + * merkleRoot or block hash. + * @param txList + */ + public void replaceTransactionList(List txList) { + replaceTransactionList(txList, false); + } + + /** + * Replace the list of transactions in the block. This method is only useful when building thin + * blocks and using different compression techniques to make blocks smaller. If recalc is true + * then the merkleRoot and block hash will be recalculated. Default is false. + * @param txList + */ + public void replaceTransactionList(List txList, boolean recalc) { + transactions = txList; + if (recalc) { + // Force a recalculation next time the values are needed. + merkleRoot = null; + hash = null; + } + // Else, Do not recalculate the merkele root or the block hash + } + /** Returns the version of the block data structure as defined by the Bitcoin protocol. */ public long getVersion() { return version; From 924cd612cfaf67fa52ef8f5c8feec5baf9dec97b Mon Sep 17 00:00:00 2001 From: magmahindenburg Date: Wed, 1 Feb 2017 14:39:24 +0900 Subject: [PATCH 2/3] Improved javadoc comments --- core/src/main/java/org/bitcoinj/core/Block.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/Block.java b/core/src/main/java/org/bitcoinj/core/Block.java index 2328fbea0..f0ebf2a01 100644 --- a/core/src/main/java/org/bitcoinj/core/Block.java +++ b/core/src/main/java/org/bitcoinj/core/Block.java @@ -778,7 +778,7 @@ public class Block extends Message { * Replace the list of transactions in the block. This method is only useful when building thin * blocks and using different compression techniques to make blocks smaller. This will not recalculate * merkleRoot or block hash. - * @param txList + * @param txList New list of transactions. Can be null. */ public void replaceTransactionList(List txList) { replaceTransactionList(txList, false); @@ -788,7 +788,8 @@ public class Block extends Message { * Replace the list of transactions in the block. This method is only useful when building thin * blocks and using different compression techniques to make blocks smaller. If recalc is true * then the merkleRoot and block hash will be recalculated. Default is false. - * @param txList + * @param txList New list of transactions. Can be null. + * @param recalc Force a recalculation next time the values are needed */ public void replaceTransactionList(List txList, boolean recalc) { transactions = txList; @@ -797,7 +798,6 @@ public class Block extends Message { merkleRoot = null; hash = null; } - // Else, Do not recalculate the merkele root or the block hash } /** Returns the version of the block data structure as defined by the Bitcoin protocol. */ From 4bbcde75a49867b573d8a47fbb7e53f0e5b0e911 Mon Sep 17 00:00:00 2001 From: magmahindenburg Date: Wed, 1 Feb 2017 14:41:37 +0900 Subject: [PATCH 3/3] Made javadoc more clear --- core/src/main/java/org/bitcoinj/core/Block.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/bitcoinj/core/Block.java b/core/src/main/java/org/bitcoinj/core/Block.java index f0ebf2a01..99905c53d 100644 --- a/core/src/main/java/org/bitcoinj/core/Block.java +++ b/core/src/main/java/org/bitcoinj/core/Block.java @@ -789,7 +789,7 @@ public class Block extends Message { * blocks and using different compression techniques to make blocks smaller. If recalc is true * then the merkleRoot and block hash will be recalculated. Default is false. * @param txList New list of transactions. Can be null. - * @param recalc Force a recalculation next time the values are needed + * @param recalc Force a recalculation next time merkleRoot and block hash are needed */ public void replaceTransactionList(List txList, boolean recalc) { transactions = txList;