From 38aabdfa24852e4412d5871e1179786ef239c060 Mon Sep 17 00:00:00 2001
From: Mike Hearn
+ * A Bitcoin address is derived from an elliptic curve public key and a set of network parameters. Not to be confused
+ * with a {@link PeerAddress} or {@link AddressMessage} which are about network (TCP) addresses.
+ * It has several possible representations:
+ * Base58 is a way to encode Bitcoin addresses as numbers and letters. Note that this is not the same base58 as used by
+ * Flickr, which you may see reference to around the internet.
+ * Satoshi says: why base-58 instead of standard base-64 encoding?
*
* A block is a group of transactions, and is one of the fundamental data structures of the Bitcoin system.
+ * It records a set of {@link Transaction}s together with some data that links it into a place in the global block
+ * chain, and proves that a difficult calculation was done over its contents. See
+ * the Bitcoin technical paper for
+ * more detail on blocks. Represents the "inv" P2P network message. An inv contains a list of hashes of either blocks or transactions. It's
+ * a bandwidth optimization - on receiving some data, a (fully validating) peer sends every connected peer an inv
+ * containing the hash of what it saw. It'll only transmit the full thing if a peer asks for it with a
+ * {@link GetDataMessage}.
+ * Tracks transactions that are being announced across the network. Typically one is created for you by a
+ * {@link PeerGroup} and then given to each Peer to update. The current purpose is to let Peers update the confidence
+ * (number of peers broadcasting). It helps address an attack scenario in which a malicious remote peer (or several)
+ * feeds you invalid transactions, eg, ones that spend coins which don't exist. If you don't see most of the peers
+ * announce the transaction within a reasonable time, it may be that the TX is not valid. Alternatively, an attacker
+ * may control your entire internet connection: in this scenario counting broadcasting peers does not help you. It is not at this time directly equivalent to the Satoshi clients memory pool, which tracks
+ * all transactions not currently included in the best chain - it's simply a cache. A Message is a data structure that can be serialized/deserialized using both the Bitcoin proprietary serialization
* format and built-in Java object serialization. Specific types of messages that are used both in the block chain,
- * and on the wire, are derived from this class.
- *
*
*
{@link Peer#getHandler()} is part of a Netty Pipeline with a Bitcoin serializer downstream of it. */ public class Peer { - public interface PeerLifecycleListener { + interface PeerLifecycleListener { /** Called when the peer is connected */ public void onPeerConnected(Peer peer); /** Called when the peer is disconnected */ @@ -45,7 +45,6 @@ public class Peer { } private static final Logger log = LoggerFactory.getLogger(Peer.class); - public static final int CONNECT_TIMEOUT_MSEC = 60000; private final NetworkParameters params; private final BlockChain blockChain; @@ -118,11 +117,11 @@ public class Peer { return eventListeners.remove(listener); } - public synchronized void addLifecycleListener(PeerLifecycleListener listener) { + synchronized void addLifecycleListener(PeerLifecycleListener listener) { lifecycleListeners.add(listener); } - public synchronized boolean removeLifecycleListener(PeerLifecycleListener listener) { + synchronized boolean removeLifecycleListener(PeerLifecycleListener listener) { return lifecycleListeners.remove(listener); } diff --git a/core/src/main/java/com/google/bitcoin/core/PeerAddress.java b/core/src/main/java/com/google/bitcoin/core/PeerAddress.java index 83e58c43..d44a52e8 100644 --- a/core/src/main/java/com/google/bitcoin/core/PeerAddress.java +++ b/core/src/main/java/com/google/bitcoin/core/PeerAddress.java @@ -28,7 +28,7 @@ import static com.google.bitcoin.core.Utils.uint64ToByteStreamLE; /** * A PeerAddress holds an IP address and port number representing the network location of - * a peer in the BitCoin P2P network. It exists primarily for serialization purposes. + * a peer in the Bitcoin P2P network. It exists primarily for serialization purposes. */ public class PeerAddress extends ChildMessage { private static final long serialVersionUID = 7501293709324197411L; diff --git a/core/src/main/java/com/google/bitcoin/core/Script.java b/core/src/main/java/com/google/bitcoin/core/Script.java index ab3d28a0..5c30a361 100644 --- a/core/src/main/java/com/google/bitcoin/core/Script.java +++ b/core/src/main/java/com/google/bitcoin/core/Script.java @@ -42,14 +42,16 @@ class ScriptChunk { } /** - * Bitcoin transactions don't specify what they do directly. Instead a - * small binary stack language is used to define programs that when evaluated return whether the transaction - * "accepts" or rejects the other transactions connected to it.
+ * Instructions for redeeming a payment. * - * BitcoinJ does not evaluate/run scripts. The reason is that doing so requires the connected transactions, ie, all + *
Bitcoin transactions don't specify what they do directly. Instead a + * small binary stack language is used to define programs that when evaluated return whether the transaction + * "accepts" or rejects the other transactions connected to it.
+ * + *bitcoinj does not evaluate/run scripts. The reason is that doing so requires the connected transactions, ie, all * transactions, and as a lightweight/SPV client we don't store them all. Instead tx validity is decided by miners * and we rely purely on the majority consensus to determine if the scripts are valid. This class therefore just lets - * you manipulate and parse them. + * you manipulate and parse them.
*/ public class Script { // Some constants used for decoding the scripts, copied from the reference client 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 25e5535f..230bd5ea 100644 --- a/core/src/main/java/com/google/bitcoin/core/Transaction.java +++ b/core/src/main/java/com/google/bitcoin/core/Transaction.java @@ -28,19 +28,18 @@ import java.util.*; import static com.google.bitcoin.core.Utils.*; /** - * A transaction represents the movement of coins from some addresses to some other addresses. It can also represent - * the minting of new coins. A Transaction object corresponds to the equivalent in the BitCoin C++ implementation.+ *
A transaction represents the movement of coins from some addresses to some other addresses. It can also represent + * the minting of new coins. A Transaction object corresponds to the equivalent in the Bitcoin C++ implementation.
* - * It implements TWO serialization protocols - the Bitcoin proprietary format which is identical to the C++ - * implementation and is used for reading/writing transactions to the wire and for hashing. It also implements Java - * serialization which is used for the wallet. This allows us to easily add extra fields used for our own accounting - * or UI purposes.- * - * All Bitcoin transactions are at risk of being reversed, though the risk is much less than with traditional payment + *
Transactions are the fundamental atoms of Bitcoin and have many powerful features. Read + * "Working with transactions" in the + * documentation to learn more about how to use this class.
+ * + *All Bitcoin transactions are at risk of being reversed, though the risk is much less than with traditional payment * systems. Transactions have confidence levels, which help you decide whether to trust a transaction or not. * Whether to trust a transaction is something that needs to be decided on a case by case basis - a rule that makes * sense for selling MP3s might not make sense for selling cars, or accepting payments from a family member. If you - * are building a wallet, how to present confidence to your users is something to consider carefully. + * are building a wallet, how to present confidence to your users is something to consider carefully.
*/ public class Transaction extends ChildMessage implements Serializable { private static final Logger log = LoggerFactory.getLogger(Transaction.class); diff --git a/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java b/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java index ee93fe7c..cb670673 100644 --- a/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java +++ b/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java @@ -161,10 +161,13 @@ public class TransactionConfidence implements Serializable { }; /** - * A confidence listener is informed when the level of confidence in a transaction is updated by something, like + *A confidence listener is informed when the level of {@link TransactionConfidence} is updated by something, like * for example a {@link Wallet}. You can add listeners to update your user interface or manage your order tracking - * system when confidence levels pass a certain threshold. Note that confidence can go down as well as up.. - * During listener execution, it's safe to remove the current listener but not others. + * system when confidence levels pass a certain threshold. Note that confidence can go down as well as up. + * For example, this can happen if somebody is doing a double-spend attack against you. Whilst it's unlikely, your + * code should be able to handle that in order to be correct.
+ * + *During listener execution, it's safe to remove the current listener but not others.
*/ public interface Listener { public void onConfidenceChanged(Transaction tx); diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index 81be8355..e55500fc 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -40,6 +40,9 @@ import static com.google.common.base.Preconditions.*; * it is able to create new transactions that spend the recorded transactions, and this is the fundamental operation * of the Bitcoin protocol. * + *To learn more about this class, read + * working with the wallet.
+ * *To fill up a Wallet with transactions, you need to use it in combination with a {@link BlockChain} and various * other objects, see the Getting started tutorial * on the website to learn more about how to set everything up.
@@ -51,9 +54,6 @@ import static com.google.common.base.Preconditions.*; * the wallet is changing very fast (eg due to a block chain sync). See * {@link Wallet#autosaveToFile(java.io.File, long, java.util.concurrent.TimeUnit, com.google.bitcoin.core.Wallet.AutosaveEventListener)} * for more information about this. - * - *Learn more about working with the wallet. - *
*/ public class Wallet implements Serializable { private static final Logger log = LoggerFactory.getLogger(Wallet.class); diff --git a/core/src/main/java/com/google/bitcoin/core/WalletEventListener.java b/core/src/main/java/com/google/bitcoin/core/WalletEventListener.java index 1e46421c..10a3baf1 100644 --- a/core/src/main/java/com/google/bitcoin/core/WalletEventListener.java +++ b/core/src/main/java/com/google/bitcoin/core/WalletEventListener.java @@ -92,17 +92,13 @@ public interface WalletEventListener { ** * To find if the transaction is dead, you can use tx.getConfidence().getConfidenceType() == - * TransactionConfidence.ConfidenceType.OVERRIDDEN_BY_DOUBLE_SPEND. If it is, you should notify the user + * TransactionConfidence.ConfidenceType.DEAD. If it is, you should notify the user * in some way so they know the thing they bought may not arrive/the thing they sold should not be dispatched. - * - * @param wallet - * @param tx */ void onTransactionConfidenceChanged(Wallet wallet, Transaction tx); /** * Called by the {@link Wallet#addKey(ECKey)} method on whatever the calling thread was. - * @param key */ void onKeyAdded(ECKey key); }