3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Take some Block setters out of the public API. The ability to create/solve blocks is intended only for unit testing in this library.

This commit is contained in:
Mike Hearn 2011-03-25 21:19:52 +00:00
parent bb017a5dab
commit af371677fd
4 changed files with 21 additions and 216 deletions

View File

@ -161,14 +161,6 @@ A block is the foundation of the BitCoin system. It records a set of <A HREF="..
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#addTransaction(com.google.bitcoin.core.Transaction)">addTransaction</A></B>(<A HREF="../../../../com/google/bitcoin/core/Transaction.html" title="class in com.google.bitcoin.core">Transaction</A>&nbsp;t)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Adds a transaction to this block.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../../../com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#cloneAsHeader()">cloneAsHeader</A></B>()</CODE>
@ -270,54 +262,6 @@ A block is the foundation of the BitCoin system. It records a set of <A HREF="..
<CODE>&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#hashCode()">hashCode</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#setDifficultyTarget(long)">setDifficultyTarget</A></B>(long&nbsp;compactForm)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#setMerkleRoot(byte[])">setMerkleRoot</A></B>(byte[]&nbsp;value)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#setNonce(long)">setNonce</A></B>(long&nbsp;nonce)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#setPrevBlockHash(byte[])">setPrevBlockHash</A></B>(byte[]&nbsp;prevBlockHash)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#setTime(long)">setTime</A></B>(long&nbsp;time)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/bitcoin/core/Block.html#setVersion(long)">setVersion</A></B>(long&nbsp;version)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
@ -550,30 +494,6 @@ public byte[] <B>getMerkleRoot</B>()</PRE>
</DL>
<HR>
<A NAME="setMerkleRoot(byte[])"><!-- --></A><H3>
setMerkleRoot</H3>
<PRE>
public void <B>setMerkleRoot</B>(byte[]&nbsp;value)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="addTransaction(com.google.bitcoin.core.Transaction)"><!-- --></A><H3>
addTransaction</H3>
<PRE>
public void <B>addTransaction</B>(<A HREF="../../../../com/google/bitcoin/core/Transaction.html" title="class in com.google.bitcoin.core">Transaction</A>&nbsp;t)</PRE>
<DL>
<DD>Adds a transaction to this block.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="getVersion()"><!-- --></A><H3>
getVersion</H3>
<PRE>
@ -587,17 +507,6 @@ public long <B>getVersion</B>()</PRE>
</DL>
<HR>
<A NAME="setVersion(long)"><!-- --></A><H3>
setVersion</H3>
<PRE>
public void <B>setVersion</B>(long&nbsp;version)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="getPrevBlockHash()"><!-- --></A><H3>
getPrevBlockHash</H3>
<PRE>
@ -611,17 +520,6 @@ public byte[] <B>getPrevBlockHash</B>()</PRE>
</DL>
<HR>
<A NAME="setPrevBlockHash(byte[])"><!-- --></A><H3>
setPrevBlockHash</H3>
<PRE>
public void <B>setPrevBlockHash</B>(byte[]&nbsp;prevBlockHash)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="getTime()"><!-- --></A><H3>
getTime</H3>
<PRE>
@ -635,17 +533,6 @@ public long <B>getTime</B>()</PRE>
</DL>
<HR>
<A NAME="setTime(long)"><!-- --></A><H3>
setTime</H3>
<PRE>
public void <B>setTime</B>(long&nbsp;time)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="getDifficultyTarget()"><!-- --></A><H3>
getDifficultyTarget</H3>
<PRE>
@ -661,17 +548,6 @@ public long <B>getDifficultyTarget</B>()</PRE>
</DL>
<HR>
<A NAME="setDifficultyTarget(long)"><!-- --></A><H3>
setDifficultyTarget</H3>
<PRE>
public void <B>setDifficultyTarget</B>(long&nbsp;compactForm)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="getNonce()"><!-- --></A><H3>
getNonce</H3>
<PRE>
@ -684,17 +560,6 @@ public long <B>getNonce</B>()</PRE>
</DL>
</DD>
</DL>
<HR>
<A NAME="setNonce(long)"><!-- --></A><H3>
setNonce</H3>
<PRE>
public void <B>setNonce</B>(long&nbsp;nonce)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>

View File

@ -108,10 +108,7 @@ Constructor for exception com.google.bitcoin.core.<A HREF="./com/google/bitcoin/
<DT><A HREF="./com/google/bitcoin/core/NetworkParameters.html#addressHeader"><B>addressHeader</B></A> -
Variable in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/NetworkParameters.html" title="class in com.google.bitcoin.core">NetworkParameters</A>
<DD>First byte of a base58 encoded address.
<DT><A HREF="./com/google/bitcoin/core/AddressMessage.html" title="class in com.google.bitcoin.core"><B>AddressMessage</B></A> - Class in <A HREF="./com/google/bitcoin/core/package-summary.html">com.google.bitcoin.core</A><DD>&nbsp;<DT><A HREF="./com/google/bitcoin/core/Block.html#addTransaction(com.google.bitcoin.core.Transaction)"><B>addTransaction(Transaction)</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A>
<DD>Adds a transaction to this block.
</DL>
<DT><A HREF="./com/google/bitcoin/core/AddressMessage.html" title="class in com.google.bitcoin.core"><B>AddressMessage</B></A> - Class in <A HREF="./com/google/bitcoin/core/package-summary.html">com.google.bitcoin.core</A><DD>&nbsp;</DL>
<HR>
<A NAME="_B_"><!-- --></A><H2>
<B>B</B></H2>
@ -639,27 +636,9 @@ Constructor for exception com.google.bitcoin.core.<A HREF="./com/google/bitcoin/
<DT><A HREF="./com/google/bitcoin/core/Wallet.html#sendCoins(com.google.bitcoin.core.Peer, com.google.bitcoin.core.Address, java.math.BigInteger)"><B>sendCoins(Peer, Address, BigInteger)</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Wallet.html" title="class in com.google.bitcoin.core">Wallet</A>
<DD>Sends coins to the given address, via the given <A HREF="./com/google/bitcoin/core/Peer.html" title="class in com.google.bitcoin.core"><CODE>Peer</CODE></A>.
<DT><A HREF="./com/google/bitcoin/core/Block.html#setDifficultyTarget(long)"><B>setDifficultyTarget(long)</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A>
<DD>&nbsp;
<DT><A HREF="./com/google/bitcoin/core/Block.html#setMerkleRoot(byte[])"><B>setMerkleRoot(byte[])</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A>
<DD>&nbsp;
<DT><A HREF="./com/google/bitcoin/core/Block.html#setNonce(long)"><B>setNonce(long)</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A>
<DD>&nbsp;
<DT><A HREF="./com/google/bitcoin/core/Block.html#setPrevBlockHash(byte[])"><B>setPrevBlockHash(byte[])</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A>
<DD>&nbsp;
<DT><A HREF="./com/google/bitcoin/core/Block.html#setTime(long)"><B>setTime(long)</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A>
<DD>&nbsp;
<DT><A HREF="./com/google/bitcoin/core/Script.html#setTracing(boolean)"><B>setTracing(boolean)</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Script.html" title="class in com.google.bitcoin.core">Script</A>
<DD>If true, running a program will log its instructions.
<DT><A HREF="./com/google/bitcoin/core/Block.html#setVersion(long)"><B>setVersion(long)</B></A> -
Method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A>
<DD>&nbsp;
<DT><A HREF="./com/google/bitcoin/core/Utils.html#sha256hash160(byte[])"><B>sha256hash160(byte[])</B></A> -
Static method in class com.google.bitcoin.core.<A HREF="./com/google/bitcoin/core/Utils.html" title="class in com.google.bitcoin.core">Utils</A>
<DD>Calculates RIPEMD160(SHA256(input)).

View File

@ -214,26 +214,6 @@ java.util.List&lt;E&gt; <B>transactions</B></PRE>
<DL>
</DL>
</DL>
<HR>
<H3>
hash</H3>
<PRE>
byte[] <B>hash</B></PRE>
<DL>
<DD>Stores the hash of the block. If null, getHash() will recalculate it.
<P>
<DL>
</DL>
</DL>
<HR>
<H3>
prevBlock</H3>
<PRE>
<A HREF="com/google/bitcoin/core/Block.html" title="class in com.google.bitcoin.core">Block</A> <B>prevBlock</B></PRE>
<DL>
<DL>
</DL>
</DL>
<P>
<A NAME="com.google.bitcoin.core.BlockStoreException"><!-- --></A>

View File

@ -51,15 +51,10 @@ public class Block extends Message {
/** If null, it means this object holds only the headers. */
List<Transaction> transactions;
/** Stores the hash of the block. If null, getHash() will recalculate it. */
transient private byte[] hash;
// If set, points towards the previous block in the chain. Note that a block may have multiple other blocks
// pointing back to it because despite being called a "chain", the block chain is in fact a tree. There can be
// splits which are resolved by selecting the head that has the largest total cumulative work when measured down
// to the genesis block.
Block prevBlock;
/** Special case constructor, used for the genesis node and unit tests. */
Block(NetworkParameters params) {
super(params);
@ -328,19 +323,17 @@ public class Block extends Message {
* @throws VerificationException
*/
public void verify() throws VerificationException {
// Now we need to prove that this block is OK. It might seem that we can just ignore
// most of these checks, given that the network is also verifying the blocks, but we
// cannot as it'd open us to a variety of obscure attacks.
// Prove that this block is OK. It might seem that we can just ignore most of these checks given that the
// network is also verifying the blocks, but we cannot as it'd open us to a variety of obscure attacks.
//
// Firstly we need to ensure this block does in fact represent real work done. If the
// difficulty is high enough, it's probably been done by the network.
// Firstly we need to ensure this block does in fact represent real work done. If the difficulty is high
// enough, it's probably been done by the network.
checkProofOfWork(true);
checkTimestamp();
// Now we need to check that the body of the block actually matches the headers. The
// network won't generate an invalid block, but if we didn't validate this then an
// untrusted man-in-the-middle could obtain the next valid block from the network and
// simply replace the transactions in it with their own fictional transactions that
// reference spent or non-existant inputs.
// Now we need to check that the body of the block actually matches the headers. The network won't generate
// an invalid block, but if we didn't validate this then an untrusted man-in-the-middle could obtain the next
// valid block from the network and simply replace the transactions in it with their own fictional
// transactions that reference spent or non-existant inputs.
if (transactions != null) {
assert transactions.size() > 0;
checkTransactions();
@ -367,15 +360,14 @@ public class Block extends Message {
return merkleRoot;
}
public void setMerkleRoot(byte[] value) {
/** Exists only for unit testing. */
void setMerkleRoot(byte[] value) {
merkleRoot = value;
hash = null;
}
/**
* Adds a transaction to this block.
*/
public void addTransaction(Transaction t) {
/** Adds a transaction to this block. */
void addTransaction(Transaction t) {
if (transactions == null) {
transactions = new ArrayList<Transaction>();
}
@ -385,38 +377,27 @@ public class Block extends Message {
hash = null;
}
/**
* Returns the version of the block data structure as defined by the BitCoin protocol.
*/
/** Returns the version of the block data structure as defined by the BitCoin protocol. */
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
this.hash = null;
}
/**
* Returns the hash of the previous block in the chain, as defined by the block header.
*/
/** Returns the hash of the previous block in the chain, as defined by the block header. */
public byte[] getPrevBlockHash() {
return prevBlockHash;
}
public void setPrevBlockHash(byte[] prevBlockHash) {
void setPrevBlockHash(byte[] prevBlockHash) {
this.prevBlockHash = prevBlockHash;
this.hash = null;
}
/**
* Returns the time at which the block was solved and broadcast, according to the clock of the solving node.
*/
/** Returns the time at which the block was solved and broadcast, according to the clock of the solving node. */
public long getTime() {
return time;
}
public void setTime(long time) {
void setTime(long time) {
this.time = time;
this.hash = null;
}
@ -430,7 +411,7 @@ public class Block extends Message {
return difficultyTarget;
}
public void setDifficultyTarget(long compactForm) {
void setDifficultyTarget(long compactForm) {
this.difficultyTarget = compactForm;
this.hash = null;
}
@ -443,7 +424,7 @@ public class Block extends Message {
return nonce;
}
public void setNonce(long nonce) {
void setNonce(long nonce) {
this.nonce = nonce;
this.hash = null;
}